Skip to content

Commit

Permalink
Update rest of the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-ramadhan committed Feb 4, 2020
1 parent 7491bc3 commit de97f59
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ function run_ocean_large_eddy_simulation_regression_test(arch, closure)
S_bcs = HorizontallyPeriodicBCs( top = BoundaryCondition(Flux, 5e-8) )

# Model instantiation
grid = RegularCartesianGrid(size=(16, 16, 16), length=(16, 16, 16),
topology=(Periodic, Periodic, Bounded))

model = Model(
architecture = arch,
grid = RegularCartesianGrid(size=(16, 16, 16), length=(16, 16, 16)),
grid = grid,
coriolis = FPlane(f=1e-4),
buoyancy = SeawaterBuoyancy(equation_of_state=LinearEquationOfState=2e-4, β=8e-4)),
closure = closure,
Expand Down
4 changes: 3 additions & 1 deletion test/regression_tests/rayleigh_benard_regression_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ function run_rayleigh_benard_regression_test(arch)
bbcs = HorizontallyPeriodicBCs( top = BoundaryCondition(Value, 0.0),
bottom = BoundaryCondition(Value, Δb))

grid = RegularCartesianGrid(size=(Nx, Ny, Nz), length=(Lx, Ly, Lz),
topology=(Periodic, Periodic, Bounded))
model = Model(
architecture = arch,
grid = RegularCartesianGrid(size=(Nx, Ny, Nz), length=(Lx, Ly, Lz)),
grid = grid,
closure = ConstantIsotropicDiffusivity=ν, κ=κ),
tracers = (:b, :c),
buoyancy = BuoyancyTracer(),
Expand Down
3 changes: 2 additions & 1 deletion test/regression_tests/thermal_bubble_regression_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ function run_thermal_bubble_regression_test(arch)
Lx, Ly, Lz = 100, 100, 100
Δt = 6

grid = RegularCartesianGrid(size=(Nx, Ny, Nz), length=(Lx, Ly, Lz))
grid = RegularCartesianGrid(size=(Nx, Ny, Nz), length=(Lx, Ly, Lz),
topology=(Periodic, Periodic, Bounded))
closure = ConstantIsotropicDiffusivity=4e-2, κ=4e-2)
model = Model(architecture=arch, grid=grid, closure=closure, coriolis=FPlane(f=1e-4))

Expand Down
12 changes: 6 additions & 6 deletions test/test_abstract_operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function z_derivative(a)
end

function x_derivative_cell(FT, arch)
grid = RegularCartesianGrid(FT, size=(3, 3, 3), length=(3, 3, 3))
grid = RegularCartesianGrid(FT, size=(3, 3, 3), length=(3, 3, 3), topology=DT)
a = Field(Cell, Cell, Cell, arch, grid)
dx_a = ∂x(a)

Expand Down Expand Up @@ -232,7 +232,7 @@ end

for FT in float_types
arch = CPU()
grid = RegularCartesianGrid(FT, size=(3, 3, 3), length=(3, 3, 3))
grid = RegularCartesianGrid(FT, size=(3, 3, 3), length=(3, 3, 3), topology=DT)
u, v, w = VelocityFields(arch, grid)
c = Field(Cell, Cell, Cell, arch, grid)

Expand Down Expand Up @@ -277,7 +277,7 @@ end
for FT in float_types
num1 = FT(π)
num2 = FT(42)
grid = RegularCartesianGrid(FT, size=(3, 3, 3), length=(3, 3, 3))
grid = RegularCartesianGrid(FT, size=(3, 3, 3), length=(3, 3, 3), topology=DT)

u, v, w = VelocityFields(arch, grid)
T, S = TracerFields(arch, grid, (:T, :S))
Expand All @@ -296,7 +296,7 @@ end
arch = CPU()
@info " Testing derivatives..."
for FT in float_types
grid = RegularCartesianGrid(FT, size=(3, 3, 3), length=(3, 3, 3))
grid = RegularCartesianGrid(FT, size=(3, 3, 3), length=(3, 3, 3), topology=DT)

u, v, w = VelocityFields(arch, grid)
T, S = TracerFields(arch, grid, (:T, :S))
Expand All @@ -314,7 +314,7 @@ end
arch = CPU()
Nx = 3 # Δx=1, xC = 0.5, 1.5, 2.5
for FT in float_types
grid = RegularCartesianGrid(FT, size=(Nx, Nx, Nx), length=(Nx, Nx, Nx))
grid = RegularCartesianGrid(FT, size=(Nx, Nx, Nx), length=(Nx, Nx, Nx), topology=DT)
a, b = (Field(Cell, Cell, Cell, arch, grid) for i in 1:2)

set!(b, 2)
Expand Down Expand Up @@ -357,7 +357,7 @@ end
model = Model(
architecture = arch,
float_type = FT,
grid = RegularCartesianGrid(FT, size=(16, 16, 16), length=(1, 1, 1))
grid = RegularCartesianGrid(FT, size=(16, 16, 16), length=(1, 1, 1), topology=DT)
)

@testset "Derivative computations [$FT, $(typeof(arch))]" begin
Expand Down
20 changes: 10 additions & 10 deletions test/test_boundary_conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ function test_z_boundary_condition_simple(arch, FT, fldname, bctype, bc, Nx, Ny)
fieldbcs = HorizontallyPeriodicBCs(top=bc)
modelbcs = HorizontallyPeriodicSolutionBCs(; Dict(fldname=>fieldbcs)...)

model = Model(grid=RegularCartesianGrid(FT; size=(Nx, Ny, Nz), length=(0.1, 0.2, 0.3)), architecture=arch,
float_type=FT, boundary_conditions=modelbcs)
grid = RegularCartesianGrid(FT, size=(Nx, Ny, Nz), length=(0.1, 0.2, 0.3), topology=DT)
model = Model(grid=grid, architecture=arch, float_type=FT, boundary_conditions=modelbcs)

time_step!(model, 1, 1e-16)

return typeof(model) <: Model
return model isa Model
end

function test_z_boundary_condition_top_bottom_alias(arch, FT, fldname)
Expand All @@ -24,8 +24,8 @@ function test_z_boundary_condition_top_bottom_alias(arch, FT, fldname)
fieldbcs = HorizontallyPeriodicBCs(top=top_bc, bottom=bottom_bc)
modelbcs = HorizontallyPeriodicSolutionBCs(; Dict(fldname=>fieldbcs)...)

model = Model(grid=RegularCartesianGrid(FT; size=(N, N, N), length=(0.1, 0.2, 0.3)), architecture=arch,
float_type=FT, boundary_conditions=modelbcs)
grid = RegularCartesianGrid(FT, size=(N, N, N), length=(0.1, 0.2, 0.3), topology=DT)
model = Model(grid=grid, architecture=arch, float_type=FT, boundary_conditions=modelbcs)

bcs = getfield(model.boundary_conditions.solution, fldname)

Expand All @@ -47,8 +47,8 @@ function test_z_boundary_condition_array(arch, FT, fldname)
fieldbcs = HorizontallyPeriodicBCs(top=value_bc)
modelbcs = HorizontallyPeriodicSolutionBCs(; Dict(fldname=>fieldbcs)...)

model = Model(grid=RegularCartesianGrid(FT; size=(Nx, Ny, Nz), length=(0.1, 0.2, 0.3)), architecture=arch,
float_type=FT, boundary_conditions=modelbcs)
grid = RegularCartesianGrid(FT, size=(Nx, Ny, Nz), length=(0.1, 0.2, 0.3), topology=DT)
model = Model(grid=grid, architecture=arch, float_type=FT, boundary_conditions=modelbcs)

bcs = getfield(model.boundary_conditions.solution, fldname)

Expand All @@ -65,7 +65,7 @@ function test_flux_budget(arch, FT, fldname)
fieldbcs = HorizontallyPeriodicBCs(bottom=flux_bc)
modelbcs = HorizontallyPeriodicSolutionBCs(; Dict(fldname=>fieldbcs)...)

grid = RegularCartesianGrid(FT; size=(N, N, N), length=(1, 1, Lz))
grid = RegularCartesianGrid(FT, size=(N, N, N), length=(1, 1, Lz), topology=DT)
closure = ConstantIsotropicDiffusivity(FT; ν=κ, κ=κ)
model = Model(grid=grid, closure=closure, architecture=arch,
float_type=FT, buoyancy=nothing, boundary_conditions=modelbcs)
Expand Down Expand Up @@ -100,7 +100,7 @@ function fluxes_with_diffusivity_boundary_conditions_are_correct(arch, FT)
flux = - κ₀ * bz

tracer_names = (:b,)
grid = RegularCartesianGrid(size=(16, 16, 16), length=(1, 1, Lz))
grid = RegularCartesianGrid(size=(16, 16, 16), length=(1, 1, Lz), topology=DT)
closure = with_tracers(tracer_names, AnisotropicMinimumDissipation())
diffusivities = TurbulentDiffusivities(arch, grid, tracer_names, closure)

Expand All @@ -111,7 +111,7 @@ function fluxes_with_diffusivity_boundary_conditions_are_correct(arch, FT)
κₑ_bcs = HorizontallyPeriodicBCs(bottom=BoundaryCondition(Value, κ₀))
diffusivities_bcs = (νₑ=νₑ_bcs, κₑ=(b=κₑ_bcs))

model_bcs = ModelBoundaryConditions(tracer_names, diffusivities, solution_bcs;
model_bcs = ModelBoundaryConditions(tracer_names, diffusivities, solution_bcs;
diffusivities=diffusivities_bcs)

model = Model(grid=grid, architecture=arch, float_type=FT, tracers=tracer_names, buoyancy=BuoyancyTracer(),
Expand Down
8 changes: 4 additions & 4 deletions test/test_diagnostics.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function horizontal_average_is_correct(arch, FT)
grid = RegularCartesianGrid(size=(16, 16, 16), length=(100, 100, 100))
grid = RegularCartesianGrid(size=(16, 16, 16), length=(100, 100, 100), topology=DT)
model = Model(grid=grid, architecture=arch, float_type=FT)

T₀(x, y, z) = 20 + 0.01*z
Expand All @@ -13,7 +13,7 @@ function horizontal_average_is_correct(arch, FT)
end

function nan_checker_aborts_simulation(arch, FT)
grid=RegularCartesianGrid(size=(16, 16, 2), length=(1, 1, 1))
grid=RegularCartesianGrid(size=(16, 16, 2), length=(1, 1, 1), topology=DT)
model = Model(grid=grid, architecture=arch, float_type=FT)

# It checks for NaNs in w by default.
Expand All @@ -26,14 +26,14 @@ function nan_checker_aborts_simulation(arch, FT)
end

TestModel(::GPU, FT, ν=1.0, Δx=0.5) =
Model(grid = RegularCartesianGrid(FT; size=(16, 16, 16), length=(16Δx, 16Δx, 16Δx)),
Model(grid = RegularCartesianGrid(FT, size=(16, 16, 16), length=(16Δx, 16Δx, 16Δx), topology=DT),
closure = ConstantIsotropicDiffusivity(FT; ν=ν, κ=ν),
architecture = GPU(),
float_type = FT
)

TestModel(::CPU, FT, ν=1.0, Δx=0.5) =
Model(grid = RegularCartesianGrid(FT; size=(3, 3, 3), length=(3Δx, 3Δx, 3Δx)),
Model(grid = RegularCartesianGrid(FT, size=(3, 3, 3), length=(3Δx, 3Δx, 3Δx), topology=DT),
closure = ConstantIsotropicDiffusivity(FT; ν=ν, κ=ν),
architecture = CPU(),
float_type = FT
Expand Down
14 changes: 7 additions & 7 deletions test/test_dynamics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function relative_error(u_num, u, time)
end

function test_diffusion_simple(fieldname)
grid = RegularCartesianGrid(size=(1, 1, 16), length=(1, 1, 1))
grid = RegularCartesianGrid(size=(1, 1, 16), length=(1, 1, 1), topology=DT)
closure = ConstantIsotropicDiffusivity=1, κ=1)
model = Model(grid=grid, closure=closure, buoyancy=nothing)
field = getmodelfield(fieldname, model)
Expand All @@ -27,7 +27,7 @@ function test_diffusion_simple(fieldname)
end

function test_diffusion_budget_default(fieldname)
grid = RegularCartesianGrid(size=(1, 1, 16), length=(1, 1, 1))
grid = RegularCartesianGrid(size=(1, 1, 16), length=(1, 1, 1), topology=DT)
closure = ConstantIsotropicDiffusivity=1, κ=1)
model = Model(grid=grid, closure=closure, buoyancy=nothing)
field = getmodelfield(fieldname, model)
Expand All @@ -39,7 +39,7 @@ function test_diffusion_budget_default(fieldname)
end

function test_diffusion_budget_channel(fieldname)
grid = RegularCartesianGrid(size=(1, 16, 4), length=(1, 1, 1))
grid = RegularCartesianGrid(size=(1, 16, 4), length=(1, 1, 1), topology=DT)
closure = ConstantIsotropicDiffusivity=1, κ=1)
model = ChannelModel(grid=grid, closure=closure, buoyancy=nothing)
field = getmodelfield(fieldname, model)
Expand All @@ -58,7 +58,7 @@ end

function test_diffusion_cosine(fieldname)
Nz, Lz, κ, m = 128, π/2, 1, 2
grid = RegularCartesianGrid(size=(1, 1, Nz), length=(1, 1, Lz))
grid = RegularCartesianGrid(size=(1, 1, Nz), length=(1, 1, Lz), topology=DT)
closure = ConstantIsotropicDiffusivity=κ, κ=κ)
model = Model(grid=grid, closure=closure, buoyancy=nothing)
field = getmodelfield(fieldname, model)
Expand Down Expand Up @@ -111,7 +111,7 @@ function internal_wave_test(; N=128, Nt=10)
b₀(x, y, z) = b(x, y, z, 0)

# Create a model where temperature = buoyancy.
grid = RegularCartesianGrid(size=(N, 1, N), length=(L, L, L))
grid = RegularCartesianGrid(size=(N, 1, N), length=(L, L, L), topology=DT)
closure = ConstantIsotropicDiffusivity=ν, κ=κ)
model = Model(grid=grid, closure=closure, buoyancy=BuoyancyTracer(), tracers=:b, coriolis=FPlane(f=f))

Expand All @@ -134,7 +134,7 @@ function passive_tracer_advection_test(; N=128, κ=1e-12, Nt=100)
v₀(x, y, z) = V
T₀(x, y, z) = T(x, y, z, 0)

grid = RegularCartesianGrid(size=(N, N, 2), length=(L, L, L))
grid = RegularCartesianGrid(size=(N, N, 2), length=(L, L, L), topology=DT)
closure = ConstantIsotropicDiffusivity=κ, κ=κ)
model = Model(grid=grid, closure=closure)

Expand Down Expand Up @@ -164,7 +164,7 @@ function taylor_green_vortex_test(arch; FT=Float64, N=64, Nt=10)
@inline v(x, y, z, t) = sin(2π*x) * exp(-4π^2 * ν * t)

model = Model(architecture = arch,
grid = RegularCartesianGrid(FT; size=(Nx, Ny, Nz), length=(Lx, Ly, Lz)),
grid = RegularCartesianGrid(FT, size=(Nx, Ny, Nz), length=(Lx, Ly, Lz), topology=DT),
closure = ConstantIsotropicDiffusivity(FT; ν=1, κ=0), # Turn off diffusivity.
tracers = nothing,
buoyancy = nothing) # turn off buoyancy
Expand Down
10 changes: 5 additions & 5 deletions test/test_forcings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function time_step_with_forcing_functions(arch)

forcing = ModelForcing(u=Fu, v=Fv, w=Fw)

grid = RegularCartesianGrid(size=(16, 16, 16), length=(1, 1, 1))
grid = RegularCartesianGrid(size=(16, 16, 16), length=(1, 1, 1), topology=DT)
model = Model(grid=grid, architecture=arch, forcing=forcing)
time_step!(model, 1, 1)
return true
Expand All @@ -27,7 +27,7 @@ function time_step_with_forcing_functions_params(arch)

forcing = ModelForcing(u=Fu, v=Fv, w=Fw)

grid = RegularCartesianGrid(size=(16, 16, 16), length=(1, 1, 1))
grid = RegularCartesianGrid(size=(16, 16, 16), length=(1, 1, 1), topology=DT)
model = Model(grid=grid, architecture=arch, forcing=forcing, parameters==60,))
time_step!(model, 1, 1)
return true
Expand All @@ -39,23 +39,23 @@ function time_step_with_forcing_functions_sin_exp(arch)

forcing = ModelForcing(u=Fu, T=FT)

grid = RegularCartesianGrid(size=(16, 16, 16), length=(1, 1, 1))
grid = RegularCartesianGrid(size=(16, 16, 16), length=(1, 1, 1), topology=DT)
model = Model(grid=grid, architecture=arch, forcing=forcing)
time_step!(model, 1, 1)
return true
end

function time_step_with_simple_forcing(arch)
u_forcing = SimpleForcing((x, y, z, t) -> sin(x))
grid = RegularCartesianGrid(size=(16, 16, 16), length=(1, 1, 1))
grid = RegularCartesianGrid(size=(16, 16, 16), length=(1, 1, 1), topology=DT)
model = Model(grid=grid, architecture=arch, forcing=ModelForcing(u=u_forcing))
time_step!(model, 1, 1)
return true
end

function time_step_with_simple_forcing_parameters(arch)
u_forcing = SimpleForcing((x, y, z, t, p) -> sin(p.ω * x), parameters==π,))
grid = RegularCartesianGrid(size=(16, 16, 16), length=(1, 1, 1))
grid = RegularCartesianGrid(size=(16, 16, 16), length=(1, 1, 1), topology=DT)
model = Model(grid=grid, architecture=arch, forcing=ModelForcing(u=u_forcing))
time_step!(model, 1, 1)
return true
Expand Down
12 changes: 6 additions & 6 deletions test/test_models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function set_velocity_tracer_fields(arch, grid, fieldname, value, answer)
end

function initial_conditions_correctly_set(arch, FT)
model = Model(grid=RegularCartesianGrid(FT; size=(16, 16, 8), length=(1, 2, 3)),
model = Model(grid=RegularCartesianGrid(FT, size=(16, 16, 8), length=(1, 2, 3), topology=DT),
architecture=arch, float_type=FT)

# Set initial condition to some basic function we can easily check for.
Expand Down Expand Up @@ -52,7 +52,7 @@ end
@testset "Doubly periodic model" begin
@info " Testing doubly periodic model construction..."
for arch in archs, FT in float_types
model = Model(grid=RegularCartesianGrid(FT; size=(16, 16, 2), length=(1, 2, 3)),
model = Model(grid=RegularCartesianGrid(FT, size=(16, 16, 2), length=(1, 2, 3), topology=DT),
architecture=arch, float_type=FT)

# Just testing that a Model was constructed with no errors/crashes.
Expand All @@ -63,8 +63,8 @@ end
@testset "Reentrant channel model" begin
@info " Testing reentrant channel model construction..."
for arch in archs, FT in float_types
model = ChannelModel(grid=RegularCartesianGrid(FT; size=(16, 16, 2), length=(1, 2, 3)),
architecture=arch, float_type=FT)
grid = RegularCartesianGrid(FT, size=(16, 16, 2), length=(1, 2, 3), topology=(Periodic, Bounded, Bounded))
model = ChannelModel(grid=grid, architecture=arch, float_type=FT)

# Just testing that a ChannelModel was constructed with no errors/crashes.
@test true
Expand All @@ -74,7 +74,7 @@ end
@testset "Non-dimensional model" begin
@info " Testing non-dimensional model construction..."
for arch in archs, FT in float_types
grid = RegularCartesianGrid(FT; size=(16, 16, 2), length=(3, 2, 1))
grid = RegularCartesianGrid(FT, size=(16, 16, 2), length=(3, 2, 1), topology=DT)
model = NonDimensionalModel(architecture=arch, float_type=FT, grid=grid, Re=1, Pr=1, Ro=Inf)

# Just testing that a NonDimensionalModel was constructed with no errors/crashes.
Expand All @@ -88,7 +88,7 @@ end
N = (16, 16, 8)
L = (2π, 3π, 5π)

grid = RegularCartesianGrid(FT; size=N, length=L)
grid = RegularCartesianGrid(FT, size=N, length=L, topology=DT)
xF = reshape(grid.xF[1:end-1], N[1], 1, 1)
yC = reshape(grid.yC, 1, N[2], 1)
zC = reshape(grid.zC, 1, 1, N[3])
Expand Down
6 changes: 3 additions & 3 deletions test/test_output_writers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function run_thermal_bubble_netcdf_tests(arch)
Lx, Ly, Lz = 100, 100, 100
Δt = 6

grid = RegularCartesianGrid(size=(Nx, Ny, Nz), length=(Lx, Ly, Lz))
grid = RegularCartesianGrid(size=(Nx, Ny, Nz), length=(Lx, Ly, Lz), topology=DT)
closure = ConstantIsotropicDiffusivity=4e-2, κ=4e-2)
model = Model(architecture=arch, grid=grid, closure=closure)

Expand Down Expand Up @@ -73,7 +73,7 @@ function run_thermal_bubble_netcdf_tests(arch)
end

function run_jld2_file_splitting_tests(arch)
model = Model(grid=RegularCartesianGrid(size=(16, 16, 16), length=(1, 1, 1)))
model = Model(grid=RegularCartesianGrid(size=(16, 16, 16), length=(1, 1, 1), topology=DT))

u(model) = Array(model.velocities.u.data.parent)
fields = Dict(:u => u)
Expand Down Expand Up @@ -120,7 +120,7 @@ function run_thermal_bubble_checkpointer_tests(arch)
Lx, Ly, Lz = 100, 100, 100
Δt = 6

grid = RegularCartesianGrid(size=(Nx, Ny, Nz), length=(Lx, Ly, Lz))
grid = RegularCartesianGrid(size=(Nx, Ny, Nz), length=(Lx, Ly, Lz), topology=DT)
closure = ConstantIsotropicDiffusivity=4e-2, κ=4e-2)
true_model = Model(architecture=arch, grid=grid, closure=closure)

Expand Down
Loading

0 comments on commit de97f59

Please sign in to comment.