Skip to content

Commit b582df3

Browse files
authored
Merge pull request #206 from marinlauber/fix-WaterLilyPlotExt
Fix Array type in flood and plot_logger for Biot-Savart
2 parents 1118a07 + 20ae992 commit b582df3

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

ext/WaterLilyPlotsExt.jl

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import WaterLily: flood,addbody,body_plot!,sim_gif!,plot_logger
1414
1515
Plot a filled contour plot of the 2D array `f`. The keyword arguments are passed to `Plots.contourf`.
1616
"""
17-
function flood(f::Array;shift=(0.,0.),cfill=:RdBu_11,clims=(),levels=10,kv...)
17+
function flood(f::AbstractArray;shift=(0.,0.),cfill=:RdBu_11,clims=(),levels=10,kv...)
1818
if length(clims)==2
1919
@assert clims[1]<clims[2]
2020
@. f=min(clims[2],max(clims[1],f))
@@ -44,7 +44,7 @@ function sim_gif!(sim;duration=1,step=0.1,verbose=true,R=inside(sim.flow.p),
4444
@time @gif for tᵢ in range(t₀,t₀+duration;step)
4545
WaterLily.sim_step!(sim,tᵢ;remeasure)
4646
@WaterLily.inside sim.flow.σ[I] = WaterLily.curl(3,I,sim.flow.u)*sim.L/sim.U
47-
flood(sim.flow.σ[R]|>Array; kv...)
47+
flood(sim.flow.σ[R]; kv...)
4848
plotbody && body_plot!(sim)
4949
verbose && println("tU/L=",round(tᵢ,digits=4),
5050
", Δt=",round(sim.flow.Δt[end],digits=3))
@@ -65,20 +65,20 @@ function plot_logger(fname="WaterLily.log")
6565
while ! eof(f)
6666
s = split(readline(f) , ",")
6767
which = s[1] != "" ? s[1] : which
68-
push!(which == "p" ? predictor : corrector,parse.(Float64,s[2:end]))
68+
push!(which == "p" ? predictor : corrector, parse.(Float64,s[2:end]))
6969
end
7070
end
7171
predictor = reduce(hcat,predictor)
7272
corrector = reduce(hcat,corrector)
73-
73+
# @log p/c, nᵖ, L∞(p), r₂, (nᵇ) this is what is logged
7474
# get index of all time steps
7575
idx = findall(==(0.0),@views(predictor[1,:]))
7676
# plot inital L∞ and L₂ norms of residuals for the predictor step
7777
p1=plot(1:length(idx),predictor[2,idx],color=:1,ls=:dash,alpha=0.8,label="predictor initial r∞",yaxis=:log,size=(800,400),dpi=600,
7878
xlabel="Time step",ylabel="L∞-norm",title="Residuals",ylims=(1e-8,1e0),xlims=(0,length(idx)))
79-
p2=plot(1:length(idx),predictor[2,idx],color=:1,ls=:dash,alpha=0.8,label="predictor initial r₂",yaxis=:log,size=(800,400),dpi=600,
79+
p2=plot(1:length(idx),predictor[3,idx],color=:1,ls=:dash,alpha=0.8,label="predictor initial r₂",yaxis=:log,size=(800,400),dpi=600,
8080
xlabel="Time step",ylabel="L₂-norm",title="Residuals",ylims=(1e-8,1e0),xlims=(0,length(idx)))
81-
# plot final L∞ and L₂norms of residuals for the predictor
81+
# plot final L∞ and L₂ norms of residuals for the predictor
8282
plot!(p1,1:length(idx),vcat(predictor[2,idx[2:end].-1],predictor[2,end]),color=:1,lw=2,alpha=0.8,label="predictor r∞")
8383
plot!(p2,1:length(idx),vcat(predictor[3,idx[2:end].-1],predictor[3,end]),color=:1,lw=2,alpha=0.8,label="predictor r₂")
8484
# plot the MG iterations for the predictor
@@ -95,8 +95,17 @@ function plot_logger(fname="WaterLily.log")
9595
plot!(p2,1:length(idx),vcat(corrector[3,idx[2:end].-1],corrector[3,end]),color=:2,lw=2,alpha=0.8,label="corrector r₂")
9696
# plot MG iterations of the corrector
9797
plot!(p3,1:length(idx),clamp.(vcat(corrector[1,idx[2:end].-1],corrector[1,end]),1/2,32),lw=2,alpha=0.8,label="corrector")
98-
# plot all together
99-
plot(p1,p2,p3,layout=@layout [a b c])
98+
if size(predictor,1) == 3
99+
# plot all together
100+
plot(p1,p2,p3,layout=@layout [a b c])
101+
else # if the BiotSavart is used, we can plot the coupling iterations
102+
p4 = plot(1:length(idx),clamp.(vcat(predictor[4,idx[2:end].-1],predictor[4,end]),1/2,32),lw=2,alpha=0.8,label="predictor",size=(800,400),dpi=600,
103+
xlabel="Time step",ylabel="Iterations",title="Biot-Savart",ylims=(1/2,32),xlims=(0,length(idx)),yaxis=:log2)
104+
yticks!([1/2,1,2,4,8,16,32],["0","1","2","4","8","16","32"])
105+
plot!(p4,1:length(idx),clamp.(vcat(corrector[4,idx[2:end].-1],corrector[4,end]),1/2,32),lw=2,alpha=0.8,label="corrector")
106+
# plot all together
107+
plot(p1,p2,p3,p4,layout=@layout [a b c d])
108+
end
100109
end
101110

102111
end # module

0 commit comments

Comments
 (0)