33@inline ϕ (a,I,f) = @inbounds (f[I]+ f[I- δ (a,I)])/ 2
44@fastmath quick (u,c,d) = median ((5 c+ 2 d- u)/ 6 ,c,median (10 c- 9 u,c,d))
55@fastmath vanLeer (u,c,d) = (c≤ min (u,d) || c≥ max (u,d)) ? c : c+ (d- c)* (c- u)/ (d- u)
6- @inline ϕu (a,I,f,u,λ= quick) = @inbounds u> 0 ? u* λ (f[I- 2 δ (a,I)],f[I- δ (a,I)],f[I]) : u* λ (f[I+ δ (a,I)],f[I],f[I- δ (a,I)])
7- @inline ϕuP (a,Ip,I,f,u,λ= quick) = @inbounds u> 0 ? u* λ (f[Ip],f[I- δ (a,I)],f[I]) : u* λ (f[I+ δ (a,I)],f[I],f[I- δ (a,I)])
8- @inline ϕuL (a,I,f,u,λ= quick) = @inbounds u> 0 ? u* ϕ (a,I,f) : u* λ (f[I+ δ (a,I)],f[I],f[I- δ (a,I)])
9- @inline ϕuR (a,I,f,u,λ= quick) = @inbounds u< 0 ? u* ϕ (a,I,f) : u* λ (f[I- 2 δ (a,I)],f[I- δ (a,I)],f[I])
6+ @fastmath cds (u,c,d) = (c+ d)/ 2
7+
8+ @inline ϕu (a,I,f,u,λ) = @inbounds u> 0 ? u* λ (f[I- 2 δ (a,I)],f[I- δ (a,I)],f[I]) : u* λ (f[I+ δ (a,I)],f[I],f[I- δ (a,I)])
9+ @inline ϕuP (a,Ip,I,f,u,λ) = @inbounds u> 0 ? u* λ (f[Ip],f[I- δ (a,I)],f[I]) : u* λ (f[I+ δ (a,I)],f[I],f[I- δ (a,I)])
10+ @inline ϕuL (a,I,f,u,λ) = @inbounds u> 0 ? u* ϕ (a,I,f) : u* λ (f[I+ δ (a,I)],f[I],f[I- δ (a,I)])
11+ @inline ϕuR (a,I,f,u,λ) = @inbounds u< 0 ? u* ϕ (a,I,f) : u* λ (f[I- 2 δ (a,I)],f[I- δ (a,I)],f[I])
1012
1113@fastmath @inline function div (I:: CartesianIndex{m} ,u) where {m}
1214 init= zero (eltype (u))
@@ -33,31 +35,31 @@ function median(a,b,c)
3335 return a
3436end
3537
36- function conv_diff! (r,u,Φ;ν= 0.1 ,perdir= ())
38+ function conv_diff! (r,u,Φ,λ :: F ;ν= 0.1 ,perdir= ()) where {F}
3739 r .= zero (eltype (r))
3840 N,n = size_u (u)
3941 for i ∈ 1 : n, j ∈ 1 : n
4042 # if it is periodic direction
4143 tagper = (j in perdir)
4244 # treatment for bottom boundary with BCs
43- lowerBoundary! (r,u,Φ,ν,i,j,N,Val {tagper} ())
45+ lowerBoundary! (r,u,Φ,ν,i,j,N,λ, Val {tagper} ())
4446 # inner cells
45- @loop (Φ[I] = ϕu (j,CI (I,i),u,ϕ (i,CI (I,j),u)) - ν* ∂ (j,CI (I,i),u);
47+ @loop (Φ[I] = ϕu (j,CI (I,i),u,ϕ (i,CI (I,j),u),λ ) - ν* ∂ (j,CI (I,i),u);
4648 r[I,i] += Φ[I]) over I ∈ inside_u (N,j)
4749 @loop r[I- δ (j,I),i] -= Φ[I] over I ∈ inside_u (N,j)
4850 # treatment for upper boundary with BCs
49- upperBoundary! (r,u,Φ,ν,i,j,N,Val {tagper} ())
51+ upperBoundary! (r,u,Φ,ν,i,j,N,λ, Val {tagper} ())
5052 end
5153end
5254
5355# Neumann BC Building block
54- lowerBoundary! (r,u,Φ,ν,i,j,N,:: Val{false} ) = @loop r[I,i] += ϕuL (j,CI (I,i),u,ϕ (i,CI (I,j),u)) - ν* ∂ (j,CI (I,i),u) over I ∈ slice (N,2 ,j,2 )
55- upperBoundary! (r,u,Φ,ν,i,j,N,:: Val{false} ) = @loop r[I- δ (j,I),i] += - ϕuR (j,CI (I,i),u,ϕ (i,CI (I,j),u)) + ν* ∂ (j,CI (I,i),u) over I ∈ slice (N,N[j],j,2 )
56+ lowerBoundary! (r,u,Φ,ν,i,j,N,λ, :: Val{false} ) = @loop r[I,i] += ϕuL (j,CI (I,i),u,ϕ (i,CI (I,j),u),λ ) - ν* ∂ (j,CI (I,i),u) over I ∈ slice (N,2 ,j,2 )
57+ upperBoundary! (r,u,Φ,ν,i,j,N,λ, :: Val{false} ) = @loop r[I- δ (j,I),i] += - ϕuR (j,CI (I,i),u,ϕ (i,CI (I,j),u),λ ) + ν* ∂ (j,CI (I,i),u) over I ∈ slice (N,N[j],j,2 )
5658
5759# Periodic BC Building block
58- lowerBoundary! (r,u,Φ,ν,i,j,N,:: Val{true} ) = @loop (
59- Φ[I] = ϕuP (j,CIj (j,CI (I,i),N[j]- 2 ),CI (I,i),u,ϕ (i,CI (I,j),u)) - ν* ∂ (j,CI (I,i),u); r[I,i] += Φ[I]) over I ∈ slice (N,2 ,j,2 )
60- upperBoundary! (r,u,Φ,ν,i,j,N,:: Val{true} ) = @loop r[I- δ (j,I),i] -= Φ[CIj (j,I,2 )] over I ∈ slice (N,N[j],j,2 )
60+ lowerBoundary! (r,u,Φ,ν,i,j,N,λ, :: Val{true} ) = @loop (
61+ Φ[I] = ϕuP (j,CIj (j,CI (I,i),N[j]- 2 ),CI (I,i),u,ϕ (i,CI (I,j),u),λ ) - ν* ∂ (j,CI (I,i),u); r[I,i] += Φ[I]) over I ∈ slice (N,2 ,j,2 )
62+ upperBoundary! (r,u,Φ,ν,i,j,N,λ, :: Val{true} ) = @loop r[I- δ (j,I),i] -= Φ[CIj (j,I,2 )] over I ∈ slice (N,N[j],j,2 )
6163
6264"""
6365 accelerate!(r,t,g,U)
@@ -137,24 +139,24 @@ function project!(a::Flow{n},b::AbstractPoisson,w=1) where n
137139end
138140
139141"""
140- mom_step!(a::Flow,b::AbstractPoisson)
142+ mom_step!(a::Flow,b::AbstractPoisson;λ=quick,udf=nothing,kwargs... )
141143
142144Integrate the `Flow` one time step using the [Boundary Data Immersion Method](https://eprints.soton.ac.uk/369635/)
143145and the `AbstractPoisson` pressure solver to project the velocity onto an incompressible flow.
144146"""
145- @fastmath function mom_step! (a:: Flow{N} ,b:: AbstractPoisson ;udf= nothing ,kwargs... ) where N
147+ @fastmath function mom_step! (a:: Flow{N} ,b:: AbstractPoisson ;λ = quick, udf= nothing ,kwargs... ) where N
146148 a. u⁰ .= a. u; scale_u! (a,0 ); t₁ = sum (a. Δt); t₀ = t₁- a. Δt[end ]
147149 # predictor u → u'
148150 @log " p"
149- conv_diff! (a. f,a. u⁰,a. σ,ν= a. ν,perdir= a. perdir)
151+ conv_diff! (a. f,a. u⁰,a. σ,λ; ν= a. ν,perdir= a. perdir)
150152 udf! (a,udf,t₀; kwargs... )
151153 accelerate! (a. f,t₀,a. g,a. uBC)
152154 BDIM! (a); BC! (a. u,a. uBC,a. exitBC,a. perdir,t₁) # BC MUST be at t₁
153155 a. exitBC && exitBC! (a. u,a. u⁰,a. Δt[end ]) # convective exit
154156 project! (a,b); BC! (a. u,a. uBC,a. exitBC,a. perdir,t₁)
155157 # corrector u → u¹
156158 @log " c"
157- conv_diff! (a. f,a. u,a. σ,ν= a. ν,perdir= a. perdir)
159+ conv_diff! (a. f,a. u,a. σ,λ; ν= a. ν,perdir= a. perdir)
158160 udf! (a,udf,t₁; kwargs... )
159161 accelerate! (a. f,t₁,a. g,a. uBC)
160162 BDIM! (a); scale_u! (a,0.5 ); BC! (a. u,a. uBC,a. exitBC,a. perdir,t₁)
0 commit comments