forked from ESCOMP/CLUBB_CESM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf_parameter_module.F90
483 lines (420 loc) · 16.7 KB
/
pdf_parameter_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
!-----------------------------------------------------------------------
! $Id$
!===============================================================================
module pdf_parameter_module
! Description:
! This module defines the derived type pdf_parameter.
! References:
! None
!-----------------------------------------------------------------------
use clubb_precision, only: &
core_rknd
implicit none
private ! Default scope
public :: pdf_parameter, & ! Variable Type(s)
implicit_coefs_terms, &
init_pdf_params ! Procedure(s)
! CLUBB's PDF parameters.
type pdf_parameter
real( kind = core_rknd ) :: &
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]
rt_1, & ! Mean of r_t (1st PDF component) [kg/kg]
rt_2, & ! Mean of r_t (2nd PDF component) [kg/kg]
varnce_rt_1, & ! Variance of r_t (1st PDF component) [kg^2/kg^2]
varnce_rt_2, & ! Variance of r_t (2nd PDF component) [kg^2/kg^2]
thl_1, & ! Mean of th_l (1st PDF component) [K]
thl_2, & ! Mean of th_l (2nd PDF component) [K]
varnce_thl_1, & ! Variance of th_l (1st PDF component) [K^2]
varnce_thl_2, & ! Variance of th_l (2nd PDF component) [K^2]
corr_w_rt_1, & ! Correlation of w and r_t (1st PDF component) [-]
corr_w_rt_2, & ! Correlation of w and r_t (2nd PDF component) [-]
corr_w_thl_1, & ! Correlation of w and th_l (1st PDF component) [-]
corr_w_thl_2, & ! Correlation of w and th_l (2nd PDF component) [-]
corr_rt_thl_1, & ! Correlation of r_t and th_l (1st PDF component) [-]
corr_rt_thl_2, & ! Correlation of r_t and th_l (2nd PDF component) [-]
alpha_thl, & ! Factor relating to normalized variance for th_l [-]
alpha_rt, & ! Factor relating to normalized variance for r_t [-]
crt_1, & ! r_t coef. in chi/eta eqns. (1st PDF comp.) [-]
crt_2, & ! r_t coef. in chi/eta eqns. (2nd PDF comp.) [-]
cthl_1, & ! th_l coef.: chi/eta eqns. (1st PDF comp.) [(kg/kg)/K]
cthl_2, & ! th_l coef.: chi/eta eqns. (2nd PDF comp.) [(kg/kg)/K]
chi_1, & ! Mean of chi (old s) (1st PDF component) [kg/kg]
chi_2, & ! Mean of chi (old s) (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 dev. of eta (old t) (1st PDF comp.) [kg/kg]
stdev_eta_2, & ! Standard dev. of eta (old t) (2nd PDF comp.) [kg/kg]
covar_chi_eta_1, & ! Covariance of chi and eta (1st PDF comp.) [kg^2/kg^2]
covar_chi_eta_2, & ! Covariance of chi and eta (2nd PDF comp.) [kg^2/kg^2]
corr_w_chi_1, & ! Correlation of w and chi (1st PDF component) [-]
corr_w_chi_2, & ! Correlation of w and chi (2nd PDF component) [-]
corr_w_eta_1, & ! Correlation of w and eta (1st PDF component) [-]
corr_w_eta_2, & ! Correlation of w and eta (2nd PDF component) [-]
corr_chi_eta_1, & ! Correlation of chi and eta (1st PDF component) [-]
corr_chi_eta_2, & ! Correlation of chi and eta (2nd PDF component) [-]
rsatl_1, & ! Saturation mixing ratio r_sat(mu_Tl_1,p) [kg/kg]
rsatl_2, & ! Saturation mixing ratio r_sat(mu_Tl_2,p) [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 ! Weight of 1st PDF component (Sk_w dependent) [-]
real( kind = core_rknd ) :: &
ice_supersat_frac_1, & ! Ice supersaturation fraction (1st PDF comp.) [-]
ice_supersat_frac_2 ! Ice supersaturation fraction (2nd PDF comp.) [-]
end type pdf_parameter
! The implicit coefficients, semi-implicit coefficients and terms, and
! explicit terms for turbulent advection of turbulent fields are calculated
! from the PDF and the resulting PDF parameters.
type implicit_coefs_terms
real ( kind = core_rknd ) :: &
coef_wp4_implicit, & ! <w'^4> = coef_wp4_implicit * <w'^2>^2 [-]
coef_wprtp2_implicit, & ! <w'rt'^2> = coef_wprtp2_implicit*<rt'^2> [m/s]
coef_wpthlp2_implicit ! <w'thl'^2>=coef_wpthlp2_implicit*<thl'^2> [m/s]
! <w'^2 rt'> = coef_wp2rtp_implicit * <w'rt'> + term_wp2rtp_explicit
real ( kind = core_rknd ) :: &
coef_wp2rtp_implicit, & ! Coefficient that is multiplied by <w'rt'> [m/s]
term_wp2rtp_explicit ! Term that is on the RHS [m^2/s^2 kg/kg]
! <w'^2 thl'> = coef_wp2thlp_implicit * <w'thl'> + term_wp2thlp_explicit
real ( kind = core_rknd ) :: &
coef_wp2thlp_implicit, & ! Coef. that is multiplied by <w'thl'> [m/s]
term_wp2thlp_explicit ! Term that is on the RHS [m^2/s^2 K]
! <w'rt'thl'> = coef_wprtpthlp_implicit*<rt'thl'> + term_wprtpthlp_explicit
real ( kind = core_rknd ) :: &
coef_wprtpthlp_implicit, & ! Coef. that is multiplied by <rt'thl'> [m/s]
term_wprtpthlp_explicit ! Term that is on the RHS [m/s(kg/kg)K]
end type implicit_coefs_terms
! The CLUBB_CAM preprocessor directives are being commented out because this
! code is now also used for WRF-CLUBB.
!#ifdef CLUBB_CAM /* Code for storing pdf_parameter structs in pbuf as array */
public :: pack_pdf_params, unpack_pdf_params
integer, public, parameter :: num_pdf_params = 47
!#endif /* CLUBB_CAM */
contains
!=============================================================================
subroutine init_pdf_params( nz, pdf_params )
! Description:
! Initializes all PDF parameters in the variable type pdf_parameter.
! References:
!--------------------------------------------------------------------
use constants_clubb, only: &
zero ! Constant(s)
implicit none
! Input Variable(s)
integer, intent(in) :: &
nz ! Number of vertical grid levels [-]
! Output Variable(s)
type(pdf_parameter), dimension(nz), intent(out) :: &
pdf_params ! PDF parameters [units vary]
integer :: k
! Initialize all PDF parameters in variable type pdf_parameter.
do k = 1, nz
pdf_params(k)%w_1 = zero
pdf_params(k)%w_2 = zero
pdf_params(k)%varnce_w_1 = zero
pdf_params(k)%varnce_w_2 = zero
pdf_params(k)%rt_1 = zero
pdf_params(k)%rt_2 = zero
pdf_params(k)%varnce_rt_1 = zero
pdf_params(k)%varnce_rt_2 = zero
pdf_params(k)%thl_1 = zero
pdf_params(k)%thl_2 = zero
pdf_params(k)%varnce_thl_1 = zero
pdf_params(k)%varnce_thl_2 = zero
pdf_params(k)%corr_w_rt_1 = zero
pdf_params(k)%corr_w_rt_2 = zero
pdf_params(k)%corr_w_thl_1 = zero
pdf_params(k)%corr_w_thl_2 = zero
pdf_params(k)%corr_rt_thl_1 = zero
pdf_params(k)%corr_rt_thl_2 = zero
pdf_params(k)%alpha_thl = zero
pdf_params(k)%alpha_rt = zero
pdf_params(k)%crt_1 = zero
pdf_params(k)%crt_2 = zero
pdf_params(k)%cthl_1 = zero
pdf_params(k)%cthl_2 = zero
pdf_params(k)%chi_1 = zero
pdf_params(k)%chi_2 = zero
pdf_params(k)%stdev_chi_1 = zero
pdf_params(k)%stdev_chi_2 = zero
pdf_params(k)%stdev_eta_1 = zero
pdf_params(k)%stdev_eta_2 = zero
pdf_params(k)%covar_chi_eta_1 = zero
pdf_params(k)%covar_chi_eta_2 = zero
pdf_params(k)%corr_w_chi_1 = zero
pdf_params(k)%corr_w_chi_2 = zero
pdf_params(k)%corr_w_eta_1 = zero
pdf_params(k)%corr_w_eta_2 = zero
pdf_params(k)%corr_chi_eta_1 = zero
pdf_params(k)%corr_chi_eta_2 = zero
pdf_params(k)%rsatl_1 = zero
pdf_params(k)%rsatl_2 = zero
pdf_params(k)%rc_1 = zero
pdf_params(k)%rc_2 = zero
pdf_params(k)%cloud_frac_1 = zero
pdf_params(k)%cloud_frac_2 = zero
pdf_params(k)%mixt_frac = zero
pdf_params(k)%ice_supersat_frac_1 = zero
pdf_params(k)%ice_supersat_frac_2 = zero
end do
return
end subroutine init_pdf_params
!=============================================================================
! The CLUBB_CAM preprocessor directives are being commented out because this
! code is now also used for WRF-CLUBB.
!#ifdef CLUBB_CAM /* Code for storing pdf_parameter structs in pbuf as array */
subroutine pack_pdf_params(pdf_params, nz, r_param_array)
implicit none
! Input a pdf_parameter array with nz instances of pdf_parameter
integer, intent(in) :: nz ! Num Vert Model Levs
type (pdf_parameter), dimension(nz), intent(in) :: pdf_params
! Output a two dimensional real array with all values
real (kind = core_rknd), dimension(nz,num_pdf_params), intent(out) :: &
r_param_array
! Local Loop vars
integer :: k, p
do k = 1,nz
do p = 1,num_pdf_params
r_param_array(k,p) = get_param_at_ind(pdf_params(k), p)
end do ! p
end do ! k
end subroutine pack_pdf_params
subroutine unpack_pdf_params(r_param_array, nz, pdf_params)
implicit none
! Input a two dimensional real array with pdf values
integer, intent(in) :: nz ! Num Vert Model Levs
real (kind = core_rknd), dimension(nz,num_pdf_params), intent(in) :: &
r_param_array
! Output a pdf_parameter array with nz instances of pdf_parameter
type (pdf_parameter), dimension(nz), intent(out) :: pdf_params
! Local Loop vars
integer :: k, p
! temp var
real (kind = core_rknd) :: value
do k = 1,nz
do p = 1,num_pdf_params
value = r_param_array(k,p)
call set_param_at_ind(pdf_params(k), p, value)
end do ! p
end do ! k
end subroutine unpack_pdf_params
real( kind = core_rknd ) function get_param_at_ind(pp_struct, ind)
use constants_clubb, only: &
fstderr ! File I/O Constant
use error_code, only : &
err_code, & ! Error Indicator
clubb_fatal_error ! Constant
implicit none
type (pdf_parameter), intent(in) :: pp_struct
integer, intent(in) :: ind
SELECT CASE (ind)
CASE (1)
get_param_at_ind = pp_struct%w_1
CASE (2)
get_param_at_ind = pp_struct%w_2
CASE (3)
get_param_at_ind = pp_struct%varnce_w_1
CASE (4)
get_param_at_ind = pp_struct%varnce_w_2
CASE (5)
get_param_at_ind = pp_struct%rt_1
CASE (6)
get_param_at_ind = pp_struct%rt_2
CASE (7)
get_param_at_ind = pp_struct%varnce_rt_1
CASE (8)
get_param_at_ind = pp_struct%varnce_rt_2
CASE (9)
get_param_at_ind = pp_struct%thl_1
CASE (10)
get_param_at_ind = pp_struct%thl_2
CASE (11)
get_param_at_ind = pp_struct%varnce_thl_1
CASE (12)
get_param_at_ind = pp_struct%varnce_thl_2
CASE (13)
get_param_at_ind = pp_struct%corr_w_rt_1
CASE (14)
get_param_at_ind = pp_struct%corr_w_rt_2
CASE (15)
get_param_at_ind = pp_struct%corr_w_thl_1
CASE (16)
get_param_at_ind = pp_struct%corr_w_thl_2
CASE (17)
get_param_at_ind = pp_struct%corr_rt_thl_1
CASE (18)
get_param_at_ind = pp_struct%corr_rt_thl_2
CASE (19)
get_param_at_ind = pp_struct%alpha_thl
CASE (20)
get_param_at_ind = pp_struct%alpha_rt
CASE (21)
get_param_at_ind = pp_struct%crt_1
CASE (22)
get_param_at_ind = pp_struct%crt_2
CASE (23)
get_param_at_ind = pp_struct%cthl_1
CASE (24)
get_param_at_ind = pp_struct%cthl_2
CASE (25)
get_param_at_ind = pp_struct%chi_1
CASE (26)
get_param_at_ind = pp_struct%chi_2
CASE (27)
get_param_at_ind = pp_struct%stdev_chi_1
CASE (28)
get_param_at_ind = pp_struct%stdev_chi_2
CASE (29)
get_param_at_ind = pp_struct%stdev_eta_1
CASE (30)
get_param_at_ind = pp_struct%stdev_eta_2
CASE (31)
get_param_at_ind = pp_struct%covar_chi_eta_1
CASE (32)
get_param_at_ind = pp_struct%covar_chi_eta_2
CASE (33)
get_param_at_ind = pp_struct%corr_w_chi_1
CASE (34)
get_param_at_ind = pp_struct%corr_w_chi_2
CASE (35)
get_param_at_ind = pp_struct%corr_w_eta_1
CASE (36)
get_param_at_ind = pp_struct%corr_w_eta_2
CASE (37)
get_param_at_ind = pp_struct%corr_chi_eta_1
CASE (38)
get_param_at_ind = pp_struct%corr_chi_eta_2
CASE (39)
get_param_at_ind = pp_struct%rsatl_1
CASE (40)
get_param_at_ind = pp_struct%rsatl_2
CASE (41)
get_param_at_ind = pp_struct%rc_1
CASE (42)
get_param_at_ind = pp_struct%rc_2
CASE (43)
get_param_at_ind = pp_struct%cloud_frac_1
CASE (44)
get_param_at_ind = pp_struct%cloud_frac_2
CASE (45)
get_param_at_ind = pp_struct%mixt_frac
CASE (46)
get_param_at_ind = pp_struct%ice_supersat_frac_1
CASE (47)
get_param_at_ind = pp_struct%ice_supersat_frac_2
CASE DEFAULT
write(fstderr,*) "Invalid index in get_param_at_ind"
err_code = clubb_fatal_error
return
END SELECT
RETURN
end function get_param_at_ind
subroutine set_param_at_ind(pp_struct, ind, val)
implicit none
type (pdf_parameter), intent(inout) :: pp_struct
integer, intent(in) :: ind
real (kind = core_rknd), intent(in) :: val
SELECT CASE (ind)
CASE (1)
pp_struct%w_1 = val
CASE (2)
pp_struct%w_2 = val
CASE (3)
pp_struct%varnce_w_1 = val
CASE (4)
pp_struct%varnce_w_2 = val
CASE (5)
pp_struct%rt_1 = val
CASE (6)
pp_struct%rt_2 = val
CASE (7)
pp_struct%varnce_rt_1 = val
CASE (8)
pp_struct%varnce_rt_2 = val
CASE (9)
pp_struct%thl_1 = val
CASE (10)
pp_struct%thl_2 = val
CASE (11)
pp_struct%varnce_thl_1 = val
CASE (12)
pp_struct%varnce_thl_2 = val
CASE (13)
pp_struct%corr_w_rt_1 = val
CASE (14)
pp_struct%corr_w_rt_2 = val
CASE (15)
pp_struct%corr_w_thl_1 = val
CASE (16)
pp_struct%corr_w_thl_2 = val
CASE (17)
pp_struct%corr_rt_thl_1 = val
CASE (18)
pp_struct%corr_rt_thl_2 = val
CASE (19)
pp_struct%alpha_thl = val
CASE (20)
pp_struct%alpha_rt = val
CASE (21)
pp_struct%crt_1 = val
CASE (22)
pp_struct%crt_2 = val
CASE (23)
pp_struct%cthl_1 = val
CASE (24)
pp_struct%cthl_2 = val
CASE (25)
pp_struct%chi_1 = val
CASE (26)
pp_struct%chi_2 = val
CASE (27)
pp_struct%stdev_chi_1 = val
CASE (28)
pp_struct%stdev_chi_2 = val
CASE (29)
pp_struct%stdev_eta_1 = val
CASE (30)
pp_struct%stdev_eta_2 = val
CASE (31)
pp_struct%covar_chi_eta_1 = val
CASE (32)
pp_struct%covar_chi_eta_2 = val
CASE (33)
pp_struct%corr_w_chi_1 = val
CASE (34)
pp_struct%corr_w_chi_2 = val
CASE (35)
pp_struct%corr_w_eta_1 = val
CASE (36)
pp_struct%corr_w_eta_2 = val
CASE (37)
pp_struct%corr_chi_eta_1 = val
CASE (38)
pp_struct%corr_chi_eta_2 = val
CASE (39)
pp_struct%rsatl_1 = val
CASE (40)
pp_struct%rsatl_2 = val
CASE (41)
pp_struct%rc_1 = val
CASE (42)
pp_struct%rc_2 = val
CASE (43)
pp_struct%cloud_frac_1 = val
CASE (44)
pp_struct%cloud_frac_2 = val
CASE (45)
pp_struct%mixt_frac = val
CASE (46)
pp_struct%ice_supersat_frac_1 = val
CASE (47)
pp_struct%ice_supersat_frac_2 = val
CASE DEFAULT
! do nothing !
END SELECT
end subroutine set_param_at_ind
!#endif /* CLUBB_CAM */
end module pdf_parameter_module