Skip to content

Commit

Permalink
Add air pressure, air temp, and humidity get_field
Browse files Browse the repository at this point in the history
Add them to the the generic get_field for
AtmosModelSimulations and specific methods
for ClimaAtmosSimulations
  • Loading branch information
imreddyTeja committed Feb 28, 2025
1 parent df5d7b6 commit 2951e9d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions experiments/ClimaEarth/components/atmosphere/climaatmos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ moisture_flux(::Union{CA.EquilMoistModel, CA.NonEquilMoistModel}, integrator) =
ρq_tot(::Union{CA.EquilMoistModel, CA.NonEquilMoistModel}, integrator) = integrator.u.c.ρq_tot

# extensions required by the Interfacer
# TODO: Is this the right value to grab, or should it be rrtmgp_model.center_pressure
# or rrtmgp_model.face_pressure, depending on which exists and is implied?
Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:air_pressure}) = CC.Fields.array2field(
sim.integrator.p.radiation.rrtmgp_model.as.p_lev[1, :],
CC.Fields.level(axes(sim.integrator.u.f), CC.Utilities.half),
)
Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:air_temperature}) = CC.Fields.array2field(
sim.integrator.p.radiation.rrtmgp_model.as.t_lev[1, :],
CC.Fields.level(axes(sim.integrator.u.f), CC.Utilities.half),
)
Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:cos_zenith_angle}) = CC.Fields.array2field(
sim.integrator.p.radiation.rrtmgp_model.cos_zenith,
CC.Fields.level(axes(sim.integrator.u.c), 1),
Expand Down Expand Up @@ -202,6 +212,8 @@ Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:LW_d}) = CC.Fields.level(
CC.Fields.array2field(sim.integrator.p.radiation.rrtmgp_model.face_lw_flux_dn, axes(sim.integrator.u.f)),
CC.Utilities.half,
)
Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:humidity}) =
CC.Fields.level(sim.integrator.u.c.ρq_tot ./ sim.integrator.u.c.ρ, 1)
Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:radiative_energy_flux_sfc}) =
surface_radiation_flux(sim.integrator.p.atmos.radiation_mode, sim.integrator)
Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:snow_precipitation}) =
Expand Down
3 changes: 3 additions & 0 deletions src/Interfacer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,14 @@ an atmosphere component model.
get_field(
sim::AtmosModelSimulation,
val::Union{
Val{:air_pressure},
Val{:air_temperature},
Val{:cos_zenith_angle},
Val{:co2},
Val{:diffuse_fraction},
Val{:height_int},
Val{:height_sfc},
Val{:humidity},
Val{:liquid_precipitation},
Val{:LW_d},
Val{:radiative_energy_flux_sfc},
Expand Down
3 changes: 3 additions & 0 deletions test/interfacer_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,14 @@ end

# Test that get_field gives correct warnings for unextended fields
for value in (
:air_pressure,
:air_temperature,
:cos_zenith_angle,
:co2,
:diffuse_fraction,
:height_int,
:height_sfc,
:humidity,
:liquid_precipitation,
:LW_d,
:radiative_energy_flux_sfc,
Expand Down

0 comments on commit 2951e9d

Please sign in to comment.