From 01cbf9461ce89a30de46535a506ec88009ab7934 Mon Sep 17 00:00:00 2001 From: Bernat Font Date: Thu, 14 Nov 2024 16:34:40 +0100 Subject: [PATCH] Added custom CFL function. --- src/Flow.jl | 4 ++-- src/WaterLily.jl | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Flow.jl b/src/Flow.jl index 9dbd39e..85acc75 100644 --- a/src/Flow.jl +++ b/src/Flow.jl @@ -150,7 +150,7 @@ end Integrate the `Flow` one time step using the [Boundary Data Immersion Method](https://eprints.soton.ac.uk/369635/) and the `AbstractPoisson` pressure solver to project the velocity onto an incompressible flow. """ -@fastmath function mom_step!(a::Flow{N},b::AbstractPoisson) where N +@fastmath function mom_step!(a::Flow{N},b::AbstractPoisson; CFL_f=CFL) where N a.u⁰ .= a.u; scale_u!(a,0) # predictor u → u' U = BCTuple(a.U,@view(a.Δt[1:end-1]),N) @@ -165,7 +165,7 @@ and the `AbstractPoisson` pressure solver to project the velocity onto an incomp accelerate!(a.f,a.Δt,a.g,a.U) BDIM!(a); scale_u!(a,0.5); BC!(a.u,U,a.exitBC,a.perdir) project!(a,b,0.5); BC!(a.u,U,a.exitBC,a.perdir) - push!(a.Δt,CFL(a)) + push!(a.Δt,CFL_f(a)) end scale_u!(a,scale) = @loop a.u[Ii] *= scale over Ii ∈ inside_u(size(a.p)) diff --git a/src/WaterLily.jl b/src/WaterLily.jl index 811cea4..d977551 100644 --- a/src/WaterLily.jl +++ b/src/WaterLily.jl @@ -94,17 +94,17 @@ Integrate the simulation `sim` up to dimensionless time `t_end`. If `remeasure=true`, the body is remeasured at every time step. Can be set to `false` for static geometries to speed up simulation. """ -function sim_step!(sim::Simulation,t_end;remeasure=true,max_steps=typemax(Int),verbose=false) +function sim_step!(sim::Simulation,t_end;remeasure=true,max_steps=typemax(Int),verbose=false,CFL_f=CFL) steps₀ = length(sim.flow.Δt) while sim_time(sim) < t_end && length(sim.flow.Δt) - steps₀ < max_steps - sim_step!(sim; remeasure) + sim_step!(sim; remeasure, CFL_f) verbose && println("tU/L=",round(sim_time(sim),digits=4), ", Δt=",round(sim.flow.Δt[end],digits=3)) end end -function sim_step!(sim::Simulation;remeasure=true) +function sim_step!(sim::Simulation;remeasure=true,CFL_f=CFL) remeasure && measure!(sim) - mom_step!(sim.flow,sim.pois) + mom_step!(sim.flow,sim.pois; CFL_f) end """