Skip to content

Commit c80d198

Browse files
committed
improve tests for non-uniform BCs and improve error message
1 parent 341f046 commit c80d198

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/WaterLily.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ mutable struct Simulation <: AbstractSimulation
6767
Δt=0.25, ν=0., g=nothing, U=nothing, ϵ=1, perdir=(),
6868
=nothing, exitBC=false, body::AbstractBody=NoBody(),
6969
T=Float32, mem=Array) where N
70-
@assert !(isa(u_BC,Function) && isa(uλ,Function)) "`u_BC` and `uλ` cannot be both specified as Function"
70+
@assert !(isa(u_BC,Function) && isa(uλ,Function)) "`u_BC` will be used to generate `uλ=u_BC(t=0)` do not provide both"
7171
@assert !(isnothing(U) && isa(u_BC,Function)) "`U` must be specified if `u_BC` is a Function"
7272
isa(g,Function) && @assert first(methods(g)).nargs==4 "g::Function needs to be defined as g(i,x,t)"
7373
isa(g,Function) && @assert all(typeof.(ntuple(i->g(i,zeros(SVector{N}),zero(T)),N)).==T) "`g` is not type stable"

test/maintests.jl

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ using ReadVTK, WriteVTK
4949
Ubc(i,x,t) = i==1 ? 1.0 : 0.5
5050
v = rand(Ng..., D) |> f # vector
5151
BC!(v,Ubc,false); BC!(u,U,false) # make sure we apply the same
52-
@test all(v[1, :, 1] . u[1, :, 1]) && all(v[2, :, 1] . u[2, :, 1]) && all(v[end, :, 1] . u[end, :, 1])
53-
@test all(v[:, 1, 2] . u[:, 1, 2]) && all(v[:, 2, 2] . u[:, 2, 2]) && all(v[:, end, 2] . u[:, end, 2])
52+
@test GPUArrays.@allowscalar all(v[1, :, 1] .== u[1, :, 1]) && all(v[2, :, 1] .== u[2, :, 1]) && all(v[end, :, 1] .== u[end, :, 1])
53+
@test GPUArrays.@allowscalar all(v[:, 1, 2] .== u[:, 1, 2]) && all(v[:, 2, 2] .== u[:, 2, 2]) && all(v[:, end, 2] .== u[:, end, 2])
5454
# test exit bc
5555
GPUArrays.@allowscalar v[end,:,1] .= 3
5656
BC!(v,Ubc,true) # save exit values
@@ -65,6 +65,20 @@ using ReadVTK, WriteVTK
6565
BC!(u,U,true,(1,)) #saveexit has no effect here as x-periodic
6666
@test GPUArrays.@allowscalar all(u[1:2, :, 1] .== u[end-1:end, :, 1]) && all(u[1:2, :, 2] .== u[end-1:end, :, 2]) &&
6767
all(u[:, 1, 2] .== U[2]) && all(u[:, 2, 2] .== U[2]) && all(u[:, end, 2] .== U[2])
68+
# test non-uniform BCs
69+
Ubc_1(i,x,t) = i==1 ? x[2] : x[1]
70+
v .= 0; BC!(v,Ubc_1)
71+
# the tangential BC change the value of the ghost cells on the other axis, so we cannot check it
72+
@test GPUArrays.@allowscalar all(v[1,2:end-1,1] .≈ v[end,2:end-1,1])
73+
@test GPUArrays.@allowscalar all(v[2:end-1,1,2] .≈ v[2:end-1,end,2])
74+
# more complex
75+
Ng, D = (8, 8, 8), 3
76+
u = zeros(Ng..., D) |> f # vector
77+
Ubc_2(i,x,t) = i==1 ? cos(2π*x[1]/8) : i==2 ? sin(2π*x[2]/8) : tan*x[3]/16)
78+
BC!(u,Ubc_2)
79+
@test GPUArrays.@allowscalar all(u[1,:,:,1] .≈ cos(-1π/4)) && all(u[2,:,:,1] .≈ cos(0)) && all(u[end,:,:,1] .≈ cos(6π/4))
80+
@test GPUArrays.@allowscalar all(u[:,1,:,2] .≈ sin(-1π/4)) && all(u[:,2,:,2] .≈ sin(0)) && all(u[:,end,:,2] .≈ sin(6π/4))
81+
@test GPUArrays.@allowscalar all(u[:,:,1,3] .≈ tan(-1π/16)) && all(u[:,:,2,3] .≈ tan(0)) && all(u[:,:,end,3].-tan(6π/16).<1e-6)
6882

6983
# test interpolation
7084
a = zeros(5,5,2) |> f; b = zeros(5,5) |> f
@@ -334,7 +348,16 @@ end
334348
)
335349
end
336350
end
337-
351+
@testset "Boundary Layer Flow" begin
352+
for f arrays
353+
make_bl_flow(L=32;T=Float32) = Simulation((L,L),
354+
(i,x,t)-> i==1 ? convert(Float32,4.0*(((x[2]+0.5)/2L)-((x[2]+0.5)/2L)^2)) : 0.f0,
355+
L;ν=0.001,U=1,mem=f,T,exitBC=false) # fails with exitBC=true, but the profile is maintained
356+
sim = make_bl_flow(32)
357+
sim_step!(sim,10)
358+
@test GPUArrays.@allowscalar all(sim.flow.u[1,:,1] .≈ sim.flow.u[end,:,1])
359+
end
360+
end
338361
@testset "Circle in accelerating flow" begin
339362
for f arrays
340363
make_accel_circle(radius=32,H=16) = Simulation(radius.*(2H,2H),

0 commit comments

Comments
 (0)