-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import ClimaAtmos as CA | ||
import SurfaceFluxes as SF | ||
import ClimaAtmos.Parameters as CAP | ||
import ClimaCore as CC | ||
import Thermodynamics as TD | ||
import CloudMicrophysics as CM | ||
import SciMLBase | ||
import ClimaCore.Spaces | ||
using Test | ||
|
||
@testset begin | ||
"Test restarts across configuration combinations" | ||
### Test Description | ||
# Generate a simulation with some complexity of | ||
# config arguments. Some config combinations are | ||
# incompatible so we do not sweep over all possible | ||
# iterations. | ||
|
||
# Modify the timestep to 1-second increments. | ||
# Save simulation state at each timestep, | ||
# and generate a restart file at 0secs, 2secs simulation time. | ||
# Verify objects are identical (i.e. restarts result | ||
# in the same simulation states as if one were to advance | ||
# the timestepper uninterrupted.) | ||
|
||
# TODO: Restart and diagnostic behaviour needs to be | ||
# clearly defined when config files have different | ||
# settings (or when tendency computations conflict with | ||
# dt / t_end parsed args) | ||
|
||
for configuration in ["column"] | ||
for moisture in ["equil"] | ||
for turb_conv in ["diagnostic_edmfx", "prognostic_edmfx"] | ||
for precip in ["0M", "1M"] | ||
|
||
output_loc = mktempdir(; cleanup = true) | ||
test_dict = Dict( | ||
"check_nan_every" => 3, | ||
"log_progress" => false, | ||
"moist" => moisture, | ||
"precip_model" => precip, | ||
"config" => configuration, | ||
"turbconv" => turb_conv, | ||
"perturb_initstate" => false, | ||
"dt" => "1secs", | ||
"t_end" => "3secs", | ||
"output_default_diagnostics" => false, | ||
"enable_diagnostics" => false, | ||
) | ||
|
||
### Boilerplate default integrator objects | ||
config = CA.AtmosConfig( | ||
merge( | ||
test_dict, | ||
Dict( | ||
"output_dir" => output_loc, | ||
"dt_save_state_to_disk" => "2secs", | ||
), | ||
), | ||
) | ||
|
||
@info config.parsed_args["output_dir"] | ||
simulation = CA.get_simulation(config) | ||
CA.solve_atmos!(simulation) | ||
|
||
restart_dir = simulation.output_dir | ||
@test isfile(joinpath(restart_dir), "day0.2.hdf5") | ||
restart₁ = joinpath(restart_dir, "day0.2.hdf5") | ||
|
||
@info "Restart #1 from: " restart₁ | ||
config₁ = CA.AtmosConfig( | ||
merge( | ||
test_dict, | ||
Dict( | ||
"restart_file" => restart₁, | ||
"output_dir" => output_loc, | ||
), | ||
), | ||
) | ||
simulation_test₁ = CA.get_simulation(config₁) | ||
@info "Advancing restarted simulation" | ||
CA.solve_atmos!(simulation_test₁) | ||
@info "Simulation complete" | ||
|
||
Y = simulation.integrator.u | ||
Y₁ = simulation_test₁.integrator.u | ||
FT = eltype(Y) | ||
|
||
@info "Check simulation states" | ||
@test Spaces.axes(Y) == Spaces.axes(Y₁) | ||
@test extrema(parent(Y₁.c.ρ) .- parent(Y.c.ρ)) == | ||
(FT(0), FT(0)) | ||
@test extrema(parent(Y₁.c.ρe_tot) .- parent(Y.c.ρe_tot)) == | ||
(FT(0), FT(0)) | ||
@test extrema(parent(Y₁.c.ρq_tot) .- parent(Y.c.ρq_tot)) == | ||
(FT(0), FT(0)) | ||
|
||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters