Skip to content

Commit

Permalink
Add more get_fields to ClimaAtmosSimulation
Browse files Browse the repository at this point in the history
Add diffuse_fraction, SW_d, LW_d, and cos of the zenith_angle
to get_field on AtmosModelSimulation in Interfacer.jl.

Add get_field methods for the above values in
ClimaAtmosSimulation

Remove safe_div and use anonymous func
  • Loading branch information
imreddyTeja committed Feb 25, 2025
1 parent 9839b78 commit 328d9b0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
24 changes: 24 additions & 0 deletions experiments/ClimaEarth/components/atmosphere/climaatmos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,36 @@ 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
function Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:diffuse_fraction})
radiation_model = sim.integrator.p.radiation.rrtmgp_model
total_flux_dn = radiation_model.face_sw_flux_dn
face_space = axes(sim.integrator.u.f)
if radiation_model.radiation_mode isa CA.RRTMGPInterface.GrayRadiation
diffuse_fractions = zero(total_flux_dn)
else
direct_flux_dn = radiation_model.face_sw_direct_flux_dn
diffuse_fractions = ((x, y) -> y > zero(y) ? x / y : zero(x)).(total_flux_dn .- direct_flux_dn, total_flux_dn)
end
return CC.Fields.level(CC.Fields.array2field(diffuse_fractions, face_space), CC.Utilities.half)
end
Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{Symbol("cos(zenith_angle)")}) = CC.Fields.array2field(
sim.integrator.p.radiation.rrtmgp_model.cos_zenith,
CC.Fields.level(axes(sim.integrator.u.c), 1),
)
Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:liquid_precipitation}) =
surface_rain_flux(sim.integrator.p.atmos.moisture_model, sim.integrator)
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{:radiative_energy_flux_sfc}) =
surface_radiation_flux(sim.integrator.p.atmos.radiation_mode, sim.integrator)
Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:snow_precipitation}) =
surface_snow_flux(sim.integrator.p.atmos.moisture_model, sim.integrator)
Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:SW_d}) = CC.Fields.level(
CC.Fields.array2field(sim.integrator.p.radiation.rrtmgp_model.face_sw_flux_dn, axes(sim.integrator.u.f)),
CC.Utilities.half,
)
Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:turbulent_energy_flux}) =
CC.Geometry.WVector.(sim.integrator.p.precomputed.sfc_conditions.ρ_flux_h_tot)
Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:turbulent_moisture_flux}) =
Expand Down
6 changes: 6 additions & 0 deletions src/Interfacer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,19 @@ an atmosphere component model.
get_field(
sim::AtmosModelSimulation,
val::Union{
Val{Symbol("cos(zenith_angle)")},
Val{:diffuse_fraction},
Val{:energy},
Val{:height_int},
Val{:height_sfc},
Val{:liquid_precipitation},
Val{:LHF},
Val{:LW_d},
Val{:radiative_energy_flux_sfc},
Val{:radiative_energy_flux_toa},
Val{:snow_precipitation},
Val{:SHF},
Val{:SW_d},
Val{:turblent_energy_flux},
Val{:turbulent_moisture_flux},
Val{:thermo_state_int},
Expand Down

0 comments on commit 328d9b0

Please sign in to comment.