forked from ESCOMP/CLUBB_CESM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadvance_clubb_core_module.F90
4484 lines (3772 loc) · 200 KB
/
advance_clubb_core_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_clubb_core_module
! Description:
! The module containing the `core' of the CLUBB parameterization.
! It advances CLUBB's equations one model time step.
!
! References:
! https://arxiv.org/pdf/1711.03675v1.pdf#nameddest=url:overview_clubb
!
! ``A PDF-Based Model for Boundary Layer Clouds. Part I:
! Method and Model Description'' Golaz, et al. (2002)
! JAS, Vol. 59, pp. 3540--3551.
!
! Copyright Notice:
!
! This code and the source code it references are (C) 2006-2018.
!
! The distribution of this code and derived works thereof
! should include this notice.
!
! Portions of this code derived from other sources (Hugh Morrison,
! ACM TOMS, Numerical Recipes, et cetera) are the intellectual
! property of their respective authors as noted and are also subject
! to copyright.
!
!
!
! Cloud Layers Unified By Binormals (CLUBB) user license
! agreement.
!
! Thank you for your interest in CLUBB. We work hard to create a
! code that implements the best software engineering practices,
! is supported to the extent allowed by our limited resources,
! and is available without cost to non-commercial users. You may
! use CLUBB if, in return, you abide by these conditions:
!
! 1. Please cite CLUBB in presentations and publications that
! contain results obtained using CLUBB.
!
! 2. You may not use any part of CLUBB to create or modify
! another single-column (1D) model that is not called CLUBB.
! However, you may modify or augment CLUBB or parts of CLUBB if
! you include "CLUBB" in the name of the resulting single-column
! model. For example, a user at MIT might modify CLUBB and call
! the modified version "CLUBB-MIT." Or, for example, a user of
! the CLM land-surface model might interface CLM to CLUBB and
! call it "CLM-CLUBB." This naming convention recognizes the
! contributions of both sets of developers.
!
! 3. You may implement CLUBB as a parameterization in a large-
! scale host model that has 2 or 3 spatial dimensions without
! including "CLUBB" in the combined model name, but please
! acknowledge in presentations and publications that CLUBB has
! been included as a parameterization.
!
! 4. You may not provide all or part of CLUBB to anyone without
! prior permission from Vincent Larson (vlarson@uwm.edu). If
! you wish to share CLUBB with your collaborators without
! seeking permission, please ask your collaborators to register
! as CLUBB users at http://clubb.larson-group.com and to
! download CLUBB from there.
!
! 5. You may not use CLUBB for commercial purposes unless you
! receive permission from Vincent Larson.
!
! 6. You may not re-license all or any part of CLUBB.
!
! 7. CLUBB is provided "as is" and without warranty.
!
! We hope that CLUBB will develop into a community resource. We
! encourage users to contribute their CLUBB modifications or
! extensions to the CLUBB development group. We will then
! consider them for inclusion in CLUBB. Such contributions will
! benefit all CLUBB users. We would be pleased to acknowledge
! contributors and list their CLUBB-related papers on our "About
! CLUBB" webpage (http://clubb.larson-group.com/about.php) for
! those contributors who so desire.
!
! Thanks so much and best wishes for your research!
!
! The CLUBB Development Group
! (Present and past contributors to the source code include
! Vincent Larson, Chris Golaz, David Schanen, Brian Griffin,
! Joshua Fasching, Adam Smith, and Michael Falk).
!-----------------------------------------------------------------------
implicit none
public :: &
setup_clubb_core, &
advance_clubb_core, &
cleanup_clubb_core, &
set_Lscale_max, &
calculate_thlp2_rad
! Options for the placement of the call to CLUBB's PDF.
integer, parameter :: &
ipdf_pre_advance_fields = 1, & ! Call before advancing predictive fields
ipdf_post_advance_fields = 2, & ! Call after advancing predictive fields
ipdf_pre_post_advance_fields = 3 ! Call both before and after advancing
! predictive fields
! Select the placement of the call to CLUBB's PDF.
integer, parameter :: &
ipdf_call_placement = ipdf_pre_advance_fields
private ! Default Scope
contains
!-----------------------------------------------------------------------
!#######################################################################
!#######################################################################
! If you change the argument list of advance_clubb_core you also have to
! change the calls to this function in the host models CAM, WRF, SAM
! and GFDL.
!#######################################################################
!#######################################################################
subroutine advance_clubb_core &
( l_implemented, dt, fcor, sfc_elevation, hydromet_dim, & ! intent(in)
thlm_forcing, rtm_forcing, um_forcing, vm_forcing, & ! intent(in)
sclrm_forcing, edsclrm_forcing, wprtp_forcing, & ! intent(in)
wpthlp_forcing, rtp2_forcing, thlp2_forcing, & ! intent(in)
rtpthlp_forcing, wm_zm, wm_zt, & ! intent(in)
wpthlp_sfc, wprtp_sfc, upwp_sfc, vpwp_sfc, & ! intent(in)
wpsclrp_sfc, wpedsclrp_sfc, & ! intent(in)
p_in_Pa, rho_zm, rho, exner, & ! intent(in)
rho_ds_zm, rho_ds_zt, invrs_rho_ds_zm, & ! intent(in)
invrs_rho_ds_zt, thv_ds_zm, thv_ds_zt, hydromet, & ! intent(in)
rfrzm, radf, & ! intent(in)
#ifdef CLUBBND_CAM
varmu, & ! intent(in)
#endif
wphydrometp, wp2hmp, rtphmp_zt, thlphmp_zt, & ! intent(in)
host_dx, host_dy, & ! intent(in)
um, vm, upwp, vpwp, up2, vp2, & ! intent(inout)
thlm, rtm, wprtp, wpthlp, & ! intent(inout)
wp2, wp3, rtp2, rtp3, thlp2, thlp3, rtpthlp, & ! intent(inout)
sclrm, & ! intent(inout)
#ifdef GFDL
sclrm_trsport_only, & ! h1g, 2010-06-16 ! intent(inout)
#endif
sclrp2, sclrprtp, sclrpthlp, & ! intent(inout)
wpsclrp, edsclrm, & ! intent(inout)
rcm, cloud_frac, & ! intent(inout)
wpthvp, wp2thvp, rtpthvp, thlpthvp, & ! intent(inout)
sclrpthvp, & ! intent(inout)
pdf_params, pdf_params_zm, & ! intent(inout)
#ifdef GFDL
RH_crit, & !h1g, 2010-06-16 ! intent(inout)
do_liquid_only_in_clubb, & ! intent(in)
#endif
#if defined(CLUBB_CAM) || defined(GFDL)
khzm, khzt, & ! intent(out)
#endif
#ifdef CLUBB_CAM
qclvar, thlprcp_out, & ! intent(out)
#endif
wprcp, ice_supersat_frac, & ! intent(out)
rcm_in_layer, cloud_cover ) ! intent(out)
! Description:
! Subroutine to advance CLUBB one timestep
! References:
! https://arxiv.org/pdf/1711.03675v1.pdf#nameddest=url:overview_clubb
!
! ``A PDF-Based Model for Boundary Layer Clouds. Part I:
! Method and Model Description'' Golaz, et al. (2002)
! JAS, Vol. 59, pp. 3540--3551.
!-----------------------------------------------------------------------
! Modules to be included
use constants_clubb, only: &
em_min, &
thl_tol, &
rt_tol, &
w_tol, &
w_tol_sqd, &
ep2, &
Cp, &
Lv, &
ep1, &
fstderr, &
zero_threshold, &
three_halves, &
one, &
unused_var, &
grav, &
eps
use parameters_tunable, only: &
taumax, & ! Variable(s)
c_K, &
mu, &
Lscale_mu_coef, &
Lscale_pert_coef, &
gamma_coef, &
gamma_coefb, &
gamma_coefc, &
c_K10, &
c_K10h, &
C1, C14, &
C5, C4, &
C_wp2_splat
use parameters_model, only: &
sclr_dim, & ! Variable(s)
edsclr_dim, &
T0, &
sclr_tol
use model_flags, only: &
l_tke_aniso, & ! Variable(s)
l_call_pdf_closure_twice, &
l_host_applies_sfc_fluxes, &
l_stability_correct_tau_zm, &
l_do_expldiff_rtm_thlm, &
l_Lscale_plume_centered, &
l_use_ice_latent, &
l_gamma_Skw, &
l_damp_wp2_using_em, &
l_advance_xp3, &
l_predict_upwp_vpwp, &
l_diag_Lscale_from_tau
use grid_class, only: &
gr, & ! Variable(s)
zm2zt, & ! Procedure(s)
zt2zm, &
ddzm, &
ddzt
use numerical_check, only: &
parameterization_check, & ! Procedure(s)
calculate_spurious_source
use variables_diagnostic_module, only: &
Skw_zt, & ! Variable(s)
Skw_zm, &
wp4, &
rtprcp, &
thlprcp, &
rcp2, &
rsat, &
wprtp2, &
wp2rtp, &
wpthlp2, &
wp2thlp, &
wprtpthlp, &
wp2rcp
use variables_diagnostic_module, only: &
thvm, &
em, &
Lscale, &
Lscale_up, &
Lscale_down, &
tau_zm, &
tau_zt, &
Kh_zm, &
Kh_zt, &
vg, &
ug, &
um_ref, &
vm_ref
use variables_diagnostic_module, only: &
wp2_zt, &
thlp2_zt, &
wpthlp_zt, &
wprtp_zt, &
rtp2_zt, &
rtpthlp_zt, &
up2_zt, &
vp2_zt, &
upwp_zt, &
vpwp_zt, &
rtm_ref, &
thlm_ref
use variables_diagnostic_module, only: &
wpedsclrp, &
sclrprcp, & ! sclr'rc'
wp2sclrp, & ! w'^2 sclr'
wpsclrp2, & ! w'sclr'^2
wpsclrprtp, & ! w'sclr'rt'
wpsclrpthlp, & ! w'sclr'thl'
wp3_zm, & ! wp3 interpolated to momentum levels
Skw_velocity, & ! Skewness velocity [m/s]
a3_coef, & ! The a3 coefficient [-]
a3_coef_zt ! The a3 coefficient interp. to the zt grid [-]
use variables_diagnostic_module, only: &
wp3_on_wp2, & ! Variable(s)
wp3_on_wp2_zt
use pdf_parameter_module, only: &
pdf_parameter, & ! Variable Type
implicit_coefs_terms
#ifdef GFDL
use advance_sclrm_Nd_module, only: & ! h1g, 2010-06-16 begin mod
advance_sclrm_Nd_diffusion_OG, &
advance_sclrm_Nd_upwind, &
advance_sclrm_Nd_semi_implicit ! h1g, 2010-06-16 end mod
#endif
use advance_xm_wpxp_module, only: &
advance_xm_wpxp ! Compute mean/flux terms
use advance_xp2_xpyp_module, only: &
advance_xp2_xpyp ! Computes variance terms
use surface_varnce_module, only: &
calc_surface_varnce ! Procedure
use mixing_length, only: &
compute_mixing_length ! Procedure
use advance_windm_edsclrm_module, only: &
advance_windm_edsclrm ! Procedure(s)
use saturation, only: &
! Procedure
sat_mixrat_liq ! Saturation mixing ratio
use advance_wp2_wp3_module, only: &
advance_wp2_wp3 ! Procedure
use advance_xp3_module, only: &
advance_xp3 ! Procedure(s)
use clubb_precision, only: &
core_rknd ! Variable(s)
use error_code, only: &
clubb_at_least_debug_level, & ! Procedure
err_code, & ! Error Indicator
clubb_fatal_error ! Constant
use Skx_module, only: &
Skx_func, & ! Procedure(s)
xp3_LG_2005_ansatz
use clip_explicit, only: &
clip_covars_denom ! Procedure(s)
use T_in_K_module, only: &
! Read values from namelist
thlm2T_in_K ! Procedure
use sigma_sqd_w_module, only: &
compute_sigma_sqd_w ! Procedure(s)
use stats_clubb_utilities, only: &
stats_accumulate ! Procedure
use stats_type_utilities, only: &
stat_update_var_pt, & ! Procedure(s)
stat_update_var, &
stat_begin_update, &
stat_begin_update_pt, &
stat_end_update, &
stat_end_update_pt
use stats_variables, only: &
irtp2_bt, & ! Variable(s)
ithlp2_bt, &
irtpthlp_bt, &
iwp2_bt, &
iwp3_bt, &
ivp2_bt, &
iup2_bt, &
iwprtp_bt, &
iwpthlp_bt, &
iupwp_bt, &
ivpwp_bt, &
irtm_bt, &
ithlm_bt, &
ivm_bt, &
ium_bt, &
irvm, &
irel_humidity, &
iwpthlp_zt
use stats_variables, only: &
iwprtp_zt, &
iup2_zt, &
ivp2_zt, &
iupwp_zt, &
ivpwp_zt, &
ithlp2_sf, &
irtp2_sf, &
irtpthlp_sf, &
iup2_sf, &
ivp2_sf, &
iwp2_sf, &
l_stats_samp, &
l_stats, &
stats_zt, &
stats_zm, &
stats_sfc, &
irtm_spur_src, &
ithlm_spur_src
use stats_variables, only: &
irfrzm, & ! Variable(s)
istability_correction
use stats_variables, only: &
iLscale_pert_1, & ! Variable(s)
iLscale_pert_2
use fill_holes, only: &
vertical_integral, & ! Procedure(s)
fill_holes_vertical
use advance_helper_module, only: &
calc_stability_correction, & ! Procedure(s)
compute_Cx_fnc_Richardson, &
calc_brunt_vaisala_freq_sqd, &
term_wp2_splat, term_wp3_splat
use interpolation, only: &
pvertinterp
implicit none
!!! External
intrinsic :: sqrt, min, max, exp, mod, real
! Constant Parameters
logical, parameter :: &
l_avg_Lscale = .false. ! Lscale is calculated in subroutine compute_mixing_length
! if l_avg_Lscale is true, compute_mixing_length is called two additional times with
! perturbed values of rtm and thlm. An average value of Lscale
! from the three calls to compute_mixing_length is then calculated.
! This reduces temporal noise in RICO, BOMEX, LBA, and other cases.
logical, parameter :: &
l_iter_xp2_xpyp = .true. ! Set to true when rtp2/thlp2/rtpthlp, et cetera are prognostic
real( kind = core_rknd ), parameter :: &
tau_const = 900._core_rknd
!!! Input Variables
logical, intent(in) :: &
l_implemented ! True if CLUBB is being run within a large-scale host model,
! rather than a standalone single-column model.
real( kind = core_rknd ), intent(in) :: &
dt ! Current timestep duration [s]
real( kind = core_rknd ), intent(in) :: &
fcor, & ! Coriolis forcing [s^-1]
sfc_elevation ! Elevation of ground level [m above MSL]
integer, intent(in) :: &
hydromet_dim ! Total number of hydrometeor species [#]
! Input Variables
real( kind = core_rknd ), intent(in), dimension(gr%nz) :: &
thlm_forcing, & ! liquid potential temp. forcing (thermodynamic levels) [K/s]
rtm_forcing, & ! total water forcing (thermodynamic levels) [(kg/kg)/s]
um_forcing, & ! eastward wind forcing (thermodynamic levels) [m/s/s]
vm_forcing, & ! northward wind forcing (thermodynamic levels) [m/s/s]
wprtp_forcing, & ! total water turbulent flux forcing (momentum levels) [m*K/s^2]
wpthlp_forcing, & ! liq pot temp turb flux forcing (momentum levels) [m*(kg/kg)/s^2]
rtp2_forcing, & ! total water variance forcing (momentum levels) [(kg/kg)^2/s]
thlp2_forcing, & ! liq pot temp variance forcing (momentum levels) [K^2/s]
rtpthlp_forcing, & ! <r_t'th_l'> covariance forcing (momentum levels) [K*(kg/kg)/s]
wm_zm, & ! vertical mean wind component on momentum levels [m/s]
wm_zt, & ! vertical mean wind component on thermo. levels [m/s]
p_in_Pa, & ! Air pressure (thermodynamic levels) [Pa]
rho_zm, & ! Air density on momentum levels [kg/m^3]
rho, & ! Air density on thermodynamic levels [kg/m^3]
exner, & ! Exner function (thermodynamic levels) [-]
rho_ds_zm, & ! Dry, static density on momentum levels [kg/m^3]
rho_ds_zt, & ! Dry, static density on thermo. levels [kg/m^3]
invrs_rho_ds_zm, & ! Inverse dry, static density on momentum levs. [m^3/kg]
invrs_rho_ds_zt, & ! Inverse dry, static density on thermo levs. [m^3/kg]
thv_ds_zm, & ! Dry, base-state theta_v on momentum levs. [K]
thv_ds_zt, & ! Dry, base-state theta_v on thermo levs. [K]
rfrzm ! Total ice-phase water mixing ratio [kg/kg]
real( kind = core_rknd ), dimension(gr%nz,hydromet_dim), intent(in) :: &
hydromet ! Array of hydrometeors [units vary]
real( kind = core_rknd ), dimension(gr%nz), intent(in) :: &
radf ! Buoyancy production at cloud top due to longwave radiative cooling [m^2/s^3]
#ifdef CLUBBND_CAM
real( kind = core_rknd ), intent(in) :: &
varmu
#endif
real( kind = core_rknd ), dimension(gr%nz, hydromet_dim), intent(in) :: &
wphydrometp, & ! Covariance of w and a hydrometeor [(m/s) <hm units>]
wp2hmp, & ! Third-order moment: < w'^2 hm' > (hm = hydrometeor) [(m/s)^2 <hm units>]
rtphmp_zt, & ! Covariance of rt and hm (on thermo levs.) [(kg/kg) <hm units>]
thlphmp_zt ! Covariance of thl and hm (on thermo levs.) [K <hm units>]
real( kind = core_rknd ), intent(in) :: &
wpthlp_sfc, & ! w' theta_l' at surface [(m K)/s]
wprtp_sfc, & ! w' r_t' at surface [(kg m)/( kg s)]
upwp_sfc, & ! u'w' at surface [m^2/s^2]
vpwp_sfc ! v'w' at surface [m^2/s^2]
! Passive scalar variables
real( kind = core_rknd ), intent(in), dimension(gr%nz,sclr_dim) :: &
sclrm_forcing ! Passive scalar forcing [{units vary}/s]
real( kind = core_rknd ), intent(in), dimension(sclr_dim) :: &
wpsclrp_sfc ! Passive scalar flux at surface [{units vary} m/s]
! Eddy passive scalar variables
real( kind = core_rknd ), intent(in), dimension(gr%nz,edsclr_dim) :: &
edsclrm_forcing ! Eddy-diffusion passive scalar forcing [{units vary}/s]
real( kind = core_rknd ), intent(in), dimension(edsclr_dim) :: &
wpedsclrp_sfc ! Eddy-diffusion passive scalar flux at surface [{units vary} m/s]
! Host model horizontal grid spacing, if part of host model.
real( kind = core_rknd ), intent(in) :: &
host_dx, & ! East-west horizontal grid spacing [m]
host_dy ! North-south horizontal grid spacing [m]
!!! Input/Output Variables
! These are prognostic or are planned to be in the future
real( kind = core_rknd ), intent(inout), dimension(gr%nz) :: &
um, & ! eastward grid-mean wind component (thermodynamic levels) [m/s]
upwp, & ! u'w' (momentum levels) [m^2/s^2]
vm, & ! northward grid-mean wind component (thermodynamic levels) [m/s]
vpwp, & ! v'w' (momentum levels) [m^2/s^2]
up2, & ! u'^2 (momentum levels) [m^2/s^2]
vp2, & ! v'^2 (momentum levels) [m^2/s^2]
rtm, & ! total water mixing ratio, r_t (thermo. levels) [kg/kg]
wprtp, & ! w' r_t' (momentum levels) [(kg/kg) m/s]
thlm, & ! liq. water pot. temp., th_l (thermo. levels) [K]
wpthlp, & ! w'th_l' (momentum levels) [(m/s) K]
rtp2, & ! r_t'^2 (momentum levels) [(kg/kg)^2]
rtp3, & ! r_t'^3 (thermodynamic levels) [(kg/kg)^3]
thlp2, & ! th_l'^2 (momentum levels) [K^2]
thlp3, & ! th_l'^3 (thermodynamic levels) [K^3]
rtpthlp, & ! r_t'th_l' (momentum levels) [(kg/kg) K]
wp2, & ! w'^2 (momentum levels) [m^2/s^2]
wp3 ! w'^3 (thermodynamic levels) [m^3/s^3]
! Passive scalar variables
real( kind = core_rknd ), intent(inout), dimension(gr%nz,sclr_dim) :: &
sclrm, & ! Passive scalar mean (thermo. levels) [units vary]
wpsclrp, & ! w'sclr' (momentum levels) [{units vary} m/s]
sclrp2, & ! sclr'^2 (momentum levels) [{units vary}^2]
sclrprtp, & ! sclr'rt' (momentum levels) [{units vary} (kg/kg)]
sclrpthlp ! sclr'thl' (momentum levels) [{units vary} K]
real( kind = core_rknd ), intent(inout), dimension(gr%nz) :: &
rcm, & ! cloud water mixing ratio, r_c (thermo. levels) [kg/kg]
cloud_frac, & ! cloud fraction (thermodynamic levels) [-]
wpthvp, & ! < w' th_v' > (momentum levels) [kg/kg K]
wp2thvp, & ! < w'^2 th_v' > (thermodynamic levels) [m^2/s^2 K]
rtpthvp, & ! < r_t' th_v' > (momentum levels) [kg/kg K]
thlpthvp ! < th_l' th_v' > (momentum levels) [K^2]
real( kind = core_rknd ), intent(inout), dimension(gr%nz,sclr_dim) :: &
sclrpthvp ! < sclr' th_v' > (momentum levels) [units vary]
type(pdf_parameter), dimension(gr%nz), intent(inout) :: &
pdf_params, & ! Fortran structure of PDF parameters on thermodynamic levels [units vary]
pdf_params_zm ! Fortran structure of PDF parameters on momentum levels [units vary]
#ifdef GFDL
real( kind = core_rknd ), intent(inout), dimension(gr%nz,sclr_dim) :: & ! h1g, 2010-06-16
sclrm_trsport_only ! Passive scalar concentration due to pure transport [{units vary}/s]
#endif
! Eddy passive scalar variable
real( kind = core_rknd ), intent(inout), dimension(gr%nz,edsclr_dim) :: &
edsclrm ! Eddy passive scalar grid-mean (thermo. levels) [units vary]
! Variables that need to be output for use in other parts of the CLUBB
! code, such as microphysics (rcm, pdf_params), forcings (rcm), and/or
! BUGSrad (cloud_cover).
real( kind = core_rknd ), intent(out), dimension(gr%nz) :: &
rcm_in_layer, & ! rcm within cloud layer [kg/kg]
cloud_cover ! cloud cover [-]
! Variables that need to be output for use in host models
real( kind = core_rknd ), intent(out), dimension(gr%nz) :: &
wprcp, & ! w'r_c' (momentum levels) [(kg/kg) m/s]
ice_supersat_frac ! ice cloud fraction (thermodynamic levels) [-]
#if defined(CLUBB_CAM) || defined(GFDL)
real( kind = core_rknd ), intent(out), dimension(gr%nz) :: &
khzt, & ! eddy diffusivity on thermo levels
khzm ! eddy diffusivity on momentum levels
#endif
#ifdef CLUBB_CAM
real( kind = core_rknd), intent(out), dimension(gr%nz) :: &
qclvar, & ! cloud water variance
thlprcp_out ! thl'rc'
#endif
#ifdef GFDL
! hlg, 2010-06-16
real( kind = core_rknd ), intent(inout), dimension(gr%nz, min(1,sclr_dim) , 2) :: &
RH_crit ! critical relative humidity for droplet and ice nucleation
! ---> h1g, 2012-06-14
logical, intent(in) :: do_liquid_only_in_clubb
! <--- h1g, 2012-06-14
#endif
! Local Variables
integer :: i, k
#ifdef CLUBB_CAM
integer :: ixind
#endif
! Eric Raut declared this variable solely for output to disk
real( kind = core_rknd ), dimension(gr%nz) :: &
rc_coef, & ! Coefficient of X'r_c' in Eq. (34) (t-levs.) [K/(kg/kg)]
rc_coef_zm ! Coefficient of X'r_c' in Eq. (34) on m-levs. [K/(kg/kg)]
real( kind = core_rknd ), dimension(gr%nz) :: &
Km_zm, & ! Eddy diffusivity for momentum on zm grid levels [m^2/s]
Kmh_zm ! Eddy diffusivity for thermodynamic variables [m^2/s]
logical, parameter :: &
l_use_buoy_mod_Km_zm = .false. ! .true. if we use a buoyancy-modified expression for Km_zm
real( kind = core_rknd ), dimension(gr%nz) :: &
tau_factor, & ! factor that includes tau_zm in expression for Km_zm [s]
Km_zm_denom_term, & ! term in denominator of Km_zm [-]
Km_zm_numerator_term ! term in numerator of Km_zm [-]
real( kind = core_rknd ), dimension(gr%nz) :: &
gamma_Skw_fnc, & ! Gamma as a function of skewness [-]
sigma_sqd_w, & ! PDF width parameter (momentum levels) [-]
sigma_sqd_w_zt, & ! PDF width parameter (thermodynamic levels) [-]
sqrt_em_zt, & ! sqrt( em ) on zt levels; where em is TKE [m/s]
Lscale_pert_1, Lscale_pert_2, & ! For avg. calculation of Lscale [m]
thlm_pert_1, thlm_pert_2, & ! For avg. calculation of Lscale [K]
rtm_pert_1, rtm_pert_2, & ! For avg. calculation of Lscale [kg/kg]
thlm_pert_pos_rt, thlm_pert_neg_rt, & ! For avg. calculation of Lscale [K]
rtm_pert_pos_rt, rtm_pert_neg_rt ! For avg. calculation of Lscale [kg/kg]
!Lscale_weight Uncomment this if you need to use this vairable at some point.
real( kind = core_rknd ), dimension(gr%nz) :: &
w_1_zm, & ! Mean w (1st PDF component) [m/s]
w_2_zm, & ! Mean w (2nd PDF component) [m/s]
varnce_w_1_zm, & ! Variance of w (1st PDF component) [m^2/s^2]
varnce_w_2_zm, & ! Variance of w (2nd PDF component) [m^2/s^2]
mixt_frac_zm ! Weight of 1st PDF component (Sk_w dependent) [-]
integer :: &
wprtp_cl_num, & ! Instance of w'r_t' clipping (1st or 3rd).
wpthlp_cl_num, & ! Instance of w'th_l' clipping (1st or 3rd).
wpsclrp_cl_num, & ! Instance of w'sclr' clipping (1st or 3rd).
upwp_cl_num, & ! Instance of u'w' clipping (1st or 2nd).
vpwp_cl_num ! Instance of v'w' clipping (1st or 2nd).
real( kind = core_rknd ), dimension(gr%nz) :: &
rcp2_zt, & ! r_c'^2 (on thermo. grid) [kg^2/kg^2]
cloud_frac_zm, & ! Cloud Fraction on momentum grid [-]
ice_supersat_frac_zm, & ! Ice Cloud Fraction on momentum grid [-]
rtm_zm, & ! Total water mixing ratio [kg/kg]
thlm_zm, & ! Liquid potential temperature [kg/kg]
rcm_zm, & ! Liquid water mixing ratio on m-levs. [kg/kg]
sign_rtpthlp, & ! Sign of the covariance rtpthlp [-]
wpsclrp_zt, & ! Scalar flux on thermo. levels [un. vary]
sclrp2_zt ! Scalar variance on thermo.levels [un. vary]
real( kind = core_rknd ), dimension(gr%nz,sclr_dim) :: &
sclrp3 ! <sclr'^3> (thermodynamic levels) [un. vary]
real( kind = core_rknd ) :: &
rtm_integral_before, &
rtm_integral_after, &
rtm_integral_forcing, &
rtm_flux_top, &
rtm_flux_sfc, &
rtm_spur_src, &
thlm_integral_before, &
thlm_integral_after, &
thlm_integral_forcing, &
thlm_flux_top, &
thlm_flux_sfc, &
thlm_spur_src, &
mu_pert_1, mu_pert_2, & ! For l_avg_Lscale
mu_pert_pos_rt, mu_pert_neg_rt ! For l_Lscale_plume_centered
!The following variables are defined for use when l_use_ice_latent = .true.
type(pdf_parameter), dimension(gr%nz) :: &
pdf_params_frz
type(implicit_coefs_terms), dimension(gr%nz) :: &
pdf_implicit_coefs_terms ! Implicit coefs / explicit terms [units vary]
real( kind = core_rknd ), dimension(gr%nz) :: &
rtm_frz, &
thlm_frz
real( kind = core_rknd ) :: &
thlm1000, &
thlm700
real( kind = core_rknd ), dimension(gr%nz) :: &
rcm_supersat_adj, & ! Adjustment to rcm due to spurious supersaturation
rel_humidity ! Relative humidity after PDF closure [-]
real( kind = core_rknd ), dimension(gr%nz) :: &
stability_correction, & ! Stability correction factor
tau_N2_zm, & ! Tau with a static stability correction applied to it [s]
tau_C6_zm, & ! Tau values used for the C6 (pr1) term in wpxp [s]
tau_C1_zm, & ! Tau values used for the C1 (dp1) term in wp2 [s]
Cx_fnc_Richardson, & ! Cx_fnc computed from Richardson_num [-]
brunt_vaisala_freq_sqd ! Buoyancy frequency squared, N^2 [s^-2}
real( kind = core_rknd ) :: Lscale_max
real( kind = core_rknd ) :: newmu
! Flag to sample stats in a particular call to subroutine
! pdf_closure_driver.
logical :: l_samp_stats_in_pdf_call
real( kind = core_rknd ), dimension(gr%nz) :: &
wp2_splat, & ! Tendency of <w'2> due to eddies compressing [m^2/s^3]
wp3_splat ! Tendency of <w'3> due to eddies compressing [m^3/s^4]
! Variables associated with upgradient momentum contributions due to cumuli
!real( kind = core_rknd ), dimension(gr%nz) :: &
! Km_Skw_factor ! Factor, with value < 1, that reduces eddy diffusivity,
! Km_zm, in skewed layers
!real( kind = core_rknd ),parameter :: &
! Km_Skw_thresh = zero_threshold, & ! Value of Skw at which Skw correction kicks in
! Km_Skw_factor_efold = 0.5_core_rknd, & ! E-folding rate of exponential Skw correction
! Km_Skw_factor_min = 0.2_core_rknd ! Minimum value of Km_Skw_factor
!----- Begin Code -----
! Sanity checks
if ( clubb_at_least_debug_level( 0 ) ) then
if ( l_Lscale_plume_centered .and. .not. l_avg_Lscale ) then
write(fstderr,*) "l_Lscale_plume_centered requires l_avg_Lscale"
write(fstderr,*) "Fatal error in advance_clubb_core"
return
end if
if ( l_damp_wp2_using_em .and. (C1 /= C14 .or. l_stability_correct_tau_zm) ) then
write(fstderr,*) "l_damp_wp2_using_em requires C1=C14 and l_stability_correct_tau_zm = F"
write(fstderr,*) "Fatal error in advance_clubb_core"
return
end if
end if
! Determine the maximum allowable value for Lscale (in meters).
call set_Lscale_max( l_implemented, host_dx, host_dy, & ! intent(in)
Lscale_max ) ! intent(out)
if ( l_stats .and. l_stats_samp ) then
! Spurious source will only be calculated if rtm_ma and thlm_ma are zero.
! Therefore, wm must be zero or l_implemented must be true.
if ( l_implemented .or. ( all( abs(wm_zt) < eps ) .and. &
all( abs(wm_zm) < eps ) ) ) then
! Get the vertical integral of rtm and thlm before this function begins
! so that spurious source can be calculated
rtm_integral_before &
= vertical_integral( (gr%nz - 2 + 1), rho_ds_zt(2:gr%nz), &
rtm(2:gr%nz), gr%dzt(2:gr%nz) )
thlm_integral_before &
= vertical_integral( (gr%nz - 2 + 1), rho_ds_zt(2:gr%nz), &
thlm(2:gr%nz), gr%dzt(2:gr%nz) )
end if
end if
!----------------------------------------------------------------
! Test input variables
!----------------------------------------------------------------
if ( clubb_at_least_debug_level( 2 ) ) then
call parameterization_check &
( thlm_forcing, rtm_forcing, um_forcing, & ! intent(in)
vm_forcing, wm_zm, wm_zt, p_in_Pa, & ! intent(in)
rho_zm, rho, exner, rho_ds_zm, & ! intent(in)
rho_ds_zt, invrs_rho_ds_zm, invrs_rho_ds_zt, & ! intent(in)
thv_ds_zm, thv_ds_zt, wpthlp_sfc, wprtp_sfc, upwp_sfc, & ! intent(in)
vpwp_sfc, um, upwp, vm, vpwp, up2, vp2, & ! intent(in)
rtm, wprtp, thlm, wpthlp, wp2, wp3, & ! intent(in)
rtp2, thlp2, rtpthlp, rcm, & ! intent(in)
"beginning of ", & ! intent(in)
wpsclrp_sfc, wpedsclrp_sfc, sclrm, wpsclrp, sclrp2, & ! intent(in)
sclrprtp, sclrpthlp, sclrm_forcing, edsclrm, edsclrm_forcing ) ! intent(in)
if ( clubb_at_least_debug_level( 0 ) ) then
if ( err_code == clubb_fatal_error ) return
end if
end if
!-----------------------------------------------------------------------
if ( l_stats_samp ) then
call stat_update_var( irfrzm, rfrzm, & ! intent(in)
stats_zt ) ! intent(inout)
end if
! Set up budget stats variables.
if ( l_stats_samp ) then
call stat_begin_update( iwp2_bt, wp2 / dt, & ! intent(in)
stats_zm ) ! intent(inout)
call stat_begin_update( ivp2_bt, vp2 / dt, & ! intent(in)
stats_zm ) ! intent(inout)
call stat_begin_update( iup2_bt, up2 / dt, & ! intent(in)
stats_zm ) ! intent(inout)
call stat_begin_update( iwprtp_bt, wprtp / dt, & ! intent(in)
stats_zm ) ! intent(inout)
call stat_begin_update( iwpthlp_bt, wpthlp / dt, & ! intent(in)
stats_zm ) ! intent(inout)
if ( l_predict_upwp_vpwp ) then
call stat_begin_update( iupwp_bt, upwp / dt, & ! intent(in)
stats_zm ) ! intent(inout)
call stat_begin_update( ivpwp_bt, vpwp / dt, & ! intent(in)
stats_zm ) ! intent(inout)
endif ! l_predict_upwp_vpwp
call stat_begin_update( irtp2_bt, rtp2 / dt, & ! intent(in)
stats_zm ) ! intent(inout)
call stat_begin_update( ithlp2_bt, thlp2 / dt, & ! intent(in)
stats_zm ) ! intent(inout)
call stat_begin_update( irtpthlp_bt, rtpthlp / dt, & ! intent(in)
stats_zm ) ! intent(inout)
call stat_begin_update( irtm_bt, rtm / dt, & ! intent(in)
stats_zt ) ! intent(inout)
call stat_begin_update( ithlm_bt, thlm / dt, & ! intent(in)
stats_zt ) ! intent(inout)
call stat_begin_update( ium_bt, um / dt, & ! intent(in)
stats_zt ) ! intent(inout)
call stat_begin_update( ivm_bt, vm / dt, & ! intent(in)
stats_zt ) ! intent(inout)
call stat_begin_update( iwp3_bt, wp3 / dt, & ! intent(in)
stats_zt ) ! intent(inout)
endif
! SET SURFACE VALUES OF FLUXES (BROUGHT IN)
! We only do this for host models that do not apply the flux
! elsewhere in the code (e.g. WRF). In other cases the _sfc variables will
! only be used to compute the variance at the surface. -dschanen 8 Sept 2009
if ( .not. l_host_applies_sfc_fluxes ) then
wpthlp(1) = wpthlp_sfc
wprtp(1) = wprtp_sfc
upwp(1) = upwp_sfc
vpwp(1) = vpwp_sfc
! Set fluxes for passive scalars (if enabled)
if ( sclr_dim > 0 ) then
wpsclrp(1,1:sclr_dim) = wpsclrp_sfc(1:sclr_dim)
end if
if ( edsclr_dim > 0 ) then
wpedsclrp(1,1:edsclr_dim) = wpedsclrp_sfc(1:edsclr_dim)
end if
else
wpthlp(1) = 0.0_core_rknd
wprtp(1) = 0.0_core_rknd
upwp(1) = 0.0_core_rknd
vpwp(1) = 0.0_core_rknd
! Set fluxes for passive scalars (if enabled)
if ( sclr_dim > 0 ) then
wpsclrp(1,1:sclr_dim) = 0.0_core_rknd
end if
if ( edsclr_dim > 0 ) then
wpedsclrp(1,1:edsclr_dim) = 0.0_core_rknd
end if
end if ! ~l_host_applies_sfc_fluxes
#ifdef CLUBBND_CAM
newmu = varmu
#else
newmu = mu
#endif
if ( ipdf_call_placement == ipdf_pre_advance_fields &
.or. ipdf_call_placement == ipdf_pre_post_advance_fields ) then
! Sample stats in this call to subroutine pdf_closure_driver for
! both of these options (ipdf_pre_advance_fields and
! ipdf_pre_post_advance_fields).
if ( ipdf_call_placement == ipdf_pre_advance_fields ) then
l_samp_stats_in_pdf_call = .true.
elseif ( ipdf_call_placement == ipdf_pre_post_advance_fields ) then
l_samp_stats_in_pdf_call = .true.
endif
!########################################################################
!####### CALL CLUBB's PDF #######
!####### AND OUTPUT PDF PARAMETERS AND INTEGRATED QUANTITITES #######
!########################################################################
!call pdf_closure_driver( dt, hydromet_dim, rtm, wprtp, & ! Intent(in)
call pdf_closure_driver( dt, hydromet_dim, wprtp, & ! Intent(in)
thlm, wpthlp, rtp2, rtp3, & ! Intent(in)
thlp2, thlp3, rtpthlp, wp2, & ! Intent(in)
wp3, wm_zm, wm_zt, p_in_Pa, & ! Intent(in)
exner, thv_ds_zm, thv_ds_zt, & ! Intent(in)
rfrzm, hydromet, wphydrometp, & ! Intent(in)
wp2hmp, rtphmp_zt, thlphmp_zt, & ! Intent(in)
sclrm, wpsclrp, sclrp2, & ! Intent(in)
sclrprtp, sclrpthlp, & ! Intent(in)
l_samp_stats_in_pdf_call, & ! Intent(in)
rtm, & ! Intent(i/o)
#ifdef GFDL
RH_crit(k, : , :), & ! Intent(i/o)
do_liquid_only_in_clubb, & ! Intent(in)
#endif
rcm, cloud_frac, & ! Intent(out)
ice_supersat_frac, wprcp, & ! Intent(out)
sigma_sqd_w, wpthvp, wp2thvp, & ! Intent(out)
rtpthvp, thlpthvp, rc_coef, & ! Intent(out)
rcm_in_layer, cloud_cover, & ! Intent(out)
rcp2_zt, thlprcp, rc_coef_zm, & ! Intent(out)
rtm_frz, thlm_frz, sclrpthvp, & ! Intent(out)
wp4, wp2rtp, wprtp2, wp2thlp, & ! Intent(out)
wpthlp2, wprtpthlp, wp2rcp, & ! Intent(out)
rtprcp, rcp2, Skw_velocity, & ! Intent(out)
cloud_frac_zm, & ! Intent(out)
ice_supersat_frac_zm, & ! Intent(out)
rtm_zm, thlm_zm, rcm_zm, & ! Intent(out)
rcm_supersat_adj, & ! Intent(out)
wp2sclrp, wpsclrp2, sclrprcp, & ! Intent(out)
wpsclrprtp, wpsclrpthlp, & ! Intent(out)
pdf_params, pdf_params_frz, & ! Intent(out)
pdf_params_zm, & ! Intent(out)
pdf_implicit_coefs_terms ) ! Intent(out)
endif ! ipdf_call_placement == ipdf_pre_advance_fields
! or ipdf_call_placement == ipdf_pre_post_advance_fields
! Interpolate wp3 to momentum levels, and wp2 to thermodynamic levels
! and then compute Skw for m & t grid.
wp2_zt = max( zm2zt( wp2 ), w_tol_sqd ) ! Positive definite quantity
wp3_zm = zt2zm( wp3 )
Skw_zt(1:gr%nz) = Skx_func( wp2_zt(1:gr%nz), wp3(1:gr%nz), w_tol )
Skw_zm(1:gr%nz) = Skx_func( wp2(1:gr%nz), wp3_zm(1:gr%nz), w_tol )
if ( ipdf_call_placement == ipdf_post_advance_fields ) then
! Calculate sigma_sqd_w here in order to avoid having to pass it in
! and out of subroutine advance_clubb_core.
if ( l_gamma_Skw .and. &
abs(gamma_coef-gamma_coefb) > abs(gamma_coef+gamma_coefb)*eps/2) then
gamma_Skw_fnc = gamma_coefb + (gamma_coef-gamma_coefb) &
*exp( -(1.0_core_rknd/2.0_core_rknd) * (Skw_zm/gamma_coefc)**2 )
else
gamma_Skw_fnc = gamma_coef
endif
! Compute sigma_sqd_w (dimensionless PDF width parameter)
sigma_sqd_w &
= compute_sigma_sqd_w( gamma_Skw_fnc, wp2, thlp2, rtp2, wpthlp, wprtp )
! Smooth in the vertical using interpolation
sigma_sqd_w = zt2zm( zm2zt( sigma_sqd_w ) )
sigma_sqd_w = max( zero_threshold, sigma_sqd_w ) ! Pos. def. quantity
endif ! ipdf_call_placement == ipdf_post_advance_fields
! Compute the a3 coefficient (formula 25 in `Equations for CLUBB')
! Note: a3 has been modified because the wp3 turbulent advection term is
! now discretized on its own. This removes the "- 3" from the end.
! a3_coef = 3.0_core_rknd * sigma_sqd_w*sigma_sqd_w &
! + 6.0_core_rknd*(1.0_core_rknd-sigma_sqd_w)*sigma_sqd_w &
! + (1.0_core_rknd-sigma_sqd_w)*(1.0_core_rknd-sigma_sqd_w)
! This is a simplified version of the formula above.
! Note: a3 has been modified because the wp3 turbulent advection term is
! now discretized on its own.
a3_coef = -2._core_rknd * ( 1._core_rknd - sigma_sqd_w )**2 + 3.0_core_rknd
! We found we obtain fewer spikes in wp3 when we clip a3 to be no greater