11# This file is included in Diagnostics.jl
22
3+ """
4+ apply_geometric_scaling!(out, z, planet_radius, FT)
5+
6+ Apply spherical shell geometric correction to radiative fluxes at radial height `z`.
7+
8+ Helper function for scaling radiation diagnostics.
9+ """
10+ function apply_geometric_scaling! (out, z, planet_radius, FT)
11+ @. out *= ((z + planet_radius) / planet_radius)^ (FT (2 ))
12+ end
313# Radiative fluxes
414
515# ##
@@ -17,18 +27,25 @@ function compute_rsd!(
1727 time,
1828 radiation_mode:: T ,
1929) where {T <: RRTMGPI.AbstractRRTMGPMode }
30+ z_lev = Fields. coordinate_field (axes (state. f)). z
31+ planet_radius = CAP. planet_radius (cache. params)
32+ FT = eltype (cache. params)
2033 if isnothing (out)
21- return copy (
34+ out = copy (
2235 Fields. array2field (
2336 cache. radiation. rrtmgp_model. face_sw_flux_dn,
2437 axes (state. f),
2538 ),
2639 )
40+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
41+ return out
2742 else
2843 out .= Fields. array2field (
2944 cache. radiation. rrtmgp_model. face_sw_flux_dn,
3045 axes (state. f),
3146 )
47+ @assert out != = nothing " Output field 'out' must not be `nothing` in this branch"
48+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
3249 end
3350end
3451
@@ -57,8 +74,11 @@ function compute_rsdt!(
5774 radiation_mode:: T ,
5875) where {T <: RRTMGPI.AbstractRRTMGPMode }
5976 nlevels = Spaces. nlevels (axes (state. c))
77+ z_max = Spaces. z_max (axes (state. f))
78+ planet_radius = CAP. planet_radius (cache. params)
79+ FT = eltype (cache. params)
6080 if isnothing (out)
61- return copy (
81+ out = copy (
6282 Fields. level (
6383 Fields. array2field (
6484 cache. radiation. rrtmgp_model. face_sw_flux_dn,
@@ -67,6 +87,8 @@ function compute_rsdt!(
6787 nlevels + half,
6888 ),
6989 )
90+ apply_geometric_scaling! (out, z_max, planet_radius, FT)
91+ return out
7092 else
7193 out .= Fields. level (
7294 Fields. array2field (
@@ -75,6 +97,7 @@ function compute_rsdt!(
7597 ),
7698 nlevels + half,
7799 )
100+ apply_geometric_scaling! (out, z_max, planet_radius, FT)
78101 end
79102end
80103
@@ -147,18 +170,24 @@ function compute_rsu!(
147170 time,
148171 radiation_mode:: T ,
149172) where {T <: RRTMGPI.AbstractRRTMGPMode }
173+ z_lev = Fields. coordinate_field (axes (state. f)). z
174+ planet_radius = CAP. planet_radius (cache. params)
175+ FT = eltype (cache. params)
150176 if isnothing (out)
151- return copy (
177+ out = copy (
152178 Fields. array2field (
153179 cache. radiation. rrtmgp_model. face_sw_flux_up,
154180 axes (state. f),
155181 ),
156182 )
183+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
184+ return out
157185 else
158186 out .= Fields. array2field (
159187 cache. radiation. rrtmgp_model. face_sw_flux_up,
160188 axes (state. f),
161189 )
190+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
162191 end
163192end
164193
@@ -187,8 +216,11 @@ function compute_rsut!(
187216 radiation_mode:: T ,
188217) where {T <: RRTMGPI.AbstractRRTMGPMode }
189218 nlevels = Spaces. nlevels (axes (state. c))
219+ z_max = Spaces. z_max (axes (state. f))
220+ planet_radius = CAP. planet_radius (cache. params)
221+ FT = eltype (cache. params)
190222 if isnothing (out)
191- return copy (
223+ out = copy (
192224 Fields. level (
193225 Fields. array2field (
194226 cache. radiation. rrtmgp_model. face_sw_flux_up,
@@ -197,6 +229,8 @@ function compute_rsut!(
197229 nlevels + half,
198230 ),
199231 )
232+ apply_geometric_scaling! (out, z_max, planet_radius, FT)
233+ return out
200234 else
201235 out .= Fields. level (
202236 Fields. array2field (
@@ -205,6 +239,7 @@ function compute_rsut!(
205239 ),
206240 nlevels + half,
207241 )
242+ apply_geometric_scaling! (out, z_max, planet_radius, FT)
208243 end
209244end
210245
@@ -277,18 +312,24 @@ function compute_rld!(
277312 time,
278313 radiation_mode:: T ,
279314) where {T <: RRTMGPI.AbstractRRTMGPMode }
315+ z_lev = Fields. coordinate_field (axes (state. f)). z
316+ planet_radius = CAP. planet_radius (cache. params)
317+ FT = eltype (cache. params)
280318 if isnothing (out)
281- return copy (
319+ out = copy (
282320 Fields. array2field (
283321 cache. radiation. rrtmgp_model. face_lw_flux_dn,
284322 axes (state. f),
285323 ),
286324 )
325+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
326+ return out
287327 else
288328 out .= Fields. array2field (
289329 cache. radiation. rrtmgp_model. face_lw_flux_dn,
290330 axes (state. f),
291331 )
332+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
292333 end
293334end
294335
@@ -361,18 +402,24 @@ function compute_rlu!(
361402 time,
362403 radiation_mode:: T ,
363404) where {T <: RRTMGPI.AbstractRRTMGPMode }
405+ z_lev = Fields. coordinate_field (axes (state. f)). z
406+ planet_radius = CAP. planet_radius (cache. params)
407+ FT = eltype (cache. params)
364408 if isnothing (out)
365- return copy (
409+ out = copy (
366410 Fields. array2field (
367411 cache. radiation. rrtmgp_model. face_lw_flux_up,
368412 axes (state. f),
369413 ),
370414 )
415+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
416+ return out
371417 else
372418 out .= Fields. array2field (
373419 cache. radiation. rrtmgp_model. face_lw_flux_up,
374420 axes (state. f),
375421 )
422+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
376423 end
377424end
378425
@@ -401,8 +448,11 @@ function compute_rlut!(
401448 radiation_mode:: T ,
402449) where {T <: RRTMGPI.AbstractRRTMGPMode }
403450 nlevels = Spaces. nlevels (axes (state. c))
451+ z_max = Spaces. z_max (axes (state. f))
452+ planet_radius = CAP. planet_radius (cache. params)
453+ FT = eltype (cache. params)
404454 if isnothing (out)
405- return copy (
455+ out = copy (
406456 Fields. level (
407457 Fields. array2field (
408458 cache. radiation. rrtmgp_model. face_lw_flux_up,
@@ -411,6 +461,8 @@ function compute_rlut!(
411461 nlevels + half,
412462 ),
413463 )
464+ apply_geometric_scaling! (out, z_max, planet_radius, FT)
465+ return out
414466 else
415467 out .= Fields. level (
416468 Fields. array2field (
@@ -419,6 +471,7 @@ function compute_rlut!(
419471 ),
420472 nlevels + half,
421473 )
474+ apply_geometric_scaling! (out, z_max, planet_radius, FT)
422475 end
423476end
424477
@@ -491,16 +544,24 @@ function compute_rsdcs!(
491544 time,
492545 radiation_mode:: RRTMGPI.AllSkyRadiationWithClearSkyDiagnostics ,
493546)
547+ z_lev = Fields. coordinate_field (axes (state. f)). z
548+ planet_radius = CAP. planet_radius (cache. params)
549+ FT = eltype (cache. params)
494550 if isnothing (out)
495- return Fields. array2field (
496- cache. radiation. rrtmgp_model. face_clear_sw_flux_dn,
497- axes (state. f),
551+ out = copy (
552+ Fields. array2field (
553+ cache. radiation. rrtmgp_model. face_clear_sw_flux_dn,
554+ axes (state. f),
555+ ),
498556 )
557+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
558+ return out
499559 else
500560 out .= Fields. array2field (
501561 cache. radiation. rrtmgp_model. face_clear_sw_flux_dn,
502562 axes (state. f),
503563 )
564+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
504565 end
505566end
506567
@@ -573,18 +634,24 @@ function compute_rsucs!(
573634 time,
574635 radiation_mode:: RRTMGPI.AllSkyRadiationWithClearSkyDiagnostics ,
575636)
637+ z_lev = Fields. coordinate_field (axes (state. f)). z
638+ planet_radius = CAP. planet_radius (cache. params)
639+ FT = eltype (cache. params)
576640 if isnothing (out)
577- return copy (
641+ out = copy (
578642 Fields. array2field (
579643 cache. radiation. rrtmgp_model. face_clear_sw_flux_up,
580644 axes (state. f),
581645 ),
582646 )
647+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
648+ return out
583649 else
584650 out .= Fields. array2field (
585651 cache. radiation. rrtmgp_model. face_clear_sw_flux_up,
586652 axes (state. f),
587653 )
654+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
588655 end
589656end
590657
@@ -613,8 +680,11 @@ function compute_rsutcs!(
613680 radiation_mode:: T ,
614681) where {T <: RRTMGPI.AbstractRRTMGPMode }
615682 nlevels = Spaces. nlevels (axes (state. c))
683+ z_max = Spaces. z_max (axes (state. f))
684+ planet_radius = CAP. planet_radius (cache. params)
685+ FT = eltype (cache. params)
616686 if isnothing (out)
617- return copy (
687+ out = copy (
618688 Fields. level (
619689 Fields. array2field (
620690 cache. radiation. rrtmgp_model. face_clear_sw_flux_up,
@@ -623,6 +693,8 @@ function compute_rsutcs!(
623693 nlevels + half,
624694 ),
625695 )
696+ apply_geometric_scaling! (out, z_max, planet_radius, FT)
697+ return out
626698 else
627699 out .= Fields. level (
628700 Fields. array2field (
@@ -631,6 +703,7 @@ function compute_rsutcs!(
631703 ),
632704 nlevels + half,
633705 )
706+ apply_geometric_scaling! (out, z_max, planet_radius, FT)
634707 end
635708end
636709
@@ -704,18 +777,24 @@ function compute_rldcs!(
704777 time,
705778 radiation_mode:: RRTMGPI.AllSkyRadiationWithClearSkyDiagnostics ,
706779)
780+ z_lev = Fields. coordinate_field (axes (state. f)). z
781+ planet_radius = CAP. planet_radius (cache. params)
782+ FT = eltype (cache. params)
707783 if isnothing (out)
708- return copy (
784+ out = copy (
709785 Fields. array2field (
710786 cache. radiation. rrtmgp_model. face_clear_lw_flux_dn,
711787 axes (state. f),
712788 ),
713789 )
790+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
791+ return out
714792 else
715793 out .= Fields. array2field (
716794 cache. radiation. rrtmgp_model. face_clear_lw_flux_dn,
717795 axes (state. f),
718796 )
797+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
719798 end
720799end
721800
@@ -788,18 +867,24 @@ function compute_rlucs!(
788867 time,
789868 radiation_mode:: RRTMGPI.AllSkyRadiationWithClearSkyDiagnostics ,
790869)
870+ z_lev = Fields. coordinate_field (axes (state. f)). z
871+ planet_radius = CAP. planet_radius (cache. params)
872+ FT = eltype (cache. params)
791873 if isnothing (out)
792- return copy (
874+ out = copy (
793875 Fields. array2field (
794876 cache. radiation. rrtmgp_model. face_clear_lw_flux_up,
795877 axes (state. f),
796878 ),
797879 )
880+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
881+ return out
798882 else
799883 out .= Fields. array2field (
800884 cache. radiation. rrtmgp_model. face_clear_lw_flux_up,
801885 axes (state. f),
802886 )
887+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
803888 end
804889end
805890
@@ -828,8 +913,11 @@ function compute_rlutcs!(
828913 radiation_mode:: T ,
829914) where {T <: RRTMGPI.AbstractRRTMGPMode }
830915 nlevels = Spaces. nlevels (axes (state. c))
916+ z_max = Spaces. z_max (axes (state. f))
917+ planet_radius = CAP. planet_radius (cache. params)
918+ FT = eltype (cache. params)
831919 if isnothing (out)
832- return copy (
920+ out = copy (
833921 Fields. level (
834922 Fields. array2field (
835923 cache. radiation. rrtmgp_model. face_clear_lw_flux_up,
@@ -838,6 +926,8 @@ function compute_rlutcs!(
838926 nlevels + half,
839927 ),
840928 )
929+ apply_geometric_scaling! (out, z_max, planet_radius, FT)
930+ return out
841931 else
842932 out .= Fields. level (
843933 Fields. array2field (
@@ -846,6 +936,7 @@ function compute_rlutcs!(
846936 ),
847937 nlevels + half,
848938 )
939+ apply_geometric_scaling! (out, z_max, planet_radius, FT)
849940 end
850941end
851942
0 commit comments