1
1
# This file is included in Diagnostics.jl
2
2
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
3
13
# Radiative fluxes
4
14
5
15
# ##
@@ -17,18 +27,25 @@ function compute_rsd!(
17
27
time,
18
28
radiation_mode:: T ,
19
29
) 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)
20
33
if isnothing (out)
21
- return copy (
34
+ out = copy (
22
35
Fields. array2field (
23
36
cache. radiation. rrtmgp_model. face_sw_flux_dn,
24
37
axes (state. f),
25
38
),
26
39
)
40
+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
41
+ return out
27
42
else
28
43
out .= Fields. array2field (
29
44
cache. radiation. rrtmgp_model. face_sw_flux_dn,
30
45
axes (state. f),
31
46
)
47
+ @assert out != = nothing " Output field 'out' must not be `nothing` in this branch"
48
+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
32
49
end
33
50
end
34
51
@@ -57,8 +74,11 @@ function compute_rsdt!(
57
74
radiation_mode:: T ,
58
75
) where {T <: RRTMGPI.AbstractRRTMGPMode }
59
76
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)
60
80
if isnothing (out)
61
- return copy (
81
+ out = copy (
62
82
Fields. level (
63
83
Fields. array2field (
64
84
cache. radiation. rrtmgp_model. face_sw_flux_dn,
@@ -67,6 +87,8 @@ function compute_rsdt!(
67
87
nlevels + half,
68
88
),
69
89
)
90
+ apply_geometric_scaling! (out, z_max, planet_radius, FT)
91
+ return out
70
92
else
71
93
out .= Fields. level (
72
94
Fields. array2field (
@@ -75,6 +97,7 @@ function compute_rsdt!(
75
97
),
76
98
nlevels + half,
77
99
)
100
+ apply_geometric_scaling! (out, z_max, planet_radius, FT)
78
101
end
79
102
end
80
103
@@ -147,18 +170,24 @@ function compute_rsu!(
147
170
time,
148
171
radiation_mode:: T ,
149
172
) 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)
150
176
if isnothing (out)
151
- return copy (
177
+ out = copy (
152
178
Fields. array2field (
153
179
cache. radiation. rrtmgp_model. face_sw_flux_up,
154
180
axes (state. f),
155
181
),
156
182
)
183
+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
184
+ return out
157
185
else
158
186
out .= Fields. array2field (
159
187
cache. radiation. rrtmgp_model. face_sw_flux_up,
160
188
axes (state. f),
161
189
)
190
+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
162
191
end
163
192
end
164
193
@@ -187,8 +216,11 @@ function compute_rsut!(
187
216
radiation_mode:: T ,
188
217
) where {T <: RRTMGPI.AbstractRRTMGPMode }
189
218
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)
190
222
if isnothing (out)
191
- return copy (
223
+ out = copy (
192
224
Fields. level (
193
225
Fields. array2field (
194
226
cache. radiation. rrtmgp_model. face_sw_flux_up,
@@ -197,6 +229,8 @@ function compute_rsut!(
197
229
nlevels + half,
198
230
),
199
231
)
232
+ apply_geometric_scaling! (out, z_max, planet_radius, FT)
233
+ return out
200
234
else
201
235
out .= Fields. level (
202
236
Fields. array2field (
@@ -205,6 +239,7 @@ function compute_rsut!(
205
239
),
206
240
nlevels + half,
207
241
)
242
+ apply_geometric_scaling! (out, z_max, planet_radius, FT)
208
243
end
209
244
end
210
245
@@ -277,18 +312,24 @@ function compute_rld!(
277
312
time,
278
313
radiation_mode:: T ,
279
314
) 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)
280
318
if isnothing (out)
281
- return copy (
319
+ out = copy (
282
320
Fields. array2field (
283
321
cache. radiation. rrtmgp_model. face_lw_flux_dn,
284
322
axes (state. f),
285
323
),
286
324
)
325
+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
326
+ return out
287
327
else
288
328
out .= Fields. array2field (
289
329
cache. radiation. rrtmgp_model. face_lw_flux_dn,
290
330
axes (state. f),
291
331
)
332
+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
292
333
end
293
334
end
294
335
@@ -361,18 +402,24 @@ function compute_rlu!(
361
402
time,
362
403
radiation_mode:: T ,
363
404
) 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)
364
408
if isnothing (out)
365
- return copy (
409
+ out = copy (
366
410
Fields. array2field (
367
411
cache. radiation. rrtmgp_model. face_lw_flux_up,
368
412
axes (state. f),
369
413
),
370
414
)
415
+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
416
+ return out
371
417
else
372
418
out .= Fields. array2field (
373
419
cache. radiation. rrtmgp_model. face_lw_flux_up,
374
420
axes (state. f),
375
421
)
422
+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
376
423
end
377
424
end
378
425
@@ -401,8 +448,11 @@ function compute_rlut!(
401
448
radiation_mode:: T ,
402
449
) where {T <: RRTMGPI.AbstractRRTMGPMode }
403
450
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)
404
454
if isnothing (out)
405
- return copy (
455
+ out = copy (
406
456
Fields. level (
407
457
Fields. array2field (
408
458
cache. radiation. rrtmgp_model. face_lw_flux_up,
@@ -411,6 +461,8 @@ function compute_rlut!(
411
461
nlevels + half,
412
462
),
413
463
)
464
+ apply_geometric_scaling! (out, z_max, planet_radius, FT)
465
+ return out
414
466
else
415
467
out .= Fields. level (
416
468
Fields. array2field (
@@ -419,6 +471,7 @@ function compute_rlut!(
419
471
),
420
472
nlevels + half,
421
473
)
474
+ apply_geometric_scaling! (out, z_max, planet_radius, FT)
422
475
end
423
476
end
424
477
@@ -491,16 +544,24 @@ function compute_rsdcs!(
491
544
time,
492
545
radiation_mode:: RRTMGPI.AllSkyRadiationWithClearSkyDiagnostics ,
493
546
)
547
+ z_lev = Fields. coordinate_field (axes (state. f)). z
548
+ planet_radius = CAP. planet_radius (cache. params)
549
+ FT = eltype (cache. params)
494
550
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
+ ),
498
556
)
557
+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
558
+ return out
499
559
else
500
560
out .= Fields. array2field (
501
561
cache. radiation. rrtmgp_model. face_clear_sw_flux_dn,
502
562
axes (state. f),
503
563
)
564
+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
504
565
end
505
566
end
506
567
@@ -573,18 +634,24 @@ function compute_rsucs!(
573
634
time,
574
635
radiation_mode:: RRTMGPI.AllSkyRadiationWithClearSkyDiagnostics ,
575
636
)
637
+ z_lev = Fields. coordinate_field (axes (state. f)). z
638
+ planet_radius = CAP. planet_radius (cache. params)
639
+ FT = eltype (cache. params)
576
640
if isnothing (out)
577
- return copy (
641
+ out = copy (
578
642
Fields. array2field (
579
643
cache. radiation. rrtmgp_model. face_clear_sw_flux_up,
580
644
axes (state. f),
581
645
),
582
646
)
647
+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
648
+ return out
583
649
else
584
650
out .= Fields. array2field (
585
651
cache. radiation. rrtmgp_model. face_clear_sw_flux_up,
586
652
axes (state. f),
587
653
)
654
+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
588
655
end
589
656
end
590
657
@@ -613,8 +680,11 @@ function compute_rsutcs!(
613
680
radiation_mode:: T ,
614
681
) where {T <: RRTMGPI.AbstractRRTMGPMode }
615
682
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)
616
686
if isnothing (out)
617
- return copy (
687
+ out = copy (
618
688
Fields. level (
619
689
Fields. array2field (
620
690
cache. radiation. rrtmgp_model. face_clear_sw_flux_up,
@@ -623,6 +693,8 @@ function compute_rsutcs!(
623
693
nlevels + half,
624
694
),
625
695
)
696
+ apply_geometric_scaling! (out, z_max, planet_radius, FT)
697
+ return out
626
698
else
627
699
out .= Fields. level (
628
700
Fields. array2field (
@@ -631,6 +703,7 @@ function compute_rsutcs!(
631
703
),
632
704
nlevels + half,
633
705
)
706
+ apply_geometric_scaling! (out, z_max, planet_radius, FT)
634
707
end
635
708
end
636
709
@@ -704,18 +777,24 @@ function compute_rldcs!(
704
777
time,
705
778
radiation_mode:: RRTMGPI.AllSkyRadiationWithClearSkyDiagnostics ,
706
779
)
780
+ z_lev = Fields. coordinate_field (axes (state. f)). z
781
+ planet_radius = CAP. planet_radius (cache. params)
782
+ FT = eltype (cache. params)
707
783
if isnothing (out)
708
- return copy (
784
+ out = copy (
709
785
Fields. array2field (
710
786
cache. radiation. rrtmgp_model. face_clear_lw_flux_dn,
711
787
axes (state. f),
712
788
),
713
789
)
790
+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
791
+ return out
714
792
else
715
793
out .= Fields. array2field (
716
794
cache. radiation. rrtmgp_model. face_clear_lw_flux_dn,
717
795
axes (state. f),
718
796
)
797
+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
719
798
end
720
799
end
721
800
@@ -788,18 +867,24 @@ function compute_rlucs!(
788
867
time,
789
868
radiation_mode:: RRTMGPI.AllSkyRadiationWithClearSkyDiagnostics ,
790
869
)
870
+ z_lev = Fields. coordinate_field (axes (state. f)). z
871
+ planet_radius = CAP. planet_radius (cache. params)
872
+ FT = eltype (cache. params)
791
873
if isnothing (out)
792
- return copy (
874
+ out = copy (
793
875
Fields. array2field (
794
876
cache. radiation. rrtmgp_model. face_clear_lw_flux_up,
795
877
axes (state. f),
796
878
),
797
879
)
880
+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
881
+ return out
798
882
else
799
883
out .= Fields. array2field (
800
884
cache. radiation. rrtmgp_model. face_clear_lw_flux_up,
801
885
axes (state. f),
802
886
)
887
+ apply_geometric_scaling! (out, z_lev, planet_radius, FT)
803
888
end
804
889
end
805
890
@@ -828,8 +913,11 @@ function compute_rlutcs!(
828
913
radiation_mode:: T ,
829
914
) where {T <: RRTMGPI.AbstractRRTMGPMode }
830
915
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)
831
919
if isnothing (out)
832
- return copy (
920
+ out = copy (
833
921
Fields. level (
834
922
Fields. array2field (
835
923
cache. radiation. rrtmgp_model. face_clear_lw_flux_up,
@@ -838,6 +926,8 @@ function compute_rlutcs!(
838
926
nlevels + half,
839
927
),
840
928
)
929
+ apply_geometric_scaling! (out, z_max, planet_radius, FT)
930
+ return out
841
931
else
842
932
out .= Fields. level (
843
933
Fields. array2field (
@@ -846,6 +936,7 @@ function compute_rlutcs!(
846
936
),
847
937
nlevels + half,
848
938
)
939
+ apply_geometric_scaling! (out, z_max, planet_radius, FT)
849
940
end
850
941
end
851
942
0 commit comments