Skip to content

Commit 52734d3

Browse files
Merge pull request #3779 from CliMA/as/test-rad-update
Testing updated RRTMGPInterface following RRTMGP changes to deep-atmosphere metrics
2 parents f54dc38 + 8cb0603 commit 52734d3

File tree

6 files changed

+77
-16
lines changed

6 files changed

+77
-16
lines changed

config/longrun_configs/amip_target_edonly.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ h_elem: 16
22
z_max: 60000.0
33
z_elem: 63
44
dz_bottom: 30.0
5-
deep_atmosphere: false
5+
deep_atmosphere: true
6+
mesh_warp_type: "SLEVE"
67
rayleigh_sponge: true
78
viscous_sponge: true
89
dt_save_state_to_disk: "30days"

perf/jet_test_nfailures.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ using Test
3838
# inference. By increasing this counter, we acknowledge that
3939
# we have introduced an inference failure. We hope to drive
4040
# this number down to 0.
41-
n_allowed_failures = 248
41+
n_allowed_failures = 249
4242
@show n
4343
if n < n_allowed_failures
4444
@info "Please update the n-failures to $n"

reproducibility_tests/ref_counter.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
235
1+
236
22

33
# **README**
44
#
@@ -20,6 +20,10 @@
2020

2121

2222
#=
23+
236
24+
- Radiation fluxes in runs with the `deep_atmosphere` configuration now take into account the
25+
column expansion with height. Affects only cases with `DeepSphericalGlobalGeometry`.
26+
2327
235
2428
- Related to #3775, the computation and update of non-orographic gravity wave (NOGW)
2529
are now separated into callback and tendencies update, affecting the NOGW-related

src/parameterized_tendencies/radiation/RRTMGPInterface.jl

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ using Random
1919
abstract type AbstractRRTMGPMode end
2020
struct GrayRadiation <: AbstractRRTMGPMode
2121
add_isothermal_boundary_layer::Bool
22+
deep_atmosphere::Bool
2223
end
2324
struct ClearSkyRadiation <: AbstractRRTMGPMode
2425
idealized_h2o::Bool
2526
add_isothermal_boundary_layer::Bool
2627
aerosol_radiation::Bool
28+
deep_atmosphere::Bool
2729
end
2830
struct AllSkyRadiation{ACR <: AbstractCloudInRadiation} <: AbstractRRTMGPMode
2931
idealized_h2o::Bool
@@ -39,6 +41,7 @@ struct AllSkyRadiation{ACR <: AbstractCloudInRadiation} <: AbstractRRTMGPMode
3941
Disable this option when running production runs.
4042
"""
4143
reset_rng_seed::Bool
44+
deep_atmosphere::Bool
4245
end
4346
struct AllSkyRadiationWithClearSkyDiagnostics{
4447
ACR <: AbstractCloudInRadiation,
@@ -56,6 +59,7 @@ struct AllSkyRadiationWithClearSkyDiagnostics{
5659
Disable this option when running production runs.
5760
"""
5861
reset_rng_seed::Bool
62+
deep_atmosphere::Bool
5963
end
6064

6165
"""
@@ -260,7 +264,7 @@ function extrap!(
260264
@. p = p⁺ * (T / T⁺)^(cₚ / R)
261265
end
262266

263-
struct RRTMGPModel{R, I, B, L, P, LWS, SWS, AS, V}
267+
struct RRTMGPModel{R, I, B, L, P, LWS, SWS, AS, V, M}
264268
radiation_mode::R
265269
interpolation::I
266270
bottom_extrapolation::B
@@ -270,6 +274,7 @@ struct RRTMGPModel{R, I, B, L, P, LWS, SWS, AS, V}
270274
sw_solver::SWS
271275
as::AS # Atmospheric state
272276
views::V # user-friendly views into the solver
277+
metric_scaling::M
273278
end
274279

275280
# Allow cache to be moved on the CPU. Used by ClimaCoupler to save checkpoints
@@ -539,6 +544,7 @@ array.
539544
`requires_z(interpolation) || requires_z(bottom_extrapolation)`:
540545
- `center_z`: z-coordinate in m at cell centers
541546
- `face_z`: z-coordinate in m at cell faces
547+
- `planet_radius`: planet radius (used to compute metric scaling factor)
542548
"""
543549
RRTMGPModel(
544550
params::RRTMGP.Parameters.ARP,
@@ -694,6 +700,11 @@ function _RRTMGPModel(
694700
end
695701

696702
p_lev = DA{FT}(undef, nlay + 1, ncol)
703+
if radiation_mode.deep_atmosphere && :planet_radius in keys(dict)
704+
metric_scaling = DA{FT}(undef, nlay + 1, ncol)
705+
else
706+
metric_scaling = nothing
707+
end
697708
t_lev = DA{FT}(undef, nlay + 1, ncol)
698709
t_sfc = DA{FT}(undef, ncol)
699710
set_and_save!(t_sfc, "surface_temperature", t..., dict)
@@ -863,7 +874,6 @@ function _RRTMGPModel(
863874
else
864875
aerosol_state = nothing
865876
end
866-
867877
as = RRTMGP.AtmosphericStates.AtmosphericState(
868878
lon,
869879
lat,
@@ -876,7 +886,6 @@ function _RRTMGPModel(
876886
cloud_state,
877887
aerosol_state,
878888
)
879-
880889
end
881890

882891
sw_solver = RRTMGP.RTE.TwoStreamSWRTE(
@@ -901,6 +910,14 @@ function _RRTMGPModel(
901910
set_and_save!(z_lay, "center_z", t..., dict)
902911
z_lev = DA{FT}(undef, nlay + 1, ncol)
903912
set_and_save!(z_lev, "face_z", t..., dict)
913+
if radiation_mode.deep_atmosphere && :planet_radius in keys(dict)
914+
planet_radius = pop!(dict, :planet_radius)
915+
# Area ratio appears in denominator of RRTMGP scaling functions,
916+
# we therefore pass the multiplicative inverse from ClimaAtmos to
917+
# use mult ops instead of div in RRTMGP GPU kernels.
918+
metric_scaling .=
919+
inv.(((z_lev .+ planet_radius) ./ planet_radius) .^ (FT(2)))
920+
end
904921
end
905922

906923
if length(dict) > 0
@@ -921,6 +938,7 @@ function _RRTMGPModel(
921938
sw_solver,
922939
as,
923940
NamedTuple(views),
941+
metric_scaling,
924942
)
925943
end
926944

@@ -1143,14 +1161,15 @@ get_vmr_h2o(vmr::RRTMGP.Vmrs.Vmr, idx_gases_sw) =
11431161
view(vmr.vmr, idx_gases_sw["h2o"], :, :)
11441162

11451163
NVTX.@annotate update_lw_fluxes!(::GrayRadiation, model) =
1146-
RRTMGP.RTESolver.solve_lw!(model.lw_solver, model.as)
1164+
RRTMGP.RTESolver.solve_lw!(model.lw_solver, model.as, model.metric_scaling)
11471165
NVTX.@annotate update_lw_fluxes!(::ClearSkyRadiation, model) =
11481166
RRTMGP.RTESolver.solve_lw!(
11491167
model.lw_solver,
11501168
model.as,
11511169
model.lookups.lookup_lw,
11521170
nothing,
11531171
model.lookups.lookup_lw_aero,
1172+
model.metric_scaling,
11541173
)
11551174
NVTX.@annotate update_lw_fluxes!(::AllSkyRadiation, model) =
11561175
RRTMGP.RTESolver.solve_lw!(
@@ -1159,6 +1178,7 @@ NVTX.@annotate update_lw_fluxes!(::AllSkyRadiation, model) =
11591178
model.lookups.lookup_lw,
11601179
model.lookups.lookup_lw_cld,
11611180
model.lookups.lookup_lw_aero,
1181+
model.metric_scaling,
11621182
)
11631183
NVTX.@annotate function update_lw_fluxes!(
11641184
::AllSkyRadiationWithClearSkyDiagnostics,
@@ -1170,6 +1190,7 @@ NVTX.@annotate function update_lw_fluxes!(
11701190
model.lookups.lookup_lw,
11711191
nothing,
11721192
model.lookups.lookup_lw_aero,
1193+
model.metric_scaling,
11731194
)
11741195
parent(model.face_clear_lw_flux_up) .= parent(model.face_lw_flux_up)
11751196
parent(model.face_clear_lw_flux_dn) .= parent(model.face_lw_flux_dn)
@@ -1180,18 +1201,20 @@ NVTX.@annotate function update_lw_fluxes!(
11801201
model.lookups.lookup_lw,
11811202
model.lookups.lookup_lw_cld,
11821203
model.lookups.lookup_lw_aero,
1204+
model.metric_scaling,
11831205
)
11841206
end
11851207

11861208
NVTX.@annotate update_sw_fluxes!(::GrayRadiation, model) =
1187-
RRTMGP.RTESolver.solve_sw!(model.sw_solver, model.as)
1209+
RRTMGP.RTESolver.solve_sw!(model.sw_solver, model.as, model.metric_scaling)
11881210
NVTX.@annotate update_sw_fluxes!(::ClearSkyRadiation, model) =
11891211
RRTMGP.RTESolver.solve_sw!(
11901212
model.sw_solver,
11911213
model.as,
11921214
model.lookups.lookup_sw,
11931215
nothing,
11941216
model.lookups.lookup_sw_aero,
1217+
model.metric_scaling,
11951218
)
11961219
NVTX.@annotate update_sw_fluxes!(::AllSkyRadiation, model) =
11971220
RRTMGP.RTESolver.solve_sw!(
@@ -1200,6 +1223,7 @@ NVTX.@annotate update_sw_fluxes!(::AllSkyRadiation, model) =
12001223
model.lookups.lookup_sw,
12011224
model.lookups.lookup_sw_cld,
12021225
model.lookups.lookup_sw_aero,
1226+
model.metric_scaling,
12031227
)
12041228
NVTX.@annotate function update_sw_fluxes!(
12051229
::AllSkyRadiationWithClearSkyDiagnostics,
@@ -1211,6 +1235,7 @@ NVTX.@annotate function update_sw_fluxes!(
12111235
model.lookups.lookup_sw,
12121236
nothing,
12131237
model.lookups.lookup_sw_aero,
1238+
model.metric_scaling,
12141239
)
12151240
parent(model.face_clear_sw_flux_up) .= parent(model.face_sw_flux_up)
12161241
parent(model.face_clear_sw_flux_dn) .= parent(model.face_sw_flux_dn)
@@ -1223,6 +1248,7 @@ NVTX.@annotate function update_sw_fluxes!(
12231248
model.lookups.lookup_sw,
12241249
model.lookups.lookup_sw_cld,
12251250
model.lookups.lookup_sw_aero,
1251+
model.metric_scaling,
12261252
)
12271253
end
12281254

src/parameterized_tendencies/radiation/radiation.jl

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ function rrtmgp_model_kwargs(
106106
ᶠspace = Spaces.face_space(space)
107107
ᶜz = Fields.coordinate_field(ᶜspace).z
108108
ᶠz = Fields.coordinate_field(ᶠspace).z
109+
if ᶜspace.grid.global_geometry isa Geometry.AbstractSphericalGlobalGeometry
110+
planet_radius = ᶜspace.grid.global_geometry.radius
111+
end
109112
bottom_coords = Fields.coordinate_field(Spaces.level(ᶜspace, 1))
110113
latitude = if eltype(bottom_coords) <: Geometry.LatLongZPoint
111114
Fields.field2array(bottom_coords.lat)
@@ -117,8 +120,18 @@ function rrtmgp_model_kwargs(
117120
optical_thickness_parameter = (@. 7.2 + (1.8 - 7.2) * sind(latitude)^2),
118121
latitude,
119122
)
120-
zkwargs =
121-
(; center_z = Fields.field2array(ᶜz), face_z = Fields.field2array(ᶠz))
123+
if ᶜspace.grid.global_geometry isa Geometry.AbstractSphericalGlobalGeometry
124+
zkwargs = (;
125+
center_z = Fields.field2array(ᶜz),
126+
face_z = Fields.field2array(ᶠz),
127+
planet_radius = planet_radius,
128+
)
129+
else
130+
zkwargs = (;
131+
center_z = Fields.field2array(ᶜz),
132+
face_z = Fields.field2array(ᶠz),
133+
)
134+
end
122135
return include_z ? (; kwargs..., zkwargs...) : kwargs
123136
end
124137

@@ -137,6 +150,9 @@ function rrtmgp_model_kwargs(
137150
ᶜΔz = Fields.Δz_field(ᶜspace)
138151
ᶜz = Fields.coordinate_field(ᶜspace).z
139152
ᶠz = Fields.coordinate_field(ᶠspace).z
153+
if ᶜspace.grid.global_geometry isa Geometry.AbstractSphericalGlobalGeometry
154+
planet_radius = ᶜspace.grid.global_geometry.radius
155+
end
140156
latitude = if eltype(bottom_coords) <: Geometry.LatLongZPoint
141157
Fields.field2array(bottom_coords.lat)
142158
else
@@ -256,11 +272,21 @@ function rrtmgp_model_kwargs(
256272
end
257273

258274
if include_z
259-
kwargs = (;
260-
kwargs...,
261-
center_z = Fields.field2array(ᶜz),
262-
face_z = Fields.field2array(ᶠz),
263-
)
275+
if ᶜspace.grid.global_geometry isa
276+
Geometry.AbstractSphericalGlobalGeometry
277+
kwargs = (;
278+
kwargs...,
279+
center_z = Fields.field2array(ᶜz),
280+
face_z = Fields.field2array(ᶠz),
281+
planet_radius = planet_radius,
282+
)
283+
else
284+
kwargs = (;
285+
kwargs...,
286+
center_z = Fields.field2array(ᶜz),
287+
face_z = Fields.field2array(ᶠz),
288+
)
289+
end
264290
end
265291
end
266292
return kwargs

src/solver/model_getters.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ function get_radiation_mode(parsed_args, ::Type{FT}) where {FT}
238238
reset_rng_seed = parsed_args["radiation_reset_rng_seed"]
239239
@assert reset_rng_seed in (true, false)
240240
radiation_name = parsed_args["rad"]
241+
deep_atmosphere = parsed_args["deep_atmosphere"]
241242
@assert radiation_name in (
242243
nothing,
243244
"nothing",
@@ -257,12 +258,13 @@ function get_radiation_mode(parsed_args, ::Type{FT}) where {FT}
257258
@warn "prescribe_clouds_in_radiation does not have any effect with $radiation_name radiation option"
258259
end
259260
return if radiation_name == "gray"
260-
RRTMGPI.GrayRadiation(add_isothermal_boundary_layer)
261+
RRTMGPI.GrayRadiation(add_isothermal_boundary_layer, deep_atmosphere)
261262
elseif radiation_name == "clearsky"
262263
RRTMGPI.ClearSkyRadiation(
263264
idealized_h2o,
264265
add_isothermal_boundary_layer,
265266
aerosol_radiation,
267+
deep_atmosphere,
266268
)
267269
elseif radiation_name == "allsky"
268270
RRTMGPI.AllSkyRadiation(
@@ -272,6 +274,7 @@ function get_radiation_mode(parsed_args, ::Type{FT}) where {FT}
272274
add_isothermal_boundary_layer,
273275
aerosol_radiation,
274276
reset_rng_seed,
277+
deep_atmosphere,
275278
)
276279
elseif radiation_name == "allskywithclear"
277280
RRTMGPI.AllSkyRadiationWithClearSkyDiagnostics(
@@ -281,6 +284,7 @@ function get_radiation_mode(parsed_args, ::Type{FT}) where {FT}
281284
add_isothermal_boundary_layer,
282285
aerosol_radiation,
283286
reset_rng_seed,
287+
deep_atmosphere,
284288
)
285289
elseif radiation_name == "DYCOMS"
286290
RadiationDYCOMS{FT}()

0 commit comments

Comments
 (0)