Skip to content

Commit d735026

Browse files
authored
Merge pull request #1191 from CliMA/kp/itime2
Add ITime
2 parents 885bd25 + 93b043e commit d735026

24 files changed

+174
-39
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Thermodynamics = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c"
1616

1717
[compat]
1818
ClimaComms = "0.6.2"
19-
ClimaCore = "0.14.17"
20-
ClimaUtilities = "0.1.9"
19+
ClimaCore = "0.14.23"
20+
ClimaUtilities = "0.1.22"
2121
Dates = "1"
2222
Logging = "1"
2323
SciMLBase = "2.11"

config/ci_configs/amip_component_dts.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dt_land: "50secs"
66
dt_ocean: "30secs"
77
dt_rad: "1hours"
88
dt_save_to_sol: "1days"
9-
dt_seaice: "75secs"
9+
dt_seaice: "37.5secs"
1010
dz_bottom: 30
1111
dz_top: 3000
1212
energy_check: false

config/ci_configs/amip_default.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ t_end: "300secs"
1616
vert_diff: "true"
1717
z_elem: 50
1818
z_stretch: false
19+
use_itime: true

docs/src/timemanager.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,17 @@ ClimaCoupler.TimeManager.strdate_to_datetime
1212
ClimaCoupler.TimeManager.datetime_to_strdate
1313
ClimaCoupler.TimeManager.maybe_trigger_callback
1414
```
15+
16+
## ITime
17+
18+
`ITime`, or _integer time_, is a time type used by CliMA simulations to keep
19+
track of simulation time. For more information, refer to the
20+
[TimeManager section](https://clima.github.io/ClimaUtilities.jl/dev/timemanager/)
21+
in ClimaUtilities and the [ITime section](https://clima.github.io/ClimaAtmos.jl/dev/itime/)
22+
in ClimaAtmos.
23+
24+
### How do I use ITime?
25+
26+
If you are running a simulation from a YAML file, you can simply set `use_itime`
27+
to true to enable `ITime`. If you do not want to use `ITime` and want to use
28+
floating point numbers, then set `use_itime` to false to not use `ITime`.

experiments/ClimaCore/sea_breeze/run.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ system before executing the simulation.
117117

118118
t_start, t_end = (0.0, 1e4)
119119
Δt_coupled = 0.1
120-
saveat = t_start:10.0:t_end
120+
saveat = collect(t_start:10.0:t_end)
121121
atm_nsteps, ocn_nsteps, lnd_nsteps = (5, 1, 1)
122122

123123
## Initialize Models

experiments/ClimaEarth/cli_options.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ function argparse_settings()
159159
help = "Boolean flag indicating whether to compute and output land model diagnostics [`true` (default), `false`]"
160160
arg_type = Bool
161161
default = true
162+
"--use_itime"
163+
help = "Boolean flag indicating whether to use ITime (integer time) or not (will use Float64) [`true` (default), `false`]"
164+
arg_type = Bool
165+
default = true
162166
end
163167
return s
164168
end

experiments/ClimaEarth/components/atmosphere/climaatmos.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import ClimaCore.Geometry: ⊗
1010
import SurfaceFluxes as SF
1111
import Thermodynamics as TD
1212
import ClimaCoupler: Checkpointer, FieldExchanger, FluxCalculator, Interfacer, Utilities
13+
import ClimaUtilities.TimeManager: ITime
1314

1415
include("climaatmos_extra_diags.jl")
1516

@@ -140,7 +141,8 @@ function Interfacer.get_field(atmos_sim::ClimaAtmosSimulation, ::Val{:energy})
140141
ᶜS_ρq_tot = p.precipitation.ᶜS_ρq_tot
141142
thermo_params = get_thermo_params(atmos_sim)
142143
return integrator.u.c.ρe_tot .-
143-
ᶜS_ρq_tot .* CA.e_tot_0M_precipitation_sources_helper.(Ref(thermo_params), ᶜts, ᶜΦ) .* integrator.dt
144+
ᶜS_ρq_tot .* CA.e_tot_0M_precipitation_sources_helper.(Ref(thermo_params), ᶜts, ᶜΦ) .*
145+
float(integrator.dt)
144146
else
145147
return integrator.u.c.ρe_tot
146148
end
@@ -249,7 +251,14 @@ function Interfacer.update_field!(sim::ClimaAtmosSimulation, ::Val{:turbulent_fl
249251
end
250252

251253
# extensions required by FieldExchanger
252-
Interfacer.step!(sim::ClimaAtmosSimulation, t) = Interfacer.step!(sim.integrator, t - sim.integrator.t, true)
254+
Interfacer.step!(sim::ClimaAtmosSimulation, t::Real) = Interfacer.step!(sim.integrator, t - sim.integrator.t, true)
255+
function Interfacer.step!(sim::ClimaAtmosSimulation, t::ITime)
256+
while sim.integrator.t < t
257+
Interfacer.step!(sim.integrator)
258+
end
259+
return nothing
260+
end
261+
253262
Interfacer.reinit!(sim::ClimaAtmosSimulation) = Interfacer.reinit!(sim.integrator)
254263

255264
function FieldExchanger.update_sim!(atmos_sim::ClimaAtmosSimulation, csf, turbulent_fluxes)

experiments/ClimaEarth/components/land/climaland_bucket.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,23 @@ Initializes the bucket model variables.
4949
"""
5050
function BucketSimulation(
5151
::Type{FT},
52-
tspan::Tuple{Float64, Float64},
52+
tspan::Tuple{TT, TT},
5353
config::String,
5454
albedo_type::String,
5555
land_initial_condition::String,
5656
land_temperature_anomaly::String,
5757
output_dir::String;
5858
space,
59-
dt::Float64,
60-
saveat::Vector{Float64},
59+
dt::TT,
60+
saveat::Vector{TT},
6161
area_fraction,
6262
stepper = CTS.RK4(),
6363
date_ref::Dates.DateTime,
64-
t_start::Float64,
64+
t_start::TT,
6565
energy_check::Bool,
6666
surface_elevation,
6767
use_land_diagnostics::Bool,
68-
) where {FT}
68+
) where {FT, TT <: Union{Float64, ITime}}
6969
if config != "sphere"
7070
println(
7171
"Currently only spherical shell domains are supported; single column set-up will be addressed in future PR.",
@@ -102,7 +102,7 @@ function BucketSimulation(
102102
d_soil = FT(3.5) # soil depth
103103
z_0m = FT(1e-3) # roughness length for momentum over smooth bare soil
104104
z_0b = FT(1e-3) # roughness length for tracers over smooth bare soil
105-
τc = FT(dt) # This is the timescale on which snow exponentially damps to zero, in the case where all
105+
τc = FT(float(dt)) # This is the timescale on which snow exponentially damps to zero, in the case where all
106106
# the snow would melt in time `τc`. It prevents us from having to specially time step in cases where
107107
# all the snow melts in a single timestep.
108108
σS_c = FT(0.2) # critical snow water equivalent

experiments/ClimaEarth/components/ocean/eisenman_seaice.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Base.@kwdef struct EisenmanOceanParameters{FT <: AbstractFloat}
4444
end
4545

4646
"""
47-
EisenmanIceSimulation(::Type{FT}, tspan; space = nothing, area_fraction = nothing, thermo_params = nothing, stepper = CTS.RK4(), dt = 0.02, saveat = 1.0e10)
47+
EisenmanIceSimulation(::Type{FT}, tspan; space = nothing, area_fraction = nothing, thermo_params = nothing, stepper = CTS.RK4(), dt, saveat = 1.0e10)
4848
4949
Initialize the Eisenman-Zhang sea ice model and simulation.
5050
"""
@@ -55,7 +55,7 @@ function EisenmanIceSimulation(
5555
area_fraction = nothing,
5656
thermo_params = nothing,
5757
stepper = CTS.RK4(),
58-
dt = 0.02,
58+
dt,
5959
saveat = [1.0e10],
6060
) where {FT}
6161

@@ -79,8 +79,13 @@ function EisenmanIceSimulation(
7979
thermo_params = thermo_params,
8080
dss_buffer = CC.Spaces.create_dss_buffer(Y),
8181
)
82-
problem = SciMLBase.ODEProblem(ode_function, Y, Float64.(tspan), cache)
83-
integrator = SciMLBase.init(problem, ode_algo, dt = Float64(dt), saveat = Float64.(saveat), adaptive = false)
82+
if typeof(dt) isa Number
83+
dt = Float64(dt)
84+
tspan = Float64.(tspan)
85+
saveat = Float64.(saveat)
86+
end
87+
problem = SciMLBase.ODEProblem(ode_function, Y, tspan, cache)
88+
integrator = SciMLBase.init(problem, ode_algo, dt = dt, saveat = saveat, adaptive = false)
8489

8590
sim = EisenmanIceSimulation(params, space, integrator)
8691
return sim
@@ -130,7 +135,7 @@ function Interfacer.get_field(sim::EisenmanIceSimulation, ::Val{:energy})
130135

131136
e_ml = @. p_o.h * p_o.ρ * p_o.c * sim.integrator.u.T_ml # heat
132137
e_ice = @. p_i.L_ice * sim.integrator.u.h_ice # phase
133-
e_qflux = @. ocean_qflux * FT(sim.integrator.t)
138+
e_qflux = @. ocean_qflux * FT(float(sim.integrator.t))
134139

135140
return @. e_ml + e_ice + e_qflux + e_base
136141
end
@@ -340,7 +345,7 @@ Calculate the tendencies for the Eisenman-Zhang sea ice model.
340345
"""
341346
function ∑tendencies(dY, Y, cache, _)
342347
FT = eltype(dY)
343-
Δt = cache.Δt
348+
Δt = float(cache.Δt)
344349
Ya = cache.Ya
345350
thermo_params = cache.thermo_params
346351
p = cache.params

experiments/ClimaEarth/components/ocean/prescr_seaice.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,13 @@ function PrescribedIceSimulation(
138138

139139
ode_algo = CTS.ExplicitAlgorithm(stepper)
140140
ode_function = CTS.ClimaODEFunction(T_exp! = ice_rhs!, dss! = (Y, p, t) -> CC.Spaces.weighted_dss!(Y, p.dss_buffer))
141-
142-
problem = SciMLBase.ODEProblem(ode_function, Y, Float64.(tspan), (; cache..., params = params))
143-
integrator = SciMLBase.init(problem, ode_algo, dt = Float64(dt), saveat = Float64.(saveat), adaptive = false)
141+
if typeof(dt) isa Number
142+
dt = Float64(dt)
143+
tspan = Float64.(tspan)
144+
saveat = Float64.(saveat)
145+
end
146+
problem = SciMLBase.ODEProblem(ode_function, Y, tspan, (; cache..., params = params))
147+
integrator = SciMLBase.init(problem, ode_algo, dt = dt, saveat = saveat, adaptive = false)
144148

145149
sim = PrescribedIceSimulation(params, space, integrator)
146150

@@ -234,7 +238,7 @@ function ice_rhs!(dY, Y, p, t)
234238
F_conductive = @. params.k_ice / (params.h) * (params.T_base - Y.T_sfc) # fluxes are defined to be positive when upward
235239
rhs = @. (-p.F_turb_energy - p.F_radiative + F_conductive) / (params.h * params.ρ * params.c)
236240
# If tendencies lead to temperature above freezing, set temperature to freezing
237-
@. rhs = min(rhs, (params.T_freeze - Y.T_sfc) / p.dt)
241+
@. rhs = min(rhs, (params.T_freeze - Y.T_sfc) / float(p.dt))
238242
# mask out no-ice areas
239243
area_mask = Utilities.binary_mask.(p.area_fraction)
240244
dY.T_sfc .= rhs .* area_mask

0 commit comments

Comments
 (0)