Skip to content

Commit

Permalink
Refactor independent time step argument reads
Browse files Browse the repository at this point in the history
The code that read the component dts used eval
and symbols to create the component dt vars.

This is changed to keep them in a dict. dt_atmos is
held in this dict, but it is not actually used. I kept
it there for consistency, but it could be removed.
  • Loading branch information
imreddyTeja committed Nov 8, 2024
1 parent 38105d0 commit 8aa5c3b
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions experiments/ClimaEarth/run_amip.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,28 +164,29 @@ t_end = Float64(time_to_seconds(config_dict["t_end"]))
t_start = 0.0
tspan = (t_start, t_end)
Δt_cpl = Float64(config_dict["dt_cpl"])
component_dt_names = [:dt_atmos, :dt_land, :dt_ocean, :dt_seaice]
component_dt_names = ["dt_atmos", "dt_land", "dt_ocean", "dt_seaice"]
component_dt_dict = Dict{String, Float64}()
# check if all component dt's are specified
if all(key -> !isnothing(config_dict[String(key)]), component_dt_names)
if all(key -> !isnothing(config_dict[key]), component_dt_names)
# when all component dt's are specified, ignore the dt field
if haskey(config_dict, "dt")
@warn "Removing dt in favor of individual component dt's"
delete!(config_dict, "dt")
end
for key in component_dt_names
component_dt = Float64(time_to_seconds(config_dict[String(key)]))
component_dt = Float64(time_to_seconds(config_dict[key]))
@assert Δt_cpl % component_dt == 0.0 "Coupler dt must be divisible by all component dt's\n dt_cpl = $Δt_cpl\n $key = $component_dt"
eval(:($key = $component_dt))
component_dt_dict[key] = component_dt
end
else
# when not all component dt's are specified, use the dt field
@assert haskey(config_dict, "dt") "dt or (dt_atmos, dt_land, dt_ocean, and dt_seaice) must be specified"
for key in component_dt_names
if !isnothing(config_dict[String(key)])
if !isnothing(config_dict[key])
@warn "Removing $key from config in favor of dt because not all component dt's are specified"
end
delete!(config_dict, String(key))
eval(:($key = Float64(time_to_seconds(config_dict["dt"]))))
delete!(config_dict, key)
component_dt_dict[key] = Float64(time_to_seconds(config_dict["dt"]))
end
end
## get component model dictionaries (if applicable)
Expand Down Expand Up @@ -334,7 +335,7 @@ if mode_name == "amip"
config_dict["land_albedo_type"],
config_dict["land_temperature_anomaly"],
dir_paths;
dt = dt_land,
dt = component_dt_dict["dt_land"],
space = boundary_space,
saveat = saveat,
area_fraction = land_area_fraction,
Expand Down Expand Up @@ -388,7 +389,7 @@ if mode_name == "amip"
ice_sim = ice_init(
FT;
tspan = tspan,
dt = dt_seaice,
dt = component_dt_dict["dt_seaice"],
space = boundary_space,
saveat = saveat,
area_fraction = ice_fraction,
Expand Down Expand Up @@ -432,7 +433,7 @@ elseif mode_name in ("slabplanet", "slabplanet_aqua", "slabplanet_terra")
config_dict["land_albedo_type"],
config_dict["land_temperature_anomaly"],
dir_paths;
dt = dt_land,
dt = component_dt_dict["dt_land"],
space = boundary_space,
saveat = saveat,
area_fraction = land_area_fraction,
Expand All @@ -447,7 +448,7 @@ elseif mode_name in ("slabplanet", "slabplanet_aqua", "slabplanet_terra")
ocean_sim = ocean_init(
FT;
tspan = tspan,
dt = dt_ocean,
dt = component_dt_dict["dt_ocean"],
space = boundary_space,
saveat = saveat,
area_fraction = (FT(1) .- land_area_fraction), ## NB: this ocean fraction includes areas covered by sea ice (unlike the one contained in the cs)
Expand Down Expand Up @@ -482,7 +483,7 @@ elseif mode_name == "slabplanet_eisenman"
config_dict["land_albedo_type"],
config_dict["land_temperature_anomaly"],
dir_paths;
dt = dt_land,
dt = component_dt_dict["dt_land"],
space = boundary_space,
saveat = saveat,
area_fraction = land_area_fraction,
Expand All @@ -497,7 +498,7 @@ elseif mode_name == "slabplanet_eisenman"
ocean_sim = ocean_init(
FT;
tspan = tspan,
dt = dt_ocean,
dt = component_dt_dict["dt_ocean"],
space = boundary_space,
saveat = saveat,
area_fraction = zeros(boundary_space), # zero, since ML is calculated below
Expand All @@ -510,7 +511,7 @@ elseif mode_name == "slabplanet_eisenman"
tspan,
space = boundary_space,
area_fraction = (FT(1) .- land_area_fraction),
dt = dt_seaice,
dt = component_dt_dict["dt_seaice"],
saveat = saveat,
thermo_params = thermo_params,
)
Expand Down

0 comments on commit 8aa5c3b

Please sign in to comment.