-
Notifications
You must be signed in to change notification settings - Fork 5
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
Tr/add get fields atmos #1205
Tr/add get fields atmos #1205
Changes from 4 commits
df5d7b6
2a48532
97874c1
0077d3c
97044ba
c8329ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,12 +171,54 @@ 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{:air_pressure}) = | ||
CC.Fields.level(sim.integrator.p.precomputed.ᶜp, 1) | ||
Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:air_temperature}) = | ||
TD.air_temperature.( | ||
sim.integrator.p.params.thermodynamics_params, | ||
CC.Fields.level(sim.integrator.p.precomputed.ᶜts, 1), | ||
) | ||
Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:cos_zenith}) = 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{: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, :] | ||
lowest_face_space = CC.Spaces.level(axes(sim.integrator.u.f), CC.Utilities.half) | ||
if radiation_model.radiation_mode isa CA.RRTMGPInterface.GrayRadiation | ||
diffuse_fraction = zero(total_flux_dn) | ||
else | ||
direct_flux_dn = radiation_model.face_sw_direct_flux_dn[1, :] | ||
FT = eltype(total_flux_dn) | ||
diffuse_fraction = | ||
clamp.( | ||
((x, y) -> y > zero(y) ? x / y : zero(y)).(total_flux_dn .- direct_flux_dn, total_flux_dn), | ||
zero(FT), | ||
one(FT), | ||
) | ||
end | ||
return CC.Fields.array2field(diffuse_fraction, lowest_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, | ||
) | ||
Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:humidity}) = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would call it |
||
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}) = | ||
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}) = | ||
|
@@ -201,15 +243,12 @@ function Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:uv_int}) | |
return @. StaticArrays.SVector(uₕ_int.components.data.:1, uₕ_int.components.data.:2) | ||
end | ||
|
||
function Interfacer.update_field!(atmos_sim::ClimaAtmosSimulation, ::Val{:co2}, field) | ||
if atmos_sim.integrator.p.atmos.radiation_mode isa CA.RRTMGPI.GrayRadiation | ||
@warn("Gray radiation model initialized, skipping CO2 update", maxlog = 1) | ||
return | ||
else | ||
atmos_sim.integrator.p.radiation.rrtmgp_model.volume_mixing_ratio_co2 .= Statistics.mean(parent(field)) | ||
end | ||
end | ||
# extensions required by the Interfacer | ||
function Interfacer.update_field!(sim::ClimaAtmosSimulation, ::Val{:emissivity}, field) | ||
# sets all 16 bands (rows) to the same values | ||
sim.integrator.p.radiation.rrtmgp_model.surface_emissivity .= | ||
reshape(CC.Fields.field2array(field), 1, length(parent(field))) | ||
end | ||
Comment on lines
+247
to
+251
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the long term, maybe we can make the RRTMGPInterface assume every band is the same if only one value is passed in (maybe this is already the behavior not? I'm not sure). This way we don't need to hard code the length(parent) here. |
||
function Interfacer.update_field!(sim::ClimaAtmosSimulation, ::Val{:surface_direct_albedo}, field) | ||
sim.integrator.p.radiation.rrtmgp_model.direct_sw_surface_albedo .= | ||
reshape(CC.Fields.field2array(field), 1, length(parent(field))) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,12 +155,20 @@ an atmosphere component model. | |
get_field( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should error if these There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought this would only error if the I think it might still make sense to split the |
||
sim::AtmosModelSimulation, | ||
val::Union{ | ||
Val{:air_pressure}, | ||
Val{:air_temperature}, | ||
Val{:cos_zenith}, | ||
Val{:co2}, | ||
Val{:diffuse_fraction}, | ||
Val{:height_int}, | ||
Val{:height_sfc}, | ||
Val{:humidity}, | ||
Val{:liquid_precipitation}, | ||
Val{:LW_d}, | ||
Val{:radiative_energy_flux_sfc}, | ||
Val{:radiative_energy_flux_toa}, | ||
Val{:snow_precipitation}, | ||
Val{:SW_d}, | ||
Val{:turblent_energy_flux}, | ||
Val{:turbulent_moisture_flux}, | ||
Val{:thermo_state_int}, | ||
|
@@ -214,7 +222,7 @@ If it isn't extended, the field won't be updated and a warning will be raised. | |
update_field!( | ||
sim::AtmosModelSimulation, | ||
val::Union{ | ||
Val{:co2}, | ||
Val{:emissivity}, | ||
Val{:surface_direct_albedo}, | ||
Val{:surface_diffuse_albedo}, | ||
Val{:surface_temperature}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(and same for other bottom variables)