Skip to content

Commit

Permalink
move folders to exp/ClimaCore
Browse files Browse the repository at this point in the history
  • Loading branch information
juliasloan25 committed Oct 19, 2023
1 parent c351b5a commit d77bca8
Show file tree
Hide file tree
Showing 26 changed files with 326 additions and 2,471 deletions.
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand All @@ -40,7 +39,6 @@ JLD2 = "0.4"
NCDatasets = "0.11, 0.12"
OrdinaryDiffEq = "5, 6"
Plots = "1"
PrettyTables = "1, 2"
SciMLBase = "1"
StaticArrays = "1"
SurfaceFluxes = "0.7"
Expand Down
11 changes: 1 addition & 10 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,7 @@ experiment_pages = [
"Sea Breeze" => map(s -> "generated/sea_breeze/$(s)", readdir(joinpath(@__DIR__, "src/generated/sea_breeze"))),
"AMIP" => map(s -> "generated/amip/$(s)", readdir(joinpath(@__DIR__, "src/generated/amip"))),
]
interface_pages = [
"couplerstate.md",
"timestepping.md",
"regridder.md",
"conservation.md",
"utilities.md",
"bcreader.md",
"testhelper.md",
"timemanager.md",
]
interface_pages = ["regridder.md", "conservation.md", "utilities.md", "bcreader.md", "testhelper.md", "timemanager.md"]
performance_pages = ["performance.md"]

pages = Any[
Expand Down
20 changes: 0 additions & 20 deletions docs/src/couplerstate.md

This file was deleted.

23 changes: 0 additions & 23 deletions docs/src/timestepping.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,86 @@ export CouplerState
export coupler_push!, coupler_pull!, coupler_put!, coupler_get, coupler_get!
export coupler_add_field!, coupler_add_map!


"""
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)


mutable struct CplFieldInfo{DT, MD}
# the coupled data
data::DT
Expand All @@ -31,7 +111,7 @@ _fields(coupler::CouplerState) = getfield(coupler, :coupled_fields)
Type for holding coupler "state". This is the namespace through which coupled components
communicate. Its role is to provide a level of indirection so that components remain modular
and so that any data communication, interpolation, reindexing/unit conversions and filtering
and so that any data communication, interpolation, reindexing/unit conversions and filtering
etc... can be embeded in the intermdediate coupling layer.
A field is exported by one component and imported by one or more other components.
Expand All @@ -47,7 +127,7 @@ end
fieldvalue,
)
Add a field to the coupler that is accessible with key `fieldname`.
Add a field to the coupler that is accessible with key `fieldname`.
# Arguments
- `coupler`: coupler object the field is added to.
Expand All @@ -58,7 +138,7 @@ function coupler_add_field!(
coupler::CouplerState,
fieldname::Symbol,
fieldvalue;
write_sim::AbstractSimulation,
write_sim::AbstractSim,
metadata = nothing,
)
push!(coupler.coupled_fields, fieldname => CplFieldInfo(fieldvalue, name(write_sim), metadata))
Expand All @@ -71,7 +151,7 @@ end
map::Operators.LinearRemap
)
Add a map to the coupler that is accessible with key `mapname`.
Add a map to the coupler that is accessible with key `mapname`.
# Arguments
- `coupler`: coupler object the field is added to.
Expand All @@ -87,7 +167,7 @@ end
Sets coupler field `fieldname` to `fieldvalue`.
"""
function coupler_put!(coupler::CouplerState, fieldname::Symbol, fieldvalue, source_sim::AbstractSimulation)
function coupler_put!(coupler::CouplerState, fieldname::Symbol, fieldvalue, source_sim::AbstractSim)
cplfield = coupler.coupled_fields[fieldname]
@assert cplfield.write_sim == name(source_sim) "$fieldname can only be written to by $(cplfield.write_sim)."

Expand All @@ -109,23 +189,23 @@ them for the coupler.
function coupler_push!(coupler::CouplerState, model) end

"""
coupler_get!(target_field::ClimaCore.Fields.Field, coupler::CouplerState, fieldname::Symbol, target_sim::AbstractSimulation)
coupler_get!(target_field::ClimaCore.Fields.Field, coupler::CouplerState, fieldname::Symbol, target_sim::AbstractSim)
Retrieve data array corresponding to `fieldname`, remap and store in `target_field`.
"""
function coupler_get!(
target_field::ClimaCore.Fields.Field,
coupler::CouplerState,
fieldname::Symbol,
target_sim::AbstractSimulation,
target_sim::AbstractSim,
)
cplfield = coupler.coupled_fields[fieldname]
map = get_remap_operator(coupler, name(target_sim), cplfield.write_sim)
Operators.remap!(target_field, map, cplfield.data)
end

"""
coupler_get(coupler::CouplerState, fieldname::Symbol [, target_sim::AbstractSimulation])
coupler_get(coupler::CouplerState, fieldname::Symbol [, target_sim::AbstractSim])
Retrieve data array corresponding to `fieldname`.
Expand All @@ -136,7 +216,7 @@ function coupler_get(coupler::CouplerState, fieldname::Symbol)
return cplfield.data
end

function coupler_get(coupler::CouplerState, fieldname::Symbol, target_sim::AbstractSimulation)
function coupler_get(coupler::CouplerState, fieldname::Symbol, target_sim::AbstractSim)
cplfield = coupler.coupled_fields[fieldname]
map = get_remap_operator(coupler, name(target_sim), cplfield.write_sim)
return Operators.remap(map, cplfield.data)
Expand Down Expand Up @@ -176,5 +256,5 @@ function Base.show(io::IO, coupler::CouplerState)
data[i, :] = [k]
end
header = (["Field Name"], [""])
pretty_table(data, header = header)
PrettyTables.pretty_table(data, header = header)
end
3 changes: 0 additions & 3 deletions experiments/ClimaCore/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
LandHydrology = "f224512b-7ae7-4422-9a84-30035e16ed2d"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Oceananigans = "9e8cae18-63c1-5223-a75c-80ca9d6e9a09"
Expand All @@ -18,10 +17,8 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"

[compat]
DiffEqCallbacks = "2.23"
IntervalSets = "0.6"
OrdinaryDiffEq = "6.15"
SciMLBase = "1.40"
StaticArrays = "1.4"
TerminalLoggers = "0.1"
UnPack = "1.0"
Loading

0 comments on commit d77bca8

Please sign in to comment.