-
Couldn't load subscription status.
- Fork 22
Implementing checkpointer for coupled model #401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 12 commits
806be1e
46b7bb2
75b8182
55106ba
61f91f5
fb5d35d
e39c87a
d15439f
a0dca49
8ff3748
3fdf785
2328bb5
9ab0df1
5bd34f8
9e2af01
4f5ff2e
ba2521a
b75d6e0
f1cae4f
dfb57fa
76dd720
3177cf2
868c870
5f02123
f9087aa
4b0ebeb
3f0b9d5
f4aa21e
0e0a168
f56ca8e
f8c1444
cfba574
9f811df
4110aca
e56515f
a9be97c
afd7a66
1fddbf2
8699207
9f9ca89
ba80b56
90abea4
9efd6b8
006574f
e3029cb
1e8d638
5a69a52
a74499f
0a46067
98ec18b
f9e9e60
39c347a
5281eab
368358e
021c306
48dd1b1
fdf45d7
875d045
1e34bb5
1f3a46b
4f9425a
bf96083
cd7f0c5
47d1121
8bd0d36
ed8c6df
72efbc4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| using ClimaOcean | ||
| using Oceananigans | ||
| using Oceananigans.Units | ||
| using CFTime | ||
| using Dates | ||
| using Printf | ||
|
|
||
| arch = CPU() | ||
|
|
||
| Nx = 144 | ||
| Ny = 60 | ||
| Nz = 40 | ||
|
|
||
| grid = LatitudeLongitudeGrid(arch; | ||
| size = (Nx, Ny, Nz), | ||
| halo = (7, 7, 7), | ||
| z = (-6000, 0), | ||
| latitude = (-75, 75), | ||
| longitude = (0, 360)) | ||
|
|
||
| ocean = ocean_simulation(grid) | ||
|
|
||
| # date = DateTimeProlepticGregorian(1993, 1, 1) | ||
| # set!(ocean.model, T=ECCOMetadata(:temperature; dates=date), | ||
| # S=ECCOMetadata(:salinity; dates=date)) | ||
|
|
||
| radiation = Radiation(arch) | ||
|
|
||
| atmosphere = JRA55PrescribedAtmosphere(arch; backend=JRA55NetCDFBackend(41)) | ||
|
|
||
| coupled_model = OceanSeaIceModel(ocean; atmosphere, radiation) | ||
|
|
||
| simulation = Simulation(coupled_model; Δt=10, stop_iteration=8) | ||
|
|
||
| wall_time = Ref(time_ns()) | ||
|
|
||
| function progress(sim) | ||
| ocean = sim.model.ocean | ||
| atmosphere = sim.model.atmosphere | ||
|
|
||
| u, v, w = ocean.model.velocities | ||
| T = ocean.model.tracers.T | ||
|
|
||
| Tmax = maximum(interior(T)) | ||
| Tmin = minimum(interior(T)) | ||
|
|
||
| umax = (maximum(abs, interior(u)), | ||
| maximum(abs, interior(v)), | ||
| maximum(abs, interior(w))) | ||
|
|
||
| step_time = 1e-9 * (time_ns() - wall_time[]) | ||
|
|
||
| msg = @sprintf("Iter: %d, sim time: %s, atmos time: %s, ocean time: %s", iteration(sim), sim.model.clock.time, atmosphere.clock.time, ocean.model.clock.time) | ||
| msg *= @sprintf(", max|u|: (%.2e, %.2e, %.2e) m s⁻¹, extrema(T): (%.2f, %.2f) ᵒC, wall time: %s", | ||
| umax..., Tmax, Tmin, prettytime(step_time)) | ||
|
|
||
| @info msg | ||
|
|
||
| wall_time[] = time_ns() | ||
| end | ||
|
|
||
| simulation.callbacks[:progress] = Callback(progress, IterationInterval(1)) | ||
|
|
||
| outputs = merge(ocean.model.tracers, ocean.model.velocities) | ||
|
|
||
| simulation.output_writers[:surface] = JLD2OutputWriter(ocean.model, outputs; | ||
| schedule = IterationInterval(2), | ||
| filename = "surface", | ||
| indices = (:, :, grid.Nz), | ||
| with_halos = true, | ||
| overwrite_existing = true, | ||
| array_type = Array{Float32}) | ||
|
|
||
| output_dir = "." | ||
| prefix = "checkpointer_mwe" | ||
|
|
||
| simulation.output_writers[:checkpoint] = Checkpointer(ocean.model; | ||
| schedule = IterationInterval(3), | ||
| prefix = prefix, | ||
| dir = output_dir, | ||
| verbose = true, | ||
| overwrite_existing = true) | ||
|
|
||
| run!(simulation) | ||
|
|
||
| simulation.stop_iteration += 5 | ||
|
|
||
| run!(simulation, pickup=true) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| using Oceananigans | ||
| using Oceananigans.OutputWriters: checkpoint_path | ||
| using Oceananigans.TimeSteppers: Clock | ||
| using Oceananigans: SeawaterBuoyancy | ||
| using ClimaSeaIce.SeaIceThermodynamics: melting_temperature | ||
| using KernelAbstractions: @kernel, @index | ||
|
|
||
| using SeawaterPolynomials: TEOS10EquationOfState | ||
|
|
||
| import Thermodynamics as AtmosphericThermodynamics | ||
|
|
@@ -13,11 +13,11 @@ import Oceananigans: fields, prognostic_fields | |
| import Oceananigans.Architectures: architecture | ||
| import Oceananigans.Fields: set! | ||
| import Oceananigans.Models: timestepper, NaNChecker, default_nan_checker | ||
| import Oceananigans.OutputWriters: default_included_properties | ||
| import Oceananigans.Simulations: reset!, initialize!, iteration | ||
| import Oceananigans.OutputWriters: default_included_properties, checkpointer_address, | ||
| write_output!, initialize_jld2_file! | ||
| import Oceananigans.Simulations: reset!, initialize!, iteration, run! | ||
| import Oceananigans.TimeSteppers: time_step!, update_state!, time | ||
| import Oceananigans.Utils: prettytime | ||
| import Oceananigans.Models: timestepper, NaNChecker, default_nan_checker | ||
|
|
||
| struct OceanSeaIceModel{I, A, O, F, C, Arch} <: AbstractModel{Nothing, Arch} | ||
| architecture :: Arch | ||
|
|
@@ -29,6 +29,7 @@ struct OceanSeaIceModel{I, A, O, F, C, Arch} <: AbstractModel{Nothing, Arch} | |
| end | ||
|
|
||
| const OSIM = OceanSeaIceModel | ||
| const OSIMSIM = Simulation{<:OceanSeaIceModel} | ||
|
|
||
| function Base.summary(model::OSIM) | ||
| A = nameof(typeof(architecture(model))) | ||
|
|
@@ -59,9 +60,11 @@ prettytime(model::OSIM) = prettytime(model.clock.time) | |
| iteration(model::OSIM) = model.clock.iteration | ||
| timestepper(::OSIM) = nothing | ||
| default_included_properties(::OSIM) = tuple() | ||
| prognostic_fields(cm::OSIM) = nothing | ||
| prognostic_fields(::OSIM) = nothing | ||
| fields(::OSIM) = NamedTuple() | ||
| default_clock(TT) = Oceananigans.TimeSteppers.Clock{TT}(0, 0, 1) | ||
| time(model::OSIM) = model.clock.time | ||
| checkpointer_address(::OSIM) = "HydrostaticFreeSurfaceModel" | ||
|
|
||
| function reset!(model::OSIM) | ||
| reset!(model.ocean) | ||
|
|
@@ -73,6 +76,26 @@ function initialize!(model::OSIM) | |
| return nothing | ||
| end | ||
|
|
||
| initialize_jld2_file!(filepath, init, jld2_kw, including, outputs, model::OSIM) = | ||
| initialize_jld2_file!(filepath, init, jld2_kw, including, outputs, model.ocean.model) | ||
|
|
||
| write_output!(c::Checkpointer, model::OSIM) = write_output!(c, model.ocean.model) | ||
|
|
||
| function set!(sim::OSIMSIM, pickup::Union{Bool, Integer, String}) | ||
navidcy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| checkpoint_file_path = checkpoint_path(pickup, sim.output_writers) | ||
|
|
||
| set!(sim.model.ocean.model, checkpoint_file_path) | ||
|
|
||
| sim.model.clock.iteration = sim.model.ocean.model.clock.iteration | ||
| sim.model.clock.time = sim.model.ocean.model.clock.time | ||
|
|
||
| # Setting the atmosphere time to the ocean time | ||
| sim.model.atmosphere.clock.iteration = sim.model.ocean.model.clock.iteration | ||
| sim.model.atmosphere.clock.time = sim.model.ocean.model.clock.time | ||
|
||
|
|
||
| return nothing | ||
| end | ||
|
|
||
| reference_density(unsupported) = | ||
| throw(ArgumentError("Cannot extract reference density from $(typeof(unsupported))")) | ||
|
|
||
|
|
@@ -114,7 +137,7 @@ function OceanSeaIceModel(ocean, sea_ice=FreezingLimitedOceanTemperature(eltype( | |
| pop!(ocean.callbacks, :wall_time_limit_exceeded, nothing) | ||
| pop!(ocean.callbacks, :nan_checker, nothing) | ||
| end | ||
|
|
||
| if sea_ice isa SeaIceSimulation | ||
| if !isnothing(sea_ice.callbacks) | ||
| pop!(sea_ice.callbacks, :stop_time_exceeded, nothing) | ||
|
|
@@ -151,10 +174,8 @@ function OceanSeaIceModel(ocean, sea_ice=FreezingLimitedOceanTemperature(eltype( | |
| return ocean_sea_ice_model | ||
| end | ||
|
|
||
| time(coupled_model::OceanSeaIceModel) = coupled_model.clock.time | ||
|
|
||
| # Check for NaNs in the first prognostic field (generalizes to prescribed velocities). | ||
| function default_nan_checker(model::OceanSeaIceModel) | ||
| function default_nan_checker(model::OSIM) | ||
| u_ocean = model.ocean.model.velocities.u | ||
| nan_checker = NaNChecker((; u_ocean)) | ||
| return nan_checker | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.