1212@fastmath @inline function dot (a,b)
1313 init= zero (eltype (a))
1414 @inbounds for ij in eachindex (a)
15- init += a[ij] * b[ij]
15+ init += a[ij] * b[ij]
1616 end
1717 return init
1818end
@@ -150,65 +150,43 @@ function pressure_moment(x₀,p,df,body,t=0)
150150 sum (To,df,dims= ntuple (i-> i,ndims (p)))[:] |> Array
151151end
152152
153- # abstract Types to distinguish AverageFlows
154- abstract type MeanFlow end
155- abstract type SpanAverage end
156153"""
157- AverageFlow{T, Sf<:AbstractArray{T}, Vf<:AbstractArray{T}, Mf<:AbstractArray{T}}
158- Holds averages of velocity, , pressure, and Reynolds stresses.
154+ MeanFlow{T, Sf<:AbstractArray{T}, Vf<:AbstractArray{T}, Mf<:AbstractArray{T}}
155+
156+ Holds temporal averages of pressure, velocity, and squared-velocity tensor.
159157"""
160- struct AverageFlow{I, T, Sf<: AbstractArray{T} , Vf<: AbstractArray{T} , Mf}
158+ struct MeanFlow{ T, Sf<: AbstractArray{T} , Vf<: AbstractArray{T} , Mf}
161159 P :: Sf # pressure scalar field
162160 U :: Vf # velocity vector field
163161 UU :: Mf # squared-velocity tensor, u⊗u
164162 t :: Vector{T} # time steps vector
165163 uu_stats :: Bool # flag to compute UU on-the-fly temporal averages
166- function AverageFlow (ϕ,v,τ,t;I= MeanFlow,uu_stats= false )
167- new {I,eltype(ϕ),typeof(ϕ),typeof(v),typeof(τ)} (ϕ,v,τ,t,uu_stats)
164+ function MeanFlow (flow:: Flow{D,T} ; t_init= time (flow), uu_stats= false ) where {D,T}
165+ mem = typeof (flow. u). name. wrapper
166+ P = zeros (T, size (flow. p)) |> mem
167+ U = zeros (T, size (flow. u)) |> mem
168+ UU = uu_stats ? zeros (T, size (flow. p)... , D, D) |> mem : nothing
169+ new {T,typeof(P),typeof(U),typeof(UU)} (P,U,UU,T[t_init],uu_stats)
170+ end
171+ function MeanFlow (N:: NTuple{D} ; mem= Array, T= Float32, t_init= 0 , uu_stats= false ) where {D}
172+ Ng = N .+ 2
173+ P = zeros (T, Ng) |> mem
174+ U = zeros (T, Ng... , D) |> mem
175+ UU = uu_stats ? zeros (T, Ng... , D, D) |> mem : nothing
176+ new {T,typeof(P),typeof(U),typeof(UU)} (P,U,UU,T[t_init],uu_stats)
168177 end
169178end
170179
171- """
172- MeanFlow{T, Sf<:AbstractArray{T}, Vf<:AbstractArray{T}, Mf<:AbstractArray{T}}
173- Holds temporal averages of pressure, velocity, and squared-velocity tensor.
174- """
175- function MeanFlow (flow:: Flow{D,T} ; t_init= time (flow), uu_stats= false ) where {D,T}
176- mem = typeof (flow. u). name. wrapper
177- P = zeros (T, size (flow. p)) |> mem
178- U = zeros (T, size (flow. p)... , D) |> mem
179- UU = uu_stats ? zeros (T, size (flow. p)... , D, D) |> mem |> mem : nothing
180- AverageFlow (P,U,UU,T[t_init];I= MeanFlow,uu_stats= uu_stats)
181- end
182- function MeanFlow (N:: NTuple{D} ; mem= Array, T= Float32, t_init= 0 , uu_stats= false ) where {D}
183- Ng = N .+ 2
184- P = zeros (T, Ng) |> mem
185- U = zeros (T, Ng... , D) |> mem
186- UU = uu_stats ? zeros (T, Ng... , D, D) |> mem : nothing
187- AverageFlow (P,U,UU,T[t_init];I= MeanFlow,uu_stats= uu_stats)
188- end
189-
190- """
191- SpanAverage{T, Sf<:AbstractArray{T}, Vf<:AbstractArray{T}, Mf<:AbstractArray{T}}
192- Holds spanwise average of pressure, velocity, and squared-velocity tensor.
193- """
194- function SpanAverage (flow:: Flow{D,T} ; t_init= time (flow), uu_stats= true ) where {D,T}
195- mem = typeof (flow. u). name. wrapper
196- P = zeros (T, Base. front (size (flow. p))) |> mem
197- U = zeros (T, Base. front (size (flow. p))... , D- 1 ) |> mem
198- UU = zeros (T, Base. front (size (flow. p))... , D- 1 , D- 1 ) |> mem
199- AverageFlow (P,U,UU,T[t_init],I= SpanAverage,uu_stats= uu_stats)
200- end
201-
202- time (avrgflow:: AverageFlow ) = avrgflow. t[end ]- avrgflow. t[1 ]
180+ time (meanflow:: MeanFlow ) = meanflow. t[end ]- meanflow. t[1 ]
203181
204- function reset! (avrgflow :: AverageFlow ; t_init= 0.0 )
205- fill! (avrgflow . P, 0 ); fill! (avrgflow . U, 0 )
206- ! isnothing (avrgflow . UU) && fill! (avrgflow . UU, 0 )
207- deleteat! (avrgflow . t, collect (1 : length (avrgflow . t)))
208- push! (avrgflow . t, t_init)
182+ function reset! (meanflow :: MeanFlow ; t_init= 0.0 )
183+ fill! (meanflow . P, 0 ); fill! (meanflow . U, 0 )
184+ ! isnothing (meanflow . UU) && fill! (meanflow . UU, 0 )
185+ deleteat! (meanflow . t, collect (1 : length (meanflow . t)))
186+ push! (meanflow . t, t_init)
209187end
210188
211- function update! (meanflow:: AverageFlow{ MeanFlow} , flow:: Flow )
189+ function update! (meanflow:: MeanFlow , flow:: Flow )
212190 dt = time (flow) - meanflow. t[end ]
213191 ε = dt / (dt + time (meanflow) + eps (eltype (flow. p)))
214192 length (meanflow. t) == 1 && (ε = 1 ) # if it's the first update, we just take the instantaneous flow field
@@ -222,58 +200,16 @@ function update!(meanflow::AverageFlow{MeanFlow}, flow::Flow)
222200 push! (meanflow. t, meanflow. t[end ] + dt)
223201end
224202
225- @inline center (i,I,u) = @inbounds (u[I,i]+ u[I+ δ (i,I),i])* 0.5 # convert face to cell center
226- @inbounds @inline squeeze (a:: AbstractArray ,I:: CartesianIndex{2} ) = (s= zero (eltype (a)); for i ∈ 1 : size (a,3 )
227- s+= a[I,i]
228- end ; s)
229- @inbounds @inline squeeze (a:: AbstractArray ,I:: CartesianIndex{3} ) = (s= zero (eltype (a)); for i ∈ 1 : size (a,3 )
230- s+= a[I. I[1 ],I. I[2 ],i,I. I[3 ]]
231- end ; s)
232-
233- function update! (spanflow:: AverageFlow{SpanAverage} , flow:: Flow )
234- ϵ = inv (size (flow. p,3 )) # sum over domain
235- # spanwise average of pressure
236- @loop spanflow. P[I] = ϵ* squeeze (flow. p,I) over I in CartesianIndices (spanflow. P)
237- # spanwise average of velocity
238- @loop spanflow. U[Ii] = ϵ* squeeze (flow. u,Ii) over Ii in CartesianIndices (spanflow. U)
239- # fluctuating spanwise average of velocity
240- if spanflow. uu_stats
241- for i ∈ 1 : 2
242- @loop flow. f[I,i] = center (i,I,flow. u) - center (i,Base. front (I),spanflow. U) over I in inside_u (flow. u)
243- end
244- for i ∈ 1 : 2 , j ∈ 1 : 2 # τᵢⱼᴿ = < u' ⊗ u' > , needs to be at cell center as ∇⋅τ is then added to faces
245- @views sum! (spanflow. UU[:,:,i,j], ϵ.* flow. f[:,:,:,i]. * flow. f[:,:,:,j])
246- end
247- end
248- push! (spanflow. t, time (flow))
249- end
250-
251- uu! (τ,a:: AverageFlow{MeanFlow} ) = for i in 1 : ndims (a. P), j in 1 : ndims (a. P)
203+ uu! (τ,a:: MeanFlow ) = for i in 1 : ndims (a. P), j in 1 : ndims (a. P)
252204 @loop τ[I,i,j] = a. UU[I,i,j] - a. U[I,i] * a. U[I,j] over I in CartesianIndices (a. P)
253205end
254- function uu (a:: AverageFlow{ MeanFlow} )
206+ function uu (a:: MeanFlow )
255207 τ = zeros (eltype (a. UU), size (a. UU)... ) |> typeof (a. UU). name. wrapper
256208 uu! (τ,a)
257209 return τ
258210end
259211
260- function copy! (a:: Flow , b:: AverageFlow{ MeanFlow} )
212+ function copy! (a:: Flow , b:: MeanFlow )
261213 a. u .= b. U
262214 a. p .= b. P
263- end
264-
265- """
266- spread!(src::Flow{2}, dest::Flow{3}; ϵ=0)
267-
268- Spread a 2D flow field `src` to a 3D flow field `dest`. The 2D flow field is spread to the 3rd dimension of the 3D flow field.
269- a random noise can be added to the spreaded data with ϵ, default is zero.
270- """
271- function spread! (src:: Flow{2} , dest:: Flow{3} ; ϵ= 0 )
272- @assert size (src. p)== Base. front (size (dest. p)) " a::Flow{2} must be the same size as b::Flow{3}[:,:,1,i] to spread"
273- spread! (src. p, dest. p; ϵ= 0 ) # spread pressure
274- spread! (src. u, dest. u; ϵ= ϵ) # spread velocity
275- end
276- spread! (src:: AbstractArray{T,2} ,dest:: AbstractArray{T,3} ;ϵ= 0 ) where T = @loop dest[I] = src[Base. front (I)] over I in CartesianIndices (dest)
277- spread! (src:: AbstractArray{T,3} ,dest:: AbstractArray{T,4} ;ϵ= 0 ) where T = for i in 1 : 2 # can only spread 2 components
278- @loop dest[I,i] = src[Base. front (I),i]+ ϵ* rand () over I in CartesianIndices (size (dest)[1 : end - 1 ])
279215end
0 commit comments