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 14, 2023
1 parent c351b5a commit de6b8e0
Show file tree
Hide file tree
Showing 24 changed files with 338 additions and 509 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.

77 changes: 77 additions & 0 deletions experiments/ClimaCore/CoupledSimulations/coupled_simulation.jl
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)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export CouplerState
export coupler_push!, coupler_pull!, coupler_put!, coupler_get, coupler_get!
export coupler_add_field!, coupler_add_map!

# Load coupled simulation interface
include("../CoupledSimulations/coupled_simulation.jl")

mutable struct CplFieldInfo{DT, MD}
# the coupled data
data::DT
Expand All @@ -31,7 +34,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 +50,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 +61,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 +74,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 +90,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 +112,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 +139,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 +179,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"
27 changes: 15 additions & 12 deletions experiments/ClimaCore/sea-ice/slab_ice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ using OrdinaryDiffEq

using Statistics

# Load utilities for coupling
include("../CouplerState/coupler_state.jl")

#src ## Setup Logging Information
global_logger(TerminalLogger())
const CI = !isnothing(get(ENV, "CI", nothing))
Expand All @@ -27,19 +30,19 @@ const FT = Float64;
# - Experiment-specific Parameters
parameters = (
## atmos parameters
zmin_atm = FT(0.0), # height of atm stack bottom [m]
zmin_atm = FT(0.0), # height of atm stack bottom [m]
zmax_atm = FT(1.0), # height of atm stack top [m]
n = 15, # number of elements in atm stack
n = 15, # number of elements in atm stack
μ = FT(0.0001), # diffusion coefficient [m^2 / s]
T_top = FT(280.0), # fixed temperature at the top of the domain_atm [K]
ρc_ml = FT(4e6), # density times heat transfer coefficient for mixed layer [J / m2 / K ]
F0_base = FT(120), # ice base transfer coefficient [W / m2 / K]
T_base = FT(273.16), # ice base temperature [K]
T_base = FT(273.16), # ice base temperature [K]
L_ice = FT(3e8), # latent heat coefficient for ice [J / m3]
h_ml = FT(1), # mixed layer depth [m]
T_freeze = FT(273.16), # temperature at freezing point [K]
h_ml = FT(1), # mixed layer depth [m]
T_freeze = FT(273.16), # temperature at freezing point [K]
k_ice = FT(2), # thermal conductivity of ice [W / m / K]
## coupling parameters
## coupling parameters
λ = FT(0.001), # coupling coefficient (J / K / s / m2)
)

Expand All @@ -56,7 +59,7 @@ Heat diffusion equation
(- μ ∇ T) = F_sfc at z = zmin_atm
We also use this model to calculate and accumulate the downward surface fluxes, F_sfc:
F_sfc = - λ * (T_sfc - T1)
F_sfc = - λ * (T_sfc - T1)
d(F_integrated)/dt = F_sfc
where
F_integrated is reset to 0 at the beginning of each coupling cycle
Expand Down Expand Up @@ -114,16 +117,16 @@ function solve_ice!(integ, Δt)
F_ice = similar(F_atm)
ΔT_sfc = similar(F_atm)

# ice thickness and mixed layer temperature changes due to atmosphereic and ocean fluxes
if h_ice[1] > 0 # ice-covered
# ice thickness and mixed layer temperature changes due to atmosphereic and ocean fluxes
if h_ice[1] > 0 # ice-covered
@. ΔT_ml = -(p.F0_base * (T_ml - p.T_base) + ocean_qflux) * Δt / (p.h_ml * p.ρc_ml)
@. Δh_ice = (F_atm - p.F0_base * (T_ml - p.T_base)) * Δt / p.L_ice
else # ice-free
@. ΔT_ml = -(F_atm + ocean_qflux) * Δt / (p.h_ml * p.ρc_ml)
@. Δh_ice = 0
end

# adjust if transition to ice-covered
# adjust if transition to ice-covered
if (T_ml[1] + ΔT_ml[1] < p.T_freeze)
@. Δh_ice = Δh_ice - (T_ml + ΔT_ml - p.T_freeze) * (p.h_ml * p.ρc_ml) / p.L_ice
@. ΔT_ml = p.T_freeze - T_ml
Expand Down Expand Up @@ -173,8 +176,8 @@ end
# - Surface Flux Calculation (coarse bulk formula)
calculate_flux(T_sfc, T1, parameters) = -parameters.λ * (T_sfc - T1);

# - Coupler Communication Functions
# These functions export / import / transform variables
# - Coupler Communication Functions
# These functions export / import / transform variables
# These functions are now just place holders for coupler transformations (e.g. regridding, masking, etc)
coupler_get(x) = copy(x);
coupler_put(x) = copy(x);
Expand Down
Loading

0 comments on commit de6b8e0

Please sign in to comment.