-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The main problem with the previous version were the `a.u .= 0` and `a.u ./= 2` lines in `mom_step!` which kept modifying the exit plane values. I changed these lines to only update the values inside the domain. I added an `flow.exit` to the struct and initialization functions and use this to trigger the convection exit behavior. The `apply!` function had the opposite problem - it WASN'T filling in the boundary value. Now it does. It also seemed weird to me that the convection exit value in Lotus was based on the old value at the boundary but the u* value (before projection) upstream. I'm not sure it matters much, but it seems more consistent to just use the old values in both places, so that's what it does now. Finally, I added a Lamp vortex dipole test case, which is nice since it should leave the exit without changing size or speed.
- Loading branch information
weymouth
committed
Oct 10, 2023
1 parent
2d4787c
commit 63b88be
Showing
5 changed files
with
63 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1,35 @@ | ||
using WaterLily | ||
using BenchmarkTools | ||
include("examples/TwoD_plots.jl") | ||
|
||
function test_conv_BC!(sim) | ||
# duration of the simulation | ||
duration = 16 | ||
step = 0.4 | ||
t₀ = 0.0 | ||
plot() | ||
|
||
@time @gif for tᵢ in range(t₀,t₀+duration;step) | ||
|
||
# update until time tᵢ in the background | ||
t = sum(sim.flow.Δt[1:end-1]) | ||
while t < tᵢ*sim.L/sim.U | ||
|
||
# update flow | ||
# mom_step_BC!(sim.flow,sim.pois) | ||
WaterLily.mom_step!(sim.flow,sim.pois) | ||
|
||
# compute motion and acceleration 1DOF | ||
Δt = sim.flow.Δt[end] | ||
t += Δt | ||
end | ||
|
||
# plot vorticity | ||
# @inside sim.flow.σ[I] = WaterLily.curl(3,I,sim.flow.u)*sim.L/sim.U | ||
# flood(sim.flow.σ; shift=(-0.5,-0.5), clims=(-5,5)) | ||
# flood(sim.flow.p; shift=(-0.5,-0.5), clims=(-1,1)) | ||
# addbody(real(z.+n/4),imag(z.+im*m/2)) | ||
plot!(sim.flow.u[end,:,1]) | ||
# plot!(sim.flow.u[end,:,1]) | ||
|
||
# print time step | ||
println("tU/L=",round(tᵢ,digits=4),", Δt=",round(sim.flow.Δt[end],digits=3)) | ||
using WaterLily,SpecialFunctions,ForwardDiff,StaticArrays | ||
|
||
function lamb_dipole(N;D=N/3,U=1,exit=false) | ||
β = 2.4394π/D | ||
@show besselj1(β*D/2) | ||
C = -2U/(β*besselj0(β*D/2)) | ||
function ψ(x,y) | ||
r = √(x^2+y^2) | ||
ifelse(r ≥ D/2, U*((D/2r)^2-1)*y, C*besselj1(β*r)*y/r) | ||
end | ||
center = SA[N/2,N/2] | ||
function uλ(i,xy) | ||
x,y = xy-center | ||
ifelse(i==1,ForwardDiff.derivative(y->ψ(x,y),y)+1+U,-ForwardDiff.derivative(x->ψ(x,y),x)) | ||
end | ||
Simulation((N, N), (1,0), D; uλ, exit) | ||
end | ||
|
||
L = 4 | ||
N = (L,L) | ||
Nd = N .+ 2 | ||
Nd = (Nd...,2) | ||
U = (1.0,0.0) | ||
u = Array{Float64}(undef, Nd...) | ||
|
||
# vertical shear | ||
println("--Before - BC(u,U)--") | ||
apply!((i, x) -> (i==1 ? x[2] : 0), u) | ||
BC!(u,zeros(2)) | ||
display(u[:,:,1]') | ||
|
||
println("--BCΔt!(u,U;Δt=1)--") | ||
BC!(u,zeros(2)) # reset BC values | ||
WaterLily.BCΔt!(u, (1,0); Δt=1.0) # convect and mass check | ||
display(u[:,:,1]') | ||
|
||
println("--BCΔt!(u,U)--") # same as BC!(u,1) | ||
BC!(u,zeros(2)) # reset BC values | ||
WaterLily.BCΔt!(u, (1,0)) # only mass check | ||
display(u[:,:,1]') | ||
|
||
# test on flow sim | ||
# some definitons | ||
U = 1 | ||
Re = 250 | ||
|
||
m, n = 32,48 | ||
println("$n x $m: ", prod((m,n))) | ||
radius = 4 | ||
|
||
# make a circle body | ||
body = AutoBody((x,t)->√sum(abs2, x .- [n/4,m/2]) - radius) | ||
z = [radius*exp(im*θ) for θ ∈ range(0,2π,length=33)] | ||
|
||
# make a simulation | ||
sim = Simulation((n,m), (U,0), radius; ν=U*radius/Re, body, T=Float64) | ||
test_conv_BC!(sim) | ||
|
||
# flood(sim.flow.u[2:end-1,2:end-1,1]) | ||
# flood(sim.flow.p[2:end-1,2:end-1]) | ||
# flood(sim.flow.μ₀[:,:,1]) | ||
# plot(sim.flow.u[end,:,1]) | ||
# plot!(sim.flow.u[end-1,:,1]) | ||
|
||
|
||
# test all contributions to mom_step! | ||
# @benchmark WaterLily.mom_step!(sim.flow,sim.pois) | ||
|
||
# # step by step | ||
# println("conv_diff!") | ||
# @benchmark WaterLily.conv_diff!(sim.flow.f,sim.flow.u⁰,sim.flow.σ,ν=sim.flow.ν) | ||
|
||
# println("BDIM!") | ||
# @benchmark WaterLily.BDIM!(sim.flow) | ||
|
||
# println("BCΔt!") | ||
# @benchmark WaterLily.BCΔt!(sim.flow.u,sim.flow.U;Δt=sim.flow.Δt[end]) | ||
|
||
# println("project!") | ||
# @benchmark WaterLily.project!(sim.flow,sim.pois) | ||
|
||
# println("BCΔt!") | ||
# @benchmark WaterLily.BC!(sim.flow.u,sim.flow.U) | ||
|
||
include("examples/TwoD_plots.jl") | ||
|
||
sim = lamb_dipole(64,U=0.25); | ||
@inside sim.flow.σ[I] = WaterLily.curl(3,I,sim.flow.u)*sim.L/sim.U | ||
flood(sim.flow.σ,clims=(-5,5)) | ||
sim_step!(sim,1.2,remeasure=false) | ||
@inside sim.flow.σ[I] = WaterLily.curl(3,I,sim.flow.u)*sim.L/sim.U | ||
flood(sim.flow.σ,clims=(-5,5)) | ||
|
||
sim = lamb_dipole(64,U=0.25,exit=true); | ||
sim_step!(sim,1.2,remeasure=false) | ||
@inside sim.flow.σ[I] = WaterLily.curl(3,I,sim.flow.u)*sim.L/sim.U | ||
flood(sim.flow.σ,clims=(-5,5)) | ||
|
||
U=2 | ||
sim = lamb_dipole(64,U=U,exit=true); | ||
sim_gif!(sim,duration=2.5/(1+U),step=0.05,clims=(-20,20)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters