forked from ESCOMP/CLUBB_CESM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_clubb_pdf_params.F90
4261 lines (3442 loc) · 176 KB
/
setup_clubb_pdf_params.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 setup_clubb_pdf_params
implicit none
private
public :: setup_pdf_parameters, &
compute_mean_stdev, &
calc_comp_mu_sigma_hm, &
norm_transform_mean_stdev, &
comp_corr_norm, &
denorm_transform_corr
private :: component_corr_w_x, &
component_corr_chi_eta, &
component_corr_w_hm_n_ip, &
component_corr_x_hm_n_ip, &
component_corr_hmx_hmy_n_ip, &
component_corr_eta_hm_n_ip, &
calc_corr_w_hm_n, &
pdf_param_hm_stats, &
pdf_param_ln_hm_stats, &
pack_hydromet_pdf_params, &
compute_rtp2_from_chi
! Prescribed parameters are set to in-cloud or outside-cloud (below-cloud)
! values based on whether or not cloud water mixing ratio has a value of at
! least rc_tol. However, this does not take into account the amount of
! cloudiness in a component, just whether or not there is any cloud in the
! component. The option l_interp_prescribed_params allows for an interpolated
! value between the in-cloud and below-cloud parameter value based on the
! component cloud fraction.
logical, parameter, private :: &
l_interp_prescribed_params = .false.
contains
!=============================================================================
subroutine setup_pdf_parameters( nz, pdf_dim, dt, & ! Intent(in)
Nc_in_cloud, rcm, cloud_frac, & ! Intent(in)
ice_supersat_frac, hydromet, wphydrometp, & ! Intent(in)
corr_array_n_cloud, corr_array_n_below, & ! Intent(in)
pdf_params, l_stats_samp, & ! Intent(in)
l_use_precip_frac, & ! Intent(in)
l_predict_upwp_vpwp, & ! Intent(in)
l_diagnose_correlations, & ! Intent(in)
l_calc_w_corr, & ! Intent(in)
l_const_Nc_in_cloud, & ! Intent(in)
l_fix_w_chi_eta_correlations, & ! Intent(in)
hydrometp2, & ! Intent(out)
mu_x_1_n, mu_x_2_n, & ! Intent(out)
sigma_x_1_n, sigma_x_2_n, & ! Intent(out)
corr_array_1_n, corr_array_2_n, & ! Intent(out)
corr_cholesky_mtx_1, corr_cholesky_mtx_2, & ! Intent(out)
hydromet_pdf_params ) ! Intent(out)
! Description:
! References:
!-----------------------------------------------------------------------
use grid_class, only: &
gr, & ! Variable(s)
zm2zt, & ! Procedure(s)
zt2zm
use constants_clubb, only: &
one, & ! Constant(s)
zero, &
rc_tol, &
Ncn_tol, &
cloud_frac_min, &
fstderr, &
zero_threshold
use pdf_parameter_module, only: &
pdf_parameter ! Variable(s)
use hydromet_pdf_parameter_module, only: &
hydromet_pdf_parameter, & ! Type
init_hydromet_pdf_params ! Procedure
use parameters_model, only: &
hydromet_dim ! Variable(s)
use array_index, only: &
hydromet_list, & ! Variable(s)
hydromet_tol, &
iiPDF_Ncn, &
iiPDF_chi, &
iiPDF_eta
use precipitation_fraction, only: &
precip_fraction
use Nc_Ncn_eqns, only: &
Nc_in_cloud_to_Ncnm ! Procedure(s)
use advance_windm_edsclrm_module, only: &
xpwp_fnc
use variables_diagnostic_module, only: &
Kh_zm
use parameters_tunable, only: &
c_K_hm
use pdf_utilities, only: &
calc_xp2, & ! Procedure(s)
compute_mean_binormal, &
compute_variance_binormal, &
stdev_L2N, &
corr_NN2NL
use clip_explicit, only: &
clip_covar_level, & ! Procedure(s)
clip_wphydrometp ! Variables(s)
use clubb_precision, only: &
core_rknd ! Variable(s)
use matrix_operations, only: &
Cholesky_factor, & ! Procedure(s)
mirror_lower_triangular_matrix
use stats_type_utilities, only: &
stat_update_var, & ! Procedure(s)
stat_update_var_pt
use stats_variables, only: &
iprecip_frac, & ! Variable(s)
iprecip_frac_1, &
iprecip_frac_2, &
iNcnm, &
ihmp2_zt, &
irtp2_from_chi, &
stats_zt, &
stats_zm
use diagnose_correlations_module, only: &
diagnose_correlations, & ! Procedure(s)
calc_cholesky_corr_mtx_approx
use corr_varnce_module, only: &
assert_corr_symmetric, & ! Procedure(s)
hmp2_ip_on_hmm2_ip, & ! Variable(s)
Ncnp2_on_Ncnm2
use error_code, only: &
clubb_at_least_debug_level, & ! Procedure
err_code, & ! Error Indicator
clubb_fatal_error ! Constant
implicit none
! Input Variables
integer, intent(in) :: &
nz, & ! Number of model vertical grid levels
pdf_dim ! Number of variables in the correlation array
real( kind = core_rknd ), intent(in) :: &
dt ! Model timestep [s]
real( kind = core_rknd ), dimension(nz), intent(in) :: &
Nc_in_cloud, & ! Mean (in-cloud) cloud droplet conc. [num/kg]
rcm, & ! Mean cloud water mixing ratio, < r_c > [kg/kg]
cloud_frac, & ! Cloud fraction [-]
ice_supersat_frac ! Ice supersaturation fraction [-]
real( kind = core_rknd ), dimension(nz,hydromet_dim), intent(in) :: &
hydromet, & ! Mean of hydrometeor, hm (overall) (t-levs.) [units]
wphydrometp ! Covariance < w'h_m' > (momentum levels) [(m/s)units]
real( kind = core_rknd ), dimension(pdf_dim,pdf_dim), &
intent(in) :: &
corr_array_n_cloud, & ! Prescribed normal space corr. array in cloud [-]
corr_array_n_below ! Prescribed normal space corr. array below cl. [-]
type(pdf_parameter), intent(in) :: &
pdf_params ! PDF parameters [units vary]
logical, intent(in) :: &
l_stats_samp ! Flag to sample statistics
logical, intent(in) :: &
l_use_precip_frac, & ! Flag to use precipitation fraction in KK microphysics. The
! precipitation fraction is automatically set to 1 when this
! flag is turned off.
l_predict_upwp_vpwp, & ! Flag to predict <u'w'> and <v'w'> along with <u> and <v>
! alongside the advancement of <rt>, <w'rt'>, <thl>,
! <wpthlp>, <sclr>, and <w'sclr'> in subroutine
! advance_xm_wpxp. Otherwise, <u'w'> and <v'w'> are still
! approximated by eddy diffusivity when <u> and <v> are
! advanced in subroutine advance_windm_edsclrm.
l_diagnose_correlations, & ! Diagnose correlations instead of using fixed ones
l_calc_w_corr, & ! Calculate the correlations between w and the hydrometeors
l_const_Nc_in_cloud, & ! Use a constant cloud droplet conc. within cloud (K&K)
l_fix_w_chi_eta_correlations ! Use a fixed correlation for s and t Mellor(chi/eta)
! Output Variables
real( kind = core_rknd ), dimension(nz,hydromet_dim), intent(out) :: &
hydrometp2 ! Variance of a hydrometeor (overall) (m-levs.) [units^2]
! Output Variables
real( kind = core_rknd ), dimension(pdf_dim, nz), intent(out) :: &
mu_x_1_n, & ! Mean array (normal space): PDF vars. (comp. 1) [un. vary]
mu_x_2_n, & ! Mean array (normal space): PDF vars. (comp. 2) [un. vary]
sigma_x_1_n, & ! Std. dev. array (normal space): PDF vars (comp. 1) [u.v.]
sigma_x_2_n ! Std. dev. array (normal space): PDF vars (comp. 2) [u.v.]
real( kind = core_rknd ), dimension(pdf_dim,pdf_dim,nz), &
intent(out) :: &
corr_array_1_n, & ! Corr. array (normal space) of PDF vars. (comp. 1) [-]
corr_array_2_n ! Corr. array (normal space) of PDF vars. (comp. 2) [-]
real( kind = core_rknd ), dimension(pdf_dim,pdf_dim,nz), &
intent(out) :: &
corr_cholesky_mtx_1, & ! Transposed corr. cholesky matrix, 1st comp. [-]
corr_cholesky_mtx_2 ! Transposed corr. cholesky matrix, 2nd comp. [-]
type(hydromet_pdf_parameter), dimension(nz), intent(out) :: &
hydromet_pdf_params ! Hydrometeor PDF parameters [units vary]
! Local Variables
real( kind = core_rknd ), dimension(pdf_dim,pdf_dim) :: &
corr_mtx_approx_1, & ! Approximated corr. matrix (C = LL'), 1st comp. [-]
corr_mtx_approx_2 ! Approximated corr. matrix (C = LL'), 2nd comp. [-]
real( kind = core_rknd ), dimension(nz) :: &
mu_w_1, & ! Mean of w (1st PDF component) [m/s]
mu_w_2, & ! Mean of w (2nd PDF component) [m/s]
mu_chi_1, & ! Mean of chi (old s) (1st PDF component) [kg/kg]
mu_chi_2, & ! Mean of chi (old s) (2nd PDF component) [kg/kg]
sigma_w_1, & ! Standard deviation of w (1st PDF component) [m/s]
sigma_w_2, & ! Standard deviation of w (2nd PDF component) [m/s]
sigma_chi_1, & ! Standard deviation of chi (1st PDF component) [kg/kg]
sigma_chi_2, & ! Standard deviation of chi (2nd PDF component) [kg/kg]
rc_1, & ! Mean of r_c (1st PDF component) [kg/kg]
rc_2, & ! Mean of r_c (2nd PDF component) [kg/kg]
cloud_frac_1, & ! Cloud fraction (1st PDF component) [-]
cloud_frac_2, & ! Cloud fraction (2nd PDF component) [-]
mixt_frac ! Mixture fraction [-]
real( kind = core_rknd ), dimension(nz) :: &
ice_supersat_frac_1, & ! Ice supersaturation fraction (1st PDF comp.) [-]
ice_supersat_frac_2 ! Ice supersaturation fraction (2nd PDF comp.) [-]
real( kind = core_rknd ), dimension(nz) :: &
Ncnm ! Mean cloud nuclei concentration, < N_cn > [num/kg]
real( kind = core_rknd ), dimension(nz) :: &
wpNcnp_zm, & ! Covariance of N_cn and w (momentum levs.) [(m/s)(num/kg)]
wpNcnp_zt ! Covariance of N_cn and w on thermo. levels [(m/s)(num/kg)]
real( kind = core_rknd ), dimension(nz,hydromet_dim) :: &
hm_1, & ! Mean of a precip. hydrometeor (1st PDF component) [units vary]
hm_2 ! Mean of a precip. hydrometeor (2nd PDF component) [units vary]
real( kind = core_rknd ), dimension(nz,hydromet_dim) :: &
hydrometp2_zt, & ! Variance of a hydrometeor (overall); t-lev [units^2]
wphydrometp_zt ! Covariance of w and hm interp. to t-levs. [(m/s)units]
real( kind = core_rknd ), dimension(nz) :: &
precip_frac, & ! Precipitation fraction (overall) [-]
precip_frac_1, & ! Precipitation fraction (1st PDF component) [-]
precip_frac_2 ! Precipitation fraction (2nd PDF component) [-]
real( kind = core_rknd ), dimension(pdf_dim,pdf_dim,nz) :: &
corr_array_1, & ! Correlation array of PDF vars. (comp. 1) [-]
corr_array_2 ! Correlation array of PDF vars. (comp. 2) [-]
real( kind = core_rknd ), dimension(pdf_dim,nz) :: &
mu_x_1, & ! Mean array of PDF vars. (1st PDF component) [units vary]
mu_x_2, & ! Mean array of PDF vars. (2nd PDF component) [units vary]
sigma_x_1, & ! Standard deviation array of PDF vars (comp. 1) [units vary]
sigma_x_2 ! Standard deviation array of PDF vars (comp. 2) [units vary]
real( kind = core_rknd ), dimension(pdf_dim) :: &
corr_array_scaling
real( kind = core_rknd ), dimension(pdf_dim,nz) :: &
sigma2_on_mu2_ip_1, & ! Ratio array sigma_hm_1^2/mu_hm_1^2 [-]
sigma2_on_mu2_ip_2 ! Ratio array sigma_hm_2^2/mu_hm_2^2 [-]
real( kind = core_rknd ), dimension(nz) :: &
const_Ncnp2_on_Ncnm2, & ! Prescribed ratio: <Ncn'^2> to <Ncn>^2 [-]
const_corr_chi_Ncn, & ! Prescribed corr. of chi (old s) & Ncn [-]
const_corr_chi_Ncn_n_cloud ! Prescribed corr. of chi & Ncn in cloud [-]
real( kind = core_rknd ) :: &
precip_frac_tol ! Min. precip. frac. when hydromet. present [-]
real( kind = core_rknd ), dimension(nz,hydromet_dim) :: &
wphydrometp_chnge ! Change in wphydrometp_zt: covar. clip. [(m/s)units]
real( kind = core_rknd ), dimension(nz) :: &
wm_zt, & ! Mean vertical velocity, <w>, on thermo. levels [m/s]
wp2_zt ! Variance of w, <w'^2> (interp. to t-levs.) [m^2/s^2]
real( kind = core_rknd ), dimension(nz) :: &
rtp2_zt_from_chi
logical :: l_corr_array_scaling
! Flags used for covariance clipping of <w'hm'>.
logical, parameter :: &
l_first_clip_ts = .true., & ! First instance of clipping in a timestep.
l_last_clip_ts = .true. ! Last instance of clipping in a timestep.
character(len=10) :: &
hydromet_name ! Name of a hydrometeor
integer :: k, i ! Loop indices
! ---- Begin Code ----
! Assertion check
! Check that all hydrometeors are positive otherwise exit the program
if ( clubb_at_least_debug_level( 0 ) ) then
do i = 1, hydromet_dim
if ( any( hydromet(:,i) < zero_threshold ) ) then
hydromet_name = hydromet_list(i)
do k = 1, nz
if ( hydromet(k,i) < zero_threshold ) then
! Write error message
write(fstderr,*) " at beginning of setup_pdf_parameters: ", &
trim( hydromet_name )//" = ", &
hydromet(k,i), " < ", zero_threshold, &
" at k = ", k
err_code = clubb_fatal_error
return
endif ! hydromet(k,i) < 0
enddo ! k = 1, nz
endif ! hydromet(:,i) < 0
enddo ! i = 1, hydromet_dim
endif !clubb_at_least_debug_level( 2 )
! Setup some of the PDF parameters
mu_w_1 = pdf_params%w_1
mu_w_2 = pdf_params%w_2
mu_chi_1 = pdf_params%chi_1
mu_chi_2 = pdf_params%chi_2
sigma_w_1 = sqrt( pdf_params%varnce_w_1 )
sigma_w_2 = sqrt( pdf_params%varnce_w_2 )
sigma_chi_1 = pdf_params%stdev_chi_1
sigma_chi_2 = pdf_params%stdev_chi_2
rc_1 = pdf_params%rc_1
rc_2 = pdf_params%rc_2
cloud_frac_1 = pdf_params%cloud_frac_1
cloud_frac_2 = pdf_params%cloud_frac_2
mixt_frac = pdf_params%mixt_frac
ice_supersat_frac_1 = pdf_params%ice_supersat_frac_1
ice_supersat_frac_2 = pdf_params%ice_supersat_frac_2
! Recalculate wm_zt and wp2_zt. Mean vertical velocity may not be easy to
! pass into this subroutine from a host model, and wp2_zt needs to have a
! value consistent with the value it had when the PDF parameters involving w
! were originally set in subroutine pdf_closure. The variable wp2 has since
! been advanced, resulting a new wp2_zt. However, the value of wp2 here
! needs to be consistent with wp2 at the time the PDF parameters were
! calculated.
do k = 1, nz, 1
! Calculate the overall mean of vertical velocity, w, on thermodynamic
! levels.
wm_zt(k) = compute_mean_binormal( mu_w_1(k), mu_w_2(k), mixt_frac(k) )
! Calculate the overall variance of vertical velocity on thermodynamic
! levels.
wp2_zt(k) = compute_variance_binormal( wm_zt(k), mu_w_1(k), mu_w_2(k), &
sigma_w_1(k), sigma_w_2(k), &
mixt_frac(k) )
enddo
! Note on hydrometeor PDF shape:
! To use a single lognormal over the entire grid level, turn off the
! l_use_precip_frac flag and set omicron to 1 and zeta_vrnce_rat to 0 in
! tunable_parameters.in.
! To use a single delta-lognormal (single lognormal in-precip.), enable the
! l_use_precip_frac flag and set omicron to 1 and zeta_vrnce_rat to 0 in
! tunable_parameters.in.
! Otherwise, with l_use_precip_frac enabled and omicron and zeta_vrnce_rat
! values that are not 1 and 0, respectively, the PDF shape is a double
! delta-lognormal (two independent lognormals in-precip.).
! Calculate precipitation fraction.
if ( l_use_precip_frac ) then
call precip_fraction( nz, hydromet, cloud_frac, cloud_frac_1, & ! In
cloud_frac_2, ice_supersat_frac, & ! In
ice_supersat_frac_1, ice_supersat_frac_2, & ! In
mixt_frac, l_stats_samp, & ! In
precip_frac, precip_frac_1, precip_frac_2, & ! Out
precip_frac_tol ) ! Out
if ( err_code == clubb_fatal_error ) return
else
precip_frac = one
precip_frac_1 = one
precip_frac_2 = one
precip_frac_tol = cloud_frac_min
endif
! Calculate <N_cn> from Nc_in_cloud, whether Nc_in_cloud is predicted or
! based on a prescribed value, and whether the value is constant or varying
! over the grid level.
if ( .not. l_const_Nc_in_cloud ) then
! Ncn varies at each vertical level.
const_Ncnp2_on_Ncnm2 = Ncnp2_on_Ncnm2
else ! l_const_Nc_in_cloud
! Ncn is constant at each vertical level.
const_Ncnp2_on_Ncnm2 = zero
endif
const_corr_chi_Ncn_n_cloud = corr_array_n_cloud(iiPDF_Ncn,iiPDF_chi)
const_corr_chi_Ncn &
= corr_NN2NL( const_corr_chi_Ncn_n_cloud, &
stdev_L2N( const_Ncnp2_on_Ncnm2 ), &
const_Ncnp2_on_Ncnm2 )
Ncnm = Nc_in_cloud_to_Ncnm( mu_chi_1, mu_chi_2, sigma_chi_1, &
sigma_chi_2, mixt_frac, Nc_in_cloud, &
cloud_frac_1, cloud_frac_2, &
const_Ncnp2_on_Ncnm2, const_corr_chi_Ncn )
! Boundary Condition.
! At thermodynamic level k = 1, which is below the model lower boundary, the
! value of Ncnm does not matter.
Ncnm(1) = Nc_in_cloud(1)
! Calculate the overall variance of a precipitating hydrometeor (hm),
!<hm'^2>.
do i = 1, hydromet_dim, 1
do k = 1, nz, 1
if ( hydromet(k,i) >= hydromet_tol(i) ) then
! There is some of the hydrometeor species found at level k.
! Calculate the variance (overall) of the hydrometeor.
hydrometp2_zt(k,i) &
= ( ( hmp2_ip_on_hmm2_ip(i) + one ) / precip_frac(k) - one ) &
* hydromet(k,i)**2
else
hydrometp2_zt(k,i) = zero
endif
enddo ! k = 1, nz, 1
! Statistics
if ( l_stats_samp ) then
if ( ihmp2_zt(i) > 0 ) then
! Variance (overall) of the hydrometeor, <hm'^2>.
call stat_update_var( ihmp2_zt(i), hydrometp2_zt(:,i), stats_zt )
endif
endif ! l_stats_samp
! Interpolate the covariances (overall) of w and precipitating
! hydrometeors to thermodynamic grid levels.
wphydrometp_zt(:,i) = zm2zt( wphydrometp(:,i) )
! When the mean value of a precipitating hydrometeor is below tolerance
! value, it is considered to have a value of 0, and the precipitating
! hydrometeor does not vary over the grid level. Any covariances
! involving that precipitating hydrometeor also have values of 0 at that
! grid level.
do k = 1, nz, 1
if ( hydromet(k,i) < hydromet_tol(i) ) then
wphydrometp_zt(k,i) = zero
endif
! Clip the value of covariance <w'hm'> on thermodynamic levels.
call clip_covar_level( clip_wphydrometp, k, l_first_clip_ts, &
l_last_clip_ts, dt, wp2_zt(k), &
hydrometp2_zt(k,i), &
l_predict_upwp_vpwp, &
wphydrometp_zt(k,i), wphydrometp_chnge(k,i) )
enddo ! k = 1, nz, 1
enddo ! i = 1, hydromet_dim, 1
! Calculate correlations involving w and Ncn by first calculating the
! overall covariance of w and Ncn using the down-gradient approximation.
if ( l_calc_w_corr ) then
wpNcnp_zm(1:nz-1) = xpwp_fnc( -c_K_hm * Kh_zm(1:nz-1), Ncnm(1:nz-1), &
Ncnm(2:nz), gr%invrs_dzm(1:nz-1) )
! Boundary conditions; We are assuming zero flux at the top.
wpNcnp_zm(nz) = zero
! Interpolate the covariances to thermodynamic grid levels.
wpNcnp_zt = zm2zt( wpNcnp_zm )
! When the mean value of Ncn is below tolerance value, it is considered
! to have a value of 0, and Ncn does not vary over the grid level. Any
! covariance involving Ncn also has a value of 0 at that grid level.
do k = 1, nz, 1
if ( Ncnm(k) <= Ncn_tol ) then
wpNcnp_zt(k) = zero
endif
enddo ! k = 1, nz, 1
endif ! l_calc_w_corr
! Statistics
if ( l_stats_samp ) then
if ( iprecip_frac > 0 ) then
! Overall precipitation fraction.
call stat_update_var( iprecip_frac, precip_frac, stats_zt )
endif
if ( iprecip_frac_1 > 0 ) then
! Precipitation fraction in PDF component 1.
call stat_update_var( iprecip_frac_1, precip_frac_1, stats_zt )
endif
if ( iprecip_frac_2 > 0 ) then
! Precipitation fraction in PDF component 2.
call stat_update_var( iprecip_frac_2, precip_frac_2, stats_zt )
endif
if ( iNcnm > 0 ) then
! Mean simplified cloud nuclei concentration (overall).
call stat_update_var( iNcnm, Ncnm, stats_zt )
endif
endif
!!! Calculate the means and standard deviations involving PDF variables
!!! -- w, chi, eta, N_cn, and any precipitating hydrometeors (hm in-precip)
!!! -- for each PDF component.
call compute_mean_stdev( nz, hydromet, hydrometp2_zt, & ! Intent(in)
Ncnm, mixt_frac, precip_frac, & ! Intent(in)
precip_frac_1, precip_frac_2, & ! Intent(in)
precip_frac_tol, & ! Intent(in)
pdf_params%w_1, & ! Intent(in)
pdf_params%w_2, & ! Intent(in)
pdf_params%varnce_w_1, & ! Intent(in)
pdf_params%varnce_w_2, & ! Intent(in)
pdf_params%chi_1, & ! Intent(in)
pdf_params%chi_2, & ! Intent(in)
pdf_params%stdev_chi_1, & ! Intent(in)
pdf_params%stdev_chi_2, & ! Intent(in)
pdf_params%stdev_eta_1, & ! Intent(in)
pdf_params%stdev_eta_2, & ! Intent(in)
pdf_params%thl_1, & ! Intent(in)
pdf_params%thl_2, & ! Intent(in)
pdf_dim, & ! Intent(in)
l_const_Nc_in_cloud, & ! Intent(in)
mu_x_1, mu_x_2, & ! Intent(out)
sigma_x_1, sigma_x_2, & ! Intent(out)
hm_1, hm_2, & ! Intent(out)
sigma2_on_mu2_ip_1, & ! Intent(out)
sigma2_on_mu2_ip_2 ) ! Intent(out)
!!! Transform the component means and standard deviations involving
!!! precipitating hydrometeors (hm in-precip) and N_cn -- ln hm and
!!! ln N_cn -- to normal space for each PDF component.
call norm_transform_mean_stdev( nz, hm_1, hm_2, & ! Intent(in)
Ncnm, pdf_dim, & ! Intent(in)
mu_x_1, mu_x_2, & ! Intent(in)
sigma_x_1, sigma_x_2, & ! Intent(in)
sigma2_on_mu2_ip_1, & ! Intent(in)
sigma2_on_mu2_ip_2, & ! Intent(in)
l_const_Nc_in_cloud, & ! Intent(in)
mu_x_1_n, mu_x_2_n, & ! Intent(out)
sigma_x_1_n, sigma_x_2_n ) ! Intent(out)
!!! Calculate the normal space correlations.
!!! The normal space correlations are the same as the true correlations
!!! except when at least one of the variables involved is a precipitating
!!! hydrometeor or Ncn. In these cases, the normal space correlation
!!! involves the natural logarithm of the precipitating hydrometeors, ln hm
!!! (for example, ln r_r and ln N_r), and ln N_cn for each PDF component.
if ( l_diagnose_correlations ) then
do k = 2, nz, 1
if ( rcm(k) > rc_tol ) then
call diagnose_correlations( pdf_dim, corr_array_n_cloud, & ! In
l_calc_w_corr, & ! In
corr_array_1_n(:,:,k) ) ! Out
call diagnose_correlations( pdf_dim, corr_array_n_cloud, & ! In
l_calc_w_corr, & ! In
corr_array_2_n(:,:,k) ) ! Out
else
call diagnose_correlations( pdf_dim, corr_array_n_below, & ! In
l_calc_w_corr, & ! In
corr_array_1_n(:,:,k) ) ! Out
call diagnose_correlations( pdf_dim, corr_array_n_below, & ! In
l_calc_w_corr, & ! In
corr_array_2_n(:,:,k) ) ! Out
endif
enddo ! k = 2, nz, 1
else ! if .not. l_diagnose_correlations
call comp_corr_norm( nz, wm_zt, rc_1, rc_2, cloud_frac_1, &
cloud_frac_2, mixt_frac, &
precip_frac_1, precip_frac_2, &
wpNcnp_zt, wphydrometp_zt, &
mu_x_1, mu_x_2, &
sigma_x_1, sigma_x_2, &
sigma_x_1_n, sigma_x_2_n, &
corr_array_n_cloud, corr_array_n_below, &
pdf_params%corr_chi_eta_1, &
pdf_params%corr_chi_eta_2, &
pdf_params%corr_w_chi_1, &
pdf_params%corr_w_chi_2, &
pdf_params%corr_w_eta_1, &
pdf_params%corr_w_eta_2, &
pdf_dim, &
l_calc_w_corr, &
l_fix_w_chi_eta_correlations, &
corr_array_1_n, corr_array_2_n )
endif ! l_diagnose_correlations
!!! Calculate the true correlations for each PDF component.
call denorm_transform_corr( nz, pdf_dim, &
sigma_x_1_n, sigma_x_2_n, &
sigma2_on_mu2_ip_1, sigma2_on_mu2_ip_2, &
corr_array_1_n, &
corr_array_2_n, &
corr_array_1, corr_array_2 )
!!! Statistics for standard PDF parameters involving hydrometeors.
call pdf_param_hm_stats( nz, pdf_dim, hm_1, hm_2, &
mu_x_1, mu_x_2, &
sigma_x_1, sigma_x_2, &
corr_array_1, corr_array_2, &
l_stats_samp )
!!! Statistics for normal space PDF parameters involving hydrometeors.
call pdf_param_ln_hm_stats( nz, pdf_dim, mu_x_1_n, &
mu_x_2_n, sigma_x_1_n, &
sigma_x_2_n, corr_array_1_n, &
corr_array_2_n, l_stats_samp )
!!! Pack the PDF parameters
call pack_hydromet_pdf_params( nz, hm_1, hm_2, pdf_dim, & ! In
mu_x_1, mu_x_2, & ! In
sigma_x_1, sigma_x_2, & ! In
corr_array_1, corr_array_2, & ! In
precip_frac, precip_frac_1, & ! In
precip_frac_2, & ! In
hydromet_pdf_params ) ! Out
!!! Setup PDF parameters loop.
! Loop over all model thermodynamic level above the model lower boundary.
! Now also including "model lower boundary" -- Eric Raut Aug 2013
! Now not including "model lower boundary" -- Eric Raut Aug 2014
do k = 2, nz, 1
if ( l_diagnose_correlations ) then
call calc_cholesky_corr_mtx_approx &
( pdf_dim, corr_array_1_n(:,:,k), & ! intent(in)
corr_cholesky_mtx_1(:,:,k), corr_mtx_approx_1 ) ! intent(out)
call calc_cholesky_corr_mtx_approx &
( pdf_dim, corr_array_2_n(:,:,k), & ! intent(in)
corr_cholesky_mtx_2(:,:,k), corr_mtx_approx_2 ) ! intent(out)
corr_array_1_n(:,:,k) = corr_mtx_approx_1
corr_array_2_n(:,:,k) = corr_mtx_approx_2
else
! Compute choleksy factorization for the correlation matrix (out of
! cloud)
call Cholesky_factor( pdf_dim, corr_array_1_n(:,:,k), & ! In
corr_array_scaling, corr_cholesky_mtx_1(:,:,k), & ! Out
l_corr_array_scaling ) ! Out
call Cholesky_factor( pdf_dim, corr_array_2_n(:,:,k), & ! In
corr_array_scaling, corr_cholesky_mtx_2(:,:,k), & ! Out
l_corr_array_scaling ) ! Out
endif
! For ease of use later in the code, we make the correlation arrays
! symmetrical
call mirror_lower_triangular_matrix( pdf_dim, corr_array_1_n(:,:,k) )
call mirror_lower_triangular_matrix( pdf_dim, corr_array_2_n(:,:,k) )
enddo ! Setup PDF parameters loop: k = 2, nz, 1
! Interpolate the overall variance of a hydrometeor, <hm'^2>, to its home on
! momentum grid levels.
do i = 1, hydromet_dim, 1
hydrometp2(:,i) = zt2zm( hydrometp2_zt(:,i) )
hydrometp2(nz,i) = zero
enddo
if ( l_stats_samp ) then
if ( irtp2_from_chi > 0 ) then
rtp2_zt_from_chi &
= compute_rtp2_from_chi( pdf_params%stdev_chi_1(:), pdf_params%stdev_chi_2(:), &
pdf_params%stdev_eta_1(:), pdf_params%stdev_eta_2(:), &
pdf_params%rt_1(:), pdf_params%rt_2(:), &
pdf_params%crt_1(:), pdf_params%crt_2(:), &
pdf_params%mixt_frac(:), &
corr_array_1_n(iiPDF_chi,iiPDF_eta,:), &
corr_array_2_n(iiPDF_chi,iiPDF_eta,:) )
call stat_update_var( irtp2_from_chi, zt2zm( rtp2_zt_from_chi ), &
stats_zm )
endif
endif
! Boundary conditions for the output variables at k=1.
mu_x_1_n(:,1) = zero
mu_x_2_n(:,1) = zero
sigma_x_1_n(:,1) = zero
sigma_x_2_n(:,1) = zero
corr_array_1_n(:,:,1) = zero
corr_array_2_n(:,:,1) = zero
corr_cholesky_mtx_1(:,:,1) = zero
corr_cholesky_mtx_2(:,:,1) = zero
call init_hydromet_pdf_params( hydromet_pdf_params(1) )
if ( clubb_at_least_debug_level( 2 ) ) then
do k = 2, nz
call assert_corr_symmetric( corr_array_1_n(:,:,k), pdf_dim)
call assert_corr_symmetric( corr_array_2_n(:,:,k), pdf_dim)
enddo
endif
return
end subroutine setup_pdf_parameters
!=============================================================================
subroutine compute_mean_stdev( nz, hydromet, hydrometp2_zt, & ! Intent(in)
Ncnm, mixt_frac, precip_frac, & ! Intent(in)
precip_frac_1, precip_frac_2, & ! Intent(in)
precip_frac_tol, & ! Intent(in)
w_1, w_2, & ! Intent(in)
varnce_w_1, varnce_w_2, & ! Intent(in)
chi_1, chi_2, & ! Intent(in)
stdev_chi_1, stdev_chi_2, & ! Intent(in)
stdev_eta_1, stdev_eta_2, & ! Intent(in)
thl_1, thl_2, & ! Intent(in)
pdf_dim, & ! Intent(in)
l_const_Nc_in_cloud, & ! Intent(in)
mu_x_1, mu_x_2, & ! Intent(out)
sigma_x_1, sigma_x_2, & ! Intent(out)
hm_1, hm_2, & ! Intent(out)
sigma_hm_1_sqd_on_mu_hm_1_sqd, & ! Intent(out)
sigma_hm_2_sqd_on_mu_hm_2_sqd ) ! Intent(out)
! Description:
! Calculates the means and standard deviations (for each PDF component) of
! chi, eta, w, Ncn, and the precipitating hydrometeors. For the
! precipitating hydrometeors, the component means and standard deviations
! are in-precip.
! References:
!-----------------------------------------------------------------------
!use grid_class, only: &
! gr ! Variable(s)
use constants_clubb, only: &
zero ! Constant(s)
use array_index, only: &
hydromet_tol, &
iiPDF_chi, &
iiPDF_eta, &
iiPDF_w, &
iiPDF_Ncn
use index_mapping, only: &
pdf2hydromet_idx ! Procedure(s)
use parameters_tunable, only: &
omicron, & ! Variable(s)
zeta_vrnce_rat
use corr_varnce_module, only: &
hmp2_ip_on_hmm2_ip, & ! Variable(s)
Ncnp2_on_Ncnm2
use parameters_model, only: &
hydromet_dim ! Variable(s)
use clubb_precision, only: &
core_rknd ! Variable(s)
implicit none
! Input Variables
integer, intent(in) :: &
nz ! Number of model vertical grid levels
real( kind = core_rknd ), dimension(nz, hydromet_dim), intent(in) :: &
hydromet, & ! Mean of a hydrometeor (overall) [hm units]
hydrometp2_zt ! Variance of a hydrometeor (overall) [(hm units)^2]
real( kind = core_rknd ), dimension(nz), intent(in) :: &
Ncnm, & ! Mean simplified cloud nuclei concentration [num/kg]
mixt_frac, & ! Mixture fraction [-]
precip_frac, & ! Precipitation fraction (overall) [-]
precip_frac_1, & ! Precipitation fraction (1st PDF component) [-]
precip_frac_2 ! Precipitation fraction (2nd PDF component) [-]
real( kind = core_rknd ), dimension(nz), intent(in) :: &
w_1, & ! Mean of w (1st PDF component) [m/s]
w_2, & ! Mean of w (2nd PDF component) [m/s]
varnce_w_1, & ! Variance of w (1st PDF component) [m^2/s^2]
varnce_w_2, & ! Variance of w (2nd PDF component) [m^2/s^2]
chi_1, & ! Mean of chi (1st PDF component) [kg/kg]
chi_2, & ! Mean of chi (2nd PDF component) [kg/kg]
stdev_chi_1, & ! Standard deviation of chi (1st PDF component) [kg/kg]
stdev_chi_2, & ! Standard deviation of chi (2nd PDF component) [kg/kg]
stdev_eta_1, & ! Standard deviation of eta (1st PDF component) [kg/kg]
stdev_eta_2, & ! Standard deviation of eta (2nd PDF component) [kg/kg]
thl_1, & ! Mean of thl (1st PDF component) [K]
thl_2 ! Mean of thl (2nd PDF component) [K]
real( kind = core_rknd ), intent(in) :: &
precip_frac_tol ! Minimum precip. frac. when hydromet. are present [-]
integer, intent(in) :: &
pdf_dim ! Number of PDF variables
logical, intent(in) :: &
l_const_Nc_in_cloud ! Use a constant cloud droplet conc. within cloud (K&K)
! Output Variables
! Note: This code assumes to be these arrays in the same order as the
! correlation arrays, etc., which is determined by the iiPDF indices.
! The order should be as follows: chi, eta, w, Ncn, <precip. hydrometeors>
! (indices increasing from left to right).
real( kind = core_rknd ), dimension(pdf_dim,nz), intent(out) :: &
mu_x_1, & ! Mean array of PDF vars. (1st PDF component) [units vary]
mu_x_2, & ! Mean array of PDF vars. (2nd PDF component) [units vary]
sigma_x_1, & ! Standard deviation array of PDF vars (comp. 1) [units vary]
sigma_x_2 ! Standard deviation array of PDF vars (comp. 2) [units vary]
real( kind = core_rknd ), dimension(nz,hydromet_dim), intent(out) :: &
hm_1, & ! Mean of a precip. hydrometeor (1st PDF component) [units vary]
hm_2 ! Mean of a precip. hydrometeor (2nd PDF component) [units vary]
real( kind = core_rknd ), dimension(pdf_dim,nz), intent(out) :: &
sigma_hm_1_sqd_on_mu_hm_1_sqd, & ! Ratio sigma_hm_1^2 / mu_hm_1^2 [-]
sigma_hm_2_sqd_on_mu_hm_2_sqd ! Ratio sigma_hm_2^2 / mu_hm_2^2 [-]
! Local Variables
real( kind = core_rknd ), dimension(nz) :: &
hmm, & ! Hydrometeor mean (overall) [hm units]
hmp2, & ! Hydromet. variance (overall) [(hm units)^2]
hmp2_ip_on_hmm2_ip_in, & ! Ratio <hm|_ip'^2> / <hm|_ip>^2 [-]
hm_tol, & ! Tolerance value of hydrometeor [hm units]
precip_frac_tol_in, & ! Min. precip. frac. when hydromet. present [-]
omicron_in, & ! Relative width param., omicron = R / Rmax [-]
zeta_vrnce_rat_in ! Width param. for sigma_hm_1^2 / mu_hm_1^2 [-]
real( kind = core_rknd ), dimension(nz) :: &
mu_hm_1, & ! Mean of hm (1st PDF component) in-precip (ip) [hm un]
mu_hm_2, & ! Mean of hm (2nd PDF component) ip [hm un]
sigma_hm_1, & ! Standard deviation of hm (1st PDF component) ip [hm un]
sigma_hm_2, & ! Standard deviation of hm (2nd PDF component) ip [hm un]
hm_1_out, & ! Mean of hm (1st PDF component) [hm un]
hm_2_out ! Mean of hm (2nd PDF component) [hm un]
real( kind = core_rknd ), dimension(nz) :: &
sigma_hm_1_sqd_on_mu_hm_1_sqd_o, & ! Ratio sigma_hm_1**2 / mu_hm_1**2 [-]
sigma_hm_2_sqd_on_mu_hm_2_sqd_o ! Ratio sigma_hm_2**2 / mu_hm_2**2 [-]
integer :: ivar ! Loop iterator
integer :: hm_idx ! Hydrometeor array index.
!!! Initialize output variables.
mu_x_1 = zero
mu_x_2 = zero
sigma_x_1 = zero
sigma_x_2 = zero
hm_1 = zero
hm_2 = zero
sigma_hm_1_sqd_on_mu_hm_1_sqd = zero
sigma_hm_2_sqd_on_mu_hm_2_sqd = zero
!!! Enter the PDF parameters.
!!! Vertical velocity, w.
! Mean of vertical velocity, w, in PDF component 1.
mu_x_1(iiPDF_w,:) = w_1
! Mean of vertical velocity, w, in PDF component 2.
mu_x_2(iiPDF_w,:) = w_2
! Standard deviation of vertical velocity, w, in PDF component 1.
sigma_x_1(iiPDF_w,:) = sqrt( varnce_w_1 )
! Standard deviation of vertical velocity, w, in PDF component 2.
sigma_x_2(iiPDF_w,:) = sqrt( varnce_w_2 )
!!! Extended liquid water mixing ratio, chi.
! Mean of extended liquid water mixing ratio, chi (old s),
! in PDF component 1.
mu_x_1(iiPDF_chi,:) = chi_1
! Mean of extended liquid water mixing ratio, chi (old s),
! in PDF component 2.
mu_x_2(iiPDF_chi,:) = chi_2
! Standard deviation of extended liquid water mixing ratio, chi (old s),
! in PDF component 1.
sigma_x_1(iiPDF_chi,:) = stdev_chi_1
! Standard deviation of extended liquid water mixing ratio, chi (old s),
! in PDF component 2.
sigma_x_2(iiPDF_chi,:) = stdev_chi_2
!!! Coordinate orthogonal to chi, eta.
! Mean of eta (old t) in PDF component 1.
! Set the component mean values of eta to 0.
! The component mean values of eta are not important. They can be set to
! anything. They cancel out in the model code. However, the best thing to
! do is to set them to 0 and avoid any kind of numerical error.
mu_x_1(iiPDF_eta,:) = zero
! Mean of eta (old t) in PDF component 2.
! Set the component mean values of eta to 0.
! The component mean values of eta are not important. They can be set to
! anything. They cancel out in the model code. However, the best thing to
! do is to set them to 0 and avoid any kind of numerical error.
mu_x_2(iiPDF_eta,:) = zero
! Standard deviation of eta (old t) in PDF component 1.
sigma_x_1(iiPDF_eta,:) = stdev_eta_1
! Standard deviation of eta (old t) in PDF component 2.
sigma_x_2(iiPDF_eta,:) = stdev_eta_2
!!! Simplified cloud nuclei concentration, Ncn.
! Mean of simplified cloud nuclei concentration, Ncn, in PDF component 1.
mu_x_1(iiPDF_Ncn,:) = Ncnm
! Mean of simplified cloud nuclei concentration, Ncn, in PDF component 2.
mu_x_2(iiPDF_Ncn,:) = Ncnm
! Standard deviation of simplified cloud nuclei concentration, Ncn,
! in PDF component 1.
if ( .not. l_const_Nc_in_cloud ) then
! Ncn varies in both PDF components.
sigma_x_1(iiPDF_Ncn,:) = sqrt( Ncnp2_on_Ncnm2 ) * Ncnm
sigma_x_2(iiPDF_Ncn,:) = sqrt( Ncnp2_on_Ncnm2 ) * Ncnm
! Ncn is not an official hydrometeor. However, both the
! sigma_hm_1_sqd_on_mu_hm_1_sqd and sigma_hm_2_sqd_on_mu_hm_2_sqd arrays
! have size pdf_dim, and both sigma_Ncn_1^2/mu_Ncn_1^2 and
! sigma_Ncn_2^2/mu_Ncn_2^2 need to be output as part of these arrays.
sigma_hm_1_sqd_on_mu_hm_1_sqd(iiPDF_Ncn,:) = Ncnp2_on_Ncnm2
sigma_hm_2_sqd_on_mu_hm_2_sqd(iiPDF_Ncn,:) = Ncnp2_on_Ncnm2
else ! l_const_Nc_in_cloud
! Ncn is constant in both PDF components.
sigma_x_1(iiPDF_Ncn,:) = zero