Skip to content

Commit

Permalink
cleanup RRTMGP types
Browse files Browse the repository at this point in the history
  • Loading branch information
szy21 committed Jul 11, 2024
1 parent 092f25d commit e734b21
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 50 deletions.
53 changes: 27 additions & 26 deletions src/callbacks/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ NVTX.@annotate function rrtmgp_model_callback!(integrator)

(; ᶜts, cloud_diagnostics_tuple, sfc_conditions) = p.precomputed
(; params) = p
(; idealized_h2o, idealized_clouds) = p.radiation
(; ᶠradiation_flux, rrtmgp_model) = p.radiation
(; radiation_mode) = p.atmos

Expand Down Expand Up @@ -94,7 +93,7 @@ NVTX.@annotate function rrtmgp_model_callback!(integrator)
rrtmgp_model.center_volume_mixing_ratio_h2o,
axes(Y.c),
)
if idealized_h2o
if radiation_mode.idealized_h2o
# slowly increase the relative humidity from 0 to 0.6 to account for
# the fact that we have a very unrealistic initial condition
max_relative_humidity = FT(0.6)
Expand Down Expand Up @@ -132,30 +131,32 @@ NVTX.@annotate function rrtmgp_model_callback!(integrator)
set_insolation_variables!(Y, p, t, p.atmos.insolation)
end

if !idealized_clouds && !(
radiation_mode isa RRTMGPI.GrayRadiation ||
radiation_mode isa RRTMGPI.ClearSkyRadiation
)
ᶜΔz = Fields.Δz_field(Y.c)
ᶜlwp = Fields.array2field(
rrtmgp_model.center_cloud_liquid_water_path,
axes(Y.c),
)
ᶜiwp = Fields.array2field(
rrtmgp_model.center_cloud_ice_water_path,
axes(Y.c),
)
ᶜfrac =
Fields.array2field(rrtmgp_model.center_cloud_fraction, axes(Y.c))
# RRTMGP needs lwp and iwp in g/m^2
kg_to_g_factor = 1000
@. ᶜlwp =
kg_to_g_factor * Y.c.ρ * cloud_diagnostics_tuple.q_liq * ᶜΔz /
max(cloud_diagnostics_tuple.cf, eps(FT))
@. ᶜiwp =
kg_to_g_factor * Y.c.ρ * cloud_diagnostics_tuple.q_ice * ᶜΔz /
max(cloud_diagnostics_tuple.cf, eps(FT))
@. ᶜfrac = cloud_diagnostics_tuple.cf
if radiation_mode isa RRTMGPI.AllSkyRadiation ||
radiation_mode isa RRTMGPI.AllSkyRadiationWithClearSkyDiagnostics
if !radiation_mode.idealized_clouds
ᶜΔz = Fields.Δz_field(Y.c)
ᶜlwp = Fields.array2field(
rrtmgp_model.center_cloud_liquid_water_path,
axes(Y.c),
)
ᶜiwp = Fields.array2field(
rrtmgp_model.center_cloud_ice_water_path,
axes(Y.c),
)
ᶜfrac = Fields.array2field(
rrtmgp_model.center_cloud_fraction,
axes(Y.c),
)
# RRTMGP needs lwp and iwp in g/m^2
kg_to_g_factor = 1000
@. ᶜlwp =
kg_to_g_factor * Y.c.ρ * cloud_diagnostics_tuple.q_liq * ᶜΔz /
max(cloud_diagnostics_tuple.cf, eps(FT))
@. ᶜiwp =
kg_to_g_factor * Y.c.ρ * cloud_diagnostics_tuple.q_ice * ᶜΔz /
max(cloud_diagnostics_tuple.cf, eps(FT))
@. ᶜfrac = cloud_diagnostics_tuple.cf
end
end

if !(radiation_mode isa RRTMGPI.GrayRadiation)
Expand Down
3 changes: 0 additions & 3 deletions src/parameterized_tendencies/radiation/RRTMGPInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ using NVTX

abstract type AbstractRRTMGPMode end
struct GrayRadiation <: AbstractRRTMGPMode
idealized_h2o::Bool
idealized_clouds::Bool
add_isothermal_boundary_layer::Bool
end
struct ClearSkyRadiation <: AbstractRRTMGPMode
idealized_h2o::Bool
idealized_clouds::Bool
add_isothermal_boundary_layer::Bool
aerosol_radiation::Bool
end
Expand Down
14 changes: 1 addition & 13 deletions src/parameterized_tendencies/radiation/radiation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function radiation_model_cache(
)
context = ClimaComms.context(axes(Y.c))
device = context.device
(; idealized_h2o, idealized_clouds) = radiation_mode
if !(radiation_mode isa RRTMGPI.GrayRadiation)
(; aerosol_radiation) = radiation_mode
if aerosol_radiation && !(any(
Expand All @@ -55,15 +54,6 @@ function radiation_model_cache(
FT = Spaces.undertype(axes(Y.c))
DA = ClimaComms.array_type(device){FT}
rrtmgp_params = CAP.rrtmgp_params(params)
if idealized_h2o && radiation_mode isa RRTMGPI.GrayRadiation
error("idealized_h2o can't be used with $radiation_mode")
end
if idealized_clouds && (
radiation_mode isa RRTMGPI.GrayRadiation ||
radiation_mode isa RRTMGPI.ClearSkyRadiation
)
error("idealized_clouds can't be used with $radiation_mode")
end

bottom_coords = Fields.coordinate_field(Spaces.level(Y.c, 1))
if eltype(bottom_coords) <: Geometry.LatLongZPoint
Expand Down Expand Up @@ -158,7 +148,7 @@ function radiation_model_cache(
)
ᶜz = Fields.coordinate_field(Y.c).z
ᶜΔz = Fields.Δz_field(Y.c)
if idealized_clouds # icy cloud on top and wet cloud on bottom
if radiation_mode.idealized_clouds # icy cloud on top and wet cloud on bottom
# TODO: can we avoid using DataLayouts with this?
# `ᶜis_bottom_cloud = similar(ᶜz, Bool)`
ᶜis_bottom_cloud = Fields.Field(
Expand Down Expand Up @@ -240,8 +230,6 @@ function radiation_model_cache(
end
return (;
orbital_data,
idealized_h2o,
idealized_clouds,
rrtmgp_model,
insolation_tuple = similar(Spaces.level(Y.c, 1), Tuple{FT, FT, FT}),
ᶠradiation_flux = similar(Y.f, Geometry.WVector{FT}),
Expand Down
11 changes: 3 additions & 8 deletions src/solver/model_getters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,14 @@ function get_radiation_mode(parsed_args, ::Type{FT}) where {FT}
"DYCOMS",
"TRMM_LBA",
)
return if radiation_name == "clearsky"
return if radiation_name == "gray"
RRTMGPI.GrayRadiation(add_isothermal_boundary_layer)
elseif radiation_name == "clearsky"
RRTMGPI.ClearSkyRadiation(
idealized_h2o,
idealized_clouds,
add_isothermal_boundary_layer,
aerosol_radiation,
)
elseif radiation_name == "gray"
RRTMGPI.GrayRadiation(
idealized_h2o,
idealized_clouds,
add_isothermal_boundary_layer,
)
elseif radiation_name == "allsky"
RRTMGPI.AllSkyRadiation(
idealized_h2o,
Expand Down

0 comments on commit e734b21

Please sign in to comment.