Skip to content

Commit a4d7d7d

Browse files
authored
Unify Interfacer argname for simulation (#1225)
The methods for each component in experiments/ClimaEarth/components/ refer to the simulation argument with different names. For the ClimaAtmosSimulation, it is refered to as both `sim` and `atmos_sim`. Similarly, the BucketSimulation is refered to as both `sim` and `bucket_sim`. This commit unifies them by changing everything to `sim`. The opposite could also be done.
1 parent 007878a commit a4d7d7d

File tree

2 files changed

+51
-56
lines changed

2 files changed

+51
-56
lines changed

experiments/ClimaEarth/components/atmosphere/climaatmos.jl

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,19 @@ end
139139

140140

141141
"""
142-
Interfacer.get_field(atmos_sim::ClimaAtmosSimulation, ::Val{:radiative_energy_flux_toa})
142+
Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:radiative_energy_flux_toa})
143143
144144
Extension of Interfacer.get_field to get the net TOA radiation, which is a sum of the
145145
upward and downward longwave and shortwave radiation.
146146
"""
147-
function Interfacer.get_field(atmos_sim::ClimaAtmosSimulation, ::Val{:radiative_energy_flux_toa})
148-
FT = eltype(atmos_sim.integrator.u)
147+
function Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:radiative_energy_flux_toa})
148+
FT = eltype(sim.integrator.u)
149149

150-
if hasradiation(atmos_sim.integrator)
151-
face_space = axes(atmos_sim.integrator.u.f)
150+
if hasradiation(sim.integrator)
151+
face_space = axes(sim.integrator.u.f)
152152
nz_faces = length(CC.Spaces.vertical_topology(face_space).mesh.faces)
153153

154-
(; face_lw_flux_dn, face_lw_flux_up, face_sw_flux_dn, face_sw_flux_up) =
155-
atmos_sim.integrator.p.radiation.rrtmgp_model
154+
(; face_lw_flux_dn, face_lw_flux_up, face_sw_flux_dn, face_sw_flux_up) = sim.integrator.p.radiation.rrtmgp_model
156155

157156
LWd_TOA = CC.Fields.level(CC.Fields.array2field(FT.(face_lw_flux_dn), face_space), nz_faces - CC.Utilities.half)
158157
LWu_TOA = CC.Fields.level(CC.Fields.array2field(FT.(face_lw_flux_up), face_space), nz_faces - CC.Utilities.half)
@@ -165,8 +164,8 @@ function Interfacer.get_field(atmos_sim::ClimaAtmosSimulation, ::Val{:radiative_
165164
end
166165
end
167166

168-
function Interfacer.get_field(atmos_sim::ClimaAtmosSimulation, ::Val{:energy})
169-
integrator = atmos_sim.integrator
167+
function Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:energy})
168+
integrator = sim.integrator
170169
p = integrator.p
171170

172171

@@ -179,7 +178,7 @@ function Interfacer.get_field(atmos_sim::ClimaAtmosSimulation, ::Val{:energy})
179178
else
180179
ᶜS_ρq_tot = p.precipitation.ᶜS_ρq_tot
181180
end
182-
thermo_params = get_thermo_params(atmos_sim)
181+
thermo_params = get_thermo_params(sim)
183182
return integrator.u.c.ρe_tot .-
184183
ᶜS_ρq_tot .* CA.e_tot_0M_precipitation_sources_helper.(Ref(thermo_params), ᶜts, ᶜΦ) .*
185184
float(integrator.dt)
@@ -274,8 +273,8 @@ Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:turbulent_moisture_flux})
274273
moisture_flux(sim.integrator.p.atmos.moisture_model, sim.integrator)
275274
Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:thermo_state_int}) =
276275
CC.Spaces.level(sim.integrator.p.precomputed.ᶜts, 1)
277-
Interfacer.get_field(atmos_sim::ClimaAtmosSimulation, ::Val{:water}) =
278-
ρq_tot(atmos_sim.integrator.p.atmos.moisture_model, atmos_sim.integrator)
276+
Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:water}) =
277+
ρq_tot(sim.integrator.p.atmos.moisture_model, sim.integrator)
279278
function Interfacer.update_field!(sim::ClimaAtmosSimulation, ::Val{:surface_temperature}, field)
280279
# note that this field is also being updated internally by the surface thermo state in ClimaAtmos
281280
# if turbulent fluxes are calculated, to ensure consistency. In case the turbulent fluxes are not
@@ -361,33 +360,33 @@ function Interfacer.add_coupler_fields!(coupler_field_names, ::ClimaAtmosSimulat
361360
push!(coupler_field_names, atmos_coupler_fields...)
362361
end
363362

364-
function FieldExchanger.update_sim!(atmos_sim::ClimaAtmosSimulation, csf, turbulent_fluxes)
363+
function FieldExchanger.update_sim!(sim::ClimaAtmosSimulation, csf, turbulent_fluxes)
365364

366-
u = atmos_sim.integrator.u
367-
p = atmos_sim.integrator.p
368-
t = atmos_sim.integrator.t
365+
u = sim.integrator.u
366+
p = sim.integrator.p
367+
t = sim.integrator.t
369368

370369
# Perform radiation-specific updates
371-
if hasradiation(atmos_sim.integrator)
370+
if hasradiation(sim.integrator)
372371
!(p.atmos.insolation isa CA.IdealizedInsolation) && CA.set_insolation_variables!(u, p, t, p.atmos.insolation)
373-
Interfacer.update_field!(atmos_sim, Val(:surface_direct_albedo), csf.surface_direct_albedo)
374-
Interfacer.update_field!(atmos_sim, Val(:surface_diffuse_albedo), csf.surface_diffuse_albedo)
375-
Interfacer.update_field!(atmos_sim, Val(:surface_temperature), csf.T_sfc)
372+
Interfacer.update_field!(sim, Val(:surface_direct_albedo), csf.surface_direct_albedo)
373+
Interfacer.update_field!(sim, Val(:surface_diffuse_albedo), csf.surface_diffuse_albedo)
374+
Interfacer.update_field!(sim, Val(:surface_temperature), csf.T_sfc)
376375
end
377376

378377
if turbulent_fluxes isa FluxCalculator.PartitionedStateFluxes
379-
Interfacer.update_field!(atmos_sim, Val(:turbulent_fluxes), csf)
378+
Interfacer.update_field!(sim, Val(:turbulent_fluxes), csf)
380379
end
381380
end
382381

383382
"""
384-
FluxCalculator.calculate_surface_air_density(atmos_sim::ClimaAtmosSimulation, T_sfc::CC.Fields.Field)
383+
FluxCalculator.calculate_surface_air_density(sim::ClimaAtmosSimulation, T_sfc::CC.Fields.Field)
385384
386385
Extension for this function to calculate surface density.
387386
"""
388-
function FluxCalculator.calculate_surface_air_density(atmos_sim::ClimaAtmosSimulation, T_sfc::CC.Fields.Field)
389-
thermo_params = get_thermo_params(atmos_sim)
390-
ts_int = Interfacer.get_field(atmos_sim, Val(:thermo_state_int))
387+
function FluxCalculator.calculate_surface_air_density(sim::ClimaAtmosSimulation, T_sfc::CC.Fields.Field)
388+
thermo_params = get_thermo_params(sim)
389+
ts_int = Interfacer.get_field(sim, Val(:thermo_state_int))
391390
FluxCalculator.extrapolate_ρ_to_sfc.(Ref(thermo_params), ts_int, Utilities.swap_space!(axes(ts_int.ρ), T_sfc))
392391
end
393392

@@ -519,18 +518,18 @@ function coupler_surface_setup(
519518
end
520519

521520
"""
522-
get_new_cache(atmos_sim::ClimaAtmosSimulation, csf)
521+
get_new_cache(sim::ClimaAtmosSimulation, csf)
523522
524523
Returns a new `p` with the updated surface conditions.
525524
"""
526-
function get_new_cache(atmos_sim::ClimaAtmosSimulation, csf)
527-
if hasmoisture(atmos_sim.integrator)
525+
function get_new_cache(sim::ClimaAtmosSimulation, csf)
526+
if hasmoisture(sim.integrator)
528527
csf_sfc = (csf.T_sfc, csf.z0m_sfc, csf.z0b_sfc, csf.beta, csf.q_sfc)
529528
else
530529
csf_sfc = (csf.T_sfc, csf.z0m_sfc, csf.z0b_sfc, csf.beta)
531530
end
532531

533-
p = atmos_sim.integrator.p
532+
p = sim.integrator.p
534533

535534
coupler_sfc_setup = coupler_surface_setup(CoupledMoninObukhov(), p, csf_sfc...)
536535

@@ -541,7 +540,7 @@ function get_new_cache(atmos_sim::ClimaAtmosSimulation, csf)
541540
end
542541

543542
"""
544-
FluxCalculator.atmos_turbulent_fluxes_most!(atmos_sim::ClimaAtmosSimulation, csf)
543+
FluxCalculator.atmos_turbulent_fluxes_most!(sim::ClimaAtmosSimulation, csf)
545544
546545
Computes turbulent surface fluxes using ClimaAtmos's `update_surface_conditions!` and
547546
and the Monin Obukhov Similarity Theory. This
@@ -556,12 +555,12 @@ For debigging atmos, we can set the following atmos defaults:
556555
csf.beta .= 1
557556
csf = merge(csf, (;q_sfc = nothing))
558557
"""
559-
function FluxCalculator.atmos_turbulent_fluxes_most!(atmos_sim::ClimaAtmosSimulation, csf)
558+
function FluxCalculator.atmos_turbulent_fluxes_most!(sim::ClimaAtmosSimulation, csf)
560559

561-
if isnothing(atmos_sim.integrator.p.sfc_setup) # trigger flux calculation if not done in Atmos internally
562-
new_p = get_new_cache(atmos_sim, csf)
563-
CA.SurfaceConditions.update_surface_conditions!(atmos_sim.integrator.u, new_p, atmos_sim.integrator.t)
564-
atmos_sim.integrator.p.precomputed.sfc_conditions .= new_p.precomputed.sfc_conditions
560+
if isnothing(sim.integrator.p.sfc_setup) # trigger flux calculation if not done in Atmos internally
561+
new_p = get_new_cache(sim, csf)
562+
CA.SurfaceConditions.update_surface_conditions!(sim.integrator.u, new_p, sim.integrator.t)
563+
sim.integrator.p.precomputed.sfc_conditions .= new_p.precomputed.sfc_conditions
565564
end
566565
end
567566

@@ -590,28 +589,28 @@ function dss_state!(sim::ClimaAtmosSimulation)
590589
end
591590

592591
"""
593-
FluxCalculator.water_albedo_from_atmosphere!(atmos_sim::ClimaAtmosSimulation, direct_albedo::CC.Fields.Field, diffuse_albedo::CC.Fields.Field)
592+
FluxCalculator.water_albedo_from_atmosphere!(sim::ClimaAtmosSimulation, direct_albedo::CC.Fields.Field, diffuse_albedo::CC.Fields.Field)
594593
595594
Extension to calculate the water surface albedo from wind speed and insolation. It can be used for prescribed ocean and lakes.
596595
"""
597596
function FluxCalculator.water_albedo_from_atmosphere!(
598-
atmos_sim::ClimaAtmosSimulation,
597+
sim::ClimaAtmosSimulation,
599598
direct_albedo::CC.Fields.Field,
600599
diffuse_albedo::CC.Fields.Field,
601600
)
602601

603-
Y = atmos_sim.integrator.u
604-
p = atmos_sim.integrator.p
605-
t = atmos_sim.integrator.t
602+
Y = sim.integrator.u
603+
p = sim.integrator.p
604+
t = sim.integrator.t
606605

607-
rrtmgp_model = atmos_sim.integrator.p.radiation.rrtmgp_model
606+
rrtmgp_model = sim.integrator.p.radiation.rrtmgp_model
608607
FT = eltype(Y)
609608
λ = FT(0) # spectral wavelength (not used for now)
610609

611610
# update for current zenith angle
612611
bottom_coords = CC.Fields.coordinate_field(CC.Spaces.level(Y.c, 1))
613612
μ = CC.Fields.array2field(rrtmgp_model.cos_zenith, axes(bottom_coords))
614-
FT = eltype(atmos_sim.integrator.u)
613+
FT = eltype(sim.integrator.u)
615614
α_model = CA.RegressionFunctionAlbedo{FT}()
616615

617616
# set the direct and diffuse surface albedos

experiments/ClimaEarth/components/land/climaland_bucket.jl

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -258,35 +258,31 @@ Interfacer.get_field(sim::BucketSimulation, ::Val{:surface_temperature}) =
258258
CL.surface_temperature(sim.model, sim.integrator.u, sim.integrator.p, sim.integrator.t)
259259

260260
"""
261-
Interfacer.get_field(bucket_sim::BucketSimulation, ::Val{:energy})
261+
Interfacer.get_field(sim::BucketSimulation, ::Val{:energy})
262262
263263
Extension of Interfacer.get_field that provides the total energy contained in the bucket, including the latent heat due to snow melt.
264264
"""
265-
function Interfacer.get_field(bucket_sim::BucketSimulation, ::Val{:energy})
265+
function Interfacer.get_field(sim::BucketSimulation, ::Val{:energy})
266266
# required by ConservationChecker
267-
e_per_area = bucket_sim.integrator.p.e_per_area .= 0
268-
CC.Operators.column_integral_definite!(
269-
e_per_area,
270-
bucket_sim.model.parameters.ρc_soil .* bucket_sim.integrator.u.bucket.T,
271-
)
267+
e_per_area = sim.integrator.p.e_per_area .= 0
268+
CC.Operators.column_integral_definite!(e_per_area, sim.model.parameters.ρc_soil .* sim.integrator.u.bucket.T)
272269

273270
e_per_area .+=
274-
-LP.LH_f0(bucket_sim.model.parameters.earth_param_set) .*
275-
LP.ρ_cloud_liq(bucket_sim.model.parameters.earth_param_set) .* bucket_sim.integrator.u.bucket.σS
271+
-LP.LH_f0(sim.model.parameters.earth_param_set) .* LP.ρ_cloud_liq(sim.model.parameters.earth_param_set) .*
272+
sim.integrator.u.bucket.σS
276273

277274
return e_per_area
278275
end
279276

280277
"""
281-
Interfacer.get_field(bucket_sim::BucketSimulation, ::Val{:water})
278+
Interfacer.get_field(sim::BucketSimulation, ::Val{:water})
282279
283280
Extension of Interfacer.get_field that provides the total water contained in the bucket, including the liquid water in snow.
284281
"""
285-
function Interfacer.get_field(bucket_sim::BucketSimulation, ::Val{:water})
286-
ρ_cloud_liq = CL.LP.ρ_cloud_liq(bucket_sim.model.parameters.earth_param_set)
282+
function Interfacer.get_field(sim::BucketSimulation, ::Val{:water})
283+
ρ_cloud_liq = CL.LP.ρ_cloud_liq(sim.model.parameters.earth_param_set)
287284
return
288-
@. (bucket_sim.integrator.u.bucket.σS + bucket_sim.integrator.u.bucket.W + bucket_sim.integrator.u.bucket.Ws) *
289-
ρ_cloud_liq # kg water / m2
285+
@. (sim.integrator.u.bucket.σS + sim.integrator.u.bucket.W + sim.integrator.u.bucket.Ws) * ρ_cloud_liq # kg water / m2
290286
end
291287

292288
function Interfacer.update_field!(sim::BucketSimulation, ::Val{:air_density}, field)

0 commit comments

Comments
 (0)