-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathclubb_intr.F90
4613 lines (3876 loc) · 218 KB
/
clubb_intr.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
module clubb_intr
!----------------------------------------------------------------------------------------------------- !
! Module to interface CAM with Cloud Layers Unified by Bi-normals (CLUBB), developed !
! by the University of Wisconsin Milwaukee Group (UWM). !
! !
! CLUBB replaces the exisiting turbulence, shallow convection, and macrophysics in CAM5 !
! !
! Lastly, a implicit diffusion solver is called, and tendencies retrieved by !
! differencing the diffused and initial states. !
! !
! Calling sequence: !
! !
!---------------------------Code history-------------------------------------------------------------- !
! Authors: P. Bogenschutz, C. Craig, A. Gettelman !
! Modified by: K Thayer-Calder !
! !
!----------------------------------------------------------------------------------------------------- !
use shr_kind_mod, only: r8=>shr_kind_r8
use ppgrid, only: pver, pverp, pcols, begchunk, endchunk
use phys_control, only: phys_getopts
use physconst, only: rairv, cpairv, cpair, gravit, latvap, latice, zvir, rh2o, karman
use spmd_utils, only: masterproc
use constituents, only: pcnst, cnst_add
use pbl_utils, only: calc_ustar, calc_obklen
use ref_pres, only: top_lev => trop_cloud_top_lev
use zm_conv_intr, only: zmconv_microp
#ifdef CLUBB_SGS
use clubb_api_module, only: pdf_parameter, implicit_coefs_terms
use clubb_api_module, only: clubb_config_flags_type
use clubb_mf, only: do_clubb_mf, do_clubb_mf_diag
#endif
implicit none
private
save
! ----------------- !
! Public interfaces !
! ----------------- !
public :: clubb_ini_cam, clubb_register_cam, clubb_tend_cam, &
#ifdef CLUBB_SGS
! This utilizes CLUBB specific variables in its interface
stats_init_clubb, &
init_clubb_config_flags, &
#endif
stats_end_timestep_clubb, &
clubb_readnl, &
clubb_init_cnst, &
clubb_implements_cnst
#ifdef CLUBB_SGS
! Both of these utilize CLUBB specific variables in their interface
private :: stats_zero, stats_avg
#endif
logical, public :: do_cldcool
logical :: clubb_do_icesuper
#ifdef CLUBB_SGS
type(clubb_config_flags_type), public :: clubb_config_flags
#endif
! ------------ !
! Private data !
! ------------ !
integer, parameter :: &
grid_type = 3, & ! The 2 option specifies stretched thermodynamic levels
hydromet_dim = 0 ! The hydromet array in SAM-CLUBB is currently 0 elements
real(r8), parameter, dimension(0) :: &
sclr_tol = 1.e-8_r8 ! Total water in kg/kg
character(len=6) :: saturation_equation
real(r8), parameter :: &
theta0 = 300._r8, & ! Reference temperature [K]
ts_nudge = 86400._r8, & ! Time scale for u/v nudging (not used) [s]
p0_clubb = 100000._r8
integer, parameter :: &
sclr_dim = 0 ! Higher-order scalars, set to zero
real(r8), parameter :: &
wp3_const = 1._r8 ! Constant to add to wp3 when moments are advected
real(r8), parameter :: &
wpthlp_const = 10.0_r8 ! Constant to add to wpthlp when moments are advected
real(r8), parameter :: &
wprtp_const = 0.01_r8 ! Constant to add to wprtp when moments are advected
real(r8), parameter :: &
rtpthlp_const = 0.01_r8 ! Constant to add to rtpthlp when moments are advected
real(r8), parameter :: unset_r8 = huge(1.0_r8)
real(r8) :: clubb_timestep = unset_r8 ! Default CLUBB timestep, unless overwriten by namelist
real(r8) :: clubb_rnevap_effic = unset_r8
real(r8) :: clubb_c1 = unset_r8
real(r8) :: clubb_c1b = unset_r8
real(r8) :: clubb_C2rt = unset_r8
real(r8) :: clubb_C2thl = unset_r8
real(r8) :: clubb_C2rtthl = unset_r8
real(r8) :: clubb_C4 = unset_r8
real(r8) :: clubb_C8 = unset_r8
real(r8) :: clubb_C8b = unset_r8
real(r8) :: clubb_C7 = unset_r8
real(r8) :: clubb_C7b = unset_r8
real(r8) :: clubb_c11 = unset_r8
real(r8) :: clubb_c11b = unset_r8
real(r8) :: clubb_c14 = unset_r8
real(r8) :: clubb_c_K9 = unset_r8
real(r8) :: clubb_nu9 = unset_r8
real(r8) :: clubb_c_K10 = unset_r8
real(r8) :: clubb_c_K10h = unset_r8
real(r8) :: clubb_gamma_coef = unset_r8
real(r8) :: clubb_gamma_coefb = unset_r8
real(r8) :: clubb_beta = unset_r8
real(r8) :: clubb_lambda0_stability_coef = unset_r8
real(r8) :: clubb_lmin_coef = unset_r8
real(r8) :: clubb_mult_coef = unset_r8
real(r8) :: clubb_Skw_denom_coef = unset_r8
real(r8) :: clubb_skw_max_mag = unset_r8
real(r8) :: clubb_up2_vp2_factor = unset_r8
real(r8) :: clubb_C_wp2_splat = unset_r8
logical :: clubb_l_brunt_vaisala_freq_moist = .false.
logical :: clubb_l_call_pdf_closure_twice = .false.
logical :: clubb_l_damp_wp3_Skw_squared = .false.
logical :: clubb_l_min_wp2_from_corr_wx = .false.
logical :: clubb_l_min_xp2_from_corr_wx = .false.
logical :: clubb_l_predict_upwp_vpwp = .false.
logical :: clubb_l_rcm_supersat_adj = .false.
logical :: clubb_l_stability_correct_tau_zm = .false.
logical :: clubb_l_trapezoidal_rule_zt = .false.
logical :: clubb_l_trapezoidal_rule_zm = .false.
logical :: clubb_l_upwind_xpyp_ta = .false.
logical :: clubb_l_use_C7_Richardson = .false.
logical :: clubb_l_use_C11_Richardson = .false.
logical :: clubb_l_use_cloud_cover = .false.
logical :: clubb_l_use_thvm_in_bv_freq = .false.
logical :: clubb_l_vert_avg_closure = .false.
logical :: clubb_l_diag_Lscale_from_tau = .false.
logical :: clubb_l_damp_wp2_using_em = .false.
! Constant parameters
logical, parameter, private :: &
l_implemented = .true., & ! Implemented in a host model (always true)
l_host_applies_sfc_fluxes = .false. ! Whether the host model applies the surface fluxes
logical, parameter, private :: &
apply_to_heat = .false. ! Apply WACCM energy fixer to heat or not (.true. = yes (duh))
logical :: lq(pcnst)
logical :: prog_modal_aero
logical :: do_rainturb
logical :: do_expldiff
logical :: clubb_do_adv
logical :: clubb_do_liqsupersat = .false.
logical :: clubb_do_energyfix = .true.
logical :: history_budget
logical :: clubb_l_lscale_plume_centered
logical :: clubb_l_use_ice_latent
integer :: history_budget_histfile_num
integer :: edsclr_dim ! Number of scalars to transport in CLUBB
integer :: offset
! define physics buffer indicies here
integer :: &
wp2_idx, & ! vertical velocity variances
wp3_idx, & ! third moment of vertical velocity
wpthlp_idx, & ! turbulent flux of thetal
wprtp_idx, & ! turbulent flux of total water
rtpthlp_idx, & ! covariance of thetal and rt
rtp2_idx, & ! variance of total water
thlp2_idx, & ! variance of thetal
rtp3_idx, & ! total water 3rd order
thlp3_idx, & ! thetal 3rd order
up2_idx, & ! variance of east-west wind
vp2_idx, & ! variance of north-south wind
up3_idx, & ! east-west wind 3rd order
vp3_idx, & ! north-south wind 3rd order
upwp_idx, & ! east-west momentum flux
vpwp_idx, & ! north-south momentum flux
thlm_idx, & ! mean thetal
rtm_idx, & ! mean total water mixing ratio
um_idx, & ! mean of east-west wind
vm_idx, & ! mean of north-south wind
wpthvp_idx, & ! buoyancy flux
wp2thvp_idx, & ! second order buoyancy term
rtpthvp_idx, & ! moisture buoyancy correlation
thlpthvp_idx, & ! temperature buoyancy correlation
sclrpthvp_idx, & ! passive scalar buoyancy correlation
cloud_frac_idx, & ! CLUBB's cloud fraction
cld_idx, & ! Cloud fraction
concld_idx, & ! Convective cloud fraction
ast_idx, & ! Stratiform cloud fraction
alst_idx, & ! Liquid stratiform cloud fraction
aist_idx, & ! Ice stratiform cloud fraction
qlst_idx, & ! Physical in-cloud LWC
qist_idx, & ! Physical in-cloud IWC
dp_frac_idx, & ! deep convection cloud fraction
sh_frac_idx, & ! shallow convection cloud fraction
kvh_idx, & ! CLUBB eddy diffusivity on thermo levels
pblh_idx, & ! PBL pbuf
icwmrdp_idx, & ! In cloud mixing ratio for deep convection
tke_idx, & ! turbulent kinetic energy
tpert_idx, & ! temperature perturbation from PBL
fice_idx, & ! fice_idx index in physics buffer
cmeliq_idx, & ! cmeliq_idx index in physics buffer
relvar_idx, & ! relative cloud water variance
accre_enhan_idx, & ! optional accretion enhancement factor for MG
npccn_idx, & ! liquid ccn number concentration
naai_idx, & ! ice number concentration
prer_evap_idx, & ! rain evaporation rate
qrl_idx, & ! longwave cooling rate
radf_idx, &
qsatfac_idx, & ! subgrid cloud water saturation scaling factor
ice_supersat_idx, & ! ice cloud fraction for SILHS
rcm_idx, & ! Cloud water mixing ratio for SILHS
ztodt_idx ! physics timestep for SILHS
! Indices for microphysical covariance tendencies
integer :: &
rtp2_mc_zt_idx, &
thlp2_mc_zt_idx, &
wprtp_mc_zt_idx, &
wpthlp_mc_zt_idx, &
rtpthlp_mc_zt_idx
integer, public :: &
ixthlp2 = 0, &
ixwpthlp = 0, &
ixwprtp = 0, &
ixwp2 = 0, &
ixwp3 = 0, &
ixrtpthlp = 0, &
ixrtp2 = 0, &
ixup2 = 0, &
ixvp2 = 0
integer :: cmfmc_sh_idx = 0
integer :: &
dlfzm_idx = -1, & ! ZM detrained convective cloud water mixing ratio.
difzm_idx = -1, & ! ZM detrained convective cloud ice mixing ratio.
dnlfzm_idx = -1, & ! ZM detrained convective cloud water num concen.
dnifzm_idx = -1 ! ZM detrained convective cloud ice num concen.
! Output arrays for CLUBB statistics
real(r8), allocatable, dimension(:,:,:) :: out_zt, out_zm, out_radzt, out_radzm, out_sfc
character(len=16) :: eddy_scheme ! Default set in phys_control.F90
character(len=16) :: deep_scheme ! Default set in phys_control.F90
character(len=16) :: subcol_scheme
integer, parameter :: ncnst=9
character(len=8) :: cnst_names(ncnst)
logical :: do_cnst=.false.
#ifdef CLUBB_SGS
type(pdf_parameter), target, allocatable, public, protected :: &
pdf_params_chnk(:,:) ! PDF parameters (thermo. levs.) [units vary]
type(pdf_parameter), target, allocatable :: pdf_params_zm_chnk(:,:) ! PDF parameters on momentum levs. [units vary]
type(implicit_coefs_terms), target, allocatable :: pdf_implicit_coefs_terms_chnk(:,:) ! PDF impl. coefs. & expl. terms [units vary]
#endif
contains
! =============================================================================== !
! !
! =============================================================================== !
subroutine clubb_register_cam( )
!-------------------------------------------------------------------------------
! Description:
! Register the constituents and fields in the physics buffer
! Author: P. Bogenschutz, C. Craig, A. Gettelman
! Modified: 7/2013 by K Thayer-Calder to include support for SILHS/subcolumns
!
!-------------------------------------------------------------------------------
#ifdef CLUBB_SGS
!------------------------------------------------ !
! Register physics buffer fields and constituents !
!------------------------------------------------ !
! Add CLUBB fields to pbuf
use physics_buffer, only: pbuf_add_field, dtype_r8, dyn_time_lvls
use subcol_utils, only: subcol_get_scheme
call phys_getopts( eddy_scheme_out = eddy_scheme, &
deep_scheme_out = deep_scheme, &
history_budget_out = history_budget, &
history_budget_histfile_num_out = history_budget_histfile_num )
subcol_scheme = subcol_get_scheme()
if (trim(subcol_scheme) == 'SILHS') then
saturation_equation = "flatau"
else
saturation_equation = "gfdl" ! Goff & Gratch (1946) approximation for SVP
end if
if (clubb_do_adv) then
cnst_names =(/'THLP2 ','RTP2 ','RTPTHLP','WPTHLP ','WPRTP ','WP2 ','WP3 ','UP2 ','VP2 '/)
do_cnst=.true.
! If CLUBB moments are advected, do not output them automatically which is typically done. Some moments
! need a constant added to them before they are advected, thus this would corrupt the output.
! Users should refer to the "XXXX_CLUBB" (THLP2_CLUBB for instance) output variables for these moments
call cnst_add(trim(cnst_names(1)),0._r8,0._r8,0._r8,ixthlp2,longname='second moment vertical velocity',cam_outfld=.false.)
call cnst_add(trim(cnst_names(2)),0._r8,0._r8,0._r8,ixrtp2,longname='second moment rtp',cam_outfld=.false.)
call cnst_add(trim(cnst_names(3)),0._r8,0._r8,-999999._r8,ixrtpthlp,longname='covariance rtp thlp',cam_outfld=.false.)
call cnst_add(trim(cnst_names(4)),0._r8,0._r8,-999999._r8,ixwpthlp,longname='CLUBB heat flux',cam_outfld=.false.)
call cnst_add(trim(cnst_names(5)),0._r8,0._r8,-999999._r8,ixwprtp,longname='CLUBB moisture flux',cam_outfld=.false.)
call cnst_add(trim(cnst_names(6)),0._r8,0._r8,0._r8,ixwp2,longname='CLUBB wp2',cam_outfld=.false.)
call cnst_add(trim(cnst_names(7)),0._r8,0._r8,-999999._r8,ixwp3,longname='CLUBB 3rd moment vert velocity',cam_outfld=.false.)
call cnst_add(trim(cnst_names(8)),0._r8,0._r8,0._r8,ixup2,longname='CLUBB 2nd moment u wind',cam_outfld=.false.)
call cnst_add(trim(cnst_names(9)),0._r8,0._r8,0._r8,ixvp2,longname='CLUBB 2nd moment v wind',cam_outfld=.false.)
end if
! put pbuf_add calls here (see macrop_driver.F90 for sample) use indicies defined at top
call pbuf_add_field('pblh', 'global', dtype_r8, (/pcols/), pblh_idx)
call pbuf_add_field('tke', 'global', dtype_r8, (/pcols, pverp/), tke_idx)
call pbuf_add_field('kvh', 'global', dtype_r8, (/pcols, pverp/), kvh_idx)
call pbuf_add_field('tpert', 'global', dtype_r8, (/pcols/), tpert_idx)
call pbuf_add_field('AST', 'global', dtype_r8, (/pcols,pver,dyn_time_lvls/), ast_idx)
call pbuf_add_field('AIST', 'global', dtype_r8, (/pcols,pver,dyn_time_lvls/), aist_idx)
call pbuf_add_field('ALST', 'global', dtype_r8, (/pcols,pver,dyn_time_lvls/), alst_idx)
call pbuf_add_field('QIST', 'global', dtype_r8, (/pcols,pver,dyn_time_lvls/), qist_idx)
call pbuf_add_field('QLST', 'global', dtype_r8, (/pcols,pver,dyn_time_lvls/), qlst_idx)
call pbuf_add_field('CONCLD', 'global', dtype_r8, (/pcols,pver,dyn_time_lvls/), concld_idx)
call pbuf_add_field('CLD', 'global', dtype_r8, (/pcols,pver,dyn_time_lvls/), cld_idx)
call pbuf_add_field('FICE', 'physpkg',dtype_r8, (/pcols,pver/), fice_idx)
call pbuf_add_field('RAD_CLUBB', 'global', dtype_r8, (/pcols,pver/), radf_idx)
call pbuf_add_field('CMELIQ', 'physpkg',dtype_r8, (/pcols,pver/), cmeliq_idx)
call pbuf_add_field('QSATFAC', 'physpkg',dtype_r8, (/pcols,pver/), qsatfac_idx)
call pbuf_add_field('WP2_nadv', 'global', dtype_r8, (/pcols,pverp,dyn_time_lvls/), wp2_idx)
call pbuf_add_field('WP3_nadv', 'global', dtype_r8, (/pcols,pverp,dyn_time_lvls/), wp3_idx)
call pbuf_add_field('WPTHLP_nadv', 'global', dtype_r8, (/pcols,pverp,dyn_time_lvls/), wpthlp_idx)
call pbuf_add_field('WPRTP_nadv', 'global', dtype_r8, (/pcols,pverp,dyn_time_lvls/), wprtp_idx)
call pbuf_add_field('RTPTHLP_nadv', 'global', dtype_r8, (/pcols,pverp,dyn_time_lvls/), rtpthlp_idx)
call pbuf_add_field('RTP2_nadv', 'global', dtype_r8, (/pcols,pverp,dyn_time_lvls/), rtp2_idx)
call pbuf_add_field('THLP2_nadv', 'global', dtype_r8, (/pcols,pverp,dyn_time_lvls/), thlp2_idx)
call pbuf_add_field('UP2_nadv', 'global', dtype_r8, (/pcols,pverp,dyn_time_lvls/), up2_idx)
call pbuf_add_field('VP2_nadv', 'global', dtype_r8, (/pcols,pverp,dyn_time_lvls/), vp2_idx)
call pbuf_add_field('RTP3', 'global', dtype_r8, (/pcols,pverp,dyn_time_lvls/), rtp3_idx)
call pbuf_add_field('THLP3', 'global', dtype_r8, (/pcols,pverp,dyn_time_lvls/), thlp3_idx)
call pbuf_add_field('UP3', 'global', dtype_r8, (/pcols,pverp,dyn_time_lvls/), up3_idx)
call pbuf_add_field('VP3', 'global', dtype_r8, (/pcols,pverp,dyn_time_lvls/), vp3_idx)
call pbuf_add_field('UPWP', 'global', dtype_r8, (/pcols,pverp,dyn_time_lvls/), upwp_idx)
call pbuf_add_field('VPWP', 'global', dtype_r8, (/pcols,pverp,dyn_time_lvls/), vpwp_idx)
call pbuf_add_field('THLM', 'global', dtype_r8, (/pcols,pverp,dyn_time_lvls/), thlm_idx)
call pbuf_add_field('RTM', 'global', dtype_r8, (/pcols,pverp,dyn_time_lvls/), rtm_idx)
call pbuf_add_field('UM', 'global', dtype_r8, (/pcols,pverp,dyn_time_lvls/), um_idx)
call pbuf_add_field('VM', 'global', dtype_r8, (/pcols,pverp,dyn_time_lvls/), vm_idx)
call pbuf_add_field('WPTHVP', 'global', dtype_r8, (/pcols,pverp/), wpthvp_idx)
call pbuf_add_field('WP2THVP', 'physpkg', dtype_r8, (/pcols,pverp/), wp2thvp_idx)
call pbuf_add_field('RTPTHVP', 'physpkg', dtype_r8, (/pcols,pverp/), rtpthvp_idx)
call pbuf_add_field('THLPTHVP', 'physpkg', dtype_r8, (/pcols,pverp/), thlpthvp_idx)
call pbuf_add_field('CLOUD_FRAC', 'physpkg', dtype_r8, (/pcols,pverp/), cloud_frac_idx)
call pbuf_add_field('ISS_FRAC', 'physpkg', dtype_r8, (/pcols,pverp/), ice_supersat_idx)
call pbuf_add_field('RCM', 'physpkg', dtype_r8, (/pcols,pverp/), rcm_idx)
call pbuf_add_field('ZTODT', 'physpkg', dtype_r8, (/pcols/), ztodt_idx)
! For SILHS microphysical covariance contributions
call pbuf_add_field('rtp2_mc_zt', 'global', dtype_r8, (/pcols,pverp/), rtp2_mc_zt_idx)
call pbuf_add_field('thlp2_mc_zt','global', dtype_r8, (/pcols,pverp/), thlp2_mc_zt_idx)
call pbuf_add_field('wprtp_mc_zt','global', dtype_r8, (/pcols,pverp/), wprtp_mc_zt_idx)
call pbuf_add_field('wpthlp_mc_zt','global',dtype_r8, (/pcols,pverp/), wpthlp_mc_zt_idx)
call pbuf_add_field('rtpthlp_mc_zt','global',dtype_r8,(/pcols,pverp/), rtpthlp_mc_zt_idx)
#endif
end subroutine clubb_register_cam
! =============================================================================== !
! !
! =============================================================================== !
function clubb_implements_cnst(name)
!----------------------------------------------------------------------------- !
! !
! Return true if specified constituent is implemented by this package !
! !
!----------------------------------------------------------------------------- !
character(len=*), intent(in) :: name ! constituent name
logical :: clubb_implements_cnst ! return value
!-----------------------------------------------------------------------
clubb_implements_cnst = (do_cnst .and. any(name == cnst_names))
end function clubb_implements_cnst
! =============================================================================== !
! !
! =============================================================================== !
subroutine clubb_init_cnst(name, latvals, lonvals, mask, q)
#ifdef CLUBB_SGS
use clubb_api_module, only: w_tol_sqd, rt_tol, thl_tol
#endif
!----------------------------------------------------------------------- !
! !
! Initialize the state if clubb_do_adv !
! !
!----------------------------------------------------------------------- !
character(len=*), intent(in) :: name ! constituent name
real(r8), intent(in) :: latvals(:) ! lat in degrees (ncol)
real(r8), intent(in) :: lonvals(:) ! lon in degrees (ncol)
logical, intent(in) :: mask(:) ! Only initialize where .true.
real(r8), intent(out) :: q(:,:) ! kg tracer/kg dry air (gcol, plev
!-----------------------------------------------------------------------
integer :: k, nlev
#ifdef CLUBB_SGS
if (clubb_do_adv) then
nlev = size(q, 2)
do k = 1, nlev
if (trim(name) == trim(cnst_names(1))) then
where(mask)
q(:,k) = thl_tol**2
end where
end if
if (trim(name) == trim(cnst_names(2))) then
where(mask)
q(:,k) = rt_tol**2
end where
end if
if (trim(name) == trim(cnst_names(3))) then
where(mask)
q(:,k) = 0.0_r8
end where
end if
if (trim(name) == trim(cnst_names(4))) then
where(mask)
q(:,k) = 0.0_r8
end where
end if
if (trim(name) == trim(cnst_names(5))) then
where(mask)
q(:,k) = 0.0_r8
end where
end if
if (trim(name) == trim(cnst_names(6))) then
where(mask)
q(:,k) = w_tol_sqd
end where
end if
if (trim(name) == trim(cnst_names(7))) then
where(mask)
q(:,k) = 0.0_r8
end where
end if
if (trim(name) == trim(cnst_names(8))) then
where(mask)
q(:,k) = w_tol_sqd
end where
end if
if (trim(name) == trim(cnst_names(9))) then
where(mask)
q(:,k) = w_tol_sqd
end where
end if
end do
end if
#endif
end subroutine clubb_init_cnst
! =============================================================================== !
! !
! =============================================================================== !
subroutine clubb_readnl(nlfile)
#ifdef CLUBB_SGS
use namelist_utils, only: find_group_name
use units, only: getunit, freeunit
use cam_abortutils, only: endrun
use clubb_api_module, only: l_stats, l_output_rad_files
use spmd_utils, only: mpicom, mstrid=>masterprocid, mpi_logical, mpi_real8
use clubb_mf, only: clubb_mf_readnl
#endif
character(len=*), intent(in) :: nlfile ! filepath for file containing namelist input
#ifdef CLUBB_SGS
character(len=*), parameter :: sub = 'clubb_readnl'
logical :: clubb_history, clubb_rad_history, clubb_cloudtop_cooling, clubb_rainevap_turb, &
clubb_expldiff ! Stats enabled (T/F)
integer :: iunit, read_status, ierr
namelist /clubb_his_nl/ clubb_history, clubb_rad_history
namelist /clubbpbl_diff_nl/ clubb_cloudtop_cooling, clubb_rainevap_turb, clubb_expldiff, &
clubb_do_adv, clubb_timestep, &
clubb_rnevap_effic,clubb_do_icesuper
namelist /clubb_params_nl/ clubb_c1, clubb_c1b, clubb_c11, clubb_c11b, clubb_c14, clubb_mult_coef, clubb_gamma_coef, &
clubb_c_K10, clubb_c_K10h, clubb_beta, clubb_C2rt, clubb_C2thl, &
clubb_C2rtthl, clubb_C8, clubb_C8b, clubb_C7, clubb_C7b, clubb_Skw_denom_coef, &
clubb_C4, clubb_c_K9, clubb_nu9, clubb_C_wp2_splat, &
clubb_lambda0_stability_coef, clubb_l_lscale_plume_centered, &
clubb_l_use_ice_latent, clubb_do_liqsupersat, clubb_do_energyfix,&
clubb_lmin_coef, clubb_skw_max_mag, clubb_l_stability_correct_tau_zm, &
clubb_gamma_coefb, clubb_up2_vp2_factor, &
clubb_l_use_C7_Richardson, clubb_l_use_C11_Richardson, &
clubb_l_brunt_vaisala_freq_moist, clubb_l_use_thvm_in_bv_freq, &
clubb_l_rcm_supersat_adj, clubb_l_damp_wp3_Skw_squared, &
clubb_l_predict_upwp_vpwp, clubb_l_min_wp2_from_corr_wx, &
clubb_l_min_xp2_from_corr_wx, clubb_l_upwind_xpyp_ta, clubb_l_vert_avg_closure, &
clubb_l_trapezoidal_rule_zt, clubb_l_trapezoidal_rule_zm, &
clubb_l_call_pdf_closure_twice, clubb_l_use_cloud_cover, &
clubb_l_diag_Lscale_from_tau, clubb_l_damp_wp2_using_em
!----- Begin Code -----
! Determine if we want clubb_history to be output
clubb_history = .false. ! Initialize to false
l_stats = .false. ! Initialize to false
l_output_rad_files = .false. ! Initialize to false
do_cldcool = .false. ! Initialize to false
do_rainturb = .false. ! Initialize to false
do_expldiff = .false. ! Initialize to false
clubb_l_lscale_plume_centered = .false. ! Initialize to false!
clubb_l_use_ice_latent = .false. ! Initialize to false!
! Call CLUBB+MF namelist
call clubb_mf_readnl(nlfile)
! Read namelist to determine if CLUBB history should be called
if (masterproc) then
iunit = getunit()
open( iunit, file=trim(nlfile), status='old' )
call find_group_name(iunit, 'clubb_his_nl', status=read_status)
if (read_status == 0) then
read(unit=iunit, nml=clubb_his_nl, iostat=read_status)
if (read_status /= 0) then
call endrun('clubb_readnl: error reading namelist')
end if
end if
call find_group_name(iunit, 'clubb_params_nl', status=read_status)
if (read_status == 0) then
read(unit=iunit, nml=clubb_params_nl, iostat=read_status)
if (read_status /= 0) then
call endrun('clubb_readnl: error reading namelist')
end if
else
call endrun('clubb_readnl: error reading namelist')
end if
call find_group_name(iunit, 'clubbpbl_diff_nl', status=read_status)
if (read_status == 0) then
read(unit=iunit, nml=clubbpbl_diff_nl, iostat=read_status)
if (read_status /= 0) then
call endrun('clubb_readnl: error reading namelist')
end if
end if
close(unit=iunit)
call freeunit(iunit)
end if
! Broadcast namelist variables
call mpi_bcast(clubb_history, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_history")
call mpi_bcast(clubb_rad_history, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_rad_history")
call mpi_bcast(clubb_do_icesuper, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_do_icesuper")
call mpi_bcast(clubb_cloudtop_cooling, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_cloudtop_cooling")
call mpi_bcast(clubb_rainevap_turb, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_rainevap_turb")
call mpi_bcast(clubb_expldiff, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_expldiff")
call mpi_bcast(clubb_do_adv, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_do_adv")
call mpi_bcast(clubb_timestep, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_timestep")
call mpi_bcast(clubb_rnevap_effic, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_rnevap_effic")
call mpi_bcast(clubb_c1, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_c1")
call mpi_bcast(clubb_c1b, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_c1b")
call mpi_bcast(clubb_c11, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_c11")
call mpi_bcast(clubb_c11b, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_c11b")
call mpi_bcast(clubb_c14, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_c14")
call mpi_bcast(clubb_mult_coef, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_mult_coef")
call mpi_bcast(clubb_gamma_coef, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_gamma_coef")
call mpi_bcast(clubb_c_K10, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_c_K10")
call mpi_bcast(clubb_c_K10h, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_c_K10h")
call mpi_bcast(clubb_beta, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_beta")
call mpi_bcast(clubb_C2rt, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_C2rt")
call mpi_bcast(clubb_C2thl, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_C2thl")
call mpi_bcast(clubb_C2rtthl, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_C2rtthl")
call mpi_bcast(clubb_C8, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_C8")
call mpi_bcast(clubb_C8b, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_C8b")
call mpi_bcast(clubb_C7, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_C7")
call mpi_bcast(clubb_C7b, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_C7b")
call mpi_bcast(clubb_Skw_denom_coef, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_Skw_denom_coef")
call mpi_bcast(clubb_C4, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_C4")
call mpi_bcast(clubb_c_K9, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_c_K9")
call mpi_bcast(clubb_nu9, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_nu9")
call mpi_bcast(clubb_C_wp2_splat, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_C_wp2_splat")
call mpi_bcast(clubb_lambda0_stability_coef, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_lambda0_stability_coef")
call mpi_bcast(clubb_l_lscale_plume_centered,1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_l_lscale_plume_centered")
call mpi_bcast(clubb_l_use_ice_latent, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_l_use_ice_latent")
call mpi_bcast(clubb_do_liqsupersat, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_do_liqsupersat")
call mpi_bcast(clubb_do_energyfix, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_do_energyfix")
call mpi_bcast(clubb_lmin_coef, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_lmin_coef")
call mpi_bcast(clubb_skw_max_mag, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_skw_max_mag")
call mpi_bcast(clubb_l_stability_correct_tau_zm, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_l_stability_correct_tau_zm")
call mpi_bcast(clubb_gamma_coefb, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_gamma_coefb")
call mpi_bcast(clubb_up2_vp2_factor, 1, mpi_real8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_up2_vp2_factor")
call mpi_bcast(clubb_l_use_C7_Richardson, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_l_use_C7_Richardson")
call mpi_bcast(clubb_l_use_C11_Richardson, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_l_use_C11_Richardson")
call mpi_bcast(clubb_l_brunt_vaisala_freq_moist, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_l_brunt_vaisala_freq_moist")
call mpi_bcast(clubb_l_use_thvm_in_bv_freq, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_l_use_thvm_in_bv_freq")
call mpi_bcast(clubb_l_rcm_supersat_adj, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_l_rcm_supersat_adj")
call mpi_bcast(clubb_l_damp_wp3_Skw_squared, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_l_damp_wp3_Skw_squared")
call mpi_bcast(clubb_l_predict_upwp_vpwp, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_l_predict_upwp_vpwp")
call mpi_bcast(clubb_l_min_wp2_from_corr_wx, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_l_min_wp2_from_corr_wx")
call mpi_bcast(clubb_l_min_xp2_from_corr_wx, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_l_min_xp2_from_corr_wx")
call mpi_bcast(clubb_l_upwind_xpyp_ta, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_l_upwind_xpyp_ta")
call mpi_bcast(clubb_l_vert_avg_closure, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_l_vert_avg_closure")
call mpi_bcast(clubb_l_trapezoidal_rule_zt, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_l_trapezoidal_rule_zt")
call mpi_bcast(clubb_l_trapezoidal_rule_zm, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_l_trapezoidal_rule_zm")
call mpi_bcast(clubb_l_call_pdf_closure_twice, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_l_call_pdf_closure_twice")
call mpi_bcast(clubb_l_use_cloud_cover, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_l_use_cloud_cover")
call mpi_bcast(clubb_l_diag_Lscale_from_tau, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_l_diag_Lscale_from_tau")
call mpi_bcast(clubb_l_damp_wp2_using_em, 1, mpi_logical, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": FATAL: mpi_bcast: clubb_l_damp_wp2_using_em")
! Overwrite defaults if they are true
if (clubb_history) l_stats = .true.
if (clubb_rad_history) l_output_rad_files = .true.
if (clubb_cloudtop_cooling) do_cldcool = .true.
if (clubb_rainevap_turb) do_rainturb = .true.
if (clubb_expldiff) do_expldiff = .true.
! Check that all namelists have been set
if(clubb_timestep == unset_r8) call endrun(sub//": FATAL: clubb_timestep is not set")
if(clubb_rnevap_effic == unset_r8) call endrun(sub//": FATAL:clubb_rnevap_effic is not set")
if(clubb_c1 == unset_r8) call endrun(sub//": FATAL: clubb_c1 is not set")
if(clubb_c1b == unset_r8) call endrun(sub//": FATAL: clubb_c1b is not set")
if(clubb_C2rt == unset_r8) call endrun(sub//": FATAL: clubb_C2rt is not set")
if(clubb_C2thl == unset_r8) call endrun(sub//": FATAL: clubb_C2thl is not set")
if(clubb_C2rtthl == unset_r8) call endrun(sub//": FATAL: clubb_C2rtthl is not set")
if(clubb_C4 == unset_r8) call endrun(sub//": FATAL: clubb_C4 is not set")
if(clubb_C8 == unset_r8) call endrun(sub//": FATAL: clubb_C8 is not set")
if(clubb_C8b == unset_r8) call endrun(sub//": FATAL: clubb_C8b is not set")
if(clubb_C7 == unset_r8) call endrun(sub//": FATAL: clubb_C7 is not set")
if(clubb_C7b == unset_r8) call endrun(sub//": FATAL: clubb_C7b is not set")
if(clubb_c11 == unset_r8) call endrun(sub//": FATAL: clubb_c11 is not set")
if(clubb_c11b == unset_r8) call endrun(sub//": FATAL: clubb_c11b is not set")
if(clubb_c14 == unset_r8) call endrun(sub//": FATAL: clubb_c14 is not set")
if(clubb_c_K9 == unset_r8) call endrun(sub//": FATAL: clubb_c_K9 is not set")
if(clubb_nu9 == unset_r8) call endrun(sub//": FATAL: clubb_nu9 is not set")
if(clubb_c_K10 == unset_r8) call endrun(sub//": FATAL: clubb_c_K10 is not set")
if(clubb_c_K10h == unset_r8) call endrun(sub//": FATAL: clubb_c_K10h is not set")
if(clubb_gamma_coef == unset_r8) call endrun(sub//": FATAL: clubb_gamma_coef is not set")
if(clubb_gamma_coefb == unset_r8) call endrun(sub//": FATAL: clubb_gamma_coefb is not set")
if(clubb_beta == unset_r8) call endrun(sub//": FATAL: clubb_beta is not set")
if(clubb_lambda0_stability_coef == unset_r8) call endrun(sub//": FATAL: clubb_lambda0_stability_coef is not set")
if(clubb_lmin_coef == unset_r8) call endrun(sub//": FATAL: clubb_lmin_coef is not set")
if(clubb_mult_coef == unset_r8) call endrun(sub//": FATAL: clubb_mult_coef is not set")
if(clubb_Skw_denom_coef == unset_r8) call endrun(sub//": FATAL: clubb_Skw_denom_coef is not set")
if(clubb_skw_max_mag == unset_r8) call endrun(sub//": FATAL: clubb_skw_max_mag is not set")
if(clubb_up2_vp2_factor == unset_r8) call endrun(sub//": FATAL: clubb_up2_vp2_factor is not set")
if(clubb_C_wp2_splat == unset_r8) call endrun(sub//": FATAL: clubb_C_wp2_splatis not set")
#endif
end subroutine clubb_readnl
! =============================================================================== !
! !
! =============================================================================== !
subroutine clubb_ini_cam(pbuf2d)
!-------------------------------------------------------------------------------
! Description:
! Initialize UWM CLUBB.
! Author: Cheryl Craig March 2011
! Modifications: Pete Bogenschutz 2011 March and onward
! Modifications: K Thayer-Calder 2013 July and onward
! Origin: Based heavily on UWM clubb_init.F90
! References:
! None
!-------------------------------------------------------------------------------
#ifdef CLUBB_SGS
! From CAM libraries
use cam_history, only: addfld, add_default, horiz_only
use ref_pres, only: pref_mid
use hb_diff, only: init_hb_diff
use rad_constituents, only: rad_cnst_get_info, rad_cnst_get_mode_num_idx, rad_cnst_get_mam_mmr_idx
use cam_abortutils, only: endrun
! From the CLUBB libraries
use clubb_api_module, only: core_rknd, &
iC11, iC11b, ibeta, iSkw_denom_coef, & ! Constant(s)
em_min, &
iC1, iC1b, iC2rt, iC2thl, iC2rtthl, igamma_coef, igamma_coefb, &
imult_coef, ic_K10, iskw_max_mag, &
iC8, iC8b, iC11, iC11b, iC4, iC14, iup2_vp2_factor, params_list
use clubb_api_module, only: &
print_clubb_config_flags_api, &
setup_clubb_core_api, &
init_pdf_params_api, &
init_pdf_implicit_coefs_terms_api, &
time_precision, &
core_rknd, &
set_clubb_debug_level_api, &
clubb_fatal_error, & ! Error code value to indicate a fatal error
nparams, &
read_parameters_api, &
l_stats, &
l_stats_samp, &
l_grads, &
stats_zt, &
stats_zm, &
stats_sfc, &
stats_rad_zt, &
stats_rad_zm, &
w_tol_sqd, &
rt_tol, &
thl_tol
! These are only needed if we're using a passive scalar
use clubb_api_module, only: &
iisclr_rt, &
iisclr_thl, &
iisclr_CO2, &
iiedsclr_rt, &
iiedsclr_thl, &
iiedsclr_CO2
! These are needed to set parameters
use clubb_api_module, only: &
ilambda0_stability_coef, ic_K10, ic_K10h, iC2rtthl, iC7, iC7b, iC8, iC8b, iC11, iC11b, &
iC14, igamma_coef, imult_coef, ilmin_coef, iSkw_denom_coef, ibeta, iskw_max_mag, &
iC2rt, iC2thl, iC2rtthl, ic_K9, inu9, iC_wp2_splat
use time_manager, only: is_first_step
use clubb_api_module, only: hydromet_dim
use constituents, only: cnst_get_ind
use phys_control, only: phys_getopts
use spmd_utils, only: iam
use cam_logfile, only: iulog
#endif
use physics_buffer, only: pbuf_get_index, pbuf_set_field, physics_buffer_desc
implicit none
! Input Variables
type(physics_buffer_desc), pointer :: pbuf2d(:,:)
#ifdef CLUBB_SGS
real(kind=time_precision) :: dum1, dum2, dum3
real(r8), dimension(nparams) :: clubb_params ! These adjustable CLUBB parameters (C1, C2 ...)
! The similar name to clubb_history is unfortunate...
logical :: history_amwg, history_clubb
integer :: err_code ! Code for when CLUBB fails
integer :: j, k, l ! Indices
integer :: ntop_eddy ! Top interface level to which eddy vertical diffusion is applied ( = 1 )
integer :: nbot_eddy ! Bottom interface level to which eddy vertical diffusion is applied ( = pver )
integer :: nmodes, nspec, m
integer :: ixq, ixcldice, ixcldliq, ixnumliq, ixnumice
integer :: lptr
logical, parameter :: l_input_fields = .false. ! Always false for CAM-CLUBB.
logical, parameter :: l_update_pressure = .false. ! Always false for CAM-CLUBB.
real(r8) :: zt_g(pverp+1-top_lev) ! Height dummy array
real(r8) :: zi_g(pverp+1-top_lev) ! Height dummy array
! CAM defines zi at the surface to be zero.
real(r8), parameter :: sfc_elevation = 0._r8
integer :: nlev
!----- Begin Code -----
nlev = pver + 1 - top_lev
if (core_rknd /= r8) then
call endrun('clubb_ini_cam: CLUBB library core_rknd must match CAM r8 and it does not')
end if
! Allocate PDF parameters across columns and chunks
allocate( &
pdf_params_chnk(pcols,begchunk:endchunk), &
pdf_params_zm_chnk(pcols,begchunk:endchunk), &
pdf_implicit_coefs_terms_chnk(pcols,begchunk:endchunk) )
! Allocate (in the vertical) and zero PDF parameters
do l = begchunk, endchunk, 1
do j = 1, pcols, 1
call init_pdf_params_api( pverp+1-top_lev, pdf_params_chnk(j,l) )
call init_pdf_params_api( pverp+1-top_lev, pdf_params_zm_chnk(j,l) )
call init_pdf_implicit_coefs_terms_api( pverp+1-top_lev, sclr_dim, &
pdf_implicit_coefs_terms_chnk(j,l) )
enddo ! j = 1, pcols, 1
enddo ! l = begchunk, endchunk, 1
! ----------------------------------------------------------------- !
! Determine how many constituents CLUBB will transport. Note that
! CLUBB does not transport aerosol consituents. Therefore, need to
! determine how many aerosols constituents there are and subtract that
! off of pcnst (the total consituents)
! ----------------------------------------------------------------- !
call phys_getopts(prog_modal_aero_out=prog_modal_aero, &
history_amwg_out=history_amwg, &
history_clubb_out=history_clubb)
! Select variables to apply tendencies back to CAM
! Initialize all consituents to true to start
lq(1:pcnst) = .true.
edsclr_dim = pcnst
call cnst_get_ind('Q',ixq)
call cnst_get_ind('NUMICE',ixnumice)
call cnst_get_ind('NUMLIQ',ixnumliq)
call cnst_get_ind('CLDLIQ',ixcldliq)
call cnst_get_ind('CLDICE',ixcldice)
if (prog_modal_aero) then
! Turn off modal aerosols and decrement edsclr_dim accordingly
call rad_cnst_get_info(0, nmodes=nmodes)
do m = 1, nmodes
call rad_cnst_get_mode_num_idx(m, lptr)
lq(lptr)=.false.
edsclr_dim = edsclr_dim-1
call rad_cnst_get_info(0, m, nspec=nspec)
do l = 1, nspec
call rad_cnst_get_mam_mmr_idx(m, l, lptr)
lq(lptr)=.false.
edsclr_dim = edsclr_dim-1
end do
end do
! In addition, if running with MAM, droplet number is transported
! in dropmixnuc, therefore we do NOT want CLUBB to apply transport
! tendencies to avoid double counted. Else, we apply tendencies.
lq(ixnumliq) = .false.
edsclr_dim = edsclr_dim-1
endif
! ----------------------------------------------------------------- !
! Set the debug level. Level 2 has additional computational expense since
! it checks the array variables in CLUBB for invalid values.
! ----------------------------------------------------------------- !
call set_clubb_debug_level_api( 0 )
! ----------------------------------------------------------------- !
! use pbuf_get_fld_idx to get existing physics buffer fields from other
! physics packages (e.g. tke)
! ----------------------------------------------------------------- !
! Defaults
l_stats_samp = .false.
l_grads = .false.
! Overwrite defaults if needbe
if (l_stats) l_stats_samp = .true.
! Define physics buffers indexes
cld_idx = pbuf_get_index('CLD') ! Cloud fraction
concld_idx = pbuf_get_index('CONCLD') ! Convective cloud cover
ast_idx = pbuf_get_index('AST') ! Stratiform cloud fraction
alst_idx = pbuf_get_index('ALST') ! Liquid stratiform cloud fraction
aist_idx = pbuf_get_index('AIST') ! Ice stratiform cloud fraction
qlst_idx = pbuf_get_index('QLST') ! Physical in-stratus LWC
qist_idx = pbuf_get_index('QIST') ! Physical in-stratus IWC
dp_frac_idx = pbuf_get_index('DP_FRAC') ! Deep convection cloud fraction
icwmrdp_idx = pbuf_get_index('ICWMRDP') ! In-cloud deep convective mixing ratio
sh_frac_idx = pbuf_get_index('SH_FRAC') ! Shallow convection cloud fraction
relvar_idx = pbuf_get_index('RELVAR') ! Relative cloud water variance
accre_enhan_idx = pbuf_get_index('ACCRE_ENHAN') ! accretion enhancement for MG
prer_evap_idx = pbuf_get_index('PRER_EVAP')
qrl_idx = pbuf_get_index('QRL')
cmfmc_sh_idx = pbuf_get_index('CMFMC_SH')
naai_idx = pbuf_get_index('NAAI')
npccn_idx = pbuf_get_index('NPCCN')
iisclr_rt = -1
iisclr_thl = -1
iisclr_CO2 = -1
iiedsclr_rt = -1
iiedsclr_thl = -1
iiedsclr_CO2 = -1
if (zmconv_microp) then
dlfzm_idx = pbuf_get_index('DLFZM')
difzm_idx = pbuf_get_index('DIFZM')
dnlfzm_idx = pbuf_get_index('DNLFZM')
dnifzm_idx = pbuf_get_index('DNIFZM')
end if
! ----------------------------------------------------------------- !
! Define number of tracers for CLUBB to diffuse
! ----------------------------------------------------------------- !
if (do_expldiff) then
offset = 2 ! diffuse temperature and moisture explicitly
edsclr_dim = edsclr_dim + offset
endif
! ----------------------------------------------------------------- !