-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c351b5a
commit de6b8e0
Showing
24 changed files
with
338 additions
and
509 deletions.
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
77 changes: 77 additions & 0 deletions
77
experiments/ClimaCore/CoupledSimulations/coupled_simulation.jl
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,77 @@ | ||
""" | ||
AbstractSim | ||
An abstract type representing a model simulation. | ||
""" | ||
abstract type AbstractSim end | ||
|
||
abstract type AbstractAtmosSim <: AbstractSim end | ||
name(::AbstractAtmosSim) = :atmos | ||
|
||
abstract type AbstractOceanSim <: AbstractSim end | ||
name(::AbstractOceanSim) = :ocean | ||
|
||
abstract type AbstractLandSim <: AbstractSim end | ||
name(::AbstractLandSim) = :land | ||
|
||
abstract type AbstractCoupledSim <: AbstractSim end | ||
name(::AbstractCoupledSim) = :coupled | ||
|
||
""" | ||
CoupledSim | ||
A subtype of the abstract type `AbstractCoupledSim` representing a model simulation. | ||
""" | ||
struct CoupledSim{CS, S, CPL, L, C} <: AbstractCoupledSim | ||
"The coupled time-stepping scheme" | ||
coupler_solver::CS | ||
"The component simulations" | ||
sims::S | ||
"The coupler" | ||
coupler::CPL | ||
"Diagnostic logger" | ||
logger::L | ||
"Clock" | ||
clock::C | ||
end | ||
|
||
""" | ||
run!(::CoupledSim) | ||
A simple outer timestepping loop for coupled system runs. | ||
This will be formalized when the `run!` functionality for component | ||
models is implemented so to have a consistent interface. | ||
""" | ||
function run!(sim::CoupledSim) | ||
clock = sim.clock | ||
while !stop_time_exceeded(clock) | ||
step!(sim, clock.dt) | ||
tick!(clock) | ||
end | ||
end | ||
|
||
""" | ||
step!(sim, dt) | ||
Advances a simulation `sim` by `dt`. | ||
Note that `dt` is not necessarily the simulation's timestep length; | ||
a simuation could take several shorter steps that total to `dt`. | ||
""" | ||
function step!(sim::AbstractSim, dt) end | ||
|
||
""" | ||
Clock{T} | ||
Manages a simulation's time information. | ||
""" | ||
mutable struct Clock{T} | ||
time::T # current simulation time | ||
dt::T # simulation timestep | ||
stop_time::T # simulation end time | ||
end | ||
|
||
tick!(clock::Clock) = (clock.time += clock.dt) | ||
|
||
stop_time_exceeded(clock::Clock) = (clock.time >= clock.stop_time) |
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
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
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
Oops, something went wrong.