Skip to content

Commit

Permalink
Add hasradiation conditionals to ClimaAtmosSim get_fields
Browse files Browse the repository at this point in the history
  • Loading branch information
imreddyTeja committed Feb 26, 2025
1 parent 0a3055e commit beb25cc
Showing 1 changed file with 45 additions and 24 deletions.
69 changes: 45 additions & 24 deletions experiments/ClimaEarth/components/atmosphere/climaatmos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,41 +171,62 @@ 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
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),
)
Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:co2}) =
sim.integrator.p.radiation.rrtmgp_model.volume_mixing_ratio_co2[]
function Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:cos_zenith_angle})
center_space = CC.Spaces.level(axes(sim.integrator.u.c), 1)
if hasradiation(atmos_sim.integrator)
return CC.Fields.array2field(sim.integrator.p.radiation.rrtmgp_model.cos_zenith, center_space)
else
return fill(one(eltype(sim.integrator.u)), center_space)
end
end
function Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:co2})
if hasradiation(atmos_sim.integrator)
return sim.integrator.p.radiation.rrtmgp_model.volume_mixing_ratio_co2[]
else
return zero(eltype(sim.integrator.u))
end
end
function Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:diffuse_fraction})
radiation_model = sim.integrator.p.radiation.rrtmgp_model
# only take the first level
total_flux_dn = radiation_model.face_sw_flux_dn[1, :]
face_space = CC.Spaces.level(axes(sim.integrator.u.f), CC.Utilities.half)
if radiation_model.radiation_mode isa CA.RRTMGPInterface.GrayRadiation
diffuse_fractions = zero(total_flux_dn)
if hasradiation(atmos_sim.integrator)
radiation_model = sim.integrator.p.radiation.rrtmgp_model
# only take the first level
total_flux_dn = radiation_model.face_sw_flux_dn[1, :]
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[1, :]
FT = eltype(total_flux_dn)
diffuse_fractions =
clamp.((total_flux_dn .- direct_flux_dn) ./ (max.(total_flux_dn, eps(FT))), zero(FT), one(FT))
end
return CC.Fields.array2field(diffuse_fractions, face_space)
else
direct_flux_dn = radiation_model.face_sw_direct_flux_dn[1, :]
FT = eltype(total_flux_dn)
diffuse_fractions =
clamp.((total_flux_dn .- direct_flux_dn) ./ (max.(total_flux_dn, eps(FT))), zero(FT), one(FT))
return fill(zero(eltype(sim.integrator.u)), face_space)
end
return CC.Fields.array2field(diffuse_fractions, face_space)
end
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,
)
function Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:LW_d})
face_space = CC.Spaces.level(axes(sim.integrator.u.f), CC.Utilities.half)
if hasradiation(atmos_sim.integrator)
return CC.Fields.array2field(sim.integrator.p.radiation.rrtmgp_model.face_lw_flux_dn[1, :], face_space)
else
return fill(zero(eltype(sim.integrator.u)), face_space)
end
end
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,
)
function Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:SW_d})
face_space = CC.Spaces.level(axes(sim.integrator.u.f), CC.Utilities.half)
if hasradiation(atmos_sim.integrator)
return CC.Fields.array2field(sim.integrator.p.radiation.rrtmgp_model.face_sw_flux_dn[1, :], face_space)
else
return fill(zero(eltype(sim.integrator.u)), face_space)
end
end
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

0 comments on commit beb25cc

Please sign in to comment.