@@ -32,6 +32,13 @@ function median(a,b,c)
3232 return a
3333end
3434
35+ """
36+ conv_diff!(r, u, Φ, λ; ν=0.1, perdir=())
37+
38+ Compute the convective and diffusive fluxes of velocity `u` using the
39+ convection scheme `λ(u,c,d)` and kinematic viscosity `ν`. The result is
40+ accumulated into `r` (force per unit volume) and `Φ` is a working scalar.
41+ """
3542function conv_diff! (r,u,Φ,λ:: F ;ν= 0.1 ,perdir= ()) where {F}
3643 r .= zero (eltype (r))
3744 N,n = size_u (u)
@@ -53,14 +60,17 @@ accelerate!(r,t,g::Function,::Union{Nothing,Tuple}) = accelerate!(r,t,g)
5360accelerate! (r,t,:: Nothing ,U:: Function ) = accelerate! (r,t,(i,x,t)-> ForwardDiff. derivative (τ-> U (i,x,τ),t))
5461accelerate! (r,t,g:: Function ,U:: Function ) = accelerate! (r,t,(i,x,t)-> g (i,x,t)+ ForwardDiff. derivative (τ-> U (i,x,τ),t))
5562"""
56- Flow{D::Int , T::Float , Sf<:AbstractArray{T,D}, Vf<:AbstractArray{T,D+1}, Tf<:AbstractArray{T,D+2} }
63+ Flow{D, T, Sf, Vf, Tf}
5764
5865Composite type for a multidimensional immersed boundary flow simulation.
5966
6067Flow solves the unsteady incompressible [Navier-Stokes equations](https://en.wikipedia.org/wiki/Navier%E2%80%93Stokes_equations) on a Cartesian grid.
6168Solid boundaries are modelled using the [Boundary Data Immersion Method](https://eprints.soton.ac.uk/369635/).
6269The primary variables are the scalar pressure `p` (an array of dimension `D`)
6370and the velocity vector field `u` (an array of dimension `D+1`).
71+
72+ All arrays use the N+4 staggered layout: `N` interior cells plus 2 ghost/boundary
73+ cells per side, giving total size `M = N + 4` per spatial dimension.
6474"""
6575struct Flow{D, T, Sf<: AbstractArray{T} , Vf<: AbstractArray{T} , Tf<: AbstractArray{T} }
6676 # Fluid fields
@@ -77,7 +87,7 @@ struct Flow{D, T, Sf<:AbstractArray{T}, Vf<:AbstractArray{T}, Tf<:AbstractArray{
7787 uBC :: Union{NTuple{D,Number},Function} # domain boundary values/function
7888 Δt:: Vector{T} # time step (stored in CPU memory)
7989 ν :: T # kinematic viscosity
80- g :: Union{Function,Nothing} # acceleration field funciton
90+ g :: Union{Function,Nothing} # acceleration field function
8191 exitBC :: Bool # Convection exit
8292 perdir :: NTuple # tuple of periodic direction
8393 function Flow (N:: NTuple{D} , uBC; f= Array, Δt= 0.25 , ν= 0. , g= nothing ,
@@ -103,12 +113,26 @@ Current flow time.
103113"""
104114time (a:: Flow ) = sum (@view (a. Δt[1 : end - 1 ]))
105115
116+ """
117+ BDIM!(a::Flow)
118+
119+ Apply the Boundary Data Immersion Method to enforce the body velocity.
120+ Uses the zeroth and first kernel moments (`μ₀`, `μ₁`) to blend the
121+ body velocity `V` with the predicted fluid velocity.
122+ """
106123function BDIM! (a:: Flow )
107124 dt = a. Δt[end ]
108125 @loop a. f[Ii] = a. u⁰[Ii]+ dt* a. f[Ii]- a. V[Ii] over Ii in CartesianIndices (a. f)
109126 @loop a. u[Ii] += μddn (Ii,a. μ₁,a. f)+ a. V[Ii]+ a. μ₀[Ii]* a. f[Ii] over Ii ∈ inside_u (size (a. p))
110127end
111128
129+ """
130+ project!(a::Flow, b::AbstractPoisson, w=1)
131+
132+ Project the velocity field onto a divergence-free field by solving
133+ the pressure Poisson equation `∇⋅(L∇p) = ∇⋅u/Δt` and correcting
134+ the velocity: `u -= L∇p`. The weight `w` scales `Δt` (0.5 for the corrector).
135+ """
112136function project! (a:: Flow{n} ,b:: AbstractPoisson ,w= 1 ) where n
113137 dt = w* a. Δt[end ]
114138 @inside b. z[I] = div (I,a. u); b. x .*= dt # set source term & solution IC
@@ -146,6 +170,12 @@ and the `AbstractPoisson` pressure solver to project the velocity onto an incomp
146170end
147171scale_u! (a,scale) = @loop a. u[Ii] *= scale over Ii ∈ inside_u (size (a. p))
148172
173+ """
174+ CFL(a::Flow; Δt_max=10)
175+
176+ Compute the CFL-limited time step from the maximum outward flux at each cell.
177+ Uses `global_min` for MPI-safe reduction across all ranks.
178+ """
149179function CFL (a:: Flow ;Δt_max= 10 )
150180 @inside a. σ[I] = flux_out (I,a. u)
151181 global_min (Δt_max,inv (maximum (a. σ)+ 5 a. ν))
0 commit comments