Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc refactoring #980

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions experiments/ClimaCore/sea_breeze/atmos_rhs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ end

# ## Coupled Atmos Wrappers
## Atmos Simulation - later to live in ClimaAtmos
struct AtmosSim <: AbstractAtmosSim
integrator::Any
struct AtmosSim{T} <: AbstractAtmosSim
integrator::T
end

function AtmosSim(Y_init, t_start, dt, t_end, timestepper, p, saveat, callbacks = CallbackSet())
Expand Down
2 changes: 1 addition & 1 deletion experiments/ClimaEarth/components/atmosphere/climaatmos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function Interfacer.get_field(atmos_sim::ClimaAtmosSimulation, ::Val{:radiative_

return @. -(LWd_TOA + SWd_TOA - LWu_TOA - SWu_TOA)
else
return [FT(0)]
return FT[0]
end
end

Expand Down
9 changes: 5 additions & 4 deletions experiments/ClimaEarth/components/ocean/slab_ocean.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ function slab_ocean_space_init(space, params)
coords = CC.Fields.coordinate_field(space)

# initial condition
T_sfc = CC.Fields.zeros(space) .+ params.T_init # FT(271) close to the average of T_1 in atmos
@. T_sfc += temp_anomaly(coords)
# FT(271) close to the average of T_1 in atmos
@. T_sfc = params.T_init + temp_anomaly(coords)

# prognostic variable
Y = CC.Fields.FieldVector(T_sfc = T_sfc)
Y = CC.Fields.FieldVector(; T_sfc = T_sfc)

return Y, space
end
Expand Down Expand Up @@ -94,7 +94,7 @@ function ocean_init(
)

ode_algo = CTS.ExplicitAlgorithm(stepper)
ode_function = CTS.ClimaODEFunction(T_exp! = slab_ocean_rhs!, dss! = weighted_dss_slab!)
ode_function = CTS.ClimaODEFunction(; T_exp! = slab_ocean_rhs!, dss! = weighted_dss_slab!)

problem = SciMLBase.ODEProblem(ode_function, Y, Float64.(tspan), cache)
integrator = SciMLBase.init(problem, ode_algo, dt = Float64(dt), saveat = Float64(saveat), adaptive = false)
Expand Down Expand Up @@ -185,6 +185,7 @@ This default case includes only an anomaly at the tropics.
"""
function temp_anomaly(coord)
# include tropics anomaly
FT = eltype(coord)
anom = FT(29 * exp(-coord.lat^2 / (2 * 26^2)))
return anom
end
Expand Down
29 changes: 14 additions & 15 deletions experiments/ClimaEarth/run_amip.jl
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,17 @@ if mode_name == "amip"
file_reader_kwargs = (; preprocess_func = (data) -> data + FT(273.15),), ## convert to Kelvin
)

SST_init = CC.Fields.zeros(boundary_space)
SST_init = zeros(boundary_space)
evaluate!(SST_init, SST_timevaryinginput, t_start)

ocean_sim = Interfacer.SurfaceStub((;
T_sfc = SST_init,
ρ_sfc = CC.Fields.zeros(boundary_space),
ρ_sfc = zeros(boundary_space),
z0m = FT(1e-3),
z0b = FT(1e-3),
beta = FT(1),
α_direct = CC.Fields.ones(boundary_space) .* FT(0.06),
α_diffuse = CC.Fields.ones(boundary_space) .* FT(0.06),
α_direct = ones(boundary_space) .* FT(0.06),
α_diffuse = ones(boundary_space) .* FT(0.06),
area_fraction = (FT(1) .- land_area_fraction),
phase = TD.Liquid(),
thermo_params = thermo_params,
Expand All @@ -312,7 +312,7 @@ if mode_name == "amip"
file_reader_kwargs = (; preprocess_func = (data) -> data / 100,), ## convert to fraction
)

SIC_init = CC.Fields.zeros(boundary_space)
SIC_init = zeros(boundary_space)
evaluate!(SIC_init, SIC_timevaryinginput, t_start)

ice_fraction = get_ice_fraction.(SIC_init, mono_surface)
Expand All @@ -329,7 +329,7 @@ if mode_name == "amip"
## CO2 concentration from temporally varying file
CO2_timevaryinginput = TimeVaryingInput(co2_data, "co2", boundary_space, reference_date = date0)

CO2_init = CC.Fields.zeros(boundary_space)
CO2_init = zeros(boundary_space)
evaluate!(CO2_init, CO2_timevaryinginput, t_start)
CO2_field = Interfacer.update_field!(atmos_sim, Val(:co2), CO2_init)

Expand Down Expand Up @@ -378,14 +378,14 @@ elseif mode_name in ("slabplanet", "slabplanet_aqua", "slabplanet_terra")

## sea ice stub (here set to zero area coverage)
ice_sim = Interfacer.SurfaceStub((;
T_sfc = CC.Fields.ones(boundary_space),
ρ_sfc = CC.Fields.zeros(boundary_space),
T_sfc = ones(boundary_space),
ρ_sfc = zeros(boundary_space),
z0m = FT(0),
z0b = FT(0),
beta = FT(1),
α_direct = CC.Fields.ones(boundary_space) .* FT(1),
α_diffuse = CC.Fields.ones(boundary_space) .* FT(1),
area_fraction = CC.Fields.zeros(boundary_space),
α_direct = ones(boundary_space) .* FT(1),
α_diffuse = ones(boundary_space) .* FT(1),
area_fraction = zeros(boundary_space),
phase = TD.Ice(),
thermo_params = thermo_params,
))
Expand Down Expand Up @@ -419,7 +419,7 @@ elseif mode_name == "slabplanet_eisenman"
dt = Δt_cpl,
space = boundary_space,
saveat = saveat,
area_fraction = CC.Fields.zeros(boundary_space), # zero, since ML is calculated below
area_fraction = zeros(boundary_space), # zero, since ML is calculated below
thermo_params = thermo_params,
)

Expand Down Expand Up @@ -468,8 +468,7 @@ coupler_field_names = (
:temp1,
:temp2,
)
coupler_fields =
NamedTuple{coupler_field_names}(ntuple(i -> CC.Fields.zeros(boundary_space), length(coupler_field_names)))
coupler_fields = NamedTuple{coupler_field_names}(ntuple(i -> zeros(boundary_space), length(coupler_field_names)))
Utilities.show_memory_usage()

## model simulations
Expand Down Expand Up @@ -710,7 +709,7 @@ function solve_coupler!(cs)
evaluate!(Interfacer.get_field(ice_sim, Val(:area_fraction)), cs.mode.SIC_timevaryinginput, t)

# TODO: get_field with :co2 is not implemented, so this is a little awkward
current_CO2 = CC.Fields.zeros(boundary_space)
current_CO2 = zeros(boundary_space)
evaluate!(current_CO2, cs.mode.CO2_timevaryinginput, t)
Interfacer.update_field!(atmos_sim, Val(:co2), current_CO2)

Expand Down
Loading