Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
glwagner committed Mar 8, 2025
1 parent f1d1fbf commit 2664904
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ext/OceananigansReactantExt/Simulations/simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function Simulation(model::ReactantModel; Δt,

return Simulation(model,
Δt,
Inf,
stop_iteration,
nothing, # disallow stop_time
Inf,
diagnostics,
Expand Down
23 changes: 17 additions & 6 deletions test/test_reactant.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ r_run!(simulation)

bottom_height(x, y) = - 0.5

function r_run!(sim, r_time_step!, r_first_time_step!)
stop_iteration = sim.stop_iteration
start_iteration = iteration(sim)
for n = start_iteration:stop_iteration
if n == 1
r_first_time_step!(sim.model, sim.Δt)
else
r_time_step!(sim.model, sim.Δt)
end
end
return nothing
end

function test_reactant_model_correctness(GridType, ModelType, grid_kw, model_kw; immersed_boundary_grid=true)
r_arch = ReactantState()
r_grid = GridType(r_arch; grid_kw...)
Expand Down Expand Up @@ -113,11 +126,11 @@ function test_reactant_model_correctness(GridType, ModelType, grid_kw, model_kw;
r_simulation = Simulation(r_model; Δt, stop_iteration, verbose=false)

@info " Compiling r_run!:"
r_run! = @compile sync=true run!(r_simulation)
# r_run! = @compile run!(r_simulation)
r_first_time_step! = @compile sync=true time_step!(r_model, Δt, euler=true)
r_time_step! = @compile sync=true time_step!(r_model, Δt)

@info " Executing r_run!:"
r_run!(r_simulation)
r_run!(r_simulation, r_time_step!, r_first_time_step!)

@info " After running 3 time steps, the reactant model:"
@test iteration(r_simulation) == stop_iteration
Expand All @@ -142,7 +155,7 @@ function test_reactant_model_correctness(GridType, ModelType, grid_kw, model_kw;

# Running a few more time-steps works too:
r_simulation.stop_iteration += 2
r_run!(r_simulation)
r_run!(r_simulation, r_time_step!, r_first_time_step!)
@test iteration(r_simulation) == 5
@test time(r_simulation) == 5Δt

Expand All @@ -160,7 +173,6 @@ end
@inbounds f[i, j, k] += 1
end

#=
@testset "Reactanigans unit tests" begin
@info "Performing Reactanigans unit tests..."
arch = ReactantState()
Expand Down Expand Up @@ -250,7 +262,6 @@ end
end
end
end
=#

@testset "Reactant Super Simple Simulation Tests" begin
@info "Performing Reactanigans super simple simulation tests..."
Expand Down

0 comments on commit 2664904

Please sign in to comment.