Skip to content

Commit 0ad9e9a

Browse files
committed
revert to master
1 parent 338fc66 commit 0ad9e9a

File tree

4 files changed

+31
-115
lines changed

4 files changed

+31
-115
lines changed

ext/WaterLilyJLD2Ext.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ save!(fname::String, sim::AbstractSimulation; dir="./") = save!(fname, sim.flow;
2121
2222
Save the `meanflow::MeanFlow` time-averaged pressure, velocity, velocity-squared, and time arrays into a JLD2-formatted binary file (HDF5 compatible).
2323
"""
24-
save!(fname, meanflow::AverageFlow; dir="./") = jldsave(
24+
save!(fname, meanflow::MeanFlow; dir="./") = jldsave(
2525
joinpath(dir, fname);
2626
P=Array(meanflow.P),
2727
U=Array(meanflow.U),
@@ -56,7 +56,7 @@ load!(sim::AbstractSimulation, ::Val{:jld2}; kwargs...) = load!(sim.flow; kwargs
5656
Load time-averaged pressure, velocity, velocity-square, and time arrays from a JLD2-formatted binary file.
5757
Keyword arguments considered are `fname="WaterLilyMean.jld2"` and `dir="./"`.
5858
"""
59-
function load!(meanflow::AverageFlow{MeanFlow}; kwargs...)
59+
function load!(meanflow::MeanFlow; kwargs...)
6060
fname = get(Dict(kwargs), :fname, "WaterLilyMean.jld2")
6161
dir = get(Dict(kwargs), :dir, "./")
6262
obj = jldopen(joinpath(dir, fname))

src/Metrics.jl

Lines changed: 28 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ end
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
1818
end
@@ -150,65 +150,43 @@ function pressure_moment(x₀,p,df,body,t=0)
150150
sum(To,df,dims=ntuple(i->i,ndims(p)))[:] |> Array
151151
end
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
169178
end
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)
209187
end
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)
223201
end
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)
253205
end
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 τ
258210
end
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])
279215
end

src/WaterLily.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ include("AutoBody.jl")
2727
export AutoBody,Bodies,measure,sdf,+,-
2828

2929
include("Metrics.jl")
30-
export AverageFlow,MeanFlow,SpanAverage,update!,uu!,uu
30+
export MeanFlow,update!,uu!,uu
3131

3232
abstract type AbstractSimulation end
3333
"""

test/maintests.jl

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,6 @@ end
408408
end
409409
end
410410

411-
function spanwise_cylinder(radius = 8; D=2, mem=Array, exitBC=false)
412-
body = AutoBody((x,t)-> sum(abs2,SA[x[1],x[2]] .- (2radius+1.5)) - radius)
413-
Simulation(radius.*(6,4,1),(1,0,0),radius; body, ν=radius/250, T=Float32, mem, perdir=(3,), exitBC)
414-
end
415-
416411
import WaterLily: ×
417412
@testset "Metrics.jl" begin
418413
J = CartesianIndex(2,3,4); x = loc(0,J,Float64); px = prod(x)
@@ -494,21 +489,6 @@ import WaterLily: ×
494489
meanflow2 = MeanFlow(size(sim.flow.p).-2; uu_stats=true)
495490
@test all(meanflow2.P .== zero(T))
496491
@test size(meanflow2.P) == size(meanflow.P)
497-
498-
# spanwise average flow
499-
sim = spanwise_cylinder(8, mem=f)
500-
spanavg = SpanAverage(sim.flow)
501-
for t in range(0,10;step=0.1)
502-
sim_step!(sim, t)
503-
update!(spanavg, sim.flow)
504-
end
505-
@test WaterLily.time(sim.flow) == WaterLily.time(spanavg)
506-
507-
WaterLily.reset!(spanavg)
508-
@test all(spanavg.U .== zero(T))
509-
@test all(spanavg.P .== zero(T))
510-
@test all(spanavg.UU .== zero(T))
511-
@test spanavg.t == T[0]
512492
end
513493
end
514494

0 commit comments

Comments
 (0)