Skip to content

Commit

Permalink
set time during initialize! model
Browse files Browse the repository at this point in the history
  • Loading branch information
milankl committed Oct 19, 2023
1 parent 0c44b11 commit 5af79aa
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
3 changes: 3 additions & 0 deletions src/SpeedyWeather.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import BitInformation: round, round!
import UnicodePlots
import ProgressMeter

# to avoid a `using Dates` to pass on DateTime arguments
export DateTime

# EXPORT MONOLITHIC INTERFACE TO SPEEDY
export run_speedy,
run_speedy!,
Expand Down
28 changes: 17 additions & 11 deletions src/dynamics/models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ $(TYPEDSIGNATURES)
Calls all `initialize!` functions for components of `model`,
except for `model.output` and `model.feedback` which are always called
at in `time_stepping!`."""
function initialize!(model::Barotropic)
function initialize!(model::Barotropic;time::DateTime = DEFAULT_DATE)
(;spectral_grid) = model

spectral_grid.nlev > 1 && @warn "Only nlev=1 supported for BarotropicModel, \
Expand All @@ -68,6 +68,7 @@ function initialize!(model::Barotropic)
# initial conditions
prognostic_variables = PrognosticVariables(spectral_grid,model)
initialize!(prognostic_variables,model.initial_conditions,model)
prognostic_variables.clock.time = time # set the time

diagnostic_variables = DiagnosticVariables(spectral_grid,model)
return Simulation(prognostic_variables,diagnostic_variables,model)
Expand Down Expand Up @@ -115,7 +116,7 @@ $(TYPEDSIGNATURES)
Calls all `initialize!` functions for components of `model`,
except for `model.output` and `model.feedback` which are always called
at in `time_stepping!` and `model.implicit` which is done in `first_timesteps!`."""
function initialize!(model::ShallowWater)
function initialize!(model::ShallowWater;time::DateTime = DEFAULT_DATE)
(;spectral_grid) = model

spectral_grid.nlev > 1 && @warn "Only nlev=1 supported for ShallowWaterModel, \
Expand All @@ -129,6 +130,7 @@ function initialize!(model::ShallowWater)
# initial conditions
prognostic_variables = PrognosticVariables(spectral_grid,model)
initialize!(prognostic_variables,model.initial_conditions,model)
prognostic_variables.clock.time = time # set the time

diagnostic_variables = DiagnosticVariables(spectral_grid,model)
return Simulation(prognostic_variables,diagnostic_variables,model)
Expand Down Expand Up @@ -189,7 +191,7 @@ $(TYPEDSIGNATURES)
Calls all `initialize!` functions for components of `model`,
except for `model.output` and `model.feedback` which are always called
at in `time_stepping!` and `model.implicit` which is done in `first_timesteps!`."""
function initialize!(model::PrimitiveDry)
function initialize!(model::PrimitiveDry;time::DateTime = DEFAULT_DATE)
(;spectral_grid) = model

# numerics (implicit is initialized later)
Expand All @@ -209,10 +211,12 @@ function initialize!(model::PrimitiveDry)
# initial conditions
prognostic_variables = PrognosticVariables(spectral_grid,model)
initialize!(prognostic_variables,model.initial_conditions,model)

(;time) = prognostic_variables.clock
initialize!(prognostic_variables.ocean,time,model)
initialize!(prognostic_variables.land,time,model)
(;clock) = prognostic_variables
clock.time = time # set the time

# initialize ocean and land and synchronize clocks
initialize!(prognostic_variables.ocean,clock.time,model)
initialize!(prognostic_variables.land,clock.time,model)

diagnostic_variables = DiagnosticVariables(spectral_grid,model)
return Simulation(prognostic_variables,diagnostic_variables,model)
Expand Down Expand Up @@ -278,7 +282,7 @@ $(TYPEDSIGNATURES)
Calls all `initialize!` functions for components of `model`,
except for `model.output` and `model.feedback` which are always called
at in `time_stepping!` and `model.implicit` which is done in `first_timesteps!`."""
function initialize!(model::PrimitiveWet)
function initialize!(model::PrimitiveWet;time::DateTime = DEFAULT_DATE)
(;spectral_grid) = model

# numerics (implicit is initialized later)
Expand All @@ -301,10 +305,12 @@ function initialize!(model::PrimitiveWet)
# initial conditions
prognostic_variables = PrognosticVariables(spectral_grid,model)
initialize!(prognostic_variables,model.initial_conditions,model)
(;clock) = prognostic_variables
clock.time = time # set the time

(;time) = prognostic_variables.clock
initialize!(prognostic_variables.ocean,time,model)
initialize!(prognostic_variables.land,time,model)
# initialize ocean and land and synchronize clocks
initialize!(prognostic_variables.ocean,clock.time,model)
initialize!(prognostic_variables.land,clock.time,model)

diagnostic_variables = DiagnosticVariables(spectral_grid,model)
return Simulation(prognostic_variables,diagnostic_variables,model)
Expand Down
5 changes: 3 additions & 2 deletions src/physics/boundary_layer.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Concrete type that disables the boundary layer drag scheme."""
struct NoBoundaryLayerDrag{NF} <: BoundaryLayerDrag{NF} end

NoBoundaryLayerDrag(SG::SpectralGrid) = NoBoundaryLayerDrag{SG.NF}()

"""NoBoundaryLayer scheme does not need any initialisation."""
function initialize!( scheme::NoBoundaryLayerDrag,
model::PrimitiveEquation)
Expand All @@ -9,8 +11,7 @@ end

"""NoBoundaryLayer scheme just passes."""
function boundary_layer_drag!( column::ColumnVariables,
scheme::NoBoundaryLayerDrag,
model::PrimitiveEquation)
scheme::NoBoundaryLayerDrag)
return nothing
end

Expand Down
9 changes: 2 additions & 7 deletions src/run_speedy.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
"""
$(TYPEDSIGNATURES)
Run a SpeedyWeather.jl `simulation`. The `simulation.model` is assumed to be initialized,
otherwise use `initialize=true` as keyword argument."""
Run a SpeedyWeather.jl `simulation`. The `simulation.model` is assumed to be initialized."""
function run!( simulation::Simulation;
n_days::Real = 10,
startdate::Union{Nothing,DateTime} = nothing,
output::Bool = false)

(;prognostic_variables, diagnostic_variables, model) = simulation
(;clock) = prognostic_variables

# set the clock
if typeof(startdate) == DateTime
clock.time = startdate
end
# set the clock's enddate
clock.n_days = n_days
initialize!(clock,model.time_stepping)

Expand Down

0 comments on commit 5af79aa

Please sign in to comment.