Skip to content

Commit 311b5b1

Browse files
committed
Change tangential BCs and add rotating Ref test
1 parent c80d198 commit 311b5b1

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/Flow.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,10 @@ upperBoundary!(r,u,Φ,ν,i,j,N,::Val{true}) = @loop r[I-δ(j,I),i] -= Φ[CIj(j,I
6262
"""
6363
accelerate!(r,t,g,U)
6464
65-
Adds a space-time acceleration field g(i,x,t) and velocity field U(i,x,t) such that `rᵢ += gᵢ(i,x,t)+dUᵢ(i,x,t)/dt` at time `t=sum(dt)` to vector field `r`.
65+
Accounts for applied and reference-frame acceleration using `rᵢ += g(i,x,t)+dU(i,x,t)/dt`
6666
"""
6767
accelerate!(r,t,::Nothing,::Union{Nothing,Tuple}) = nothing
68-
accelerate!(r,t,f) = for i 1:last(size(r))
69-
@loop r[I,i] += f(i,loc(i,I,eltype(r)),t) over I CartesianIndices(Base.front(size(r)))
70-
end
68+
accelerate!(r,t,f::Function) = @loop r[Ii] += f(last(Ii),loc(Ii,eltype(r)),t) over Ii CartesianIndices(r)
7169
accelerate!(r,t,g::Function,::Union{Nothing,Tuple}) = accelerate!(r,t,g)
7270
accelerate!(r,t,::Nothing,U::Function) = accelerate!(r,t,(i,x,t)->ForwardDiff.derivative->U(i,x,τ),t))
7371
accelerate!(r,t,g::Function,U::Function) = accelerate!(r,t,(i,x,t)->g(i,x,t)+ForwardDiff.derivative->U(i,x,τ),t))

src/util.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ function BC!(a,u_BC::Function,saveexit=false,perdir=(),t=0)
203203
end
204204
(!saveexit || i>1) && (@loop a[I,i] = u_BC(i,loc(i,I),t) over I slice(N,N[j],j)) # overwrite exit
205205
else # Tangential directions, Neumann
206-
@loop a[I,i] = a[I+δ(j,I),i] over I slice(N,1,j)
207-
@loop a[I,i] = a[I-δ(j,I),i] over I slice(N,N[j],j)
206+
@loop a[I,i] = u_BC(i,loc(i,I),t)+a[I+δ(j,I),i]-u_BC(i,loc(i,I+δ(j,I)),t) over I slice(N,1,j)
207+
@loop a[I,i] = u_BC(i,loc(i,I),t)+a[I-δ(j,I),i]-u_BC(i,loc(i,I-δ(j,I)),t) over I slice(N,N[j],j)
208208
end
209209
end
210210
end

test/maintests.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,26 @@ end
358358
@test GPUArrays.@allowscalar all(sim.flow.u[1,:,1] .≈ sim.flow.u[end,:,1])
359359
end
360360
end
361+
362+
@testset "Rotating reference frame" begin
363+
function rotating_reference(N,x₀::SVector{2,T}::T,mem=Array) where T
364+
function velocity(i,x,t)
365+
s,c = sincos*t); y = ω*(x-x₀)
366+
i==1 ? s*y[1]+c*y[2] : -c*y[1]+s*y[2]
367+
end
368+
coriolis(i,x,t) = i==1 ? 2ω*velocity(2,x,t) : -2ω*velocity(1,x,t)
369+
centrifugal(i,x,t) = ω^2*(x-x₀)[i]
370+
g(i,x,t) = coriolis(i,x,t)+centrifugal(i,x,t)
371+
udf(a::Flow,t) = WaterLily.@loop a.f[Ii] += g(last(Ii),loc(Ii,eltype(a.f)),t) over Ii in CartesianIndices(a.f)
372+
simg = Simulation((N,N),velocity,N; g, U=1, T, mem) # use g
373+
simg,Simulation((N,N),velocity,N; U=1, T, mem),udf
374+
end
375+
L = 4
376+
simg,sim,udf = rotating_reference(2L,SA_F64[L,L],1/L,Array)
377+
sim_step!(simg);sim_step!(sim;udf)
378+
@test L₂(simg.flow.p)==L₂(simg.flow.p)<3e-3 # should be zero
379+
end
380+
361381
@testset "Circle in accelerating flow" begin
362382
for f arrays
363383
make_accel_circle(radius=32,H=16) = Simulation(radius.*(2H,2H),

0 commit comments

Comments
 (0)