Skip to content

Commit

Permalink
Concatenate monitors; beautify rotor, enstrophy, and Cd monitors
Browse files Browse the repository at this point in the history
  • Loading branch information
EdoAlvarezR committed Mar 5, 2023
1 parent c2be536 commit a17dfe8
Showing 1 changed file with 94 additions and 31 deletions.
125 changes: 94 additions & 31 deletions src/FLOWUnsteady_monitors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ function generate_monitor_rotors( rotors::Array{vlm.Rotor, 1},
t_scale=1.0, # Time scaling factor
t_lbl="Simulation time (s)", # Time-axis label
# OUTPUT OPTIONS
out_figs=[],
out_figaxs=[],
save_path=nothing,
run_name="rotor",
figname="monitor_rotor",
disp_conv=true,
conv_suff="_convergence.csv",
save_init_plots=true,
figsize_factor=5/6,
nsteps_plot=1,
nsteps_savefig=10,
colors="rgbcmy"^100,
stls="o^*.px"^100, )
Expand All @@ -60,9 +64,12 @@ function generate_monitor_rotors( rotors::Array{vlm.Rotor, 1},
# Call figure
if disp_conv
formatpyplot()
fig = plt.figure(figname, figsize=(7*3,5*2))
fig = plt.figure(figname, figsize=[7*3, 5*2]*figsize_factor)
axs = fig.subplots(2, 3)
axs = [axs[1], axs[3], axs[5], axs[2], axs[4], axs[6]]

push!(out_figs, fig)
push!(out_figaxs, axs)
end

# Function for run_vpm! to call on each iteration
Expand All @@ -79,32 +86,42 @@ function generate_monitor_rotors( rotors::Array{vlm.Rotor, 1},
# Format subplots
if disp_conv
ax = axs[1]
ax.title.set_text("Circulation Distribution")
ax.set_title("Circulation distribution", color="gray")
ax.set_xlabel("Element index")
ax.set_ylabel(L"Circulation $\Gamma$ (m$^2$/s)")
ax.grid(true, color="0.8", linestyle="--")

ax = axs[2]
ax.title.set_text("Plane-of-rotation Normal Force")
ax.set_title("Normal force distribution", color="gray")
ax.set_xlabel("Element index")
ax.set_ylabel(L"Normal Force $N_p$ (N/m)")
ax.grid(true, color="0.8", linestyle="--")
ax.set_ylabel(L"Normal load $N_p$ (N/m)")

ax = axs[3]
ax.title.set_text("Plane-of-rotation Tangential Force")
ax.set_title("Tangential force distribution", color="gray")
ax.set_xlabel("Element index")
ax.set_ylabel(L"Tangential Force $T_p$ (N/m)")
ax.grid(true, color="0.8", linestyle="--")
ax.set_ylabel(L"Tangential load $T_p$ (N/m)")

ax = axs[4]
ax.set_title(L"$C_T = \frac{T}{\rho n^2 d^4}$", color="gray")
ax.set_xlabel(t_lbl)
ax.set_ylabel(L"Thrust $C_T$")
ax.grid(true, color="0.8", linestyle="--")

ax = axs[5]
ax.set_title(L"$C_Q = \frac{Q}{\rho n^2 d^5}$", color="gray")
ax.set_xlabel(t_lbl)
ax.set_ylabel(L"Torque $C_Q$")
ax.grid(true, color="0.8", linestyle="--")

ax = axs[6]
ax.set_title(L"$\eta = \frac{T u_\infty}{2\pi n Q}$", color="gray")
ax.set_xlabel(t_lbl)
ax.set_ylabel(L"Propulsive efficiency $\eta$")
ax.grid(true, color="0.8", linestyle="--")


for ax in axs
ax.spines["right"].set_visible(false)
ax.spines["top"].set_visible(false)
# ax.grid(true, color="0.8", linestyle="--")
end

fig.tight_layout()
end

Expand Down Expand Up @@ -137,7 +154,7 @@ function generate_monitor_rotors( rotors::Array{vlm.Rotor, 1},


# Plot circulation and loads distributions
if disp_conv
if PFIELD.nt%nsteps_plot==0 && disp_conv

cratio = PFIELD.nt/nsteps_sim
cratio = cratio > 1 ? 1 : cratio
Expand Down Expand Up @@ -168,11 +185,11 @@ function generate_monitor_rotors( rotors::Array{vlm.Rotor, 1},
end

# Plot performance parameters
for (i,rotor) in enumerate(rotors)
for (i, rotor) in enumerate(rotors)
CT, CQ = vlm.calc_thrust_torque_coeffs(rotor, rho_ref)
eta = J_ref*CT/(2*pi*CQ)

if disp_conv
if PFIELD.nt%nsteps_plot==0 && disp_conv
axs[4].plot([t_scaled], [CT], "$(stls[i])", alpha=alpha, color=clr)
axs[5].plot([t_scaled], [CQ], "$(stls[i])", alpha=alpha, color=clr)
axs[6].plot([t_scaled], [eta], "$(stls[i])", alpha=alpha, color=clr)
Expand All @@ -185,7 +202,7 @@ function generate_monitor_rotors( rotors::Array{vlm.Rotor, 1},

if disp_conv
# Save figure
if fcalls%nsteps_savefig==0 && fcalls!=0 && save_path!=nothing
if PFIELD.nt%nsteps_savefig==0 && fcalls!=0 && save_path!=nothing
fig.savefig(joinpath(save_path, run_name*"_convergence.png"),
transparent=false, dpi=300)
end
Expand Down Expand Up @@ -244,7 +261,7 @@ polar), and unsteady-circulation force.
will also generate a CSV file with \$C_L\$ and \$C_D\$.
Here is an example of this monitor:
![image](http://edoalvar2.groups.et.byu.net/public/FLOWUnsteady/wingexample_convergence.png)
![image](http://edoalvar2.groups.et.byu.net/public/FLOWUnsteady/wing-example_convergence.png)
"""
function generate_monitor_wing(wing, Vinf::Function, b_ref::Real, ar_ref::Real,
rho_ref::Real, qinf_ref::Real, nsteps_sim::Int;
Expand Down Expand Up @@ -276,8 +293,8 @@ function generate_monitor_wing(wing, Vinf::Function, b_ref::Real, ar_ref::Real,
S_proj=t->[0, 1, 0],
conv_suff="_convergence.csv",
figsize_factor=5/6,
nsteps_plot=10,
nsteps_savefig=1,
nsteps_plot=1,
nsteps_savefig=10,
debug=false)

fcalls = 0 # Number of function calls
Expand Down Expand Up @@ -478,6 +495,9 @@ step. The state variables are vehicle velocity, vehicle angular velocity, and
vehicle position.
Use `save_path` to indicate a directory where to save the plots.
Here is an example of this monitor on a vehicle flying a circular path:
![image](http://edoalvar2.groups.et.byu.net/public/FLOWUnsteady/tetheredwing-example-statemonitor.png)
"""
function generate_monitor_statevariables(; figname="monitor_statevariables",
out_figs=[],
Expand Down Expand Up @@ -557,17 +577,27 @@ Use `save_path` to indicate a directory where to save the plots. If so, it
will also generate a CSV file with ξ.
"""
function generate_monitor_enstrophy(; save_path=nothing, run_name="",
disp_plot=true,
figname="monitor_enstrophy",
nsteps_savefig=10,
nsteps_plot=10)
out_figs=[],
out_figaxs=[],
disp_plot=true,
figname="monitor_enstrophy",
figsize_factor=5/6,
nsteps_savefig=10,
nsteps_plot=1)

if disp_plot
formatpyplot()
fig = plt.figure(figname, figsize=[7*1, 5*1])
fig = plt.figure(figname, figsize=[7*1, 5*1]*figsize_factor)
ax = fig.gca()

ax.set_xlabel("Simulation time (s)")
ax.set_ylabel(L"Enstrophy ($\mathrm{m}^3/\mathrm{s}^2$)")

ax.spines["right"].set_visible(false)
ax.spines["top"].set_visible(false)

push!(out_figs, fig)
push!(out_figaxs, ax)
end

enstrophy = []
Expand Down Expand Up @@ -614,26 +644,38 @@ will also generate a CSV file with the statistics of \$C_d\$ (particles whose
coefficients have been clipped are ignored).
"""
function generate_monitor_Cd(; save_path=nothing, run_name="",
disp_plot=true,
figname="monitor_Cd",
nsteps_savefig=10,
nsteps_plot=10,
ylims=[1e-5, 1e0])
out_figs=[],
out_figaxs=[],
disp_plot=true,
figname="monitor_Cd",
figsize_factor=5/6,
nsteps_plot=1,
nsteps_savefig=10,
ylims=[1e-5, 1e0])

if disp_plot
formatpyplot()
fig = plt.figure(figname, figsize=[7*2, 5*1])
fig = plt.figure(figname, figsize=[7*2, 5*1]*figsize_factor)
axs = fig.subplots(1, 2)

ax = axs[1]
ax.set_ylim(ylims)
ax.set_yscale("log")
ax.set_xlabel("Simulation time (s)")
ax.set_ylabel(L"Mean $\Vert C_d \Vert$")

ax = axs[2]
ax.set_xlabel("Simulation time")
ax.set_ylabel(L"Ratio of $C_d$-zeroes"*
L" $\frac{n_\mathrm{zeroes}}{n_\mathrm{particles}}$")
L" $\frac{n_\mathrm{zeroes}}{n_\mathrm{particles}}$")

for ax in axs
ax.spines["right"].set_visible(false)
ax.spines["top"].set_visible(false)
end

push!(out_figs, fig)
push!(out_figaxs, axs)
end

meanCds, stdCds, zeroCds, ts, out = [], [], [], [], []
Expand Down Expand Up @@ -686,3 +728,24 @@ function generate_monitor_Cd(; save_path=nothing, run_name="",

return extra_runtime_function
end

"""
concatenate(monitors::Array{Function})
concatenate(monitors::NTuple{N, Function})
concatenate(monitor1, monitor2, ...)
Concatenates a collection of monitors into a pipeline, returning one monitor of
the form
```julia
monitor(args...; optargs...) =
monitors[1](args...; optargs...) || monitors[2](args...; optargs...) || ...
```
"""
function concatenate(monitors...)

monitor(args...; optargs...) = !prod(!f(args...; optargs...) for f in monitors)

return monitor
end

concatenate(monitors) = concatenate(monitors...)

0 comments on commit a17dfe8

Please sign in to comment.