forked from ESCOMP/CLUBB_CESM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadvance_xp2_xpyp_module.F90
3693 lines (2979 loc) · 148 KB
/
advance_xp2_xpyp_module.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!-----------------------------------------------------------------------
! $Id$
!===============================================================================
module advance_xp2_xpyp_module
! Description:
! Contains the subroutine advance_xp2_xpyp and ancillary functions.
!-----------------------------------------------------------------------
implicit none
public :: advance_xp2_xpyp, &
update_xp2_mc
private :: xp2_xpyp_lhs, &
xp2_xpyp_solve, &
xp2_xpyp_uv_rhs, &
xp2_xpyp_rhs, &
xp2_xpyp_implicit_stats, &
term_tp, &
term_dp1_lhs, &
term_dp1_rhs, &
term_pr1, &
term_pr2
private ! Set default scope
! Private named constants to avoid string comparisons
integer, parameter, private :: &
xp2_xpyp_rtp2 = 1, & ! Named constant for rtp2 solves
xp2_xpyp_thlp2 = 2, & ! Named constant for thlp2 solves
xp2_xpyp_rtpthlp = 3, & ! Named constant for rtpthlp solves
xp2_xpyp_up2_vp2 = 4, & ! Named constant for up2_vp2 solves
xp2_xpyp_up2 = 5, & ! Named constant for up2 solves
xp2_xpyp_vp2 = 6, & ! Named constant for vp2 solves
xp2_xpyp_scalars = 7, & ! Named constant for scalar solves
xp2_xpyp_sclrp2 = 8, & ! Named constant for sclrp2 solves
xp2_xpyp_sclrprtp = 9, & ! Named constant for sclrprtp solves
xp2_xpyp_sclrpthlp = 10 ! Named constant for sclrpthlp solves
contains
!=============================================================================
subroutine advance_xp2_xpyp( tau_zm, wm_zm, rtm, wprtp, thlm, & ! In
wpthlp, wpthvp, um, vm, wp2, wp2_zt, & ! In
wp3, upwp, vpwp, sigma_sqd_w, Skw_zm, & ! In
wprtp2, wpthlp2, wprtpthlp, & ! In
Kh_zt, rtp2_forcing, thlp2_forcing, & ! In
rtpthlp_forcing, rho_ds_zm, rho_ds_zt, & ! In
invrs_rho_ds_zm, thv_ds_zm, cloud_frac, & ! In
Lscale, wp3_on_wp2, wp3_on_wp2_zt, & ! In
pdf_implicit_coefs_terms, & ! In
l_iter, dt, & ! In
sclrm, wpsclrp, & ! In
wpsclrp2, wpsclrprtp, wpsclrpthlp, & ! In
wp2_splat, & ! In
rtp2, thlp2, rtpthlp, up2, vp2, & ! Inout
sclrp2, sclrprtp, sclrpthlp) ! Inout
! Description:
! Prognose scalar variances, scalar covariances, and horizontal turbulence components.
! References:
! https://arxiv.org/pdf/1711.03675v1.pdf#nameddest=url:xpyp_eqns
!
! https://arxiv.org/pdf/1711.03675v1.pdf#nameddest=url:up2_vp2_eqns
!
! Eqn. 13, 14, 15 on p. 3545 of
! ``A PDF-Based Model for Boundary Layer Clouds. Part I:
! Method and Model Description'' Golaz, et al. (2002)
! JAS, Vol. 59, pp. 3540--3551.
! See also:
! ``Equations for CLUBB'', Section 4:
! /Steady-state solution for the variances/
!-----------------------------------------------------------------------
use constants_clubb, only: &
w_tol_sqd, & ! Constant(s)
rt_tol, &
thl_tol, &
max_mag_correlation_flux, &
cloud_frac_min, &
fstderr, &
one, &
two_thirds, &
one_half, &
one_third, &
zero, &
zero_threshold
use model_flags, only: &
l_hole_fill, & ! logical constants
l_single_C2_Skw, &
l_explicit_turbulent_adv_xpyp, &
l_upwind_xpyp_ta, &
l_min_xp2_from_corr_wx, &
l_C2_cloud_frac
use parameters_tunable, only: &
C2rt, & ! Variable(s)
C2thl, &
C2rtthl, &
c_K2, &
nu2_vert_res_dep, &
c_K9, &
nu9_vert_res_dep, &
beta, &
C4, &
C14, &
C5, &
C2, &
C2b, &
C2c
use parameters_model, only: &
sclr_dim, & ! Variable(s)
sclr_tol
use grid_class, only: &
gr, & ! Variable(s)
zm2zt, & ! Procedure(s)
zt2zm
use pdf_closure_module, only: &
iiPDF_ADG1, & ! Variable(s)
iiPDF_new, &
iiPDF_type
use pdf_parameter_module, only: &
implicit_coefs_terms ! Variable Type
use turbulent_adv_pdf, only: &
sgn_turbulent_velocity ! Procedure(s)
use clubb_precision, only: &
core_rknd ! Variable(s)
use clip_explicit, only: &
clip_covar, & ! Procedure(s)
clip_variance, &
clip_variance_level, &
clip_sclrp2, &
clip_sclrprtp, &
clip_sclrpthlp
use sponge_layer_damping, only: &
up2_vp2_sponge_damp_settings, & ! Variable(s)
up2_vp2_sponge_damp_profile, &
sponge_damp_xp2 ! Procedure(s)
use stats_type_utilities, only: &
stat_begin_update, & ! Procedure(s)
stat_end_update, &
stat_modify, &
stat_update_var
use error_code, only: &
clubb_at_least_debug_level, & ! Procedure
err_code, & ! Error Indicator
clubb_fatal_error ! Constants
use stats_variables, only: &
stats_zm, & ! Variable(s)
stats_zt, &
icoef_wprtp2_implicit, &
iterm_wprtp2_explicit, &
icoef_wpthlp2_implicit, &
iterm_wpthlp2_explicit, &
icoef_wprtpthlp_implicit, &
iterm_wprtpthlp_explicit, &
irtp2_cl, &
iup2_sdmp, &
ivp2_sdmp, &
iup2_cl, &
ivp2_cl, &
l_stats_samp
use array_index, only: &
iisclr_rt, &
iisclr_thl
implicit none
! Intrinsic functions
intrinsic :: &
exp, sqrt, min
! Constant parameters
logical, parameter :: &
l_clip_large_rtp2 = .true. ! Clip rtp2 to be < rtm^2 * coef
real( kind = core_rknd ), parameter :: &
rtp2_clip_coef = one_half ! Coefficient appled the clipping threshold on rtp2 [-]
! Input variables
real( kind = core_rknd ), intent(in), dimension(gr%nz) :: &
tau_zm, & ! Time-scale tau on momentum levels [s]
wm_zm, & ! w-wind component on momentum levels [m/s]
rtm, & ! Total water mixing ratio (t-levs) [kg/kg]
wprtp, & ! <w'r_t'> (momentum levels) [(m/s)(kg/kg)]
thlm, & ! Liquid potential temp. (t-levs) [K]
wpthlp, & ! <w'th_l'> (momentum levels) [(m K)/s]
wpthvp, & ! <w'th_v'> (momentum levels) [(m K)/s]
um, & ! u wind (thermodynamic levels) [m/s]
vm, & ! v wind (thermodynamic levels) [m/s]
wp2, & ! <w'^2> (momentum levels) [m^2/s^2]
wp2_zt, & ! <w'^2> interpolated to thermo. levels [m^2/s^2]
wp3, & ! <w'^3> (thermodynamic levels) [m^3/s^3]
upwp, & ! <u'w'> (momentum levels) [m^2/s^2]
vpwp, & ! <v'w'> (momentum levels) [m^2/s^2]
sigma_sqd_w, & ! sigma_sqd_w (momentum levels) [-]
Skw_zm, & ! Skewness of w on momentum levels [-]
wprtp2, & ! <w'r_t'^2> (thermodynamic levels) [m/s (kg/kg)^2]
wpthlp2, & ! <w'th_l'^2> (thermodynamic levels) [m/s K^2]
wprtpthlp, & ! <w'r_t'th_l'> (thermodynamic levels) [m/s (kg/kg) K]
Kh_zt, & ! Eddy diffusivity on thermo. levels [m^2/s]
rtp2_forcing, & ! <r_t'^2> forcing (momentum levels) [(kg/kg)^2/s]
thlp2_forcing, & ! <th_l'^2> forcing (momentum levels) [K^2/s]
rtpthlp_forcing, & ! <r_t'th_l'> forcing (momentum levels) [(kg/kg)K/s]
rho_ds_zm, & ! Dry, static density on momentum levs. [kg/m^3]
rho_ds_zt, & ! Dry, static density on thermo. levels [kg/m^3]
invrs_rho_ds_zm, & ! Inv. dry, static density @ mom. levs. [m^3/kg]
thv_ds_zm, & ! Dry, base-state theta_v on mom. levs. [K]
cloud_frac, & ! Cloud fraction (thermodynamic levels) [-]
Lscale, & ! Mixing length [m]
wp3_on_wp2, & ! Smoothed version of <w'^3>/<w'^2> zm [m/s]
wp3_on_wp2_zt ! Smoothed version of <w'^3>/<w'^2> zt [m/s]
type(implicit_coefs_terms), dimension(gr%nz), intent(in) :: &
pdf_implicit_coefs_terms ! Implicit coefs / explicit terms [units vary]
logical, intent(in) :: l_iter ! Whether variances are prognostic
real( kind = core_rknd ), intent(in) :: &
dt ! Model timestep [s]
! Passive scalar input
real( kind = core_rknd ), intent(in), dimension(gr%nz, sclr_dim) :: &
sclrm, & ! Mean value; pass. scalar (t-levs.) [{sclr units}]
wpsclrp, & ! <w'sclr'> (momentum levels) [m/s{sclr units}]
wpsclrp2, & ! <w'sclr'^2> (thermodynamic levels) [m/s{sclr units}^2]
wpsclrprtp, & ! <w'sclr'r_t'> (thermo. levels) [m/s{sclr units)kg/kg]
wpsclrpthlp ! <w'sclr'th_l'> (thermo. levels) [m/s{sclr units}K]
real( kind = core_rknd ), dimension(gr%nz), intent(in) :: &
wp2_splat ! Gustiness tendency for wp2 equation
! Input/Output variables
! An attribute of (inout) is also needed to import the value of the variances
! at the surface. Brian. 12/18/05.
real( kind = core_rknd ), intent(inout), dimension(gr%nz) :: &
rtp2, & ! <r_t'^2> [(kg/kg)^2]
thlp2, & ! <th_l'^2> [K^2]
rtpthlp, & ! <r_t'th_l'> [(kg K)/kg]
up2, & ! <u'^2> [m^2/s^2]
vp2 ! <v'^2> [m^2/s^2]
! Passive scalar output
real( kind = core_rknd ), intent(inout), dimension(gr%nz, sclr_dim) :: &
sclrp2, sclrprtp, sclrpthlp
! Local Variables
real( kind = core_rknd ), dimension(gr%nz) :: &
C2sclr_1d, C2rt_1d, C2thl_1d, C2rtthl_1d, &
C4_C14_1d ! Parameters C4 and C14 combined for simplicity
real( kind = core_rknd ), dimension(gr%nz) :: &
a1 ! a_1 (momentum levels); See eqn. 24 in `Equations for CLUBB' [-]
real( kind = core_rknd ), dimension(gr%nz) :: &
upwp_zt, & ! <u'w'> interpolated to thermodynamic levels [m^2/s^2]
vpwp_zt, & ! <v'w'> interpolated to thermodynamic levels [m^2/s^2]
wpsclrp_zt ! <w'sclr'> interp. to thermo. levels [m/s {sclrm units}]
real( kind = core_rknd ) :: &
threshold ! Minimum value for variances [units vary]
real( kind = core_rknd ), dimension(3,gr%nz) :: &
lhs ! Tridiagonal matrix
real( kind = core_rknd ), dimension(gr%nz,1) :: &
rhs ! RHS vector of tridiagonal matrix
real( kind = core_rknd ), dimension(gr%nz,2) :: &
uv_rhs, &! RHS vectors of tridiagonal system for up2/vp2
uv_solution ! Solution to the tridiagonal system for up2/vp2
real( kind = core_rknd ), dimension(gr%nz,sclr_dim*3) :: &
sclr_rhs, & ! RHS vectors of tridiagonal system for the passive scalars
sclr_solution ! Solution to tridiagonal system for the passive scalars
! Variables for turbulent advection of predictive variances and covariances.
! <w'rt'^2> = coef_wprtp2_implicit * <rt'^2> + term_wprtp2_explicit
real ( kind = core_rknd ), dimension(gr%nz) :: &
coef_wprtp2_implicit, & ! Coefficient that is multiplied by <rt'^2> [m/s]
term_wprtp2_explicit ! Term that is on the RHS [m/s(kg/kg)^2]
real ( kind = core_rknd ), dimension(gr%nz) :: &
coef_wprtp2_implicit_zm, & ! coef_wprtp2_implicit interp. to m-levs [m/s]
term_wprtp2_explicit_zm ! term_wprtp2_expl interp m-levs [m/s(kg/kg)^2]
! <w'thl'^2> = coef_wpthlp2_implicit * <thl'^2> + term_wpthlp2_explicit
real ( kind = core_rknd ), dimension(gr%nz) :: &
coef_wpthlp2_implicit, & ! Coef. that is multiplied by <thl'^2> [m/s]
term_wpthlp2_explicit ! Term that is on the RHS [m/s K^2]
real ( kind = core_rknd ), dimension(gr%nz) :: &
coef_wpthlp2_implicit_zm, & ! coef_wpthlp2_implicit interp. m-levs [m/s]
term_wpthlp2_explicit_zm ! term_wpthlp2_expl interp to m-levs [m/s K^2]
! <w'rt'thl'> = coef_wprtpthlp_implicit*<rt'thl'> + term_wprtpthlp_explicit
real ( kind = core_rknd ), dimension(gr%nz) :: &
coef_wprtpthlp_implicit, & ! Coef. that is multiplied by <rt'thl'> [m/s]
term_wprtpthlp_explicit ! Term that is on the RHS [m/s(kg/kg)K]
real ( kind = core_rknd ), dimension(gr%nz) :: &
coef_wprtpthlp_implicit_zm, & ! coef_wprtpthlp_impl interp. m-levs [m/s]
term_wprtpthlp_explicit_zm ! term_wprtpthlp_expl intrp zm [m/s(kg/kg)K]
! CLUBB does not produce a PDF for horizontal wind components u and v.
! However, turbulent advection of the variances of the horizontal wind
! components, <u'^2> and <v'^2>, is still handled by equations of the form:
! <w'u'^2> = coef_wpup2_implicit * <u'^2> + term_wpup2_explicit; and
! <w'v'^2> = coef_wpvp2_implicit * <v'^2> + term_wpvp2_explicit.
real ( kind = core_rknd ), dimension(gr%nz) :: &
coef_wpup2_wpvp2_implicit, & ! Coef. that is mult. by <u'^2>/<v'^2> [m/s]
term_wpup2_explicit, & ! Term that is on the RHS (<u'^2>) [m^3/s^3]
term_wpvp2_explicit ! Term that is on the RHS (<v'^2>) [m^3/s^3]
real ( kind = core_rknd ), dimension(gr%nz) :: &
coef_wpup2_wpvp2_implicit_zm, & ! coef_wpup2_wpvp2_impl intrp m-levs [m/s]
term_wpup2_explicit_zm, & ! term_wpup2_expl interp. m-levs [m^3/s^3]
term_wpvp2_explicit_zm ! term_wpvp2_expl interp. m-levs [m^3/s^3]
! Sign of turbulent velocity (used for "upwind" turbulent advection)
real ( kind = core_rknd ), dimension(gr%nz) :: &
sgn_t_vel_rtp2, & ! Sign of the turbulent velocity for <rt'^2> [-]
sgn_t_vel_thlp2, & ! Sign of the turbulent velocity for <thl'^2> [-]
sgn_t_vel_rtpthlp, & ! Sign of the turbulent velocity for <rt'thl'> [-]
sgn_t_vel_up2_vp2 ! Sign of the turbulent vel. for <u'^2>/<v'^2> [-]
! <w'sclr'x'> = coef_wpsclrpxp_implicit*<sclr'x'> + term_wpsclrpxp_explicit;
! where x is sclr, rt, or thl.
real ( kind = core_rknd ), dimension(gr%nz) :: &
coef_wpsclrpxp_implicit, & ! Coef. that is multiplied by <sclr'x'> [m/s]
term_wpsclrp2_explicit, & ! Term that is on the RHS [units vary]
term_wpsclrprtp_explicit, & ! Term that is on the RHS [units vary]
term_wpsclrpthlp_explicit ! Term that is on the RHS [units vary]
real ( kind = core_rknd ), dimension(gr%nz) :: &
coef_wpsclrpxp_implicit_zm, & ! coef_wpsclrpxp_impl interp. m-levs [m/s]
term_wpsclrp2_explicit_zm, & ! term_wpsclrp2_expl interp zm [un vary]
term_wpsclrprtp_explicit_zm, & ! term_wpsclrprtp_expl interp zm [un vary]
term_wpsclrpthlp_explicit_zm ! term_wpsclrpthlp_expl intrp zm [un vary]
! Sign of turbulent velocity (used for "upwind" turbulent advection)
real ( kind = core_rknd ), dimension(gr%nz) :: &
sgn_t_vel_sclrpxp, & ! Sign of the turbulent velocity for <sclr'x'> [-]
sgn_t_vel_sclrp2, & ! Sign of the turbulent velocity for <sclr'^2> [-]
sgn_t_vel_sclrprtp, & ! Sign of the turbulent velocity for <sclr'rt'> [-]
sgn_t_vel_sclrpthlp ! Sign of the turbulent vel. for <sclr'thl'> [-]
! Eddy Diffusion for Variances and Covariances.
real( kind = core_rknd ), dimension(gr%nz) :: &
Kw2, & ! For rtp2, thlp2, rtpthlp, and passive scalars [m^2/s]
Kw9 ! For up2 and vp2 [m^2/s]
real( kind = core_rknd ), dimension(gr%nz) :: &
a1_zt, & ! a_1 interpolated to thermodynamic levels [-]
wprtp_zt, & ! w'r_t' interpolated to thermodynamic levels [(kg/kg) m/s]
wpthlp_zt ! w'th_l' interpolated to thermodyamnic levels [K m/s]
real( kind = core_rknd ), dimension(gr%nz) :: &
rtpthlp_chnge ! Net change in r_t'th_l' due to clipping [(kg/kg) K]
real( kind = core_rknd ), dimension(gr%nz,sclr_dim) :: &
sclrprtp_chnge, & ! Net change in sclr'r_t' due to clipping [units vary]
sclrpthlp_chnge ! Net change in sclr'th_l' due to clipping [units vary]
real( kind = core_rknd ), dimension(gr%nz) :: &
sclrp2_forcing, & ! <sclr'^2> forcing (momentum levels) [units vary]
sclrprtp_forcing, & ! <sclr'r_t'> forcing (momentum levels) [units vary]
sclrpthlp_forcing ! <sclr'th_l'> forcing (momentum levels) [units vary]
logical :: l_scalar_calc, l_first_clip_ts, l_last_clip_ts
! Minimum value of cloud fraction to multiply C2 by to calculate the
! adjusted value of C2.
real( kind = core_rknd ), parameter :: &
min_cloud_frac_mult = 0.10_core_rknd
! Loop indices
integer :: i, k
!---------------------------- Begin Code ----------------------------------
if ( clubb_at_least_debug_level( 0 ) ) then
! Assertion check for C5
if ( C5 > one .or. C5 < zero ) then
write(fstderr,*) "The C5 variable is outside the valid range"
err_code = clubb_fatal_error
return
end if
end if
if ( l_single_C2_Skw ) then
! Use a single value of C2 for all equations.
C2rt_1d = C2b + ( C2 - C2b ) * exp( -one_half * ( Skw_zm / C2c )**2 )
if ( l_C2_cloud_frac ) then
do k = 1, gr%nz, 1
if ( cloud_frac(k) >= cloud_frac_min ) then
C2rt_1d(k) &
= C2rt_1d(k) * max( min_cloud_frac_mult, cloud_frac(k) )
endif ! cloud_frac(k) >= cloud_frac_min
enddo ! k = 1, gr%nz, 1
endif ! l_C2_cloud_frac
C2thl_1d = C2rt_1d
C2rtthl_1d = C2rt_1d
C2sclr_1d = C2rt_1d
else ! .not. l_single_C2_Skw
! Use 3 different values of C2 for rtp2, thlp2, rtpthlp.
if ( l_C2_cloud_frac ) then
do k = 1, gr%nz, 1
if ( cloud_frac(k) >= cloud_frac_min ) then
C2rt_1d(k) = C2rt * max( min_cloud_frac_mult, cloud_frac(k) )
C2thl_1d(k) = C2thl * max( min_cloud_frac_mult, cloud_frac(k) )
C2rtthl_1d(k) = C2rtthl &
* max( min_cloud_frac_mult, cloud_frac(k) )
else ! cloud_frac(k) < cloud_frac_min
C2rt_1d(k) = C2rt
C2thl_1d(k) = C2thl
C2rtthl_1d(k) = C2rtthl
endif ! cloud_frac(k) >= cloud_frac_min
enddo ! k = 1, gr%nz, 1
else
C2rt_1d = C2rt
C2thl_1d = C2thl
C2rtthl_1d = C2rtthl
endif ! l_C2_cloud_frac
C2sclr_1d = C2rt ! Use rt value for now
endif ! l_single_C2_Skw
! Combine C4 and C14 for simplicity
C4_C14_1d(1:gr%nz) = ( two_thirds * C4 ) + ( one_third * C14 )
! Are we solving for passive scalars as well?
if ( sclr_dim > 0 ) then
l_scalar_calc = .true.
else
l_scalar_calc = .false.
end if
! Define a_1 (located on momentum levels).
! It is a variable that is a function of sigma_sqd_w (where sigma_sqd_w is
! located on the momentum levels). This will be used for the turbulent
! advection (ta) terms for the ADG1 PDF. This will also be used for the
! turbulent advection of <u'^2> and <v'^2>, regardless of which PDF type or
! turbulent advection option is used.
a1(1:gr%nz) = one / ( one - sigma_sqd_w(1:gr%nz) )
! Interpolate a_1 from the momentum levels to the thermodynamic levels.
a1_zt = max( zm2zt( a1 ), zero_threshold ) ! Positive definite quantity
! Set up the implicit coefficients and explicit terms for turbulent
! advection of <rt'^2>, <thl'^2>, and <rt'thl'>.
if ( l_explicit_turbulent_adv_xpyp ) then
! The turbulent advection of <x'y'> is handled explicitly.
! The <rt'^2> turbulent advection term is entirely explicit, as
! term_wprtp2_explicit is equal to <w'rt'^2> as calculated using PDF
! parameters, which is general for any PDF type. The value of
! <w'rt'^2> is calculated on thermodynamic levels. The value of
! coef_wprtp2_implicit is always 0.
coef_wprtp2_implicit = zero
term_wprtp2_explicit = wprtp2
if ( l_upwind_xpyp_ta ) then
! Interpolate term_wprtp2_explicit to momentum levels as
! term_wprtp2_explicit_zm. The value of coef_wprtp2_implicit_zm is
! always 0.
coef_wprtp2_implicit_zm = zero
term_wprtp2_explicit_zm = zt2zm( term_wprtp2_explicit )
! Calculate the sign of the turbulent velocity for <rt'^2>.
sgn_t_vel_rtp2 &
= sgn_turbulent_velocity( term_wprtp2_explicit_zm, rtp2 )
endif ! l_upwind_xpyp_ta
! The <thl'^2> turbulent advection term is entirely explicit, as
! term_wpthlp2_explicit is equal to <w'thl'^2> as calculated using PDF
! parameters, which is general for any PDF type. The value of
! <w'thl'^2> is calculated on thermodynamic levels. The value of
! coef_wpthlp2_implicit is always 0.
coef_wpthlp2_implicit = zero
term_wpthlp2_explicit = wpthlp2
if ( l_upwind_xpyp_ta ) then
! Interpolate term_wpthlp2_explicit to momentum levels as
! term_wpthlp2_explicit_zm. The value of coef_wpthlp2_implicit_zm is
! always 0.
coef_wpthlp2_implicit_zm = zero
term_wpthlp2_explicit_zm = zt2zm( term_wpthlp2_explicit )
! Calculate the sign of the turbulent velocity for <thl'^2>.
sgn_t_vel_thlp2 &
= sgn_turbulent_velocity( term_wpthlp2_explicit_zm, thlp2 )
endif ! l_upwind_xpyp_ta
! The <rt'thl'> turbulent advection term is entirely explicit, as
! term_wprtpthlp_explicit is equal to <w'rt'thl'> as calculated using PDF
! parameters, which is general for any PDF type. The value of
! <w'rt'thl'> is calculated on thermodynamic levels. The value of
! coef_wprtpthlp_implicit is always 0.
coef_wprtpthlp_implicit = zero
term_wprtpthlp_explicit = wprtpthlp
if ( l_upwind_xpyp_ta ) then
! Interpolate term_wprtpthlp_explicit to momentum levels as
! term_wprtpthlp_explicit_zm. The value of coef_wprtpthlp_implicit_zm
! is always 0.
coef_wprtpthlp_implicit_zm = zero
term_wprtpthlp_explicit_zm = zt2zm( term_wprtpthlp_explicit )
! Calculate the sign of the turbulent velocity for <rt'thl'>.
sgn_t_vel_rtpthlp &
= sgn_turbulent_velocity( term_wprtpthlp_explicit_zm, rtpthlp )
endif ! l_upwind_xpyp_ta
else ! .not. l_explicit_turbulent_adv_xpyp
! The turbulent advection of <x'y'> is handled implicitly or
! semi-implicitly.
if ( iiPDF_type == iiPDF_ADG1 ) then
! The ADG1 PDF is used.
! Calculate the implicit coefficients and explicit terms on
! thermodynamic grid levels.
! Interpolate <w'rt'> and <w'thl'> from the momentum levels to the
! thermodynamic levels. These will be used for the turbulent
! advection terms for the ADG1 PDF.
wprtp_zt = zm2zt( wprtp )
wpthlp_zt = zm2zt( wpthlp )
! Implicit coefficient on <rt'^2> in <w'rt'^2> equation.
coef_wprtp2_implicit = one_third * beta * a1_zt * wp3_on_wp2_zt
! Explicit (RHS) term in <w'rt'^2> equation.
term_wprtp2_explicit &
= ( one - one_third * beta ) * a1_zt**2 * wprtp_zt**2 &
* wp3_on_wp2_zt / wp2_zt
if ( l_upwind_xpyp_ta ) then
! Calculate coef_wprtp2_implicit and term_wprtp2_explicit on
! momentum levels as coef_wprtp2_implicit_zm and
! term_wprtp2_explicit_zm, respectively.
coef_wprtp2_implicit_zm = one_third * beta * a1 * wp3_on_wp2
term_wprtp2_explicit_zm &
= ( one - one_third * beta ) * a1**2 * wprtp**2 * wp3_on_wp2 / wp2
! For ADG1, the sign of the turbulent velocity is the sign of
! <w'^3> / <w'^2>. For simplicity, the sign of turbulent velocity
! is set to wp3_on_wp2.
sgn_t_vel_rtp2 = wp3_on_wp2
endif ! l_upwind_xpyp_ta
! Implicit coefficient on <thl'^2> in <w'thl'^2> equation.
! For ADG1, this is the same as coef_wprtp2_implicit.
coef_wpthlp2_implicit = coef_wprtp2_implicit
! Explicit (RHS) term in <w'thl'^2> equation.
term_wpthlp2_explicit &
= ( one - one_third * beta ) * a1_zt**2 * wpthlp_zt**2 &
* wp3_on_wp2_zt / wp2_zt
if ( l_upwind_xpyp_ta ) then
! Calculate coef_wpthlp2_implicit and term_wpthlp2_explicit on
! momentum levels as coef_wpthlp2_implicit_zm and
! term_wpthlp2_explicit_zm, respectively.
coef_wpthlp2_implicit_zm = coef_wprtp2_implicit_zm
term_wpthlp2_explicit_zm &
= ( one - one_third * beta ) * a1**2 * wpthlp**2 * wp3_on_wp2 / wp2
! For ADG1, the sign of the turbulent velocity is the sign of
! <w'^3> / <w'^2>. For simplicity, the sign of turbulent velocity
! is set to wp3_on_wp2.
sgn_t_vel_thlp2 = wp3_on_wp2
endif ! l_upwind_xpyp_ta
! Implicit coefficient on <rt'thl'> in <w'rt'thl'> equation.
! For ADG1, this is the same as coef_wprtp2_implicit.
coef_wprtpthlp_implicit = coef_wprtp2_implicit
! Explicit (RHS) term in <w'rt'thl'> equation.
term_wprtpthlp_explicit &
= ( one - one_third * beta ) * a1_zt**2 * wprtp_zt * wpthlp_zt &
* wp3_on_wp2_zt / wp2_zt
if ( l_upwind_xpyp_ta ) then
! Calculate coef_wprtpthlp_implicit and term_wprtpthlp_explicit
! on momentum levels as coef_wprtpthlp_implicit_zm and
! term_wprtpthlp_explicit_zm, respectively.
coef_wprtpthlp_implicit_zm = coef_wprtp2_implicit_zm
term_wprtpthlp_explicit_zm &
= ( one - one_third * beta ) * a1**2 * wprtp * wpthlp &
* wp3_on_wp2 / wp2
! For ADG1, the sign of the turbulent velocity is the sign of
! <w'^3> / <w'^2>. For simplicity, the sign of turbulent velocity
! is set to wp3_on_wp2.
sgn_t_vel_rtpthlp = wp3_on_wp2
endif ! l_upwind_xpyp_ta
elseif ( iiPDF_type == iiPDF_new ) then
! The new PDF is used.
! Unpack the variables coef_wprtp2_implicit, coef_wpthlp2_implicit,
! coef_wprtpthlp_implicit, and term_wprtpthlp_explicit from
! pdf_implicit_coefs_terms. The PDF parameters and the resulting
! implicit coefficients and explicit terms are calculated on
! thermodynamic levels.
! Implicit coefficient on <rt'^2> in <w'rt'^2> equation.
coef_wprtp2_implicit = pdf_implicit_coefs_terms%coef_wprtp2_implicit
! The <rt'^2> turbulent advection term is entirely implicit, as
! <w'rt'^2> = coef_wprtp2_implicit * <rt'^2>. The value of
! term_wprtp2_explicit is always 0.
term_wprtp2_explicit = zero
if ( l_upwind_xpyp_ta ) then
! Interpolate coef_wprtp2_implicit to momentum levels as
! coef_wprtp2_implicit_zm. The value of term_wprtp2_explicit_zm is
! always 0.
coef_wprtp2_implicit_zm = zt2zm( coef_wprtp2_implicit )
term_wprtp2_explicit_zm = zero
! Calculate the sign of the turbulent velocity for <rt'^2>.
sgn_t_vel_rtp2 &
= sgn_turbulent_velocity( coef_wprtp2_implicit_zm * rtp2, rtp2 )
endif ! l_upwind_xpyp_ta
! Implicit coefficient on <thl'^2> in <w'thl'^2> equation.
coef_wpthlp2_implicit = pdf_implicit_coefs_terms%coef_wpthlp2_implicit
! The <thl'^2> turbulent advection term is entirely implicit, as
! <w'thl'^2> = coef_wpthlp2_implicit * <thl'^2>. The value of
! term_wpthlp2_explicit is always 0.
term_wpthlp2_explicit = zero
if ( l_upwind_xpyp_ta ) then
! Interpolate coef_wpthlp2_implicit to momentum levels as
! coef_wpthlp2_implicit_zm. The value of term_wpthlp2_explicit_zm
! is always 0.
coef_wpthlp2_implicit_zm = zt2zm( coef_wpthlp2_implicit )
term_wpthlp2_explicit_zm = zero
! Calculate the sign of the turbulent velocity for <thlp'^2>.
sgn_t_vel_thlp2 &
= sgn_turbulent_velocity( coef_wpthlp2_implicit_zm * thlp2, thlp2 )
endif ! l_upwind_xpyp_ta
! Implicit coefficient on <rt'thl'> in <w'rt'thl'> equation.
coef_wprtpthlp_implicit &
= pdf_implicit_coefs_terms%coef_wprtpthlp_implicit
! Explicit (RHS) term in <w'rt'thl'> equation.
term_wprtpthlp_explicit &
= pdf_implicit_coefs_terms%term_wprtpthlp_explicit
if ( l_upwind_xpyp_ta ) then
! Interpolate coef_wprtpthlp_implicit and term_wprtpthlp_explicit
! to momentum levels as coef_wprtpthlp_implicit_zm and
! term_wprtpthlp_explicit_zm, respectively.
coef_wprtpthlp_implicit_zm = zt2zm( coef_wprtpthlp_implicit )
term_wprtpthlp_explicit_zm = zt2zm( term_wprtpthlp_explicit )
! Calculate the sign of the turbulent velocity for <rt'thl'>.
sgn_t_vel_rtpthlp &
= sgn_turbulent_velocity( coef_wprtpthlp_implicit_zm * rtpthlp &
+ term_wprtpthlp_explicit_zm, rtpthlp )
endif ! l_upwind_xpyp_ta
endif ! iiPDF_type
endif ! l_explicit_turbulent_adv_xpyp
if ( l_stats_samp ) then
call stat_update_var( icoef_wprtp2_implicit, coef_wprtp2_implicit, &
stats_zt )
call stat_update_var( iterm_wprtp2_explicit, term_wprtp2_explicit, &
stats_zt )
call stat_update_var( icoef_wpthlp2_implicit, coef_wpthlp2_implicit, &
stats_zt )
call stat_update_var( iterm_wpthlp2_explicit, term_wpthlp2_explicit, &
stats_zt )
call stat_update_var( icoef_wprtpthlp_implicit, &
coef_wprtpthlp_implicit, stats_zt )
call stat_update_var( iterm_wprtpthlp_explicit, &
term_wprtpthlp_explicit, stats_zt )
endif ! l_stats_samp
! Set up the implicit coefficients and explicit terms for turbulent
! advection of <u'^2> and <v'^2>.
! CLUBB does not produce a PDF for horizontal wind components u and v.
! However, the code for the ADG1 PDF is still used to handle the turbulent
! advection for the variances of the horizontal wind components, <u'^2>
! and <v'^2>. The ADG1 code is used regardless of which PDF type or
! turbulent advection option is used. The implicit coefficients and
! explicit terms are calculated on thermodynamic grid levels.
! Interpolate <u'w'> and <v'w'> from the momentum levels to the
! thermodynamic levels. These will be used for the turbulent advection
! terms in each equation.
upwp_zt = zm2zt( upwp )
vpwp_zt = zm2zt( vpwp )
! Implicit coefficient on <u'^2> or <v'^2> in <w'u'^2> or <w'v'^2> equation.
coef_wpup2_wpvp2_implicit = one_third * beta * a1_zt * wp3_on_wp2_zt
! Explicit (RHS) term in <w'u'^2> equation.
term_wpup2_explicit &
= ( one - one_third * beta ) * a1_zt**2 * upwp_zt**2 &
* wp3_on_wp2_zt / wp2_zt
! Explicit (RHS) term in <w'v'^2> equation.
term_wpvp2_explicit &
= ( one - one_third * beta ) * a1_zt**2 * vpwp_zt**2 &
* wp3_on_wp2_zt / wp2_zt
if ( l_upwind_xpyp_ta ) then
! Calculate coef_wpup2_wpvp2_implicit, term_wpup2_explicit, and
! term_wpvp2_explicit on momentum levels as coef_wpup2_wpvp2_implicit_zm,
! term_wpup2_explicit_zm, and term_wpvp2_explicit_zm, respectively.
coef_wpup2_wpvp2_implicit_zm = one_third * beta * a1 * wp3_on_wp2
term_wpup2_explicit_zm &
= ( one - one_third * beta ) * a1**2 * upwp**2 * wp3_on_wp2 / wp2
term_wpvp2_explicit_zm &
= ( one - one_third * beta ) * a1**2 * vpwp**2 * wp3_on_wp2 / wp2
! For ADG1, the sign of the turbulent velocity is the sign of
! <w'^3> / <w'^2>. For simplicity, the sign of turbulent velocity is set
! to wp3_on_wp2.
sgn_t_vel_up2_vp2 = wp3_on_wp2
endif ! l_upwind_xpyp_ta
! Define the Coefficent of Eddy Diffusivity for the variances
! and covariances.
do k = 1, gr%nz, 1
! Kw2 is used for variances and covariances rtp2, thlp2, rtpthlp, and
! passive scalars. The variances and covariances are located on the
! momentum levels. Kw2 is located on the thermodynamic levels.
! Kw2 = c_K2 * Kh_zt
Kw2(k) = c_K2 * Kh_zt(k)
! Kw9 is used for variances up2 and vp2. The variances are located on
! the momentum levels. Kw9 is located on the thermodynamic levels.
! Kw9 = c_K9 * Kh_zt
Kw9(k) = c_K9 * Kh_zt(k)
enddo
!!!!!***** r_t'^2 *****!!!!!
! Implicit contributions to term rtp2
call xp2_xpyp_lhs( dt, l_iter, & ! In
coef_wprtp2_implicit, coef_wprtp2_implicit_zm, & ! In
sgn_t_vel_rtp2, tau_zm, wm_zm, Kw2, & ! In
rho_ds_zt, rho_ds_zm, invrs_rho_ds_zm, & ! In
C2rt_1d, nu2_vert_res_dep, & ! In
lhs ) ! Out
call xp2_xpyp_rhs( xp2_xpyp_rtp2, dt, l_iter, & ! In
coef_wprtp2_implicit, coef_wprtp2_implicit_zm, & ! In
term_wprtp2_explicit, term_wprtp2_explicit_zm, & ! In
sgn_t_vel_rtp2, wprtp, wprtp, & ! In
rtm, rtm, rtp2, rtp2_forcing, & ! In
rho_ds_zm, rho_ds_zt, invrs_rho_ds_zm, & ! In
C2rt_1d, tau_zm, rt_tol**2, & ! In
rhs ) ! Out
! Solve the tridiagonal system
call xp2_xpyp_solve( xp2_xpyp_rtp2, 1, & ! Intent(in)
rhs, lhs, rtp2 ) ! Intent(inout)
if ( l_stats_samp ) then
call xp2_xpyp_implicit_stats( xp2_xpyp_rtp2, rtp2 ) ! Intent(in)
end if
!!!!!***** th_l'^2 *****!!!!!
! Implicit contributions to term thlp2
call xp2_xpyp_lhs( dt, l_iter, & ! In
coef_wpthlp2_implicit, coef_wpthlp2_implicit_zm, & ! In
sgn_t_vel_thlp2, tau_zm, wm_zm, Kw2, & ! In
rho_ds_zt, rho_ds_zm, invrs_rho_ds_zm, & ! In
C2thl_1d, nu2_vert_res_dep, & ! In
lhs ) ! Out
! Explicit contributions to thlp2
call xp2_xpyp_rhs( xp2_xpyp_thlp2, dt, l_iter, & ! In
coef_wpthlp2_implicit, coef_wpthlp2_implicit_zm, & ! In
term_wpthlp2_explicit, term_wpthlp2_explicit_zm, & ! In
sgn_t_vel_thlp2, wpthlp, wpthlp, & ! In
thlm, thlm, thlp2, thlp2_forcing, & ! In
rho_ds_zm, rho_ds_zt, invrs_rho_ds_zm, & ! In
C2thl_1d, tau_zm, thl_tol**2, & ! In
rhs ) ! Out
! Solve the tridiagonal system
call xp2_xpyp_solve( xp2_xpyp_thlp2, 1, & ! Intent(in)
rhs, lhs, thlp2 ) ! Intent(inout)
if ( l_stats_samp ) then
call xp2_xpyp_implicit_stats( xp2_xpyp_thlp2, thlp2 ) ! Intent(in)
end if
!!!!!***** r_t'th_l' *****!!!!!
! Implicit contributions to term rtpthlp
call xp2_xpyp_lhs( dt, l_iter, & ! In
coef_wprtpthlp_implicit, coef_wprtpthlp_implicit_zm, &!In
sgn_t_vel_rtpthlp, tau_zm, wm_zm, Kw2, & ! In
rho_ds_zt, rho_ds_zm, invrs_rho_ds_zm, & ! In
C2rtthl_1d, nu2_vert_res_dep, & ! In
lhs ) ! Out
! Explicit contributions to rtpthlp
call xp2_xpyp_rhs( xp2_xpyp_rtpthlp, dt, l_iter, & ! In
coef_wprtpthlp_implicit, coef_wprtpthlp_implicit_zm, &!In
term_wprtpthlp_explicit, term_wprtpthlp_explicit_zm, &!In
sgn_t_vel_rtpthlp, wprtp, wpthlp, & ! In
rtm, thlm, rtpthlp, rtpthlp_forcing, & ! In
rho_ds_zm, rho_ds_zt, invrs_rho_ds_zm, & ! In
C2rtthl_1d, tau_zm, zero_threshold, & ! In
rhs ) ! Out
! Solve the tridiagonal system
call xp2_xpyp_solve( xp2_xpyp_rtpthlp, 1, & ! Intent(in)
rhs, lhs, rtpthlp ) ! Intent(inout)
if ( l_stats_samp ) then
call xp2_xpyp_implicit_stats( xp2_xpyp_rtpthlp, rtpthlp ) ! Intent(in)
end if
!!!!!***** u'^2 / v'^2 *****!!!!!
! Implicit contributions to term up2/vp2
call xp2_xpyp_lhs( dt, l_iter, & ! In
coef_wpup2_wpvp2_implicit, & ! In
coef_wpup2_wpvp2_implicit_zm, & ! In
sgn_t_vel_up2_vp2, tau_zm, wm_zm, Kw9, & ! In
rho_ds_zt, rho_ds_zm, invrs_rho_ds_zm, & ! In
C4_C14_1d, nu9_vert_res_dep, & ! In
lhs ) ! Out
! Explicit contributions to up2
call xp2_xpyp_uv_rhs( xp2_xpyp_up2, dt, l_iter, & ! In
coef_wpup2_wpvp2_implicit, & ! In
coef_wpup2_wpvp2_implicit_zm, & ! In
term_wpup2_explicit, term_wpup2_explicit_zm, & ! In
sgn_t_vel_up2_vp2, wp2, wp2_zt, wpthvp, & ! In
Lscale, C4_C14_1d, tau_zm, & ! In
um, vm, upwp, vpwp, up2, vp2, & ! In
rho_ds_zt, rho_ds_zm, invrs_rho_ds_zm, & ! In
thv_ds_zm, C4, C5, C14, wp2_splat, & ! In
uv_rhs(:,1) ) ! Out
! Explicit contributions to vp2
call xp2_xpyp_uv_rhs( xp2_xpyp_vp2, dt, l_iter, & ! In
coef_wpup2_wpvp2_implicit, & ! In
coef_wpup2_wpvp2_implicit_zm, & ! In
term_wpvp2_explicit, term_wpvp2_explicit_zm, & ! In
sgn_t_vel_up2_vp2, wp2, wp2_zt, wpthvp, & ! In
Lscale, C4_C14_1d, tau_zm, & ! In
vm, um, vpwp, upwp, vp2, up2, & ! In
rho_ds_zt, rho_ds_zm, invrs_rho_ds_zm, & ! In
thv_ds_zm, C4, C5, C14, wp2_splat, & ! In
uv_rhs(:,2) ) ! Out
! Solve the tridiagonal system
call xp2_xpyp_solve( xp2_xpyp_up2_vp2, 2, & ! Intent(in)
uv_rhs, lhs, & ! Intent(inout)
uv_solution ) ! Intent(out)
up2(1:gr%nz) = uv_solution(1:gr%nz,1)
vp2(1:gr%nz) = uv_solution(1:gr%nz,2)
if ( l_stats_samp ) then
call xp2_xpyp_implicit_stats( xp2_xpyp_up2, up2 ) ! Intent(in)
call xp2_xpyp_implicit_stats( xp2_xpyp_vp2, vp2 ) ! Intent(in)
end if
! Apply the positive definite scheme to variances
if ( l_hole_fill ) then
call pos_definite_variances( xp2_xpyp_rtp2, dt, rt_tol**2, & ! Intent(in)
rho_ds_zm, rho_ds_zt, & ! Intent(in)
rtp2 ) ! Intent(inout)
call pos_definite_variances( xp2_xpyp_thlp2, dt, thl_tol**2, & ! Intent(in)
rho_ds_zm, rho_ds_zt, & ! Intent(in)
thlp2 ) ! Intent(inout)
call pos_definite_variances( xp2_xpyp_up2, dt, w_tol_sqd, & ! Intent(in)
rho_ds_zm, rho_ds_zt, & ! Intent(in)
up2 ) ! Intent(inout)
call pos_definite_variances( xp2_xpyp_vp2, dt, w_tol_sqd, & ! Intent(in)
rho_ds_zm, rho_ds_zt, & ! Intent(in)
vp2 ) ! Intent(inout)
endif
! Clipping for r_t'^2
!threshold = zero_threshold
!
!where ( wp2 >= w_tol_sqd ) &
! threshold = rt_tol*rt_tol
! The value of rtp2 is not allowed to become smaller than the threshold
! value of rt_tol^2. Additionally, that threshold value may be boosted at
! any grid level in order to keep the overall correlation of w and rt
! between the values of -max_mag_correlation_flux and
! max_mag_correlation_flux by boosting rtp2 rather than by limiting the
! magnitude of wprtp.
if ( l_min_xp2_from_corr_wx ) then
! The overall correlation of w and rt is:
!
! corr_w_rt = wprtp / ( sqrt( wp2 ) * sqrt( rtp2 ) ).
!
! Squaring both sides, the equation becomes:
!
! corr_w_rt^2 = wprtp^2 / ( wp2 * rtp2 ).
!
! Using max_mag_correlation_flux for the correlation and then solving for
! the minimum of rtp2, the equation becomes:
!
! rtp2|_min = wprtp^2 / ( wp2 * max_mag_correlation_flux^2 ).
do k = 1, gr%nz, 1
threshold &
= max( rt_tol**2, &
wprtp(k)**2 / ( wp2(k) * max_mag_correlation_flux**2 ) )
call clip_variance_level( xp2_xpyp_rtp2, dt, threshold, k, & ! In
rtp2(k) ) ! In/out
enddo ! k = 1, gr%nz, 1
else
! Consider only the minimum tolerance threshold value for rtp2.