Skip to content

Commit

Permalink
rename radiation_model to rrtmgp_model
Browse files Browse the repository at this point in the history
  • Loading branch information
szy21 committed Jul 3, 2024
1 parent d36c0f6 commit 32a322e
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 80 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ ClimaAtmos.jl Release Notes

Main
-------
- ![][badge-💥breaking] Change "radiation_model" in the radiation cache to "rrtmgp_model".
PR [#3167](https://github.com/CliMA/ClimaAtmos.jl/pull/3167)
- ![][badge-💥breaking] Change the "idealized_insolation" argument to "insolation",
and add RCEMIP insolation. PR [#3150](https://github.com/CliMA/ClimaAtmos.jl/pull/3150)

Expand Down
4 changes: 2 additions & 2 deletions src/cache/surface_albedo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Set the surface albedo to a constant value.
function set_surface_albedo!(Y, p, t, α_model::ConstantAlbedo{FT}) where {FT}

(; direct_sw_surface_albedo, diffuse_sw_surface_albedo) =
p.radiation.radiation_model
p.radiation.rrtmgp_model

@. direct_sw_surface_albedo = α_model.α
@. diffuse_sw_surface_albedo = α_model.α
Expand All @@ -75,7 +75,7 @@ function set_surface_albedo!(
) where {FT}

(; direct_sw_surface_albedo, diffuse_sw_surface_albedo, cos_zenith) =
p.radiation.radiation_model
p.radiation.rrtmgp_model

λ = FT(0) # spectral wavelength (not used for now)
μ = cos_zenith
Expand Down
51 changes: 24 additions & 27 deletions src/callbacks/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ 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, radiation_model) = p.radiation
(; ᶠradiation_flux, rrtmgp_model) = p.radiation
(; radiation_mode) = p.atmos

# If we have prescribed aerosols, we need to update them
Expand All @@ -75,24 +75,21 @@ NVTX.@annotate function rrtmgp_model_callback!(integrator)
T_max = CAP.optics_lookup_temperature_max(params)

sfc_ts = sfc_conditions.ts
sfc_T =
Fields.array2field(radiation_model.surface_temperature, axes(sfc_ts))
sfc_T = Fields.array2field(rrtmgp_model.surface_temperature, axes(sfc_ts))
@. sfc_T = TD.air_temperature(thermo_params, sfc_ts)

ᶜp = Fields.array2field(radiation_model.center_pressure, axes(Y.c))
ᶜT = Fields.array2field(radiation_model.center_temperature, axes(Y.c))
ᶜp = Fields.array2field(rrtmgp_model.center_pressure, axes(Y.c))
ᶜT = Fields.array2field(rrtmgp_model.center_temperature, axes(Y.c))
@. ᶜp = TD.air_pressure(thermo_params, ᶜts)
# TODO: move this to RRTMGP
@. ᶜT =
min(max(TD.air_temperature(thermo_params, ᶜts), FT(T_min)), FT(T_max))

if !(radiation_mode isa RRTMGPI.GrayRadiation)
ᶜrh = Fields.array2field(
radiation_model.center_relative_humidity,
axes(Y.c),
)
ᶜrh =
Fields.array2field(rrtmgp_model.center_relative_humidity, axes(Y.c))
ᶜvmr_h2o = Fields.array2field(
radiation_model.center_volume_mixing_ratio_h2o,
rrtmgp_model.center_volume_mixing_ratio_h2o,
axes(Y.c),
)
if idealized_h2o
Expand Down Expand Up @@ -139,15 +136,15 @@ NVTX.@annotate function rrtmgp_model_callback!(integrator)
)
ᶜΔz = Fields.local_geometry_field(Y.c).∂x∂ξ.components.data.:9
ᶜlwp = Fields.array2field(
radiation_model.center_cloud_liquid_water_path,
rrtmgp_model.center_cloud_liquid_water_path,
axes(Y.c),
)
ᶜiwp = Fields.array2field(
radiation_model.center_cloud_ice_water_path,
rrtmgp_model.center_cloud_ice_water_path,
axes(Y.c),
)
ᶜfrac =
Fields.array2field(radiation_model.center_cloud_fraction, axes(Y.c))
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 =
Expand All @@ -163,7 +160,7 @@ NVTX.@annotate function rrtmgp_model_callback!(integrator)
if radiation_mode.aerosol_radiation
ᶜΔz = Fields.local_geometry_field(Y.c).∂x∂ξ.components.data.:9
ᶜaero_conc = Fields.array2field(
radiation_model.center_aerosol_column_mass_density,
rrtmgp_model.center_aerosol_column_mass_density,
axes(Y.c),
)
@. ᶜaero_conc = p.tracers.prescribed_aerosol_fields.:SO4 * ᶜΔz
Expand All @@ -172,18 +169,18 @@ NVTX.@annotate function rrtmgp_model_callback!(integrator)

set_surface_albedo!(Y, p, t, p.atmos.surface_albedo)

RRTMGPI.update_fluxes!(radiation_model)
Fields.field2array(ᶠradiation_flux) .= radiation_model.face_flux
RRTMGPI.update_fluxes!(rrtmgp_model)
Fields.field2array(ᶠradiation_flux) .= rrtmgp_model.face_flux
return nothing
end

#Uniform insolation, magnitudes from Wing et al. (2018)
#Note that the TOA downward shortwave fluxes won't be the same as the values in the paper if add_isothermal_boundary_layer is true
function set_insolation_variables!(Y, p, t, ::RCEMIPIIInsolation)
FT = Spaces.undertype(axes(Y.c))
(; radiation_model) = p.radiation
radiation_model.cos_zenith .= cosd(FT(42.05))
radiation_model.weighted_irradiance .= FT(551.58)
(; rrtmgp_model) = p.radiation
rrtmgp_model.cos_zenith .= cosd(FT(42.05))
rrtmgp_model.weighted_irradiance .= FT(551.58)
end

function set_insolation_variables!(Y, p, t, ::IdealizedInsolation)
Expand All @@ -194,20 +191,20 @@ function set_insolation_variables!(Y, p, t, ::IdealizedInsolation)
else
latitude = Fields.field2array(zero(bottom_coords.z)) # flat space is on Equator
end
(; radiation_model) = p.radiation
(; rrtmgp_model) = p.radiation
# perpetual equinox with no diurnal cycle
radiation_model.cos_zenith .= cos(FT(π) / 3)
rrtmgp_model.cos_zenith .= cos(FT(π) / 3)
weighted_irradiance =
@. 1360 * (1 + FT(1.2) / 4 * (1 - 3 * sind(latitude)^2)) /
(4 * cos(FT(π) / 3))
radiation_model.weighted_irradiance .= weighted_irradiance
rrtmgp_model.weighted_irradiance .= weighted_irradiance
end

function set_insolation_variables!(Y, p, t, ::TimeVaryingInsolation)
FT = Spaces.undertype(axes(Y.c))
params = p.params
insolation_params = CAP.insolation_params(params)
(; insolation_tuple, radiation_model) = p.radiation
(; insolation_tuple, rrtmgp_model) = p.radiation

current_datetime = p.start_date + Dates.Second(round(Int, t)) # current time
max_zenith_angle = FT(π) / 2 - eps(FT)
Expand All @@ -225,9 +222,9 @@ function set_insolation_variables!(Y, p, t, ::TimeVaryingInsolation)
bottom_coords = Fields.coordinate_field(Spaces.level(Y.c, 1))
if eltype(bottom_coords) <: Geometry.LatLongZPoint
cos_zenith =
Fields.array2field(radiation_model.cos_zenith, axes(bottom_coords))
Fields.array2field(rrtmgp_model.cos_zenith, axes(bottom_coords))
weighted_irradiance = Fields.array2field(
radiation_model.weighted_irradiance,
rrtmgp_model.weighted_irradiance,
axes(bottom_coords),
)
@. insolation_tuple = instantaneous_zenith_angle(
Expand All @@ -242,9 +239,9 @@ function set_insolation_variables!(Y, p, t, ::TimeVaryingInsolation)
else
# assume that the latitude and longitude are both 0 for flat space
insolation_tuple = instantaneous_zenith_angle(d, δ, η_UTC, FT(0), FT(0))
radiation_model.cos_zenith .=
rrtmgp_model.cos_zenith .=
cos(min(first(insolation_tuple), max_zenith_angle))
radiation_model.weighted_irradiance .=
rrtmgp_model.weighted_irradiance .=
irradiance * (au / last(insolation_tuple))^2
end
end
Expand Down
Loading

0 comments on commit 32a322e

Please sign in to comment.