Line data Source code
1 : !-------------------------------------------------------------------------
2 : ! $Id$
3 : !===============================================================================
4 : module setup_clubb_pdf_params
5 :
6 : implicit none
7 :
8 : private
9 :
10 : public :: setup_pdf_parameters, &
11 : compute_mean_stdev, &
12 : calc_comp_mu_sigma_hm, &
13 : norm_transform_mean_stdev, &
14 : comp_corr_norm, &
15 : denorm_transform_corr
16 :
17 : private :: component_corr_w_x, &
18 : component_corr_chi_eta, &
19 : component_corr_w_hm_n_ip, &
20 : component_corr_x_hm_n_ip, &
21 : component_corr_hmx_hmy_n_ip, &
22 : component_corr_eta_hm_n_ip, &
23 : calc_corr_w_hm_n, &
24 : pdf_param_hm_stats, &
25 : pdf_param_ln_hm_stats, &
26 : pack_hydromet_pdf_params, &
27 : compute_rtp2_from_chi
28 :
29 : ! The component correlations of w and r_t and the component correlations of
30 : ! w and theta_l must both be 0 when using the ADG1 PDF. In other words, w
31 : ! and r_t (theta_l) have overall covariance w'r_t' (w'theta_l'), but the
32 : ! individual component covariance and correlation are defined to be 0.
33 : ! Since the component covariances (or correlations) of w and chi (old s) and
34 : ! of w and eta (old t) are based on the covariances (or correlations) of w
35 : ! and r_t and of w and theta_l, the individual component correlation and
36 : ! covariance of w and chi, as well of as w and eta, are defined to be 0.
37 : !
38 : ! The PDF component correlation of w and x, calculated as part of the PDF
39 : ! parameters, comes out to be 0 (within numerical roundoff) when the ADG1
40 : ! PDF is used. However, when l_fix_w_chi_eta_correlations is enabled, the
41 : ! component correlations of PDF variables are specified, and the values
42 : ! that were calculated as part of the PDF parameters are ignored in the
43 : ! correlation array. When this happens, and when the ADG1 PDF is selected,
44 : ! the l_follow_ADG1_PDF_standards flag can be used to force the component
45 : ! correlations of w and x to have a value of 0, following the ADG1 standard,
46 : ! rather than whatever value might be specified in the correlation array.
47 : !
48 : ! Note: the ADG2 PDF follows the same standards as the ADG1 PDF.
49 : logical, parameter :: &
50 : l_follow_ADG1_PDF_standards = .true.
51 :
52 : contains
53 :
54 : !=============================================================================
55 0 : subroutine setup_pdf_parameters( gr, nz, ngrdcol, pdf_dim, dt, & ! Intent(in)
56 0 : Nc_in_cloud, cloud_frac, Kh_zm, & ! Intent(in)
57 0 : ice_supersat_frac, hydromet, wphydrometp, & ! Intent(in)
58 0 : corr_array_n_cloud, corr_array_n_below, & ! Intent(in)
59 : pdf_params, & ! Intent(in)
60 : clubb_params, & ! Intent(in)
61 : iiPDF_type, & ! Intent(in)
62 : l_use_precip_frac, & ! Intent(in)
63 : l_predict_upwp_vpwp, & ! Intent(in)
64 : l_diagnose_correlations, & ! Intent(in)
65 : l_calc_w_corr, & ! Intent(in)
66 : l_const_Nc_in_cloud, & ! Intent(in)
67 : l_fix_w_chi_eta_correlations, & ! Intent(in)
68 : stats_metadata, & ! Intent(in)
69 0 : stats_zt, stats_zm, stats_sfc, & ! intent(inout)
70 0 : hydrometp2, & ! Intent(out)
71 0 : mu_x_1_n, mu_x_2_n, & ! Intent(out)
72 0 : sigma_x_1_n, sigma_x_2_n, & ! Intent(out)
73 0 : corr_array_1_n, corr_array_2_n, & ! Intent(out)
74 0 : corr_cholesky_mtx_1, corr_cholesky_mtx_2, & ! Intent(out)
75 : precip_fracs, & ! Intent(out)
76 0 : hydromet_pdf_params ) ! Intent(out)
77 :
78 : ! Description:
79 :
80 : ! References:
81 : !-----------------------------------------------------------------------
82 :
83 : use grid_class, only: &
84 : grid, & ! Type
85 : zm2zt, & ! Procedure(s)
86 : zt2zm
87 :
88 : use constants_clubb, only: &
89 : one, & ! Constant(s)
90 : zero, &
91 : rc_tol, &
92 : Ncn_tol, &
93 : cloud_frac_min, &
94 : fstderr, &
95 : zero_threshold
96 :
97 : use pdf_parameter_module, only: &
98 : pdf_parameter ! Variable(s)
99 :
100 : use hydromet_pdf_parameter_module, only: &
101 : hydromet_pdf_parameter, & ! Type
102 : precipitation_fractions, &
103 : init_hydromet_pdf_params ! Procedure
104 :
105 : use parameters_model, only: &
106 : hydromet_dim ! Variable(s)
107 :
108 : use array_index, only: &
109 : hydromet_list, & ! Variable(s)
110 : hydromet_tol, &
111 : iiPDF_Ncn, &
112 : iiPDF_chi, &
113 : iiPDF_eta
114 :
115 : use precipitation_fraction, only: &
116 : precip_fraction
117 :
118 : use Nc_Ncn_eqns, only: &
119 : Nc_in_cloud_to_Ncnm ! Procedure(s)
120 :
121 : use parameter_indices, only: &
122 : nparams, & ! Variable(s)
123 : ic_K_hm, &
124 : iomicron, &
125 : izeta_vrnce_rat
126 :
127 : use pdf_utilities, only: &
128 : calc_xp2, & ! Procedure(s)
129 : compute_mean_binormal, &
130 : compute_variance_binormal, &
131 : stdev_L2N, &
132 : corr_NN2NL
133 :
134 : use clip_explicit, only: &
135 : clip_covar_level, & ! Procedure(s)
136 : clip_wphydrometp ! Variables(s)
137 :
138 : use clubb_precision, only: &
139 : core_rknd ! Variable(s)
140 :
141 : use matrix_operations, only: &
142 : Cholesky_factor ! Procedure(s)
143 :
144 : use stats_type_utilities, only: &
145 : ! stat_update_var, & ! Procedure(s)
146 : stat_update_var_pt
147 :
148 : use diagnose_correlations_module, only: &
149 : diagnose_correlations, & ! Procedure(s)
150 : calc_cholesky_corr_mtx_approx
151 :
152 : use corr_varnce_module, only: &
153 : assert_corr_symmetric, & ! Procedure(s)
154 : hmp2_ip_on_hmm2_ip, & ! Variable(s)
155 : Ncnp2_on_Ncnm2
156 :
157 : use error_code, only: &
158 : clubb_at_least_debug_level, & ! Procedure
159 : err_code, & ! Error Indicator
160 : clubb_fatal_error ! Constant
161 :
162 : use stats_type, only: stats ! Type
163 :
164 : use advance_helper_module, only : &
165 : calc_xpwp ! Procedure(s)
166 :
167 : use stats_variables, only: &
168 : stats_metadata_type
169 :
170 : implicit none
171 :
172 : !------------------------ Input Variables ------------------------
173 : integer, intent(in) :: &
174 : nz, & ! Number of model vertical grid levels
175 : pdf_dim, & ! Number of variables in the correlation array
176 : ngrdcol ! Number of grid columns
177 :
178 : type (grid), target, intent(in) :: gr
179 :
180 : real( kind = core_rknd ), intent(in) :: &
181 : dt ! Model timestep [s]
182 :
183 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(in) :: &
184 : Nc_in_cloud, & ! Mean (in-cloud) cloud droplet conc. [num/kg]
185 : cloud_frac, & ! Cloud fraction [-]
186 : Kh_zm, & ! Eddy diffusivity coef. on momentum levels [m^2/s]
187 : ice_supersat_frac ! Ice supersaturation fraction [-]
188 :
189 : real( kind = core_rknd ), dimension(ngrdcol,nz,hydromet_dim), intent(in) :: &
190 : hydromet, & ! Mean of hydrometeor, hm (overall) (t-levs.) [units]
191 : wphydrometp ! Covariance < w'h_m' > (momentum levels) [(m/s)units]
192 :
193 : real( kind = core_rknd ), dimension(pdf_dim,pdf_dim), &
194 : intent(in) :: &
195 : corr_array_n_cloud, & ! Prescribed normal space corr. array in cloud [-]
196 : corr_array_n_below ! Prescribed normal space corr. array below cl. [-]
197 :
198 : type(pdf_parameter), intent(in) :: &
199 : pdf_params ! PDF parameters [units vary]
200 :
201 : real( kind = core_rknd ), dimension(nparams), intent(in) :: &
202 : clubb_params ! Array of CLUBB's tunable parameters [units vary]
203 :
204 : integer, intent(in) :: &
205 : iiPDF_type ! Selected option for the two-component normal (double
206 : ! Gaussian) PDF type to use for the w, rt, and theta-l (or
207 : ! w, chi, and eta) portion of CLUBB's multivariate,
208 : ! two-component PDF.
209 :
210 : logical, intent(in) :: &
211 : l_use_precip_frac, & ! Flag to use precipitation fraction in KK microphysics. The
212 : ! precipitation fraction is automatically set to 1 when this
213 : ! flag is turned off.
214 : l_predict_upwp_vpwp, & ! Flag to predict <u'w'> and <v'w'> along with <u> and <v>
215 : ! alongside the advancement of <rt>, <w'rt'>, <thl>,
216 : ! <wpthlp>, <sclr>, and <w'sclr'> in subroutine
217 : ! advance_xm_wpxp. Otherwise, <u'w'> and <v'w'> are still
218 : ! approximated by eddy diffusivity when <u> and <v> are
219 : ! advanced in subroutine advance_windm_edsclrm.
220 : l_diagnose_correlations, & ! Diagnose correlations instead of using fixed ones
221 : l_calc_w_corr, & ! Calculate the correlations between w and the hydrometeors
222 : l_const_Nc_in_cloud, & ! Use a constant cloud droplet conc. within cloud (K&K)
223 : l_fix_w_chi_eta_correlations ! Use a fixed correlation for s and t Mellor(chi/eta)
224 :
225 : type (stats_metadata_type), intent(in) :: &
226 : stats_metadata
227 :
228 : !------------------------ Input/Output Variables ------------------------
229 : type (stats), target, dimension(ngrdcol), intent(inout) :: &
230 : stats_zt, &
231 : stats_zm, &
232 : stats_sfc
233 :
234 : !------------------------ Output Variables ------------------------
235 : real( kind = core_rknd ), dimension(ngrdcol,nz,hydromet_dim), intent(out) :: &
236 : hydrometp2 ! Variance of a hydrometeor (overall) (m-levs.) [units^2]
237 :
238 : real( kind = core_rknd ), dimension(ngrdcol,nz,pdf_dim), intent(out) :: &
239 : mu_x_1_n, & ! Mean array (normal space): PDF vars. (comp. 1) [un. vary]
240 : mu_x_2_n, & ! Mean array (normal space): PDF vars. (comp. 2) [un. vary]
241 : sigma_x_1_n, & ! Std. dev. array (normal space): PDF vars (comp. 1) [u.v.]
242 : sigma_x_2_n ! Std. dev. array (normal space): PDF vars (comp. 2) [u.v.]
243 :
244 : real( kind = core_rknd ), dimension(ngrdcol,nz,pdf_dim,pdf_dim), intent(out) :: &
245 : corr_array_1_n, & ! Corr. array (normal space) of PDF vars. (comp. 1) [-]
246 : corr_array_2_n ! Corr. array (normal space) of PDF vars. (comp. 2) [-]
247 :
248 : real( kind = core_rknd ), dimension(ngrdcol,nz,pdf_dim,pdf_dim), intent(out) :: &
249 : corr_cholesky_mtx_1, & ! Transposed corr. cholesky matrix, 1st comp. [-]
250 : corr_cholesky_mtx_2 ! Transposed corr. cholesky matrix, 2nd comp. [-]
251 :
252 : ! This is only an output, but it contains allocated arrays, so we need to treat it as inout
253 : type(precipitation_fractions), intent(inout) :: &
254 : precip_fracs ! Precipitation fractions [-]
255 :
256 : type(hydromet_pdf_parameter), dimension(ngrdcol,nz), optional, intent(out) :: &
257 : hydromet_pdf_params ! Hydrometeor PDF parameters [units vary]
258 :
259 : !------------------------ Local Variables ------------------------
260 :
261 : real( kind = core_rknd ), dimension(ngrdcol,nz) :: &
262 0 : Kh_zm_c_K_hm ! Eddy diffusivity coef. on momentum levels [m^2/s]
263 :
264 : real( kind = core_rknd ), dimension(ngrdcol,nz) :: &
265 0 : sigma_w_1, & ! Standard deviation of w (1st PDF component) [m/s]
266 0 : sigma_w_2 ! Standard deviation of w (2nd PDF component) [m/s]
267 :
268 : real( kind = core_rknd ), dimension(ngrdcol,nz) :: &
269 : ice_supersat_frac_1, & ! Ice supersaturation fraction (1st PDF comp.) [-]
270 : ice_supersat_frac_2 ! Ice supersaturation fraction (2nd PDF comp.) [-]
271 :
272 : real( kind = core_rknd ), dimension(ngrdcol,nz) :: &
273 0 : Ncnm ! Mean cloud nuclei concentration, < N_cn > [num/kg]
274 :
275 : real( kind = core_rknd ), dimension(ngrdcol,nz) :: &
276 0 : rcm_pdf ! Liquid water mixing ratio [kg/kg]
277 :
278 : real( kind = core_rknd ), dimension(ngrdcol,nz) :: &
279 0 : wpNcnp_zm, & ! Covariance of N_cn and w (momentum levs.) [(m/s)(num/kg)]
280 0 : wpNcnp_zt ! Covariance of N_cn and w on thermo. levels [(m/s)(num/kg)]
281 :
282 : real( kind = core_rknd ), dimension(ngrdcol,nz,hydromet_dim) :: &
283 0 : hm_1, & ! Mean of a precip. hydrometeor (1st PDF component) [units vary]
284 0 : hm_2 ! Mean of a precip. hydrometeor (2nd PDF component) [units vary]
285 :
286 : real( kind = core_rknd ), dimension(ngrdcol,nz,hydromet_dim) :: &
287 0 : hydrometp2_zt, & ! Variance of a hydrometeor (overall); t-lev [units^2]
288 0 : wphydrometp_zt ! Covariance of w and hm interp. to t-levs. [(m/s)units]
289 :
290 : real( kind = core_rknd ), dimension(ngrdcol,nz,pdf_dim,pdf_dim) :: &
291 0 : corr_array_1, & ! Correlation array of PDF vars. (comp. 1) [-]
292 0 : corr_array_2 ! Correlation array of PDF vars. (comp. 2) [-]
293 :
294 : real( kind = core_rknd ), dimension(ngrdcol,nz,pdf_dim) :: &
295 0 : mu_x_1, & ! Mean array of PDF vars. (1st PDF component) [units vary]
296 0 : mu_x_2, & ! Mean array of PDF vars. (2nd PDF component) [units vary]
297 0 : sigma_x_1, & ! Standard deviation array of PDF vars (comp. 1) [units vary]
298 0 : sigma_x_2 ! Standard deviation array of PDF vars (comp. 2) [units vary]
299 :
300 : real( kind = core_rknd ), dimension(pdf_dim) :: &
301 0 : corr_array_scaling
302 :
303 : real( kind = core_rknd ), dimension(ngrdcol,nz,pdf_dim) :: &
304 0 : sigma2_on_mu2_ip_1, & ! Ratio array sigma_hm_1^2/mu_hm_1^2 [-]
305 0 : sigma2_on_mu2_ip_2 ! Ratio array sigma_hm_2^2/mu_hm_2^2 [-]
306 :
307 : real( kind = core_rknd ), dimension(ngrdcol,nz) :: &
308 0 : const_Ncnp2_on_Ncnm2, & ! Prescribed ratio: <Ncn'^2> to <Ncn>^2 [-]
309 0 : stdev_const_Ncnp2_on_Ncnm2, & ! Standard deviation of const_Ncnp2_on_Ncnm2
310 0 : const_corr_chi_Ncn, & ! Prescribed corr. of chi (old s) & Ncn [-]
311 0 : const_corr_chi_Ncn_n_cloud ! Prescribed corr. of chi & Ncn in cloud [-]
312 :
313 : real( kind = core_rknd ), dimension(ngrdcol) :: &
314 0 : precip_frac_tol ! Min. precip. frac. when hydromet. present [-]
315 :
316 : real( kind = core_rknd ), dimension(ngrdcol,nz,hydromet_dim) :: &
317 0 : wphydrometp_chnge ! Change in wphydrometp_zt: covar. clip. [(m/s)units]
318 :
319 : real( kind = core_rknd ), dimension(ngrdcol,nz) :: &
320 0 : wm_zt, & ! Mean vertical velocity, <w>, on thermo. levels [m/s]
321 0 : wp2_zt ! Variance of w, <w'^2> (interp. to t-levs.) [m^2/s^2]
322 :
323 : real( kind = core_rknd ), dimension(ngrdcol,nz) :: &
324 0 : rtp2_zt_from_chi, &
325 0 : rtp2_zm_from_chi
326 :
327 : real( kind = core_rknd ) :: &
328 : omicron, & ! Relative width parameter, omicron = R / Rmax [-]
329 : zeta_vrnce_rat ! Width parameter for sigma_hm_1^2 / mu_hm_1^2 [-]
330 :
331 : logical :: l_corr_array_scaling
332 :
333 : ! Flags used for covariance clipping of <w'hm'>.
334 : logical, parameter :: &
335 : l_first_clip_ts = .true., & ! First instance of clipping in a timestep.
336 : l_last_clip_ts = .true. ! Last instance of clipping in a timestep.
337 :
338 : character(len=10) :: &
339 : hydromet_name ! Name of a hydrometeor
340 :
341 : integer :: k, i, j ! Loop indices
342 :
343 : ! ---- Begin Code ----
344 :
345 : ! Assertion check
346 : ! Check that all hydrometeors are positive otherwise exit the program
347 0 : if ( clubb_at_least_debug_level( 0 ) ) then
348 0 : if ( any(hydromet < zero_threshold) ) then
349 0 : do j = 1, hydromet_dim
350 0 : hydromet_name = hydromet_list(j)
351 0 : do k = 1, nz
352 0 : do i = 1, ngrdcol
353 0 : if ( hydromet(i,k,j) < zero_threshold ) then
354 : ! Write error message
355 0 : write(fstderr,*) " at beginning of setup_pdf_parameters: ", &
356 0 : trim( hydromet_name )//" = ", &
357 0 : hydromet(i,k,j), " < ", zero_threshold, &
358 0 : " at k = ", k
359 0 : err_code = clubb_fatal_error
360 0 : return
361 : end if ! hydromet(k,i) < 0
362 : end do ! k = 1, nz
363 : end do ! i = 1, hydromet_dim
364 : end do
365 : end if
366 : end if !clubb_at_least_debug_level( 0 )
367 :
368 : ! Setup some of the PDF parameters
369 0 : do k = 1, nz
370 0 : do i = 1, ngrdcol
371 0 : sigma_w_1(i,k) = sqrt( pdf_params%varnce_w_1(i,k) )
372 0 : sigma_w_2(i,k) = sqrt( pdf_params%varnce_w_2(i,k) )
373 : end do
374 : end do
375 :
376 : ! Compute rcm_pdf for use within SILHS
377 0 : do i = 1, ngrdcol
378 0 : rcm_pdf(i,:) = compute_mean_binormal( pdf_params%rc_1(i,:), pdf_params%rc_2(i,:), &
379 0 : pdf_params%mixt_frac(i,:) )
380 : end do
381 :
382 : ! Note on hydrometeor PDF shape:
383 : ! To use a single lognormal over the entire grid level, turn off the
384 : ! l_use_precip_frac flag and set omicron to 1 and zeta_vrnce_rat to 0 in
385 : ! tunable_parameters.in.
386 : ! To use a single delta-lognormal (single lognormal in-precip.), enable the
387 : ! l_use_precip_frac flag and set omicron to 1 and zeta_vrnce_rat to 0 in
388 : ! tunable_parameters.in.
389 : ! Otherwise, with l_use_precip_frac enabled and omicron and zeta_vrnce_rat
390 : ! values that are not 1 and 0, respectively, the PDF shape is a double
391 : ! delta-lognormal (two independent lognormals in-precip.).
392 :
393 : ! Calculate precipitation fraction.
394 0 : if ( l_use_precip_frac ) then
395 :
396 : call precip_fraction( nz, ngrdcol, & ! In
397 : hydromet(:,:,:), cloud_frac(:,:), pdf_params%cloud_frac_1(:,:), & ! In
398 : pdf_params%cloud_frac_2(:,:), ice_supersat_frac(:,:), & ! In
399 : pdf_params%ice_supersat_frac_1(:,:), pdf_params%ice_supersat_frac_2(:,:), & ! In
400 : pdf_params%mixt_frac(:,:), clubb_params, & ! In
401 : stats_metadata, & ! In
402 : stats_sfc(:), & ! Inout
403 : precip_fracs%precip_frac(:,:), & ! Out
404 : precip_fracs%precip_frac_1(:,:), & ! Out
405 : precip_fracs%precip_frac_2(:,:), & ! Out
406 0 : precip_frac_tol(:) ) ! Out
407 :
408 0 : if ( err_code == clubb_fatal_error ) then
409 0 : write(fstderr,*) " in setup_pdf_parameters after calling precip_fraction"
410 0 : return
411 : end if
412 :
413 : else
414 :
415 0 : precip_fracs%precip_frac(:,:) = one
416 0 : precip_fracs%precip_frac_1(:,:) = one
417 0 : precip_fracs%precip_frac_2(:,:) = one
418 0 : precip_frac_tol(:) = cloud_frac_min
419 :
420 : end if
421 :
422 : ! Calculate <N_cn> from Nc_in_cloud, whether Nc_in_cloud is predicted or
423 : ! based on a prescribed value, and whether the value is constant or varying
424 : ! over the grid level.
425 0 : if ( .not. l_const_Nc_in_cloud ) then
426 : ! Ncn varies at each vertical level.
427 0 : do k = 1, nz
428 0 : do i = 1, ngrdcol
429 0 : const_Ncnp2_on_Ncnm2(i,k) = Ncnp2_on_Ncnm2
430 : end do
431 : end do
432 :
433 0 : stdev_const_Ncnp2_on_Ncnm2(:,:) = stdev_L2N( const_Ncnp2_on_Ncnm2(:,:) )
434 :
435 : else ! l_const_Nc_in_cloud
436 : ! Ncn is constant at each vertical level.
437 0 : const_Ncnp2_on_Ncnm2(:,:) = zero
438 0 : stdev_const_Ncnp2_on_Ncnm2(:,:) = zero
439 : end if
440 :
441 0 : const_corr_chi_Ncn_n_cloud(:,:) = corr_array_n_cloud(iiPDF_Ncn,iiPDF_chi)
442 :
443 : call corr_NN2NL( nz, ngrdcol, & ! intent(in)
444 : const_corr_chi_Ncn_n_cloud(:,:), & ! intent(in)
445 : stdev_const_Ncnp2_on_Ncnm2(:,:), const_Ncnp2_on_Ncnm2(:,:), & ! intent(in)
446 0 : const_corr_chi_Ncn(:,:) ) ! intent(out)
447 :
448 : Ncnm(:,:) = Nc_in_cloud_to_Ncnm( &
449 0 : pdf_params%chi_1(:,:), pdf_params%chi_2(:,:), pdf_params%stdev_chi_1(:,:), &
450 0 : pdf_params%stdev_chi_2(:,:), pdf_params%mixt_frac(:,:), Nc_in_cloud(:,:), &
451 0 : pdf_params%cloud_frac_1(:,:), pdf_params%cloud_frac_2(:,:), &
452 0 : const_Ncnp2_on_Ncnm2(:,:), const_corr_chi_Ncn(:,:) )
453 :
454 : ! Boundary Condition.
455 : ! At thermodynamic level k = 1, which is below the model lower boundary, the
456 : ! value of Ncnm does not matter.
457 0 : Ncnm(:,1) = Nc_in_cloud(:,1)
458 :
459 :
460 : ! Calculate the overall variance of a precipitating hydrometeor (hm),
461 : !<hm'^2>.
462 0 : do j = 1, hydromet_dim
463 0 : do k = 1, nz, 1
464 0 : do i = 1, ngrdcol
465 :
466 0 : if ( hydromet(i,k,j) >= hydromet_tol(j) ) then
467 : ! There is some of the hydrometeor species found at level k.
468 : ! Calculate the variance (overall) of the hydrometeor.
469 : hydrometp2_zt(i,k,j) &
470 0 : = ( ( hmp2_ip_on_hmm2_ip(j) + one ) / precip_fracs%precip_frac(i,k) - one ) &
471 0 : * hydromet(i,k,j)**2
472 : else
473 0 : hydrometp2_zt(i,k,j) = zero
474 : end if
475 :
476 : end do ! k = 1, nz, 1
477 : end do
478 : end do
479 :
480 : ! Interpolate the overall variance of a hydrometeor, <hm'^2>, to its home on
481 : ! momentum grid levels.
482 0 : do i = 1, hydromet_dim, 1
483 0 : hydrometp2(:,:,i) = zt2zm( nz, ngrdcol, gr, hydrometp2_zt(:,:,i) )
484 0 : hydrometp2(:,nz,i) = zero
485 : end do
486 :
487 :
488 : ! Calculate correlations involving w and Ncn by first calculating the
489 : ! overall covariance of w and Ncn using the down-gradient approximation.
490 0 : if ( l_calc_w_corr ) then
491 :
492 : ! Recalculate wm_zt and wp2_zt. Mean vertical velocity may not be easy to
493 : ! pass into this subroutine from a host model, and wp2_zt needs to have a
494 : ! value consistent with the value it had when the PDF parameters involving w
495 : ! were originally set in subroutine pdf_closure. The variable wp2 has since
496 : ! been advanced, resulting a new wp2_zt. However, the value of wp2 here
497 : ! needs to be consistent with wp2 at the time the PDF parameters were
498 : ! calculated.
499 :
500 : ! Calculate the overall mean of vertical velocity, w, on thermodynamic
501 : ! levels.
502 0 : wm_zt(:,:) = compute_mean_binormal( pdf_params%w_1(:,:), pdf_params%w_2(:,:), &
503 0 : pdf_params%mixt_frac(:,:) )
504 :
505 : ! Calculate the overall variance of vertical velocity on thermodynamic
506 : ! levels.
507 : wp2_zt(:,:) = compute_variance_binormal( wm_zt(:,:), &
508 0 : pdf_params%w_1(:,:), pdf_params%w_2(:,:), &
509 : sigma_w_1(:,:), sigma_w_2(:,:), &
510 0 : pdf_params%mixt_frac(:,:) )
511 :
512 : ! Interpolate the covariances (overall) of w and precipitating
513 : ! hydrometeors to thermodynamic grid levels.
514 0 : do i = 1, hydromet_dim
515 0 : wphydrometp_zt(:,:,i) = zm2zt( nz, ngrdcol, gr, wphydrometp(:,:,i) )
516 : end do
517 :
518 0 : do j = 1, hydromet_dim
519 0 : do k = 1, nz
520 0 : do i = 1, ngrdcol
521 0 : if ( hydromet(i,k,j) < hydromet_tol(j) ) then
522 0 : wphydrometp_zt(i,k,j) = zero
523 : end if
524 : end do
525 : end do
526 : end do
527 :
528 : ! When the mean value of a precipitating hydrometeor is below tolerance
529 : ! value, it is considered to have a value of 0, and the precipitating
530 : ! hydrometeor does not vary over the grid level. Any covariances
531 : ! involving that precipitating hydrometeor also have values of 0 at that
532 : ! grid level.
533 0 : do j = 1, hydromet_dim
534 0 : do k = 1, nz, 1
535 0 : do i = 1, ngrdcol
536 :
537 : ! Clip the value of covariance <w'hm'> on thermodynamic levels.
538 : call clip_covar_level( clip_wphydrometp, k, l_first_clip_ts, & ! In
539 0 : l_last_clip_ts, dt, wp2_zt(i,k), & ! In
540 0 : hydrometp2_zt(i,k,j), & ! In
541 : l_predict_upwp_vpwp, & ! In
542 : stats_metadata, & ! In
543 : stats_zm(i), & ! Inout
544 : wphydrometp_zt(i,k,j), & ! Inout
545 0 : wphydrometp_chnge(i,k,j) ) ! Out
546 :
547 : end do ! k = 1, nz, 1
548 : end do ! i = 1, hydromet_dim, 1
549 : end do
550 :
551 0 : Kh_zm_c_K_hm(:,:) = -clubb_params(ic_K_hm) * Kh_zm(:,:)
552 :
553 : call calc_xpwp( nz, ngrdcol, gr, &
554 : Kh_zm_c_K_hm, Ncnm, &
555 0 : wpNcnp_zm )
556 :
557 : ! Boundary conditions; We are assuming zero flux at the top.
558 0 : wpNcnp_zm(:,nz) = zero
559 :
560 : ! Interpolate the covariances to thermodynamic grid levels.
561 0 : wpNcnp_zt(:,:) = zm2zt( nz, ngrdcol, gr, wpNcnp_zm(:,:) )
562 :
563 : ! When the mean value of Ncn is below tolerance value, it is considered
564 : ! to have a value of 0, and Ncn does not vary over the grid level. Any
565 : ! covariance involving Ncn also has a value of 0 at that grid level.
566 0 : do k = 1, nz, 1
567 0 : do i = 1, ngrdcol
568 0 : if ( Ncnm(i,k) <= Ncn_tol ) then
569 0 : wpNcnp_zt(i,k) = zero
570 : end if
571 : end do ! k = 1, nz, 1
572 : end do
573 :
574 : end if ! l_calc_w_corr
575 :
576 : ! Unpack CLUBB parameters
577 0 : omicron = clubb_params(iomicron)
578 0 : zeta_vrnce_rat = clubb_params(izeta_vrnce_rat)
579 :
580 : !!! Calculate the means and standard deviations involving PDF variables
581 : !!! -- w, chi, eta, N_cn, and any precipitating hydrometeors (hm in-precip)
582 : !!! -- for each PDF component.
583 : call compute_mean_stdev( nz, ngrdcol, &
584 : hydromet(:,:,:), hydrometp2_zt(:,:,:), & ! Intent(in)
585 : Ncnm(:,:), pdf_params%mixt_frac(:,:), & ! Intent(in)
586 : precip_fracs%precip_frac(:,:), & ! Intent(in)
587 : precip_fracs%precip_frac_1(:,:), & ! Intent(in)
588 : precip_fracs%precip_frac_2(:,:), & ! Intent(in)
589 : precip_frac_tol(:), & ! Intent(in)
590 : pdf_params%w_1(:,:), & ! Intent(in)
591 : pdf_params%w_2(:,:), & ! Intent(in)
592 : sigma_w_1(:,:), & ! Intent(in)
593 : sigma_w_1(:,:), & ! Intent(in)
594 : pdf_params%chi_1(:,:), & ! Intent(in)
595 : pdf_params%chi_2(:,:), & ! Intent(in)
596 : pdf_params%stdev_chi_1(:,:), & ! Intent(in)
597 : pdf_params%stdev_chi_2(:,:), & ! Intent(in)
598 : pdf_params%stdev_eta_1(:,:), & ! Intent(in)
599 : pdf_params%stdev_eta_2(:,:), & ! Intent(in)
600 : pdf_params%thl_1(:,:), & ! Intent(in)
601 : pdf_params%thl_2(:,:), & ! Intent(in)
602 : pdf_dim, & ! Intent(in)
603 : omicron, zeta_vrnce_rat, & ! Intent(in)
604 : l_const_Nc_in_cloud, & ! Intent(in)
605 : mu_x_1(:,:,:), mu_x_2(:,:,:), & ! Intent(out)
606 : sigma_x_1(:,:,:), sigma_x_2(:,:,:), & ! Intent(out)
607 : hm_1(:,:,:), hm_2(:,:,:), & ! Intent(out)
608 : sigma2_on_mu2_ip_1(:,:,:), & ! Intent(out)
609 0 : sigma2_on_mu2_ip_2(:,:,:) ) ! Intent(out)
610 :
611 : !!! Transform the component means and standard deviations involving
612 : !!! precipitating hydrometeors (hm in-precip) and N_cn -- ln hm and
613 : !!! ln N_cn -- to normal space for each PDF component.
614 : call norm_transform_mean_stdev( nz, ngrdcol, & ! Intent(in)
615 : hm_1(:,:,:), hm_2(:,:,:), & ! Intent(in)
616 : Ncnm(:,:), pdf_dim, & ! Intent(in)
617 : mu_x_1(:,:,:), mu_x_2(:,:,:), & ! Intent(in)
618 : sigma_x_1(:,:,:), sigma_x_2(:,:,:), & ! Intent(in)
619 : sigma2_on_mu2_ip_1(:,:,:), & ! Intent(in)
620 : sigma2_on_mu2_ip_2(:,:,:), & ! Intent(in)
621 : l_const_Nc_in_cloud, & ! Intent(in)
622 : mu_x_1_n(:,:,:), mu_x_2_n(:,:,:), & ! Intent(out)
623 0 : sigma_x_1_n(:,:,:), sigma_x_2_n(:,:,:) ) ! Intent(out)
624 :
625 :
626 : !!! Calculate the normal space correlations.
627 : !!! The normal space correlations are the same as the true correlations
628 : !!! except when at least one of the variables involved is a precipitating
629 : !!! hydrometeor or Ncn. In these cases, the normal space correlation
630 : !!! involves the natural logarithm of the precipitating hydrometeors, ln hm
631 : !!! (for example, ln r_r and ln N_r), and ln N_cn for each PDF component.
632 0 : if ( l_diagnose_correlations ) then
633 :
634 0 : do k = 2, nz, 1
635 0 : do i = 1, ngrdcol
636 :
637 0 : if ( rcm_pdf(i,k) > rc_tol ) then
638 :
639 : call diagnose_correlations( pdf_dim, corr_array_n_cloud, & ! In
640 : l_calc_w_corr, & ! In
641 0 : corr_array_1_n(i,k,:,:) ) ! Out
642 :
643 : call diagnose_correlations( pdf_dim, corr_array_n_cloud, & ! In
644 : l_calc_w_corr, & ! In
645 0 : corr_array_2_n(i,k,:,:) ) ! Out
646 :
647 : else
648 :
649 : call diagnose_correlations( pdf_dim, corr_array_n_below, & ! In
650 : l_calc_w_corr, & ! In
651 0 : corr_array_1_n(i,k,:,:) ) ! Out
652 :
653 : call diagnose_correlations( pdf_dim, corr_array_n_below, & ! In
654 : l_calc_w_corr, & ! In
655 0 : corr_array_2_n(i,k,:,:) ) ! Out
656 :
657 : end if
658 :
659 : end do
660 : end do
661 :
662 0 : do k = 2, nz, 1
663 0 : do i = 1, ngrdcol
664 : call calc_cholesky_corr_mtx_approx &
665 0 : ( pdf_dim, corr_array_1_n(i,k,:,:), & ! intent(in)
666 0 : corr_cholesky_mtx_1(i,k,:,:), corr_array_1_n(i,k,:,:) ) ! intent(out)
667 : end do
668 : end do
669 :
670 0 : do k = 2, nz, 1
671 0 : do i = 1, ngrdcol
672 : call calc_cholesky_corr_mtx_approx &
673 0 : ( pdf_dim, corr_array_2_n(i,k,:,:), & ! intent(in)
674 0 : corr_cholesky_mtx_2(i,k,:,:), corr_array_2_n(i,k,:,:) ) ! intent(out)
675 : end do
676 : end do
677 :
678 : else ! if .not. l_diagnose_correlations
679 :
680 : if ( l_fix_w_chi_eta_correlations &
681 0 : .and. .not. l_calc_w_corr ) then
682 :
683 : ! When the flags are set this way, the correlation matrices do not vary with any vertical
684 : ! values, and instead are determined entirely by prescribed values. This results in there
685 : ! being only two unique correlation matrices, one for when the grid box is in cloud
686 : ! and one for when it is not. So instead of setting up correlation matrices for all
687 : ! grid boxes then calculating their Cholesky decomps, we can simply set up two correlation
688 : ! matrices, one for in cloud and one for out cloud, calculate the corresponding
689 : ! Cholesky decompositions, then use the value of rc at each grid box to determine whether
690 : ! we assign the in cloud or out of cloud matrices to that grid box.
691 : call calc_corr_norm_and_cholesky_factor( nz, ngrdcol, pdf_dim, iiPDF_type, & ! intent(in)
692 : pdf_params%rc_1, pdf_params%rc_2, & ! intent(in)
693 : corr_array_n_cloud, corr_array_n_below, &
694 : corr_array_1_n, corr_array_2_n, & ! intent(out)
695 0 : corr_cholesky_mtx_1, corr_cholesky_mtx_2 )!out
696 :
697 : else
698 :
699 : ! The correlation matrices can vary with vertical values. So we need to set the
700 : ! correlation matrices up for each grid box, then find the Cholesky decomp for each
701 : ! grid box individually. This is very computationally expensive.
702 :
703 : call comp_corr_norm( nz, pdf_dim, ngrdcol, wm_zt(:,:), & ! In
704 : pdf_params%rc_1(:,:), pdf_params%rc_2(:,:), & ! In
705 : pdf_params%mixt_frac(:,:), & ! In
706 : precip_fracs%precip_frac_1(:,:), & ! In
707 : precip_fracs%precip_frac_2(:,:), & ! In
708 : wpNcnp_zt(:,:), wphydrometp_zt(:,:,:), & ! In
709 : mu_x_1(:,:,:), mu_x_2(:,:,:), & ! In
710 : sigma_x_1(:,:,:), sigma_x_2(:,:,:), & ! In
711 : sigma_x_1_n(:,:,:), sigma_x_2_n(:,:,:), & ! In
712 : corr_array_n_cloud, corr_array_n_below, & ! In
713 : pdf_params, & ! In
714 : iiPDF_type, & ! In
715 : l_calc_w_corr, & ! In
716 : l_fix_w_chi_eta_correlations, & ! In
717 0 : corr_array_1_n(:,:,:,:), corr_array_2_n(:,:,:,:) ) ! Out
718 :
719 : ! Compute choleksy factorization for the correlation matrix of 1st PDF component
720 0 : do k = 2, nz, 1
721 0 : do i = 1, ngrdcol
722 0 : call Cholesky_factor( pdf_dim, corr_array_1_n(i,k,:,:), & ! In
723 0 : corr_array_scaling, corr_cholesky_mtx_1(i,k,:,:), & ! Out
724 0 : l_corr_array_scaling ) ! Out
725 : end do
726 : end do
727 :
728 : ! Compute choleksy factorization for the correlation matrix of 2nd PDF component
729 0 : do k = 2, nz, 1
730 0 : do i = 1, ngrdcol
731 0 : call Cholesky_factor( pdf_dim, corr_array_2_n(i,k,:,:), & ! In
732 0 : corr_array_scaling, corr_cholesky_mtx_2(i,k,:,:), & ! Out
733 0 : l_corr_array_scaling ) ! Out
734 : end do
735 : end do
736 :
737 : end if
738 :
739 : end if ! l_diagnose_correlations
740 :
741 : ! hydromet_pdf_params is optional, so if it is not present we simply skip the steps
742 : ! to compute it.
743 0 : if ( present(hydromet_pdf_params) ) then
744 :
745 : !!! Calculate the true correlations for each PDF component.
746 : call denorm_transform_corr( nz, ngrdcol, pdf_dim, & ! In
747 : sigma_x_1_n(:,:,:), sigma_x_2_n(:,:,:), & ! In
748 : sigma2_on_mu2_ip_1(:,:,:), sigma2_on_mu2_ip_2(:,:,:), & ! In
749 : corr_array_1_n(:,:,:,:), & ! In
750 : corr_array_2_n(:,:,:,:), & ! In
751 0 : corr_array_1(:,:,:,:), corr_array_2(:,:,:,:) ) ! Out
752 :
753 : !!! Pack the PDF parameters
754 : call pack_hydromet_pdf_params( nz, ngrdcol, hm_1(:,:,:), hm_2(:,:,:), pdf_dim, & ! In
755 : mu_x_1(:,:,:), mu_x_2(:,:,:), & ! In
756 : sigma_x_1(:,:,:), sigma_x_2(:,:,:), & ! In
757 : corr_array_1(:,:,:,:), corr_array_2(:,:,:,:), & ! In
758 0 : hydromet_pdf_params(:,:) ) ! Out
759 :
760 0 : do i = 1, ngrdcol
761 0 : call init_hydromet_pdf_params( hydromet_pdf_params(i,1) ) ! intent(out)
762 : end do
763 :
764 : end if
765 :
766 0 : if ( stats_metadata%l_stats_samp ) then
767 :
768 0 : do j = 1, hydromet_dim
769 0 : if ( stats_metadata%ihmp2_zt(j) > 0 ) then
770 : ! Variance (overall) of the hydrometeor, <hm'^2>.
771 : ! call stat_update_var( stats_metadata%ihmp2_zt(i), hydrometp2_zt(:,i), stats_zt )
772 : ! Switch back to using stat_update_var once the code is generalized
773 : ! to pass in the number of vertical levels.
774 0 : do k = 1, nz, 1
775 0 : do i = 1, ngrdcol
776 0 : call stat_update_var_pt( stats_metadata%ihmp2_zt(j), k, hydrometp2_zt(i,k,j), & ! intent(in)
777 0 : stats_zt(i) ) ! intent(inout)
778 : end do ! k = 1, nz, 1
779 : end do
780 : end if
781 : end do
782 :
783 0 : do i = 1, ngrdcol
784 0 : call pdf_param_hm_stats( nz, pdf_dim, hm_1(i,:,:), hm_2(i,:,:), & ! intent(in)
785 0 : mu_x_1(i,:,:), mu_x_2(i,:,:), & ! intent(in)
786 0 : sigma_x_1(i,:,:), sigma_x_2(i,:,:), & ! intent(in)
787 0 : corr_array_1(i,:,:,:), corr_array_2(i,:,:,:), & ! intent(in)
788 : stats_metadata, & ! intent(in)
789 0 : stats_zt(i) ) ! intent(inout)
790 : end do
791 :
792 : !!! Statistics for normal space PDF parameters involving hydrometeors.
793 0 : do i = 1, ngrdcol
794 0 : call pdf_param_ln_hm_stats( nz, pdf_dim, mu_x_1_n(i,:,:), & ! intent(in)
795 0 : mu_x_2_n(i,:,:), sigma_x_1_n(i,:,:), & ! intent(in)
796 0 : sigma_x_2_n(i,:,:), corr_array_1_n(i,:,:,:), & ! intent(in)
797 0 : corr_array_2_n(i,:,:,:), & ! intent(in)
798 : stats_metadata, &
799 0 : stats_zt(i) ) ! intent(inout)
800 : end do
801 :
802 0 : if ( stats_metadata%irtp2_from_chi > 0 ) then
803 :
804 0 : do i = 1, ngrdcol
805 : rtp2_zt_from_chi(i,:) &
806 0 : = compute_rtp2_from_chi( pdf_params%stdev_chi_1(i,:), pdf_params%stdev_chi_2(i,:), &
807 0 : pdf_params%stdev_eta_1(i,:), pdf_params%stdev_eta_2(i,:), &
808 0 : pdf_params%rt_1(i,:), pdf_params%rt_2(j,:), &
809 0 : pdf_params%crt_1(i,:), pdf_params%crt_2(i,:), &
810 0 : pdf_params%mixt_frac(i,:), &
811 0 : corr_array_1_n(i,:,iiPDF_chi,iiPDF_eta), &
812 0 : corr_array_2_n(i,:,iiPDF_chi,iiPDF_eta) )
813 : end do
814 :
815 0 : rtp2_zm_from_chi = zt2zm( nz, ngrdcol, gr, rtp2_zt_from_chi )
816 :
817 : ! Switch back to using stat_update_var once the code is generalized
818 : ! to pass in the number of vertical levels.
819 : ! call stat_update_var( irtp2_from_chi, zt2zm( rtp2_zt_from_chi ), &
820 : ! stats_zm )
821 0 : do k = 1, nz, 1
822 0 : do i = 1, ngrdcol
823 0 : call stat_update_var_pt( stats_metadata%irtp2_from_chi, k, rtp2_zm_from_chi(i,k), & !in
824 0 : stats_zm(i) ) ! intent(inout)
825 : end do
826 : end do ! k = 1, nz, 1
827 :
828 : end if
829 :
830 0 : do i = 1, ngrdcol
831 : ! Switch back to using stat_update_var once the code is generalized
832 : ! to pass in the number of vertical levels.
833 0 : if ( stats_metadata%iprecip_frac > 0 ) then
834 : ! Overall precipitation fraction.
835 : ! call stat_update_var( stats_metadata%iprecip_frac, precip_frac, stats_zt )
836 0 : do k = 1, nz, 1
837 0 : call stat_update_var_pt( stats_metadata%iprecip_frac, k, precip_fracs%precip_frac(i,k), & ! intent(in)
838 0 : stats_zt(i) ) ! intent(inout)
839 : end do ! k = 1, nz, 1
840 : end if
841 :
842 0 : if ( stats_metadata%iprecip_frac_1 > 0 ) then
843 : ! Precipitation fraction in PDF component 1.
844 : ! call stat_update_var( stats_metadata%iprecip_frac_1, precip_frac_1, stats_zt )
845 0 : do k = 1, nz, 1
846 0 : call stat_update_var_pt( stats_metadata%iprecip_frac_1, k, precip_fracs%precip_frac_1(i,k), & ! In
847 0 : stats_zt(i) ) ! intent(inout)
848 : end do ! k = 1, nz, 1
849 : end if
850 :
851 0 : if ( stats_metadata%iprecip_frac_2 > 0 ) then
852 : ! Precipitation fraction in PDF component 2.
853 : ! call stat_update_var( stats_metadata%iprecip_frac_2, precip_frac_2, stats_zt )
854 0 : do k = 1, nz, 1
855 0 : call stat_update_var_pt( stats_metadata%iprecip_frac_2, k, precip_fracs%precip_frac_2(i,k), & ! In
856 0 : stats_zt(i) ) ! intent(inout)
857 : end do ! k = 1, nz, 1
858 : end if
859 :
860 0 : if ( stats_metadata%iNcnm > 0 ) then
861 : ! Mean simplified cloud nuclei concentration (overall).
862 : ! call stat_update_var( stats_metadata%iNcnm, Ncnm, stats_zt )
863 0 : do k = 1, nz, 1
864 0 : call stat_update_var_pt( stats_metadata%iNcnm, k, Ncnm(i,k), & ! intent(in)
865 0 : stats_zt(i) ) ! intent(inout)
866 : end do ! k = 1, nz, 1
867 : end if
868 : end do
869 :
870 : end if
871 :
872 : ! Boundary conditions for the output variables at k=1.
873 0 : mu_x_1_n(:,1,:) = zero
874 0 : mu_x_2_n(:,1,:) = zero
875 0 : sigma_x_1_n(:,1,:) = zero
876 0 : sigma_x_2_n(:,1,:) = zero
877 0 : corr_array_1_n(:,1,:,:) = zero
878 0 : corr_array_2_n(:,1,:,:) = zero
879 0 : corr_cholesky_mtx_1(:,1,:,:) = zero
880 0 : corr_cholesky_mtx_2(:,1,:,:) = zero
881 :
882 0 : precip_fracs%precip_frac(:,1) = zero
883 0 : precip_fracs%precip_frac_1(:,1) = zero
884 0 : precip_fracs%precip_frac_2(:,1) = zero
885 :
886 0 : if ( clubb_at_least_debug_level( 2 ) ) then
887 0 : do k = 2, nz
888 0 : do i = 1, ngrdcol
889 0 : call assert_corr_symmetric( corr_array_1_n(i,k,:,:), pdf_dim) ! intent(in)
890 0 : call assert_corr_symmetric( corr_array_2_n(i,k,:,:), pdf_dim) ! intent(in)
891 : end do
892 : end do
893 : end if
894 :
895 : return
896 :
897 0 : end subroutine setup_pdf_parameters
898 :
899 : !=============================================================================
900 0 : subroutine compute_mean_stdev( nz, ngrdcol, & ! Intent(in)
901 0 : hydromet, hydrometp2_zt, & ! Intent(in)
902 0 : Ncnm, mixt_frac, & ! Intent(in)
903 0 : precip_frac, & ! Intent(in)
904 0 : precip_frac_1, & ! Intent(in)
905 0 : precip_frac_2, & ! Intent(in)
906 0 : precip_frac_tol, & ! Intent(in)
907 0 : w_1, w_2, & ! Intent(in)
908 0 : stdev_w_1, stdev_w_2, & ! Intent(in)
909 0 : chi_1, chi_2, & ! Intent(in)
910 0 : stdev_chi_1, stdev_chi_2, & ! Intent(in)
911 0 : stdev_eta_1, stdev_eta_2, & ! Intent(in)
912 0 : thl_1, thl_2, & ! Intent(in)
913 : pdf_dim, & ! Intent(in)
914 : omicron, zeta_vrnce_rat, & ! Intent(in)
915 : l_const_Nc_in_cloud, & ! Intent(in)
916 0 : mu_x_1, mu_x_2, & ! Intent(out)
917 0 : sigma_x_1, sigma_x_2, & ! Intent(out)
918 0 : hm_1, hm_2, & ! Intent(out)
919 0 : sigma_hm_1_sqd_on_mu_hm_1_sqd, & ! Intent(out)
920 0 : sigma_hm_2_sqd_on_mu_hm_2_sqd ) ! Intent(out)
921 :
922 : ! Description:
923 : ! Calculates the means and standard deviations (for each PDF component) of
924 : ! chi, eta, w, Ncn, and the precipitating hydrometeors. For the
925 : ! precipitating hydrometeors, the component means and standard deviations
926 : ! are in-precip.
927 :
928 : ! References:
929 : !-----------------------------------------------------------------------
930 :
931 : use constants_clubb, only: &
932 : zero ! Constant(s)
933 :
934 : use array_index, only: &
935 : hydromet_tol, &
936 : iiPDF_chi, &
937 : iiPDF_eta, &
938 : iiPDF_w, &
939 : iiPDF_Ncn
940 :
941 : use index_mapping, only: &
942 : pdf2hydromet_idx ! Procedure(s)
943 :
944 : use corr_varnce_module, only: &
945 : hmp2_ip_on_hmm2_ip, & ! Variable(s)
946 : Ncnp2_on_Ncnm2
947 :
948 : use parameters_model, only: &
949 : hydromet_dim ! Variable(s)
950 :
951 : use clubb_precision, only: &
952 : core_rknd ! Variable(s)
953 :
954 : implicit none
955 :
956 : ! Input Variables
957 : integer, intent(in) :: &
958 : nz, & ! Number of model vertical grid levels
959 : pdf_dim, & ! Number of PDF variables
960 : ngrdcol ! Number of grid columns
961 :
962 : real( kind = core_rknd ), dimension(ngrdcol,nz,hydromet_dim), intent(in) :: &
963 : hydromet, & ! Mean of a hydrometeor (overall) [hm units]
964 : hydrometp2_zt ! Variance of a hydrometeor (overall) [(hm units)^2]
965 :
966 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(in) :: &
967 : Ncnm, & ! Mean simplified cloud nuclei concentration [num/kg]
968 : mixt_frac, & ! Mixture fraction [-]
969 : precip_frac, & ! Precipitation fraction (overall) [-]
970 : precip_frac_1, & ! Precipitation fraction (1st PDF component) [-]
971 : precip_frac_2 ! Precipitation fraction (2nd PDF component) [-]
972 :
973 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(in) :: &
974 : w_1, & ! Mean of w (1st PDF component) [m/s]
975 : w_2, & ! Mean of w (2nd PDF component) [m/s]
976 : stdev_w_1, & ! Variance of w (1st PDF component) [m^2/s^2]
977 : stdev_w_2, & ! Variance of w (2nd PDF component) [m^2/s^2]
978 : chi_1, & ! Mean of chi (1st PDF component) [kg/kg]
979 : chi_2, & ! Mean of chi (2nd PDF component) [kg/kg]
980 : stdev_chi_1, & ! Standard deviation of chi (1st PDF component) [kg/kg]
981 : stdev_chi_2, & ! Standard deviation of chi (2nd PDF component) [kg/kg]
982 : stdev_eta_1, & ! Standard deviation of eta (1st PDF component) [kg/kg]
983 : stdev_eta_2, & ! Standard deviation of eta (2nd PDF component) [kg/kg]
984 : thl_1, & ! Mean of thl (1st PDF component) [K]
985 : thl_2 ! Mean of thl (2nd PDF component) [K]
986 :
987 : real( kind = core_rknd ), dimension(ngrdcol), intent(in) :: &
988 : precip_frac_tol ! Minimum precip. frac. when hydromet. are present [-]
989 :
990 : real( kind = core_rknd ), intent(in) :: &
991 : omicron, & ! Relative width parameter, omicron = R / Rmax [-]
992 : zeta_vrnce_rat ! Width parameter for sigma_hm_1^2 / mu_hm_1^2 [-]
993 :
994 : logical, intent(in) :: &
995 : l_const_Nc_in_cloud ! Use a constant cloud droplet conc. within cloud (K&K)
996 :
997 : ! Output Variables
998 : ! Note: This code assumes to be these arrays in the same order as the
999 : ! correlation arrays, etc., which is determined by the iiPDF indices.
1000 : ! The order should be as follows: chi, eta, w, Ncn, <precip. hydrometeors>
1001 : ! (indices increasing from left to right).
1002 : real( kind = core_rknd ), dimension(ngrdcol,nz,pdf_dim), intent(out) :: &
1003 : mu_x_1, & ! Mean array of PDF vars. (1st PDF component) [units vary]
1004 : mu_x_2, & ! Mean array of PDF vars. (2nd PDF component) [units vary]
1005 : sigma_x_1, & ! Standard deviation array of PDF vars (comp. 1) [units vary]
1006 : sigma_x_2 ! Standard deviation array of PDF vars (comp. 2) [units vary]
1007 :
1008 : real( kind = core_rknd ), dimension(ngrdcol,nz,hydromet_dim), intent(out) :: &
1009 : hm_1, & ! Mean of a precip. hydrometeor (1st PDF component) [units vary]
1010 : hm_2 ! Mean of a precip. hydrometeor (2nd PDF component) [units vary]
1011 :
1012 : real( kind = core_rknd ), dimension(ngrdcol,nz,pdf_dim), intent(out) :: &
1013 : sigma_hm_1_sqd_on_mu_hm_1_sqd, & ! Ratio sigma_hm_1^2 / mu_hm_1^2 [-]
1014 : sigma_hm_2_sqd_on_mu_hm_2_sqd ! Ratio sigma_hm_2^2 / mu_hm_2^2 [-]
1015 :
1016 : integer :: ivar ! Loop iterator
1017 :
1018 : integer :: hm_idx ! Hydrometeor array index.
1019 :
1020 :
1021 : !!! Initialize output variables.
1022 0 : hm_1(:,:,:) = zero
1023 0 : hm_2(:,:,:) = zero
1024 0 : sigma_hm_1_sqd_on_mu_hm_1_sqd(:,:,:) = zero
1025 0 : sigma_hm_2_sqd_on_mu_hm_2_sqd(:,:,:) = zero
1026 :
1027 :
1028 : !!! Enter the PDF parameters.
1029 :
1030 : !!! Vertical velocity, w.
1031 :
1032 : ! Mean of vertical velocity, w, in PDF component 1.
1033 0 : mu_x_1(:,:,iiPDF_w) = w_1(:,:)
1034 :
1035 : ! Mean of vertical velocity, w, in PDF component 2.
1036 0 : mu_x_2(:,:,iiPDF_w) = w_2(:,:)
1037 :
1038 : ! Standard deviation of vertical velocity, w, in PDF component 1.
1039 0 : sigma_x_1(:,:,iiPDF_w) = stdev_w_1(:,:)
1040 :
1041 : ! Standard deviation of vertical velocity, w, in PDF component 2.
1042 0 : sigma_x_2(:,:,iiPDF_w) = stdev_w_2(:,:)
1043 :
1044 :
1045 : !!! Extended liquid water mixing ratio, chi.
1046 :
1047 : ! Mean of extended liquid water mixing ratio, chi (old s),
1048 : ! in PDF component 1.
1049 0 : mu_x_1(:,:,iiPDF_chi) = chi_1(:,:)
1050 :
1051 : ! Mean of extended liquid water mixing ratio, chi (old s),
1052 : ! in PDF component 2.
1053 0 : mu_x_2(:,:,iiPDF_chi) = chi_2(:,:)
1054 :
1055 : ! Standard deviation of extended liquid water mixing ratio, chi (old s),
1056 : ! in PDF component 1.
1057 0 : sigma_x_1(:,:,iiPDF_chi) = stdev_chi_1(:,:)
1058 :
1059 : ! Standard deviation of extended liquid water mixing ratio, chi (old s),
1060 : ! in PDF component 2.
1061 0 : sigma_x_2(:,:,iiPDF_chi) = stdev_chi_2(:,:)
1062 :
1063 :
1064 : !!! Coordinate orthogonal to chi, eta.
1065 :
1066 : ! Mean of eta (old t) in PDF component 1.
1067 : ! Set the component mean values of eta to 0.
1068 : ! The component mean values of eta are not important. They can be set to
1069 : ! anything. They cancel out in the model code. However, the best thing to
1070 : ! do is to set them to 0 and avoid any kind of numerical error.
1071 0 : mu_x_1(:,:,iiPDF_eta) = zero
1072 :
1073 : ! Mean of eta (old t) in PDF component 2.
1074 : ! Set the component mean values of eta to 0.
1075 : ! The component mean values of eta are not important. They can be set to
1076 : ! anything. They cancel out in the model code. However, the best thing to
1077 : ! do is to set them to 0 and avoid any kind of numerical error.
1078 0 : mu_x_2(:,:,iiPDF_eta) = zero
1079 :
1080 : ! Standard deviation of eta (old t) in PDF component 1.
1081 0 : sigma_x_1(:,:,iiPDF_eta) = stdev_eta_1(:,:)
1082 :
1083 : ! Standard deviation of eta (old t) in PDF component 2.
1084 0 : sigma_x_2(:,:,iiPDF_eta) = stdev_eta_2(:,:)
1085 :
1086 :
1087 : !!! Simplified cloud nuclei concentration, Ncn.
1088 :
1089 : ! Mean of simplified cloud nuclei concentration, Ncn, in PDF component 1.
1090 0 : mu_x_1(:,:,iiPDF_Ncn) = Ncnm(:,:)
1091 :
1092 : ! Mean of simplified cloud nuclei concentration, Ncn, in PDF component 2.
1093 0 : mu_x_2(:,:,iiPDF_Ncn) = Ncnm(:,:)
1094 :
1095 : ! Standard deviation of simplified cloud nuclei concentration, Ncn,
1096 : ! in PDF component 1.
1097 0 : if ( .not. l_const_Nc_in_cloud ) then
1098 :
1099 : ! Ncn varies in both PDF components.
1100 0 : sigma_x_1(:,:,iiPDF_Ncn) = sqrt( Ncnp2_on_Ncnm2 ) * Ncnm(:,:)
1101 :
1102 0 : sigma_x_2(:,:,iiPDF_Ncn) = sqrt( Ncnp2_on_Ncnm2 ) * Ncnm(:,:)
1103 :
1104 : ! Ncn is not an official hydrometeor. However, both the
1105 : ! sigma_hm_1_sqd_on_mu_hm_1_sqd and sigma_hm_2_sqd_on_mu_hm_2_sqd arrays
1106 : ! have size pdf_dim, and both sigma_Ncn_1^2/mu_Ncn_1^2 and
1107 : ! sigma_Ncn_2^2/mu_Ncn_2^2 need to be output as part of these arrays.
1108 0 : sigma_hm_1_sqd_on_mu_hm_1_sqd(:,:,iiPDF_Ncn) = Ncnp2_on_Ncnm2
1109 0 : sigma_hm_2_sqd_on_mu_hm_2_sqd(:,:,iiPDF_Ncn) = Ncnp2_on_Ncnm2
1110 :
1111 : else ! l_const_Nc_in_cloud
1112 :
1113 : ! Ncn is constant in both PDF components.
1114 0 : sigma_x_1(:,:,iiPDF_Ncn) = zero
1115 :
1116 0 : sigma_x_2(:,:,iiPDF_Ncn) = zero
1117 :
1118 : ! Ncn is not an official hydrometeor. However, both the
1119 : ! sigma_hm_1_sqd_on_mu_hm_1_sqd and sigma_hm_2_sqd_on_mu_hm_2_sqd arrays
1120 : ! have size pdf_dim, and both sigma_Ncn_1^2/mu_Ncn_1^2 and
1121 : ! sigma_Ncn_2^2/mu_Ncn_2^2 need to be output as part of these arrays.
1122 0 : sigma_hm_1_sqd_on_mu_hm_1_sqd(:,:,iiPDF_Ncn) = zero
1123 0 : sigma_hm_2_sqd_on_mu_hm_2_sqd(:,:,iiPDF_Ncn) = zero
1124 :
1125 : end if ! .not. l_const_Nc_in_cloud
1126 :
1127 :
1128 : !!! Precipitating hydrometeor species.
1129 0 : do ivar = iiPDF_Ncn+1, pdf_dim, 1
1130 :
1131 0 : hm_idx = pdf2hydromet_idx(ivar)
1132 :
1133 : call calc_comp_mu_sigma_hm( nz, ngrdcol, & ! In
1134 : hydromet(:,:,hm_idx), hydrometp2_zt(:,:,hm_idx), & ! In
1135 0 : hmp2_ip_on_hmm2_ip(hm_idx), & ! In
1136 : mixt_frac(:,:), precip_frac(:,:), & ! In
1137 : precip_frac_1(:,:), precip_frac_2(:,:), & ! In
1138 0 : hydromet_tol(hm_idx), precip_frac_tol(:), & ! In
1139 : thl_1(:,:), thl_2(:,:), & ! In
1140 : omicron, zeta_vrnce_rat, & ! In
1141 : mu_x_1(:,:,ivar), mu_x_2(:,:,ivar), & ! Out
1142 : sigma_x_1(:,:,ivar), sigma_x_2(:,:,ivar), & ! Out
1143 : hm_1(:,:,hm_idx), hm_2(:,:,hm_idx), & ! Out
1144 : sigma_hm_1_sqd_on_mu_hm_1_sqd(:,:,ivar), & ! Out
1145 0 : sigma_hm_2_sqd_on_mu_hm_2_sqd(:,:,ivar) ) ! Out
1146 :
1147 : end do ! ivar = iiPDF_Ncn+1, pdf_dim, 1
1148 :
1149 :
1150 0 : return
1151 :
1152 : end subroutine compute_mean_stdev
1153 :
1154 : !=============================================================================
1155 0 : subroutine calc_corr_norm_and_cholesky_factor( nz, ngrdcol, pdf_dim, iiPDF_type, &
1156 0 : rc_1, rc_2, &
1157 0 : corr_array_n_cloud, corr_array_n_below, &
1158 0 : corr_array_1_n, corr_array_2_n, &
1159 0 : corr_cholesky_mtx_1, corr_cholesky_mtx_2 )
1160 :
1161 : ! Description: This subroutine computes the correlation arrays and correlation
1162 : ! Cholesky matrices of PDF vars for both components. Here, we assume that
1163 : ! there are only two unique correlation arrays, which allows us to compute
1164 : ! these two unique arrays and their corresponding Cholesky decompositions,
1165 : ! then use rc to determine which one to assign to each grid column and
1166 : ! vertical level. If the correlation arrays vary based on vertically varying
1167 : ! values, then this subroutine is not appropriate.
1168 : !
1169 : ! References:
1170 : ! https://github.com/larson-group/cam/issues/129#issuecomment-816205563
1171 : !-----------------------------------------------------------------------
1172 :
1173 : use constants_clubb, only: &
1174 : rc_tol, &
1175 : zero
1176 :
1177 : use clubb_precision, only: &
1178 : core_rknd ! Variable(s)
1179 :
1180 : use array_index, only: &
1181 : iiPDF_chi, & ! Variable(s)
1182 : iiPDF_eta, &
1183 : iiPDF_w, &
1184 : iiPDF_Ncn
1185 :
1186 : use model_flags, only: &
1187 : iiPDF_ADG1, & ! Variable(s)
1188 : iiPDF_ADG2, &
1189 : iiPDF_new_hybrid
1190 :
1191 : use pdf_parameter_module, only: &
1192 : pdf_parameter ! Variable(s)
1193 :
1194 : use matrix_operations, only: &
1195 : Cholesky_factor ! Procedure(s)
1196 :
1197 : implicit none
1198 :
1199 : ! Input Variables
1200 : integer, intent(in) :: &
1201 : nz, & ! Number of vertical levels
1202 : pdf_dim, & ! Number of variables in the corr/mean/stdev arrays
1203 : ngrdcol ! Number of grid columns
1204 :
1205 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(in) :: &
1206 : rc_1, & ! Mean of r_c (1st PDF component) [kg/kg]
1207 : rc_2 ! Mean of r_c (2nd PDF component) [kg/kg]
1208 :
1209 : real( kind = core_rknd ), dimension(pdf_dim,pdf_dim), intent(in) :: &
1210 : corr_array_n_cloud, & ! Prescribed correlation array in cloud [-]
1211 : corr_array_n_below ! Prescribed correlation array below cloud [-]
1212 :
1213 : integer, intent(in) :: &
1214 : iiPDF_type ! Selected option for the two-component normal (double
1215 : ! Gaussian) PDF type to use for the w, rt, and theta-l (or
1216 : ! w, chi, and eta) portion of CLUBB's multivariate,
1217 : ! two-component PDF.
1218 :
1219 : ! Output Variables
1220 : real( kind = core_rknd ), dimension(ngrdcol,nz,pdf_dim,pdf_dim), intent(out) :: &
1221 : corr_array_1_n, & ! Corr. array (normal space) of PDF vars. (comp. 1) [-]
1222 : corr_array_2_n, & ! Corr. array (normal space) of PDF vars. (comp. 2) [-]
1223 : corr_cholesky_mtx_1, & ! Transposed corr. cholesky matrix, 1st comp. [-]
1224 : corr_cholesky_mtx_2 ! Transposed corr. cholesky matrix, 2nd comp. [-]
1225 :
1226 : ! Local Variables
1227 : real( kind = core_rknd ), dimension(pdf_dim,pdf_dim) :: &
1228 0 : corr_array_cloud, & ! General in cloud corr. matrix
1229 0 : corr_array_below, & ! General out of cloud corr. matrix
1230 0 : corr_cholesky_mtx_cloud, & ! General in cloud Cholesky matrix
1231 0 : corr_cholesky_mtx_below ! General out of cloud Cholesky matrix
1232 :
1233 : logical :: &
1234 : l_corr_array_scaling ! Dummy variable that we need for calling Cholesky_factor
1235 :
1236 : real( kind = core_rknd ), dimension(pdf_dim) :: &
1237 0 : corr_array_scaling ! Dummy variable that we need for calling Cholesky_factor
1238 :
1239 : integer :: ivar, jvar, i, k ! Indices
1240 :
1241 : !-------------------- Begin Code --------------------
1242 :
1243 : ! Initialize correlation arrays with prescribed values
1244 0 : corr_array_cloud(:,:) = corr_array_n_cloud(:,:)
1245 0 : corr_array_below(:,:) = corr_array_n_below(:,:)
1246 :
1247 : ! The ADG1 PDF fixes the correlation of w and rt and the correlation of
1248 : ! w and theta_l to be 0, which means the correlation of w and chi and the
1249 : ! correlation of w and eta must also be 0.
1250 : if ( ( iiPDF_type == iiPDF_ADG1 .or. iiPDF_type == iiPDF_ADG2 &
1251 : .or. iiPDF_type == iiPDF_new_hybrid ) &
1252 0 : .and. l_follow_ADG1_PDF_standards ) then
1253 :
1254 0 : corr_array_cloud(iiPDF_w,iiPDF_chi) = zero
1255 0 : corr_array_below(iiPDF_w,iiPDF_chi) = zero
1256 :
1257 0 : corr_array_cloud(iiPDF_w,iiPDF_eta) = zero
1258 0 : corr_array_below(iiPDF_w,iiPDF_eta) = zero
1259 :
1260 : end if
1261 :
1262 : ! Ncn is an inherently in-cloud property, so replace out of cloud correlation values
1263 : ! with in cloud ones.
1264 0 : corr_array_below(iiPDF_Ncn,iiPDF_chi) = corr_array_cloud(iiPDF_Ncn,iiPDF_chi)
1265 0 : corr_array_below(iiPDF_Ncn,iiPDF_eta) = corr_array_cloud(iiPDF_Ncn,iiPDF_eta)
1266 :
1267 :
1268 : ! Estimates the correlation of the natural logarithm of a
1269 : ! hydrometeor species and eta using the correlation of chi and eta and the
1270 : ! correlation of chi and the natural logarithm of the hydrometeor. This
1271 : ! facilitates the Cholesky decomposability of the correlation array that will
1272 : ! inevitably be decomposed for SILHS purposes. Without this estimation, we
1273 : ! have found that the resulting correlation matrix cannot be decomposed.
1274 0 : do jvar = iiPDF_Ncn+1, pdf_dim
1275 :
1276 0 : corr_array_cloud(jvar,iiPDF_eta) = corr_array_cloud(iiPDF_eta,iiPDF_chi) &
1277 0 : * corr_array_cloud(jvar,iiPDF_chi)
1278 :
1279 : corr_array_below(jvar,iiPDF_eta) = corr_array_below(iiPDF_eta,iiPDF_chi) &
1280 0 : * corr_array_below(jvar,iiPDF_chi)
1281 :
1282 : end do
1283 :
1284 : ! Calc in cloud Cholesky
1285 : call Cholesky_factor( pdf_dim, corr_array_cloud(:,:), & ! In
1286 : corr_array_scaling, corr_cholesky_mtx_cloud(:,:), & ! Out
1287 0 : l_corr_array_scaling ) ! Out
1288 :
1289 : ! Calc out of cloud Cholesky
1290 : call Cholesky_factor( pdf_dim, corr_array_below(:,:), & ! In
1291 : corr_array_scaling, corr_cholesky_mtx_below(:,:), & ! Out
1292 0 : l_corr_array_scaling ) ! Out
1293 :
1294 : ! Use rc_1 to determine which correlation and Cholesky matrices to assign to 1st PDF
1295 : ! Correlation matrices are symmetric, so we copy ij values to ji indices as well
1296 : ! Cholesky matrices are lower triangular, so we only copy those values
1297 0 : do ivar = 1, pdf_dim
1298 0 : do jvar = ivar, pdf_dim
1299 0 : do k = 1, nz
1300 0 : do i = 1, ngrdcol
1301 :
1302 0 : if ( rc_1(i,k) > rc_tol ) then
1303 : ! Assign in cloud matrices to 1st PDF component
1304 0 : corr_array_1_n(i,k,jvar,ivar) = corr_array_cloud(jvar,ivar)
1305 0 : corr_array_1_n(i,k,ivar,jvar) = corr_array_cloud(jvar,ivar)
1306 0 : corr_cholesky_mtx_1(i,k,jvar,ivar) = corr_cholesky_mtx_cloud(jvar,ivar)
1307 : else
1308 : ! Assign out of cloud matrices to 1st PDF component
1309 0 : corr_array_1_n(i,k,jvar,ivar) = corr_array_below(jvar,ivar)
1310 0 : corr_array_1_n(i,k,ivar,jvar) = corr_array_below(jvar,ivar)
1311 0 : corr_cholesky_mtx_1(i,k,jvar,ivar) = corr_cholesky_mtx_below(jvar,ivar)
1312 : end if
1313 :
1314 : end do
1315 : end do
1316 : end do
1317 : end do
1318 :
1319 : ! Use rc_1 to determine which correlation and Cholesky matrices to assign to 2nd PDF
1320 : ! Correlation matrices are symmetric, so we copy ij values to ji indices as well
1321 : ! Cholesky matrices are lower triangular, so we only copy those values
1322 0 : do ivar = 1, pdf_dim
1323 0 : do jvar = ivar, pdf_dim
1324 0 : do k = 1, nz
1325 0 : do i = 1, ngrdcol
1326 :
1327 0 : if ( rc_2(i,k) > rc_tol ) then
1328 : ! Assign in cloud matrices to 2nd PDF component
1329 0 : corr_array_2_n(i,k,jvar,ivar) = corr_array_cloud(jvar,ivar)
1330 0 : corr_array_2_n(i,k,ivar,jvar) = corr_array_cloud(jvar,ivar)
1331 0 : corr_cholesky_mtx_2(i,k,jvar,ivar) = corr_cholesky_mtx_cloud(jvar,ivar)
1332 : else
1333 : ! Assign out of cloud matrices to 2nd PDF component
1334 0 : corr_array_2_n(i,k,jvar,ivar) = corr_array_below(jvar,ivar)
1335 0 : corr_array_2_n(i,k,ivar,jvar) = corr_array_below(jvar,ivar)
1336 0 : corr_cholesky_mtx_2(i,k,jvar,ivar) = corr_cholesky_mtx_below(jvar,ivar)
1337 : end if
1338 :
1339 : end do
1340 : end do
1341 : end do
1342 : end do
1343 :
1344 : ! Set upper triangular parts of Cholesky matrices to zero
1345 0 : do ivar = 1, pdf_dim
1346 0 : do jvar = 1, ivar-1
1347 0 : corr_cholesky_mtx_1(:,:,jvar,ivar) = zero
1348 0 : corr_cholesky_mtx_2(:,:,jvar,ivar) = zero
1349 : end do
1350 : end do
1351 :
1352 0 : end subroutine calc_corr_norm_and_cholesky_factor
1353 :
1354 : !=============================================================================
1355 0 : subroutine comp_corr_norm( nz, pdf_dim, ngrdcol, wm_zt, rc_1, rc_2, &
1356 0 : mixt_frac, &
1357 0 : precip_frac_1, &
1358 0 : precip_frac_2, &
1359 0 : wpNcnp_zt, wphydrometp_zt, &
1360 0 : mu_x_1, mu_x_2, sigma_x_1, sigma_x_2, &
1361 0 : sigma_x_1_n, sigma_x_2_n, &
1362 0 : corr_array_n_cloud, corr_array_n_below, &
1363 : pdf_params, &
1364 : iiPDF_type, &
1365 : l_calc_w_corr, &
1366 : l_fix_w_chi_eta_correlations, &
1367 0 : corr_array_1_n, corr_array_2_n )
1368 :
1369 : ! Description:
1370 :
1371 : ! References:
1372 : !-----------------------------------------------------------------------
1373 :
1374 : use constants_clubb, only: &
1375 : Ncn_tol, &
1376 : one, &
1377 : zero
1378 :
1379 : use diagnose_correlations_module, only: &
1380 : calc_mean, & ! Procedure(s)
1381 : calc_w_corr
1382 :
1383 : use index_mapping, only: &
1384 : pdf2hydromet_idx ! Procedure(s)
1385 :
1386 : use parameters_model, only: &
1387 : hydromet_dim ! Variable(s)
1388 :
1389 : use clubb_precision, only: &
1390 : core_rknd ! Variable(s)
1391 :
1392 : use array_index, only: &
1393 : iiPDF_chi, & ! Variable(s)
1394 : iiPDF_eta, &
1395 : iiPDF_w, &
1396 : iiPDF_Ncn, &
1397 : hydromet_tol
1398 :
1399 : use pdf_parameter_module, only: &
1400 : pdf_parameter ! Variable(s)
1401 :
1402 : use matrix_operations, only: &
1403 : mirror_lower_triangular_matrix
1404 :
1405 : implicit none
1406 :
1407 : ! Input Variables
1408 : integer, intent(in) :: &
1409 : nz, & ! Number of vertical levels
1410 : pdf_dim, & ! Number of variables in the corr/mean/stdev arrays
1411 : ngrdcol ! Number of grid columns
1412 :
1413 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(in) :: &
1414 : wm_zt, & ! Mean vertical velocity, <w>, on thermo. levels [m/s]
1415 : rc_1, & ! Mean of r_c (1st PDF component) [kg/kg]
1416 : rc_2, & ! Mean of r_c (2nd PDF component) [kg/kg]
1417 : mixt_frac, & ! Mixture fraction [-]
1418 : precip_frac_1, & ! Precipitation fraction (1st PDF component) [-]
1419 : precip_frac_2, & ! Precipitation fraction (2nd PDF component) [-]
1420 : wpNcnp_zt ! Covariance of w and N_cn on t-levs. [(m/s) num/kg]
1421 :
1422 : real( kind = core_rknd ), dimension(ngrdcol,nz,hydromet_dim), intent(in) :: &
1423 : wphydrometp_zt ! Covariance of w and hm interp. to t-levs. [(m/s)u.v.]
1424 :
1425 : real( kind = core_rknd ), dimension(ngrdcol,nz,pdf_dim), intent(in) :: &
1426 : mu_x_1, & ! Mean of x array (1st PDF component) [units vary]
1427 : mu_x_2, & ! Mean of x array (2nd PDF component) [units vary]
1428 : sigma_x_1, & ! Standard deviation of x array (1st PDF comp.) [un. vary]
1429 : sigma_x_2, & ! Standard deviation of x array (2nd PDF comp.) [un. vary]
1430 : sigma_x_1_n, & ! Std. dev. array (normal space): PDF vars (comp. 1) [u.v.]
1431 : sigma_x_2_n ! Std. dev. array (normal space): PDF vars (comp. 2) [u.v.]
1432 :
1433 : real( kind = core_rknd ), dimension(pdf_dim,pdf_dim), &
1434 : intent(in) :: &
1435 : corr_array_n_cloud, & ! Prescribed correlation array in cloud [-]
1436 : corr_array_n_below ! Prescribed correlation array below cloud [-]
1437 :
1438 : type(pdf_parameter), intent(in) :: &
1439 : pdf_params ! PDF parameters [units vary]
1440 :
1441 : integer, intent(in) :: &
1442 : iiPDF_type ! Selected option for the two-component normal (double
1443 : ! Gaussian) PDF type to use for the w, rt, and theta-l (or
1444 : ! w, chi, and eta) portion of CLUBB's multivariate,
1445 : ! two-component PDF.
1446 :
1447 : logical, intent(in) :: &
1448 : l_calc_w_corr, & ! Calculate the correlations between w and the hydrometeors
1449 : l_fix_w_chi_eta_correlations ! Use a fixed correlation for s and t Mellor(chi/eta)
1450 :
1451 : ! Output Variables
1452 : real( kind = core_rknd ), dimension(ngrdcol,nz,pdf_dim,pdf_dim), &
1453 : intent(out) :: &
1454 : corr_array_1_n, & ! Corr. array (normal space) of PDF vars. (comp. 1) [-]
1455 : corr_array_2_n ! Corr. array (normal space) of PDF vars. (comp. 2) [-]
1456 :
1457 : ! Local Variables
1458 : real( kind = core_rknd ), dimension(ngrdcol,nz,pdf_dim) :: &
1459 0 : corr_w_hm_1_n, & ! Correlation of w and ln hm (1st PDF component) ip [-]
1460 0 : corr_w_hm_2_n ! Correlation of w and ln hm (2nd PDF component) ip [-]
1461 :
1462 : real( kind = core_rknd ), dimension(ngrdcol,nz) :: &
1463 0 : corr_w_Ncn_1_n, & ! Correlation of w and ln Ncn (1st PDF component) [-]
1464 0 : corr_w_Ncn_2_n ! Correlation of w and ln Ncn (2nd PDF component) [-]
1465 :
1466 : real( kind = core_rknd ), dimension(ngrdcol,nz) :: &
1467 0 : ones_vector, & ! Vector of 1s
1468 0 : Ncn_tol_in, & ! Tolerance value for Ncn
1469 0 : hydromet_tol_in ! Tolerance value for hydromet
1470 :
1471 : logical :: &
1472 : l_limit_corr_chi_eta ! Flag to limit the correlation of chi and eta [-]
1473 :
1474 : integer :: ivar, jvar, hm_idx, i, k ! Indices
1475 :
1476 : ! ---- Begin Code ----
1477 :
1478 :
1479 : !!! Normal space correlations
1480 :
1481 : ! Initialize corr_w_hm_1_n and corr_w_hm_2_n arrays to 0.
1482 0 : corr_w_hm_1_n(:,:,:) = zero
1483 0 : corr_w_hm_2_n(:,:,:) = zero
1484 :
1485 :
1486 : ! Set ones_vector to a vector of 1s.
1487 0 : ones_vector = one
1488 :
1489 : ! Calculate normal space correlations involving w by first calculating total
1490 : ! covariances involving w (<w'Ncn'>, etc.) using the down-gradient
1491 : ! approximation.
1492 0 : if ( l_calc_w_corr ) then
1493 :
1494 0 : Ncn_tol_in = Ncn_tol
1495 :
1496 : ! Calculate the correlation of w and ln Ncn in each PDF component.
1497 : ! The subroutine calc_corr_w_hm_n can be used to do this as long as a
1498 : ! value of 1 is sent in for precip_frac_1 and precip_frac_2.
1499 0 : jvar = iiPDF_Ncn
1500 0 : do i = 1, ngrdcol
1501 0 : call calc_corr_w_hm_n( wm_zt(i,:), wpNcnp_zt(i,:), &
1502 0 : mu_x_1(i,:,iiPDF_w), mu_x_2(i,:,iiPDF_w), &
1503 0 : mu_x_1(i,:,jvar), mu_x_2(i,:,jvar), &
1504 : sigma_x_1(i,:,iiPDF_w), sigma_x_2(i,:,iiPDF_w), &
1505 : sigma_x_1(i,:,jvar), sigma_x_2(i,:,jvar), &
1506 : sigma_x_1_n(i,:,jvar), sigma_x_2_n(i,:,jvar), &
1507 : mixt_frac(i,:), ones_vector(i,:), &
1508 : ones_vector(i,:), Ncn_tol_in(i,:), &
1509 0 : corr_w_Ncn_1_n(i,:), corr_w_Ncn_2_n(i,:) )
1510 : end do
1511 :
1512 : ! Calculate the correlation of w and the natural logarithm of the
1513 : ! hydrometeor for each PDF component and each hydrometeor type.
1514 0 : do jvar = iiPDF_Ncn+1, pdf_dim
1515 :
1516 0 : hm_idx = pdf2hydromet_idx(jvar)
1517 :
1518 0 : hydromet_tol_in(:,:) = hydromet_tol(hm_idx)
1519 :
1520 0 : do i = 1, ngrdcol
1521 0 : call calc_corr_w_hm_n( wm_zt(i,:), wphydrometp_zt(i,:,hm_idx), & ! intent(in)
1522 0 : mu_x_1(i,:,iiPDF_w), mu_x_2(i,:,iiPDF_w), & ! intent(in)
1523 0 : mu_x_1(i,:,jvar), mu_x_2(i,:,jvar), & ! intent(in)
1524 : sigma_x_1(i,:,iiPDF_w), sigma_x_2(i,:,iiPDF_w), & ! intent(in)
1525 : sigma_x_1(i,:,jvar), sigma_x_2(i,:,jvar), & ! intent(in)
1526 : sigma_x_1_n(i,:,jvar), sigma_x_2_n(i,:,jvar), & ! intent(in)
1527 : mixt_frac(i,:), precip_frac_1(i,:), & ! intent(in)
1528 : precip_frac_2(i,:), hydromet_tol_in(i,:), & ! intent(in)
1529 0 : corr_w_hm_1_n(i,:,jvar), corr_w_hm_2_n(i,:,jvar) ) ! intent(out)
1530 : end do
1531 :
1532 : end do ! jvar = iiPDF_Ncn+1, pdf_dim
1533 :
1534 : end if ! l_calc_w_corr
1535 :
1536 : ! In order to decompose the normal space correlation matrix,
1537 : ! we must not have a perfect correlation of chi and
1538 : ! eta. Thus, we impose a limitation.
1539 0 : l_limit_corr_chi_eta = .true.
1540 :
1541 :
1542 : ! Initialize the normal space correlation arrays
1543 0 : corr_array_1_n(:,:,:,:) = zero
1544 0 : corr_array_2_n(:,:,:,:) = zero
1545 :
1546 : !!! The corr_arrays are assumed to be lower triangular matrices
1547 : ! Set diagonal elements to 1
1548 0 : do ivar=1, pdf_dim
1549 0 : do k = 1, nz
1550 0 : do i = 1, ngrdcol
1551 0 : corr_array_1_n(i,k,ivar,ivar) = one
1552 0 : corr_array_2_n(i,k,ivar,ivar) = one
1553 : end do
1554 : end do
1555 : end do
1556 :
1557 :
1558 : !!! This code assumes the following order in the prescribed correlation
1559 : !!! arrays (iiPDF indices):
1560 : !!! chi, eta, w, Ncn, <hydrometeors> (indices increasing from left to right)
1561 0 : if ( l_fix_w_chi_eta_correlations ) then
1562 : ! Correlation of chi (old s) and eta (old t)
1563 : call component_corr_chi_eta( nz, ngrdcol, & ! intent(in)
1564 : rc_1(:,:), & ! intent(in)
1565 : rc_2(:,:), & ! intent(in)
1566 0 : corr_array_n_cloud(iiPDF_eta,iiPDF_chi), & ! intent(in)
1567 : corr_array_n_below(iiPDF_eta,iiPDF_chi), & ! intent(in)
1568 : l_limit_corr_chi_eta, & ! intent(in)
1569 : corr_array_1_n(:,:,iiPDF_eta,iiPDF_chi), & ! intent(out)
1570 0 : corr_array_2_n(:,:,iiPDF_eta,iiPDF_chi) ) ! intent(out)
1571 : else
1572 :
1573 : ! Preferred, more accurate version.
1574 0 : do i = 1, ngrdcol
1575 0 : corr_array_1_n(i,:,iiPDF_eta,iiPDF_chi) = pdf_params%corr_chi_eta_1(i,:)
1576 0 : corr_array_2_n(i,:,iiPDF_eta,iiPDF_chi) = pdf_params%corr_chi_eta_2(i,:)
1577 : end do
1578 :
1579 : end if
1580 :
1581 0 : if ( l_fix_w_chi_eta_correlations ) then
1582 : ! Correlation of chi (old s) and w
1583 : call component_corr_w_x( nz, ngrdcol, & ! intent(in)
1584 : rc_1(:,:), & ! intent(in)
1585 : rc_2(:,:), & ! intent(in)
1586 0 : corr_array_n_cloud(iiPDF_w,iiPDF_chi), & ! intent(in)
1587 : corr_array_n_below(iiPDF_w,iiPDF_chi), & ! intent(in)
1588 : iiPDF_type, & ! intent(in)
1589 : corr_array_1_n(:,:,iiPDF_w,iiPDF_chi), & ! intent(out)
1590 0 : corr_array_2_n(:,:,iiPDF_w,iiPDF_chi) ) ! intent(out)
1591 : else
1592 :
1593 : ! Preferred, more accurate version.
1594 0 : do i = 1, ngrdcol
1595 0 : corr_array_1_n(i,:,iiPDF_w,iiPDF_chi) = pdf_params%corr_w_chi_1(i,:)
1596 0 : corr_array_2_n(i,:,iiPDF_w,iiPDF_chi) = pdf_params%corr_w_chi_2(i,:)
1597 : end do
1598 :
1599 : end if
1600 :
1601 :
1602 : ! Correlation of chi (old s) and ln Ncn, corr_array_n_cloud used twice because
1603 : ! Ncn is an inherently in-cloud property.
1604 : call component_corr_x_hm_n_ip( nz, ngrdcol, & ! intent(in)
1605 : rc_1(:,:), & ! intent(in)
1606 : rc_2(:,:), & ! intent(in)
1607 0 : corr_array_n_cloud(iiPDF_Ncn,iiPDF_chi), & ! intent(in)
1608 : corr_array_n_cloud(iiPDF_Ncn,iiPDF_chi), & ! intent(in)
1609 : corr_array_1_n(:,:,iiPDF_Ncn,iiPDF_chi), & ! intent(out)
1610 0 : corr_array_2_n(:,:,iiPDF_Ncn,iiPDF_chi) ) ! intent(out)
1611 :
1612 : ! Correlation of chi (old s) and the natural logarithm of the hydrometeors
1613 0 : do jvar = iiPDF_Ncn+1, pdf_dim
1614 : call component_corr_x_hm_n_ip( nz, ngrdcol, & ! intent(in)
1615 : rc_1(:,:), & ! intent(in)
1616 : rc_2(:,:), & ! intent(in)
1617 0 : corr_array_n_cloud(jvar,iiPDF_chi), & ! intent(in)
1618 : corr_array_n_below(jvar,iiPDF_chi), & ! intent(in)
1619 : corr_array_1_n(:,:,jvar,iiPDF_chi), & ! intent(out)
1620 0 : corr_array_2_n(:,:,jvar,iiPDF_chi) ) ! intent(out)
1621 : end do
1622 :
1623 : ! Correlation of eta (old t) and w
1624 0 : if ( l_fix_w_chi_eta_correlations ) then
1625 : ! Correlation of chi (old s) and w
1626 : call component_corr_w_x( nz, ngrdcol, & ! intent(in)
1627 : rc_1(:,:), & ! intent(in)
1628 : rc_2(:,:), & ! intent(in)
1629 0 : corr_array_n_cloud(iiPDF_w,iiPDF_eta), & ! intent(in)
1630 : corr_array_n_below(iiPDF_w,iiPDF_eta), & ! intent(in)
1631 : iiPDF_type, & ! intent(in)
1632 : corr_array_1_n(:,:,iiPDF_w,iiPDF_eta), & ! intent(out)
1633 0 : corr_array_2_n(:,:,iiPDF_w,iiPDF_eta) ) ! intent(out)
1634 : else
1635 :
1636 : ! Preferred, more accurate version.
1637 0 : do i = 1, ngrdcol
1638 0 : corr_array_1_n(i,:,iiPDF_w,iiPDF_chi) = pdf_params%corr_w_chi_1(i,:)
1639 0 : corr_array_2_n(i,:,iiPDF_w,iiPDF_chi) = pdf_params%corr_w_chi_2(i,:)
1640 : end do
1641 :
1642 : end if
1643 :
1644 : ! Correlation of eta (old t) and ln Ncn, corr_array_n_cloud used twice because
1645 : ! Ncn is an inherently in-cloud property.
1646 : call component_corr_x_hm_n_ip( nz, ngrdcol, & ! intent(in)
1647 : rc_1(:,:), & ! intent(in)
1648 : rc_2(:,:), & ! intent(in)
1649 0 : corr_array_n_cloud(iiPDF_Ncn,iiPDF_eta), & ! intent(in)
1650 : corr_array_n_cloud(iiPDF_Ncn,iiPDF_eta), & ! intent(in)
1651 : corr_array_1_n(:,:,iiPDF_Ncn,iiPDF_eta), & ! intent(out)
1652 0 : corr_array_2_n(:,:,iiPDF_Ncn,iiPDF_eta) ) ! intent(out)
1653 :
1654 :
1655 : ! Correlation of eta (old t) and the natural logarithm of the hydrometeors
1656 0 : do jvar = iiPDF_Ncn+1, pdf_dim
1657 : call component_corr_eta_hm_n_ip( nz, ngrdcol, & ! intent(in)
1658 : corr_array_1_n(:,:,iiPDF_eta,iiPDF_chi), & ! intent(in)
1659 : corr_array_1_n(:,:,jvar,iiPDF_chi), & ! intent(in)
1660 : corr_array_2_n(:,:,iiPDF_eta,iiPDF_chi), & ! intent(in)
1661 : corr_array_2_n(:,:,jvar,iiPDF_chi), & ! intent(in)
1662 : corr_array_1_n(:,:,jvar,iiPDF_eta), & ! intent(out)
1663 0 : corr_array_2_n(:,:,jvar,iiPDF_eta) ) ! intent(out)
1664 : end do
1665 :
1666 :
1667 : ! Correlation of w and ln Ncn
1668 : call component_corr_w_hm_n_ip( nz, ngrdcol, & ! intent(in)
1669 : corr_w_Ncn_1_n(:,:), rc_1(:,:), & ! intent(in)
1670 : corr_w_Ncn_2_n(:,:), rc_2(:,:), & ! intent(in)
1671 0 : corr_array_n_cloud(iiPDF_Ncn,iiPDF_w), & ! intent(in)
1672 : corr_array_n_below(iiPDF_Ncn,iiPDF_w), & ! intent(in)
1673 : l_calc_w_corr, & ! intent(in)
1674 : corr_array_1_n(:,:,iiPDF_Ncn,iiPDF_w), & ! intent(out)
1675 0 : corr_array_2_n(:,:,iiPDF_Ncn,iiPDF_w) ) ! intent(out)
1676 :
1677 : ! Correlation of w and the natural logarithm of the hydrometeors
1678 0 : do jvar = iiPDF_Ncn+1, pdf_dim
1679 : call component_corr_w_hm_n_ip( nz, ngrdcol, & ! intent(in)
1680 : corr_w_hm_1_n(:,:,jvar), rc_1(:,:), & ! intent(in)
1681 : corr_w_hm_2_n(:,:,jvar), rc_2(:,:), & ! intent(in)
1682 0 : corr_array_n_cloud(jvar,iiPDF_w), & ! intent(in)
1683 : corr_array_n_below(jvar,iiPDF_w), & ! intent(in)
1684 : l_calc_w_corr, & ! intent(in)
1685 : corr_array_1_n(:,:,jvar,iiPDF_w), & ! intent(out)
1686 0 : corr_array_2_n(:,:,jvar,iiPDF_w) ) ! intent(out)
1687 : end do
1688 :
1689 : ! Correlation of ln Ncn and the natural logarithm of the hydrometeors
1690 0 : do jvar = iiPDF_Ncn+1, pdf_dim
1691 :
1692 : call component_corr_hmx_hmy_n_ip( nz, ngrdcol, & ! intent(in)
1693 : rc_1(:,:), & ! intent(in)
1694 : rc_2(:,:), & ! intent(in)
1695 0 : corr_array_n_cloud(jvar,iiPDF_Ncn), & ! intent(in)
1696 : corr_array_n_below(jvar,iiPDF_Ncn), & ! intent(in)
1697 : corr_array_1_n(:,:,jvar,iiPDF_Ncn), & ! intent(out)
1698 0 : corr_array_2_n(:,:,jvar,iiPDF_Ncn) ) ! intent(out)
1699 : end do
1700 :
1701 : ! Correlation of the natural logarithm of two hydrometeors
1702 0 : do ivar = iiPDF_Ncn+1, pdf_dim-1
1703 0 : do jvar = ivar+1, pdf_dim
1704 :
1705 :
1706 : call component_corr_hmx_hmy_n_ip( nz, ngrdcol, & ! intent(in)
1707 : rc_1(:,:), & ! intent(in)
1708 : rc_2(:,:), & ! intent(in)
1709 0 : corr_array_n_cloud(jvar,ivar), & ! intent(in)
1710 : corr_array_n_below(jvar,ivar), & ! intent(in)
1711 : corr_array_1_n(:,:,jvar,ivar), & ! intent(out)
1712 0 : corr_array_2_n(:,:,jvar,ivar) ) ! intent(out)
1713 :
1714 : end do ! jvar
1715 : end do ! ivar
1716 :
1717 : ! For ease of use later in the code, we make the correlation arrays
1718 : ! symmetrical
1719 0 : do k = 2, nz, 1
1720 0 : do i = 1, ngrdcol
1721 0 : call mirror_lower_triangular_matrix( pdf_dim, corr_array_1_n(i,k,:,:) )
1722 0 : call mirror_lower_triangular_matrix( pdf_dim, corr_array_2_n(i,k,:,:) )
1723 : end do
1724 : end do
1725 :
1726 0 : return
1727 :
1728 : end subroutine comp_corr_norm
1729 :
1730 : !=============================================================================
1731 0 : subroutine calc_comp_mu_sigma_hm( nz, ngrdcol, & ! In
1732 0 : hmm, hmp2, & ! In
1733 : hmp2_ip_on_hmm2_ip, & ! In
1734 0 : mixt_frac, precip_frac, & ! In
1735 0 : precip_frac_1, precip_frac_2, & ! In
1736 0 : hm_tol, precip_frac_tol, & ! In
1737 0 : mu_thl_1, mu_thl_2, & ! In
1738 : omicron, zeta_vrnce_rat_in, & ! In
1739 0 : mu_hm_1, mu_hm_2, & ! Out
1740 0 : sigma_hm_1, sigma_hm_2, & ! Out
1741 0 : hm_1, hm_2, & ! Out
1742 0 : sigma_hm_1_sqd_on_mu_hm_1_sqd, & ! Out
1743 0 : sigma_hm_2_sqd_on_mu_hm_2_sqd ) ! Out
1744 :
1745 :
1746 : ! Description:
1747 : ! Calculates the in-precipitation mean and in-precipitation standard
1748 : ! deviation in both PDF components for a precipitating hydrometeor.
1749 : !
1750 : ! When precipitation is found in both PDF components (precip_frac_1 > 0 and
1751 : ! precip_frac_2 > 0), the method that solves for in-precip. mean and
1752 : ! in-precip. standard deviation in each PDF component, preserving overall
1753 : ! mean and overall variance, is used. When precipitation fraction is found
1754 : ! in one PDF component but not the other one (precip_frac_1 > 0 and
1755 : ! precip_frac_2 = 0, or precip_frac_1 = 0 and precip_frac_2 > 0), the
1756 : ! calculation of component in-precip. mean and in-precip. standard deviation
1757 : ! is simple. When precipitation is not found in either component
1758 : ! (precip_frac_1 = 0 and precip_frac_2 = 0), there isn't any precipitation
1759 : ! found overall (at that grid level).
1760 : !
1761 : !
1762 : ! DESCRIPTION OF THE METHOD THAT SOLVES FOR TWO IN-PRECIPITATION COMPONENTS
1763 : ! =========================================================================
1764 : !
1765 : ! OVERVIEW
1766 : !
1767 : ! The goal is to calculate the in-precip. mean of the hydrometeor field in
1768 : ! each PDF component (mu_hm_1 and mu_hm_2) in a scenario when there is
1769 : ! precipitation found in both PDF components. The fields provided are the
1770 : ! overall mean of the hydrometeor, <hm>, the overall variance of the
1771 : ! hydrometeor, <hm’^2>, the mixture fraction, a, the overall precipitation
1772 : ! fraction, f_p, and the precipitation fraction in each PDF component
1773 : ! (f_p_1 and f_p_2).
1774 : !
1775 : ! The PDF equation for <hm> is:
1776 : !
1777 : ! <hm> = a * f_p_1 * mu_hm_1 + ( 1- a ) * f_p_2 * mu_hm_2.
1778 : !
1779 : ! Likewise, the PDF equation for <hm’^2> is:
1780 : !
1781 : ! <hm’^2> = a * f_p_1 * ( mu_hm_1^2 + sigma_hm_1^2 )
1782 : ! + ( 1 - a ) * f_p_2 * ( mu_hm_2^2 + sigma_hm_2^2 )
1783 : ! - <hm>^2;
1784 : !
1785 : ! where sigma_hm_1 and sigma_hm_2 are the in-precip. standard deviations of
1786 : ! the hydrometeor field in each PDF component. This can be rewritten as:
1787 : !
1788 : ! <hm’^2>
1789 : ! = a * f_p_1 * ( 1 + sigma_hm_1^2 / mu_hm_1^2 ) * mu_hm_1^2
1790 : ! + ( 1 - a ) * f_p_2 * ( 1 + sigma_hm_2^2 / mu_hm_2^2 ) * mu_hm_2^2
1791 : ! - <hm>^2.
1792 : !
1793 : ! The ratio of sigma_hm_2^2 to mu_hm_2^2 is denoted R:
1794 : !
1795 : ! R = sigma_hm_2^2 / mu_hm_2^2.
1796 : !
1797 : ! In order to allow sigma_hm_1^2 / mu_hm_1^2 to have a different ratio, the
1798 : ! parameter zeta is introduced, such that:
1799 : !
1800 : ! R * ( 1 + zeta ) = sigma_hm_1^2 / mu_hm_1^2;
1801 : !
1802 : ! where zeta > -1. When -1 < zeta < 0, the ratio sigma_hm_2^2 / mu_hm_2^2
1803 : ! grows at the expense of sigma_hm_1^2 / mu_hm_1^2, which narrows. When
1804 : ! zeta = 0, the ratio sigma_hm_1^2 / mu_hm_1^2 is the same as
1805 : ! sigma_hm_2^2 / mu_hm_2^2. When zeta > 0, sigma_hm_1^2 / mu_hm_1^2 grows
1806 : ! at the expense of sigma_hm_2^2 / mu_hm_2^2, which narrows. The component
1807 : ! variances are written as:
1808 : !
1809 : ! sigma_hm_1^2 = R * ( 1 + zeta ) * mu_hm_1^2; and
1810 : ! sigma_hm_2^2 = R * mu_hm_2^2,
1811 : !
1812 : ! and the component standard deviations are simply:
1813 : !
1814 : ! sigma_hm_1 = sqrt( R * ( 1 + zeta ) ) * mu_hm_1; and
1815 : ! sigma_hm_2 = sqrt( R ) * mu_hm_2.
1816 : !
1817 : ! The equation for <hm’^2> can be rewritten as:
1818 : !
1819 : ! <hm’^2> = a * f_p_1 * ( 1 + R * ( 1 + zeta ) ) * mu_hm_1^2
1820 : ! + ( 1 - a ) * f_p_2 * ( 1 + R ) * mu_hm_2^2
1821 : ! - <hm>^2.
1822 : !
1823 : !
1824 : ! HYDROMETEOR IN-PRECIP. VARIANCE:
1825 : ! THE SPREAD OF THE MEANS VS. THE STANDARD DEVIATIONS
1826 : !
1827 : ! Part I: Minimum and Maximum Values for R
1828 : !
1829 : ! The in-precip. variance of the hydrometeor is accounted for through a
1830 : ! combination of the variance of each PDF component and the spread between
1831 : ! the means of each PDF component. At one extreme, the standard deviation
1832 : ! of each component could be set to 0 and the in-prccip. variance could be
1833 : ! accounted for by spreading the PDF component (in-precip.) means far apart.
1834 : ! The value of R in this scenario would be its minimum possible value, which
1835 : ! is 0. At the other extreme, the means of each component could be set
1836 : ! equal to each other and the in-precip. variance could be accounted for
1837 : ! entirely by the PDF component (in-precip.) standard deviations. The value
1838 : ! of R in this scenario would be its maximum possible value, which is Rmax.
1839 : !
1840 : ! In order to calculate the value of Rmax, use the equation set but set
1841 : ! mu_hm_1 = mu_hm_2 and R = Rmax. When this happens:
1842 : !
1843 : ! <hm> = ( a * f_p_1 + ( 1- a ) * f_p_2 ) * mu_hm_i;
1844 : !
1845 : ! and since f_p = a * f_p_1 + ( 1 - a ) * f_p_2:
1846 : !
1847 : ! mu_hm_i = <hm> / f_p = <hm|_ip>;
1848 : !
1849 : ! where <hm|_ip> is the in-precip. mean of the hydrometeor. The equation
1850 : ! for hydrometeor variance in this scenario becomes:
1851 : !
1852 : ! <hm’^2> = <hm|_ip>^2 * ( a * f_p_1 * ( 1 + Rmax * ( 1 + zeta ) )
1853 : ! + ( 1 - a ) * f_p_2 * ( 1 + Rmax ) )
1854 : ! - <hm>^2.
1855 : !
1856 : ! The general equation for the in-precip. variance of a hydrometeor,
1857 : ! <hm|_ip’^2>, is given by:
1858 : !
1859 : ! <hm|_ip’^2> = ( <hm’^2> + <hm>^2 - f_p * <hm|_ip>^2 ) / f_p;
1860 : !
1861 : ! which can be rewritten as:
1862 : !
1863 : ! <hm’^2> + <hm>^2 = f_p * ( <hm|_ip’^2> + <hm|_ip>^2 ).
1864 : !
1865 : ! When the above equation is substituted into the modified PDF equation for
1866 : ! <hm’^2>, Rmax is solved for and the equation is:
1867 : !
1868 : ! Rmax = ( f_p / ( a * f_p_1 * ( 1 + zeta ) + ( 1 - a ) * f_p_2 ) )
1869 : ! * ( <hm|_ip’^2> / <hm|_ip>^2 ).
1870 : !
1871 : ! Here, in the scenario that zeta = 0, both PDF components have the same
1872 : ! mean and same variance, which reduces the in-precip. distribution to an
1873 : ! assumed single lognormal, and the above equation reduces to:
1874 : !
1875 : ! Rmax = <hm|_ip’^2> / <hm|_ip>^2;
1876 : !
1877 : ! which is what is expected in that case.
1878 : !
1879 : !
1880 : ! Part II: Enter omicron
1881 : !
1882 : ! A parameter is used to prescribe the ratio of R to its maximum value,
1883 : ! Rmax. The prescribed parameter is called omicron, where:
1884 : !
1885 : ! R = omicron * Rmax;
1886 : !
1887 : ! where 0 <= omicron <= 1. When omicron = 0, the standard deviation of each
1888 : ! PDF component is 0, and mu_hm_1 is spread as far away from mu_hm_2 as it
1889 : ! needs to be to account for the in-precip. variance. When omicron = 1,
1890 : ! mu_hm_1 is equal to mu_hm_2, and the standard deviations of the PDF
1891 : ! components account for all of the in-precip. variance (and when zeta = 0,
1892 : ! the PDF shape is a single lognormal in-precip.). At intermediate values
1893 : ! of omicron, the means of each PDF component are somewhat spread and each
1894 : ! PDF component has some width. The modified parameters are listed below.
1895 : !
1896 : ! The ratio of sigma_hm_2^2 to mu_hm_2^2 is:
1897 : !
1898 : ! sigma_hm_2^2 / mu_hm_2^2 = omicron * Rmax;
1899 : !
1900 : ! and the ratio of sigma_hm_1^2 / mu_hm_1^2 is:
1901 : !
1902 : ! sigma_hm_1^2 / mu_hm_1^2 = omicron * Rmax * ( 1 + zeta ).
1903 : !
1904 : ! The component variances are written as:
1905 : !
1906 : ! sigma_hm_1^2 = omicron * Rmax * ( 1 + zeta ) * mu_hm_1^2; and
1907 : ! sigma_hm_2^2 = omicron * Rmax * mu_hm_2^2,
1908 : !
1909 : ! and the component standard deviations are simply:
1910 : !
1911 : ! sigma_hm_1 = sqrt( omicron * Rmax * ( 1 + zeta ) ) * mu_hm_1; and
1912 : ! sigma_hm_2 = sqrt( omicron * Rmax ) * mu_hm_2.
1913 : !
1914 : ! The equation set becomes:
1915 : !
1916 : ! [1] <hm> = a * f_p_1 * mu_hm_1 + ( 1- a ) * f_p_2 * mu_hm_2; and
1917 : !
1918 : ! [2] <hm’^2>
1919 : ! = a * f_p_1 * ( 1 + omicron * Rmax * ( 1 + zeta ) ) * mu_hm_1^2
1920 : ! + ( 1 - a ) * f_p_2 * ( 1 + omicron * Rmax ) * mu_hm_2^2
1921 : ! - <hm>^2.
1922 : !
1923 : !
1924 : ! SOLVING THE EQUATION SET FOR MU_HM_1 AND MU_HM_2.
1925 : !
1926 : ! The above system of two equations can be solved for mu_hm_1 and mu_hm_2.
1927 : ! All other quantities in the equation set are known quantities. The
1928 : ! equation for <hm> is rewritten to isolate mu_hm_2:
1929 : !
1930 : ! mu_hm_2 = ( <hm> - a * f_p_1 * mu_hm_1 ) / ( ( 1 - a ) * f_p_2 ).
1931 : !
1932 : ! The above equation is substituted into the equation for <hm’^2>. The
1933 : ! equation for <hm’^2> is rewritten, resulting in:
1934 : !
1935 : ! [ a * f_p_1 * ( 1 + omicron * Rmax * ( 1 + zeta ) )
1936 : ! + a^2 * f_p_1^2 * ( 1 + omicron * Rmax ) / ( ( 1 - a ) * f_p_2 ) ]
1937 : ! * mu_hm_1^2
1938 : ! + [ - 2 * <hm> * a * f_p_1 * ( 1 + omicron * Rmax )
1939 : ! / ( ( 1 - a ) * f_p_2 ) ] * mu_hm_1
1940 : ! + [ - ( <hm’^2>
1941 : ! + ( 1 - ( 1 + omicron * Rmax ) / ( ( 1 - a ) * f_p_2 ) )
1942 : ! * <hm>^2 ) ]
1943 : ! = 0.
1944 : !
1945 : ! This equation is of the form:
1946 : !
1947 : ! A * mu_hm_1^2 + B * mu_hm_1 + C = 0;
1948 : !
1949 : ! so the solution for mu_hm_1 is:
1950 : !
1951 : ! mu_hm_1 = ( -B +/- sqrt( B^2 - 4*A*C ) ) / (2*A);
1952 : !
1953 : ! where:
1954 : !
1955 : ! A = a * f_p_1 * ( 1 + omicron * Rmax * ( 1 + zeta ) )
1956 : ! + a^2 * f_p_1^2 * ( 1 + omicron * Rmax ) / ( ( 1 - a ) * f_p_2 );
1957 : !
1958 : ! B = - 2 * <hm> * a * f_p_1 * ( 1 + omicron * Rmax )
1959 : ! / ( ( 1 - a ) * f_p_2 );
1960 : !
1961 : ! and
1962 : !
1963 : ! C = - ( <hm’^2>
1964 : ! + ( 1 - ( 1 + omicron * Rmax ) / ( ( 1 - a ) * f_p_2 ) )
1965 : ! * <hm>^2 ).
1966 : !
1967 : ! The signs of the coefficients:
1968 : !
1969 : ! 1) coefficient A is always positive,
1970 : ! 2) coefficient B is always negative (this means that -B is always
1971 : ! positive), and
1972 : ! 3) coefficient C can be positive, negative, or zero.
1973 : !
1974 : ! Since ( 1 - ( 1 + omicron * Rmax ) / ( ( 1 - a ) * f_p_2 ) ) * <hm>^2 is
1975 : ! always negative and <hm’^2> is always positive, the sign of coefficient C
1976 : ! depends on which term is greater in magnitude.
1977 : !
1978 : ! When <hm’^2> is greater, the sign of coefficient C is negative. This
1979 : ! means that -4*A*C is positive, which in turn means that
1980 : ! sqrt( B^2 - 4*A*C ) is greater in magnitude than -B. If the subtraction
1981 : ! option of the +/- were to be chosen, the value of mu_hm_1 would be
1982 : ! negative in this scenerio. So the natural thing to do would be to always
1983 : ! choose the addition option. However, this method requires that mu_hm_1
1984 : ! equals mu_hm_2 when omicron = 1. When zeta >= 0, this happens when the
1985 : ! addition option is chosen, but not when the subtraction option is chosen.
1986 : ! However, when zeta < 0, this happens when the subtraction option is
1987 : ! chosen, but not when the addition option is chosen. So, the equation for
1988 : ! mu_hm_1 becomes:
1989 : !
1990 : ! mu_hm_1 = ( -B + sqrt( B^2 - 4*A*C ) ) / (2*A); when zeta >= 0; and
1991 : ! mu_hm_1 = ( -B - sqrt( B^2 - 4*A*C ) ) / (2*A); when zeta < 0.
1992 : !
1993 : ! Once this is set, of course:
1994 : !
1995 : ! mu_hm_2 = ( <hm> - a * f_p_1 * mu_hm_1 ) / ( ( 1 - a ) * f_p_2 ).
1996 : !
1997 : ! The system has been solved and the in-precip. PDF component means have
1998 : ! been found!
1999 : !
2000 : !
2001 : ! NOTES
2002 : !
2003 : ! Note 1:
2004 : !
2005 : ! The term B^2 - 4*A*C has been analyzed, and mathematically:
2006 : !
2007 : ! B^2 - 4*A*C >= 0
2008 : !
2009 : ! always holds true. Additionally, the minimum value:
2010 : !
2011 : ! B^2 - 4*A*C = 0,
2012 : !
2013 : ! can only occur when omicron = 1 and zeta = 0 (or alternatively to
2014 : ! zeta = 0, Rmax = 0, but this only occurs when <hm|_ip'^2> / <hm|_ip>^2 has
2015 : ! a value of 0).
2016 : !
2017 : ! Numerically, when omicron = 1 and zeta = 0, B^2 - 4*A*C can produce very
2018 : ! small (on the order of epsilon) negative values. This is due to numerical
2019 : ! round off error. When this happens, the erroneous small, negative value
2020 : ! of B^2 - 4*A*C is simply reset to the value it's supposed to have, which
2021 : ! is 0.
2022 : !
2023 : !
2024 : ! Note 2:
2025 : !
2026 : ! As the value of <hm|_ip'^2> / <hm|_ip>^2 increases and as the value of
2027 : ! omicron decreases (narrowing the in-precip standard deviations and
2028 : ! increasing the spread between the in-precip means), a situtation arises
2029 : ! where the value of one of the component means will become negative. This
2030 : ! is because there is a limit to the amount of in-precip variance that can
2031 : ! be represented by this kind of distribution. In order to prevent
2032 : ! out-of-bounds values of mu_hm_1 or mu_hm_2, lower limits will be
2033 : ! declared, called mu_hm_1_min and mu_hm_2_min. The value of the
2034 : ! hydrometeor in-precip. component mean will be limited from going any
2035 : ! smaller (or negative) at this value. From there, the value of the other
2036 : ! hydrometeor in-precip. component mean is easy to calculate. Then, both
2037 : ! values will be entered into the calculation of hydrometeor variance, which
2038 : ! will be rewritten to solve for R. Then, both the hydrometeor mean and
2039 : ! hydrometeor variance will be preserved with a valid distribution.
2040 : !
2041 : ! In this emergency scenario, the value of R is:
2042 : !
2043 : ! R = ( <hm'^2> + <hm>^2 - a * f_p_1 * mu_hm_1^2
2044 : ! - ( 1 - a ) * f_p_2 * mu_hm_2^2 )
2045 : ! / ( a * f_p_1 * ( 1 + zeta ) * mu_hm_1^2
2046 : ! + ( 1 - a ) * f_p_2 * mu_hm_2^2 ).
2047 : !
2048 : ! The minimum values of the in-precip. component means are bounded by:
2049 : !
2050 : ! mu_hm_1_min >= hm_tol / f_p_1; and
2051 : ! mu_hm_2_min >= hm_tol / f_p_2.
2052 : !
2053 : ! These are set this way because hm_1 ( = mu_hm_1 * f_p_1 ) and
2054 : ! hm_2 ( = mu_hm_2 * f_p_2 ) need to have values of at least hm_tol when
2055 : ! precipitation is found in both PDF components.
2056 : !
2057 : ! However, an in-precip. component mean value of hm_tol / f_p_1 or
2058 : ! hm_tol / f_p_2 often produces a distribution where one component centers
2059 : ! around values that are too small to be a good match with data taken from
2060 : ! Large Eddy Simulations (LES). It is desirable to increase the minimum
2061 : ! threshold of mu_hm_1 and mu_hm_2.
2062 : !
2063 : ! As the minimum threshold increases, the value of the in-precip. component
2064 : ! mean that is from the component that is not being set to the minimum
2065 : ! threshold decreases. If the minimum threshold were to be boosted as high
2066 : ! as <hm> / f_p (in most cases, <hm> / f_p >> hm_tol / f_p_i), both
2067 : ! components would have a value of <hm> / f_p. The minimum threshold should
2068 : ! not be set this high.
2069 : !
2070 : ! Additionally, the minimum threshold for one in-precip. component mean
2071 : ! cannot be set so high as to drive the other in-precip. component mean
2072 : ! below hm_tol / f_p_i. (This doesn't come into play unless <hm> is close
2073 : ! to hm_tol.) The upper limit for the in-precip. mean values are:
2074 : !
2075 : ! mu_hm_1|_(upper. lim.) = ( <hm> - ( 1 - a ) * f_p_2 * ( hm_tol / f_p_2 ) )
2076 : ! / ( a * f_p_1 ); and
2077 : !
2078 : ! mu_hm_2|_(upper. lim.) = ( <hm> - a * f_p_1 * ( hm_tol / f_p_1 ) )
2079 : ! / ( ( 1 - a ) * f_p_2 );
2080 : !
2081 : ! which reduces to:
2082 : !
2083 : ! mu_hm_1|_(upper. lim.) = ( <hm> - ( 1 - a ) * hm_tol ) / ( a * f_p_1 );
2084 : ! and
2085 : ! mu_hm_2|_(upper. lim.) = ( <hm> - a * hm_tol ) / ( ( 1 - a ) * f_p_2 ).
2086 : !
2087 : ! An appropriate minimum value for mu_hm_1 can be set by:
2088 : !
2089 : ! mu_hm_1_min = | min( hm_tol / f_p_1
2090 : ! | + mu_hm_min_coef * ( <hm> / f_p - hm_tol / f_p_1 ),
2091 : ! | ( <hm> - ( 1 - a ) * hm_tol ) / ( a * f_p_1 ) );
2092 : ! | where <hm> / f_p > hm_tol / f_p_1;
2093 : ! | hm_tol / f_p_1;
2094 : ! | where <hm> / f_p <= hm_tol / f_p_1;
2095 : !
2096 : ! and similarly for mu_hm_2:
2097 : !
2098 : ! mu_hm_2_min = | min( hm_tol / f_p_2
2099 : ! | + mu_hm_min_coef * ( <hm> / f_p - hm_tol / f_p_2 ),
2100 : ! | ( <hm> - a * hm_tol ) / ( ( 1 - a ) * f_p_2 ) );
2101 : ! | where <hm> / f_p > hm_tol / f_p_2;
2102 : ! | hm_tol / f_p_2;
2103 : ! | where <hm> / f_p <= hm_tol / f_p_2;
2104 : !
2105 : ! where mu_hm_min_coef is a coefficient that has a value
2106 : ! 0 <= mu_hm_min_coef < 1. When the value of mu_hm_min_coef is 0,
2107 : ! mu_hm_1_min reverts to hm_tol / f_p_1 and mu_hm_2_min reverts to
2108 : ! hm_tol / f_p_2. An appropriate value for mu_hm_min_coef should be small,
2109 : ! such as 0.01 - 0.05.
2110 : !
2111 : !
2112 : ! Note 3:
2113 : !
2114 : ! When the value of zeta >= 0, the value of mu_hm_1 tends to be larger than
2115 : ! the value of mu_hm_2. Likewise when the value of zeta < 0, the value of
2116 : ! mu_hm_2 tends to be larger than the value of mu_hm_1. Since most cloud
2117 : ! water and cloud fraction tends to be found in PDF component 1, it is
2118 : ! advantageous to have the larger in-precip. component mean of the
2119 : ! hydrometeor also found in PDF component 1. The recommended value of zeta
2120 : ! is a value greater than or equal to 0.
2121 : !
2122 : !
2123 : ! Update:
2124 : !
2125 : ! In order to better represent the increase in <th_l'^2> near the ground
2126 : ! from the evaporation of rain, the code is modified to tend towards a
2127 : ! negative correlation of th_l and hm. When mu_thl_1 <= mu_thl_2,
2128 : ! mu_hm_1 >= mu_hm_2; otherwise, when mu_thl_1 > mu_thl_2,
2129 : ! mu_hm_1 <= mu_hm_2.
2130 : !
2131 : ! In the original derivation, mu_hm_1 >= mu_hm_2 when zeta >= 0, and
2132 : ! mu_hm_1 < mu_hm_2 when zeta < 0, where zeta is a tunable or adjustable
2133 : ! parameter. In order to allow the relationship of mu_hm_1 to mu_hm_2 to
2134 : ! depend on the relationship of mu_thl_1 to mu_thl_2, the value of zeta must
2135 : ! also depend on the relationship of mu_thl_1 to mu_thl_2.
2136 : !
2137 : ! When mu_thl_1 <= mu_thl_2:
2138 : !
2139 : ! The relationship of mu_hm_1 to mu_hm_2 is mu_hm_1 >= mu_hm_2, so
2140 : ! zeta >= 0. The tunable value of zeta is referred to as zeta_in. When
2141 : ! zeta_in is already greater than 0 (meaning sigma_hm_1^2 / mu_hm_1^2 is
2142 : ! greater than sigma_hm_2^2 / mu_hm_2^2), zeta is simply set to zeta_in. In
2143 : ! other words, the component with the greater mean value of the hydrometeor
2144 : ! also has the greater value of component variance to the square of the
2145 : ! component mean. However, when zeta_in is less than 0, zeta must be
2146 : ! adjusted to be greater than 0. The following equation is used to set the
2147 : ! value of zeta:
2148 : !
2149 : ! | zeta_in; when zeta_in >= 0
2150 : ! zeta = |
2151 : ! | ( 1 / ( 1 + zeta_in ) ) - 1; when zeta_in < 0.
2152 : !
2153 : ! Previously, when zeta_in < 0, mu_hm_1 < mu_hm_2, and
2154 : ! sigma_hm_1^2 / mu_hm_1^2 < sigma_hm_2^2 / mu_hm_2^2. Now that zeta has to
2155 : ! be greater than 0, sigma_hm_1^2 / mu_hm_1^2 > sigma_hm_2^2 / mu_hm_2^2.
2156 : ! The ratio of the greater variance-over-mean-squared to the smaller
2157 : ! variance-over-mean-squared remains the same when using the equation for
2158 : ! zeta listed above.
2159 : !
2160 : ! When mu_thl_1 > mu_thl_2:
2161 : !
2162 : ! The relationship of mu_hm_1 to mu_hm_2 is mu_hm_1 <= mu_hm_2, so
2163 : ! zeta <= 0. When zeta_in is already less than 0 (meaning
2164 : ! sigma_hm_1^2 / mu_hm_1^2 is less than sigma_hm_2^2 / mu_hm_2^2), zeta is
2165 : ! simply set to zeta_in. In other words, the component with the greater
2166 : ! mean value of the hydrometeor also has the greater value of component
2167 : ! variance to the square of the component mean. However, when zeta_in is
2168 : ! greater than 0, zeta must be adjusted to be less than 0. The following
2169 : ! equation is used to set the value of zeta:
2170 : !
2171 : ! | zeta_in; when zeta_in <= 0
2172 : ! zeta = |
2173 : ! | ( 1 / ( 1 + zeta_in ) ) - 1; when zeta_in > 0.
2174 : !
2175 : ! Previously, when zeta_in > 0, mu_hm_1 > mu_hm_2, and
2176 : ! sigma_hm_1^2 / mu_hm_1^2 > sigma_hm_2^2 / mu_hm_2^2. Now that zeta has to
2177 : ! be less than 0, sigma_hm_1^2 / mu_hm_1^2 < sigma_hm_2^2 / mu_hm_2^2.
2178 : ! The ratio of the greater variance-over-mean-squared to the smaller
2179 : ! variance-over-mean-squared remains the same when using the equation for
2180 : ! zeta listed above.
2181 : !
2182 : !
2183 : ! Brian Griffin; February 2015.
2184 :
2185 : ! References:
2186 : !-----------------------------------------------------------------------
2187 :
2188 : use constants_clubb, only: &
2189 : four, & ! Constant(s)
2190 : two, &
2191 : one, &
2192 : zero
2193 :
2194 : use clubb_precision, only: &
2195 : core_rknd ! Variable(s)
2196 :
2197 : implicit none
2198 :
2199 : ! Input Variables
2200 : integer, intent(in) :: &
2201 : nz, & ! Number of model vertical grid levels
2202 : ngrdcol ! Number of grid columns
2203 :
2204 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(in) :: &
2205 : hmm, & ! Hydrometeor mean (overall), <hm> [hm units]
2206 : hmp2, & ! Hydrometeor variance (overall), <hm'^2> [hm units^2]
2207 : mixt_frac, & ! Mixture fraction [-]
2208 : precip_frac, & ! Precipitation fraction (overall) [-]
2209 : precip_frac_1, & ! Precipitation fraction (1st PDF component) [-]
2210 : precip_frac_2, & ! Precipitation fraction (2nd PDF component) [-]
2211 : mu_thl_1, & ! Mean of th_l (1st PDF component) [K]
2212 : mu_thl_2 ! Mean of th_l (2nd PDF component) [K]
2213 :
2214 : real( kind = core_rknd ), intent(in) :: &
2215 : hmp2_ip_on_hmm2_ip, & ! Ratio <hm|_ip'^2> / <hm|_ip>^2 [-]
2216 : hm_tol ! Tolerance value of hydrometeor [hm units]
2217 :
2218 : real( kind = core_rknd ), dimension(ngrdcol), intent(in) :: &
2219 : precip_frac_tol ! Min. precip. frac. when hydromet. are present [-]
2220 :
2221 : real( kind = core_rknd ), intent(in) :: &
2222 : omicron, & ! Relative width parameter, omicron = R / Rmax [-]
2223 : zeta_vrnce_rat_in ! Width parameter for sigma_hm_1^2 / mu_hm_1^2 [-]
2224 :
2225 : ! Output Variables
2226 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(out) :: &
2227 : mu_hm_1, & ! Mean of hm (1st PDF component) in-precip (ip) [hm un]
2228 : mu_hm_2, & ! Mean of hm (2nd PDF component) ip [hm un]
2229 : sigma_hm_1, & ! Standard deviation of hm (1st PDF component) ip [hm un]
2230 : sigma_hm_2, & ! Standard deviation of hm (2nd PDF component) ip [hm un]
2231 : hm_1, & ! Mean of hm (1st PDF component) [hm un]
2232 : hm_2 ! Mean of hm (2nd PDF component) [hm un]
2233 :
2234 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(out) :: &
2235 : sigma_hm_1_sqd_on_mu_hm_1_sqd, & ! Ratio sigma_hm_1**2 / mu_hm_1**2 [-]
2236 : sigma_hm_2_sqd_on_mu_hm_2_sqd ! Ratio sigma_hm_2**2 / mu_hm_2**2 [-]
2237 :
2238 : ! Local Variables
2239 : real( kind = core_rknd ) :: &
2240 : Rmax, & ! Maximum possible value of ratio R [-]
2241 : coef_A, & ! Coefficient A in A*mu_hm_1^2 + B*mu_hm_1 + C = 0 [-]
2242 : coef_B, & ! Coefficient B in A*mu_hm_1^2 + B*mu_hm_1 + C = 0 [hm un]
2243 : coef_C, & ! Coefficient C in A*mu_hm_1^2 + B*mu_hm_1 + C = 0 [hm un^2]
2244 : Bsqd_m_4AC ! Value B^2 - 4*A*C in quadratic eqn. for mu_hm_1 [hm un^2]
2245 :
2246 : real( kind = core_rknd ) :: &
2247 : zeta_vrnce_rat ! Width parameter for sigma_hm_1^2 / mu_hm_1^2 [-]
2248 :
2249 : real( kind = core_rknd ) :: &
2250 : mu_hm_1_min, & ! Minimum value of mu_hm_1 (precip. in both comps.) [hm un]
2251 : mu_hm_2_min ! Minimum value of mu_hm_2 (precip. in both comps.) [hm un]
2252 :
2253 : real( kind = core_rknd ), parameter :: &
2254 : mu_hm_min_coef = 0.01_core_rknd ! Coef. for mu_hm_1_min and mu_hm_2_min
2255 :
2256 : integer :: i, k ! Loop iterators
2257 :
2258 0 : do k = 1, nz
2259 0 : do i = 1, ngrdcol
2260 :
2261 0 : if ( hmm(i,k) >= hm_tol &
2262 : .and. precip_frac_1(i,k) >= precip_frac_tol(i) &
2263 0 : .and. precip_frac_2(i,k) >= precip_frac_tol(i) ) then
2264 :
2265 : ! Adjust the value of zeta based on the relationship of mu_thl_1 to
2266 : ! mu_thl_2.
2267 0 : if ( mu_thl_1(i,k) <= mu_thl_2(i,k) ) then
2268 0 : if ( zeta_vrnce_rat_in >= zero ) then
2269 : zeta_vrnce_rat = zeta_vrnce_rat_in
2270 : else ! zeta_vrnce_rat_in < 0
2271 0 : zeta_vrnce_rat = ( one / ( one + zeta_vrnce_rat_in ) ) - one
2272 : end if ! zeta_vrnce_rat_in >= 0
2273 : else ! mu_thl_1 > mu_thl_2
2274 0 : if ( zeta_vrnce_rat_in <= zero ) then
2275 : zeta_vrnce_rat = zeta_vrnce_rat_in
2276 : else ! zeta_vrnce_rat_in > 0
2277 0 : zeta_vrnce_rat = ( one / ( one + zeta_vrnce_rat_in ) ) - one
2278 : end if ! zeta_vrnce_rat_in <= 0
2279 : end if ! mu_thl_1 <= mu_thl_2
2280 :
2281 : ! Calculate the value of Rmax.
2282 : ! Rmax = ( f_p / ( a * f_p_1 * ( 1 + zeta ) + ( 1 - a ) * f_p_2 ) )
2283 : ! * ( <hm|_ip’^2> / <hm|_ip>^2 ).
2284 : ! The parameter zeta is written in the code as zeta_vrnce_rat.
2285 : Rmax = ( precip_frac(i,k) &
2286 : / ( mixt_frac(i,k) * precip_frac_1(i,k) * ( one + zeta_vrnce_rat ) &
2287 : + ( one - mixt_frac(i,k) ) * precip_frac_2(i,k) ) ) &
2288 0 : * hmp2_ip_on_hmm2_ip
2289 :
2290 : ! Calculate the value of coefficient A.
2291 : ! A = a * f_p_1 * ( 1 + omicron * Rmax * ( 1 + zeta ) )
2292 : ! + a^2 * f_p_1^2 * ( 1 + omicron * Rmax ) / ( ( 1 - a ) * f_p_2 ).
2293 : coef_A = mixt_frac(i,k) * precip_frac_1(i,k) &
2294 : * ( one + omicron * Rmax * ( one + zeta_vrnce_rat ) ) &
2295 : + mixt_frac(i,k)**2 * precip_frac_1(i,k)**2 &
2296 : * ( one + omicron * Rmax ) &
2297 0 : / ( ( one - mixt_frac(i,k) ) * precip_frac_2(i,k) )
2298 :
2299 : ! Calculate the value of coefficient B.
2300 : ! B = - 2 * <hm> * a * f_p_1 * ( 1 + omicron * Rmax )
2301 : ! / ( ( 1 - a ) * f_p_2 ).
2302 : coef_B = -two * hmm(i,k) * mixt_frac(i,k) * precip_frac_1(i,k) &
2303 : * ( one + omicron * Rmax ) &
2304 0 : / ( ( one - mixt_frac(i,k) ) * precip_frac_2(i,k) )
2305 :
2306 : ! Calculate the value of coefficient C.
2307 : ! C = - ( <hm’^2>
2308 : ! + ( 1 - ( 1 + omicron * Rmax ) / ( ( 1 - a ) * f_p_2 ) )
2309 : ! * <hm>^2 ).
2310 : coef_C = - ( hmp2(i,k) + ( one &
2311 : - ( one + omicron * Rmax ) &
2312 : / ( ( one - mixt_frac(i,k) ) * precip_frac_2(i,k) ) &
2313 0 : ) * hmm(i,k)**2 )
2314 :
2315 : ! Calculate value of B^2 - 4*A*C.
2316 0 : Bsqd_m_4AC = coef_B**2 - four * coef_A * coef_C
2317 :
2318 : ! Mathematically, the value of B^2 - 4*A*C cannot be less than 0.
2319 : ! Numerically, this can happen when numerical round off error causes an
2320 : ! epsilon-sized negative value. When this happens, reset the value of
2321 : ! B^2 - 4*A*C to 0.
2322 0 : if ( Bsqd_m_4AC < zero ) then
2323 0 : Bsqd_m_4AC = zero
2324 : end if
2325 :
2326 : ! Calculate the mean (in-precip.) of the hydrometeor in the 1st PDF
2327 : ! component.
2328 0 : if ( mu_thl_1(i,k) <= mu_thl_2(i,k) ) then
2329 0 : mu_hm_1(i,k) = ( -coef_B + sqrt( Bsqd_m_4AC ) ) / ( two * coef_A )
2330 : else ! mu_thl_1 > mu_thl_2
2331 0 : mu_hm_1(i,k) = ( -coef_B - sqrt( Bsqd_m_4AC ) ) / ( two * coef_A )
2332 : end if ! mu_thl_1 <= mu_thl_2
2333 :
2334 : ! Calculate the mean (in-precip.) of the hydrometeor in the 2nd PDF
2335 : ! component.
2336 : mu_hm_2(i,k) = ( hmm(i,k) - mixt_frac(i,k) * precip_frac_1(i,k) * mu_hm_1(i,k) ) &
2337 0 : / ( ( one - mixt_frac(i,k) ) * precip_frac_2(i,k) )
2338 :
2339 : ! Calculate the value of the ratio R (which is sigma_hm_2^2 / mu_hm_2^2),
2340 : ! where R = omicron * Rmax. The name of the variable used for R is
2341 : ! sigma_hm_2_sqd_on_mu_hm_2_sqd.
2342 0 : sigma_hm_2_sqd_on_mu_hm_2_sqd(i,k) = omicron * Rmax
2343 :
2344 : ! Calculate minimum allowable values for mu_hm_1 and mu_hm_2.
2345 0 : if ( hmm(i,k) / precip_frac(i,k) > hm_tol / precip_frac_1(i,k) ) then
2346 : mu_hm_1_min &
2347 : = min( hm_tol / precip_frac_1(i,k) &
2348 : + mu_hm_min_coef * ( hmm(i,k) / precip_frac(i,k) &
2349 : - hm_tol / precip_frac_1(i,k) ), &
2350 : ( hmm(i,k) - ( one - mixt_frac(i,k) ) * hm_tol ) &
2351 0 : / ( mixt_frac(i,k) * precip_frac_1(i,k) ) )
2352 : else ! hmm / precip_frac <= hm_tol / precip_frac_1
2353 : mu_hm_1_min = hm_tol / precip_frac_1(i,k)
2354 : end if
2355 0 : if ( hmm(i,k) / precip_frac(i,k) > hm_tol / precip_frac_2(i,k) ) then
2356 : mu_hm_2_min &
2357 : = min( hm_tol / precip_frac_2(i,k) &
2358 : + mu_hm_min_coef * ( hmm(i,k) / precip_frac(i,k) &
2359 : - hm_tol / precip_frac_2(i,k) ), &
2360 : ( hmm(i,k) - mixt_frac(i,k) * hm_tol ) &
2361 0 : / ( ( one - mixt_frac(i,k) ) * precip_frac_2(i,k) ) )
2362 : else ! hmm / precip_frac <= hm_tol / precip_frac_2
2363 : mu_hm_2_min = hm_tol / precip_frac_2(i,k)
2364 : end if
2365 :
2366 : ! Handle the "emergency" situation when the specified value of omicron is
2367 : ! too small for the value of <hm|_ip'^2> / <hm|_ip>^2, resulting in a
2368 : ! component mean that is too small (below tolerance value) or negative.
2369 0 : if ( mu_hm_1(i,k) < mu_hm_1_min ) then
2370 :
2371 : ! Set the value of mu_hm_1 to the threshold positive value.
2372 0 : mu_hm_1(i,k) = mu_hm_1_min
2373 :
2374 : ! Recalculate the mean (in-precip.) of the hydrometeor in the 2nd PDF
2375 : ! component.
2376 : mu_hm_2(i,k) = ( hmm(i,k) - mixt_frac(i,k) * precip_frac_1(i,k) * mu_hm_1(i,k) ) &
2377 0 : / ( ( one - mixt_frac(i,k) ) * precip_frac_2(i,k) )
2378 :
2379 : ! Recalculate the value of R ( sigma_hm_2^2 / mu_hm_2^2 ) in this
2380 : ! scenario.
2381 : ! R = ( <hm'^2> + <hm>^2 - a * f_p_1 * mu_hm_1^2
2382 : ! - ( 1 - a ) * f_p_2 * mu_hm_2^2 )
2383 : ! / ( a * f_p_1 * ( 1 + zeta ) * mu_hm_1^2
2384 : ! + ( 1 - a ) * f_p_2 * mu_hm_2^2 ).
2385 : sigma_hm_2_sqd_on_mu_hm_2_sqd(i,k) &
2386 : = ( hmp2(i,k) + hmm(i,k)**2 - mixt_frac(i,k) * precip_frac_1(i,k) * mu_hm_1(i,k)**2 &
2387 : - ( one - mixt_frac(i,k) ) * precip_frac_2(i,k) * mu_hm_2(i,k)**2 ) &
2388 : / ( mixt_frac(i,k) * precip_frac_1(i,k) &
2389 : * ( one + zeta_vrnce_rat ) * mu_hm_1(i,k)**2 &
2390 0 : + ( one - mixt_frac(i,k) ) * precip_frac_2(i,k) * mu_hm_2(i,k)**2 )
2391 :
2392 : ! Mathematically, this ratio can never be less than 0. In case
2393 : ! numerical round off error produces a negative value in extreme
2394 : ! cases, reset the value of R to 0.
2395 0 : if ( sigma_hm_2_sqd_on_mu_hm_2_sqd(i,k) < zero ) then
2396 0 : sigma_hm_2_sqd_on_mu_hm_2_sqd(i,k) = zero
2397 : end if
2398 :
2399 0 : elseif ( mu_hm_2(i,k) < mu_hm_2_min ) then
2400 :
2401 : ! Set the value of mu_hm_2 to the threshold positive value.
2402 0 : mu_hm_2(i,k) = mu_hm_2_min
2403 :
2404 : ! Recalculate the mean (in-precip.) of the hydrometeor in the 1st PDF
2405 : ! component.
2406 : mu_hm_1(i,k) = ( hmm(i,k) - ( one - mixt_frac(i,k) ) &
2407 : * precip_frac_2(i,k) * mu_hm_2(i,k) ) &
2408 0 : / ( mixt_frac(i,k) * precip_frac_1(i,k) )
2409 :
2410 : ! Recalculate the value of R ( sigma_hm_2^2 / mu_hm_2^2 ) in this
2411 : ! scenario.
2412 : ! R = ( <hm'^2> + <hm>^2 - a * f_p_1 * mu_hm_1^2
2413 : ! - ( 1 - a ) * f_p_2 * mu_hm_2^2 )
2414 : ! / ( a * f_p_1 * ( 1 + zeta ) * mu_hm_1^2
2415 : ! + ( 1 - a ) * f_p_2 * mu_hm_2^2 ).
2416 : sigma_hm_2_sqd_on_mu_hm_2_sqd(i,k) &
2417 : = ( hmp2(i,k) + hmm(i,k)**2 - mixt_frac(i,k) * precip_frac_1(i,k) * mu_hm_1(i,k)**2 &
2418 : - ( one - mixt_frac(i,k) ) * precip_frac_2(i,k) * mu_hm_2(i,k)**2 ) &
2419 : / ( mixt_frac(i,k) * precip_frac_1(i,k) &
2420 : * ( one + zeta_vrnce_rat ) * mu_hm_1(i,k)**2 &
2421 0 : + ( one - mixt_frac(i,k) ) * precip_frac_2(i,k) * mu_hm_2(i,k)**2 )
2422 :
2423 : ! Mathematically, this ratio can never be less than 0. In case
2424 : ! numerical round off error produces a negative value in extreme
2425 : ! cases, reset the value of R to 0.
2426 0 : if ( sigma_hm_2_sqd_on_mu_hm_2_sqd(i,k) < zero ) then
2427 0 : sigma_hm_2_sqd_on_mu_hm_2_sqd(i,k) = zero
2428 : end if
2429 :
2430 : end if
2431 :
2432 : ! Calculate the standard deviation (in-precip.) of the hydrometeor in the
2433 : ! 1st PDF component.
2434 : sigma_hm_1(i,k) = sqrt( sigma_hm_2_sqd_on_mu_hm_2_sqd(i,k) &
2435 : * ( one + zeta_vrnce_rat ) ) &
2436 0 : * mu_hm_1(i,k)
2437 :
2438 : ! Calculate the standard deviation (in-precip.) of the hydrometeor in the
2439 : ! 2nd PDF component.
2440 0 : sigma_hm_2(i,k) = sqrt( sigma_hm_2_sqd_on_mu_hm_2_sqd(i,k) ) * mu_hm_2(i,k)
2441 :
2442 : ! Calculate the mean of the hydrometeor in the 1st PDF component.
2443 0 : hm_1(i,k) = max( mu_hm_1(i,k) * precip_frac_1(i,k), hm_tol )
2444 :
2445 : ! Calculate the mean of the hydrometeor in the 1st PDF component.
2446 0 : hm_2(i,k) = max( mu_hm_2(i,k) * precip_frac_2(i,k), hm_tol )
2447 :
2448 : ! Calculate the ratio of sigma_hm_1^2 / mu_hm_1^2.
2449 0 : sigma_hm_1_sqd_on_mu_hm_1_sqd(i,k) = sigma_hm_1(i,k)**2 / mu_hm_1(i,k)**2
2450 :
2451 : ! The value of R, sigma_hm_2_sqd_on_mu_hm_2_sqd, has already been
2452 : ! calculated.
2453 :
2454 :
2455 0 : elseif ( hmm(i,k) >= hm_tol .and. precip_frac_1(i,k) >= precip_frac_tol(i) ) then
2456 :
2457 : ! Precipitation is found in the 1st PDF component, but not in the 2nd
2458 : ! PDF component (precip_frac_2 = 0).
2459 0 : mu_hm_1(i,k) = hmm(i,k) / ( mixt_frac(i,k) * precip_frac_1(i,k) )
2460 0 : mu_hm_2(i,k) = zero
2461 :
2462 : sigma_hm_1(i,k) = sqrt( max( ( hmp2(i,k) + hmm(i,k)**2 &
2463 : - mixt_frac(i,k) * precip_frac_1(i,k) * mu_hm_1(i,k)**2 ) &
2464 : / ( mixt_frac(i,k) * precip_frac_1(i,k) ), &
2465 0 : zero ) )
2466 0 : sigma_hm_2(i,k) = zero
2467 :
2468 0 : hm_1(i,k) = mu_hm_1(i,k) * precip_frac_1(i,k)
2469 0 : hm_2(i,k) = zero
2470 :
2471 0 : sigma_hm_1_sqd_on_mu_hm_1_sqd(i,k) = sigma_hm_1(i,k)**2 / mu_hm_1(i,k)**2
2472 : ! The ratio sigma_hm_2^2 / mu_hm_2^2 is undefined.
2473 0 : sigma_hm_2_sqd_on_mu_hm_2_sqd(i,k) = zero
2474 :
2475 :
2476 0 : elseif ( hmm(i,k) >= hm_tol .and. precip_frac_2(i,k) >= precip_frac_tol(i) ) then
2477 :
2478 : ! Precipitation is found in the 2nd PDF component, but not in the 1st
2479 : ! PDF component (precip_frac_1 = 0).
2480 0 : mu_hm_1(i,k) = zero
2481 0 : mu_hm_2(i,k) = hmm(i,k) / ( ( one - mixt_frac(i,k) ) * precip_frac_2(i,k) )
2482 :
2483 0 : sigma_hm_1(i,k) = zero
2484 : sigma_hm_2(i,k) &
2485 : = sqrt( max( ( hmp2(i,k) + hmm(i,k)**2 &
2486 : - ( one - mixt_frac(i,k) ) * precip_frac_2(i,k) * mu_hm_2(i,k)**2 ) &
2487 : / ( ( one - mixt_frac(i,k) ) * precip_frac_2(i,k) ), &
2488 0 : zero ) )
2489 :
2490 0 : hm_1(i,k) = zero
2491 0 : hm_2(i,k) = mu_hm_2(i,k) * precip_frac_2(i,k)
2492 :
2493 : ! The ratio sigma_hm_1^2 / mu_hm_1^2 is undefined.
2494 0 : sigma_hm_1_sqd_on_mu_hm_1_sqd(i,k) = zero
2495 0 : sigma_hm_2_sqd_on_mu_hm_2_sqd(i,k) = sigma_hm_2(i,k)**2 / mu_hm_2(i,k)**2
2496 :
2497 :
2498 : else ! hm < hm_tol or ( precip_frac_1 = 0 and precip_frac_2 = 0 ).
2499 :
2500 : ! Precipitation is not found in either PDF component.
2501 0 : mu_hm_1(i,k) = zero
2502 0 : mu_hm_2(i,k) = zero
2503 :
2504 0 : sigma_hm_1(i,k) = zero
2505 0 : sigma_hm_2(i,k) = zero
2506 :
2507 0 : hm_1(i,k) = zero
2508 0 : hm_2(i,k) = zero
2509 :
2510 : ! The ratio sigma_hm_1^2 / mu_hm_1^2 is undefined.
2511 0 : sigma_hm_1_sqd_on_mu_hm_1_sqd(i,k) = zero
2512 : ! The ratio sigma_hm_2^2 / mu_hm_2^2 is undefined.
2513 0 : sigma_hm_2_sqd_on_mu_hm_2_sqd(i,k) = zero
2514 :
2515 :
2516 : end if ! hmm >= hm_tol and precip_frac_1 >= precip_frac_tol
2517 : ! and precip_frac_2 >= precip_frac_tol
2518 : end do
2519 : end do
2520 :
2521 0 : return
2522 :
2523 : end subroutine calc_comp_mu_sigma_hm
2524 :
2525 : !=============================================================================
2526 0 : subroutine component_corr_w_x( nz, ngrdcol, &
2527 0 : rc_1, &
2528 0 : rc_2, &
2529 : corr_w_x_NN_cloud, corr_w_x_NN_below, &
2530 : iiPDF_type, &
2531 0 : corr_w_x_1, &
2532 0 : corr_w_x_2 )
2533 :
2534 : ! Description:
2535 : ! Calculates the correlation of w and x within the ith PDF component.
2536 : ! Here, x is a variable with a normally distributed individual marginal PDF,
2537 : ! such as chi or eta.
2538 :
2539 : ! References:
2540 : !-----------------------------------------------------------------------
2541 :
2542 : use constants_clubb, only: &
2543 : zero, &
2544 : rc_tol
2545 :
2546 : use model_flags, only: &
2547 : iiPDF_ADG1, & ! Variable(s)
2548 : iiPDF_ADG2, &
2549 : iiPDF_new_hybrid
2550 :
2551 : use clubb_precision, only: &
2552 : core_rknd ! Variable(s)
2553 :
2554 : implicit none
2555 :
2556 : ! Input Variables
2557 : integer, intent(in) :: &
2558 : nz, & ! Number of model vertical grid levels
2559 : ngrdcol ! Number of grid columns
2560 :
2561 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(in) :: &
2562 : rc_1, & ! Mean cloud water mixing ratio (1st PDF comp.) [kg/kg]
2563 : rc_2 ! Mean cloud water mixing ratio (2nd PDF comp.) [kg/kg]
2564 :
2565 : real( kind = core_rknd ), intent(in) :: &
2566 : corr_w_x_NN_cloud, & ! Corr. of w and x (ith PDF comp.); cloudy levs [-]
2567 : corr_w_x_NN_below ! Corr. of w and x (ith PDF comp.); clear levs [-]
2568 :
2569 : integer, intent(in) :: &
2570 : iiPDF_type ! Selected option for the two-component normal (double
2571 : ! Gaussian) PDF type to use for the w, rt, and theta-l (or
2572 : ! w, chi, and eta) portion of CLUBB's multivariate,
2573 : ! two-component PDF.
2574 :
2575 : ! Output Variable
2576 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(out) :: &
2577 : corr_w_x_1, & ! Correlation of w and x (1st PDF component) [-]
2578 : corr_w_x_2 ! Correlation of w and x (2nd PDF component) [-]
2579 :
2580 : ! Local Variables
2581 : integer :: i, k
2582 :
2583 : ! Correlation of w and x in the ith PDF component.
2584 :
2585 : ! The PDF variables chi and eta result from a transformation of the PDF
2586 : ! involving r_t and theta_l. The correlation of w and x (whether x is chi
2587 : ! or eta) depends on the correlation of w and r_t, the correlation of w and
2588 : ! theta_l, as well as the variances of r_t and theta_l, and other factors.
2589 : ! The correlation of w and x is subject to change at every vertical level
2590 : ! and model time step, and is calculated as part of the CLUBB PDF
2591 : ! parameters.
2592 :
2593 : ! The ADG1 PDF fixes the correlation of w and rt and the correlation of
2594 : ! w and theta_l to be 0, which means the correlation of w and chi and the
2595 : ! correlation of w and eta must also be 0.
2596 : if ( ( iiPDF_type == iiPDF_ADG1 .or. iiPDF_type == iiPDF_ADG2 &
2597 : .or. iiPDF_type == iiPDF_new_hybrid ) &
2598 0 : .and. l_follow_ADG1_PDF_standards ) then
2599 :
2600 0 : corr_w_x_1(:,:) = zero
2601 0 : corr_w_x_2(:,:) = zero
2602 :
2603 : else ! use prescribed paramter values
2604 :
2605 0 : do k = 1, nz
2606 0 : do i = 1, ngrdcol
2607 :
2608 0 : if ( rc_1(i,k) > rc_tol ) then
2609 0 : corr_w_x_1(i,k) = corr_w_x_NN_cloud
2610 : else
2611 0 : corr_w_x_1(i,k) = corr_w_x_NN_below
2612 : end if
2613 :
2614 0 : if ( rc_2(i,k) > rc_tol ) then
2615 0 : corr_w_x_2(i,k) = corr_w_x_NN_cloud
2616 : else
2617 0 : corr_w_x_2(i,k) = corr_w_x_NN_below
2618 : end if
2619 :
2620 : end do
2621 : end do
2622 :
2623 : end if ! iiPDF_type
2624 :
2625 0 : return
2626 :
2627 : end subroutine component_corr_w_x
2628 :
2629 : !=============================================================================
2630 0 : subroutine component_corr_chi_eta( nz, ngrdcol, &
2631 0 : rc_1, &
2632 0 : rc_2, &
2633 : corr_chi_eta_NN_cloud, &
2634 : corr_chi_eta_NN_below, &
2635 : l_limit_corr_chi_eta, &
2636 0 : corr_chi_eta_1, &
2637 0 : corr_chi_eta_2 )
2638 :
2639 : ! Description:
2640 : ! Calculates the correlation of chi (old s) and eta (old t) within the
2641 : ! ith PDF component.
2642 :
2643 : ! References:
2644 : !-----------------------------------------------------------------------
2645 :
2646 : use constants_clubb, only: &
2647 : rc_tol, &
2648 : max_mag_correlation
2649 :
2650 : use clubb_precision, only: &
2651 : core_rknd ! Constant
2652 :
2653 : implicit none
2654 :
2655 : ! Input Variables
2656 : integer, intent(in) :: &
2657 : nz, & ! Number of model vertical grid levels
2658 : ngrdcol ! Number of grid columns
2659 :
2660 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(in) :: &
2661 : rc_1, & ! Mean cloud water mix. rat. (1st PDF comp.) [kg/kg]&
2662 : rc_2 ! Mean cloud water mix. rat. (2nd PDF comp.) [kg/kg]
2663 :
2664 : real( kind = core_rknd ), intent(in) :: &
2665 : corr_chi_eta_NN_cloud, & ! Corr. of chi & eta (ith PDF comp.); cloudy [-]
2666 : corr_chi_eta_NN_below ! Corr. of chi & eta (ith PDF comp.); clear [-]
2667 :
2668 : logical, intent(in) :: &
2669 : l_limit_corr_chi_eta ! We must limit the correlation of chi and eta if
2670 : ! we are to take the Cholesky decomposition of the
2671 : ! resulting correlation matrix. This is because a
2672 : ! perfect correlation of chi and eta was found to
2673 : ! be unrealizable.
2674 :
2675 : ! Output Variable
2676 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(out) :: &
2677 : corr_chi_eta_1, & ! Correlation of chi and eta (1st PDF component) [-]
2678 : corr_chi_eta_2 ! Correlation of chi and eta (2nd PDF component) [-]
2679 :
2680 : ! Local Variables
2681 : integer :: i, k
2682 :
2683 : ! Correlation of chi (old s) and eta (old t) in the ith PDF component.
2684 :
2685 : ! The PDF variables chi and eta result from a transformation of the PDF
2686 : ! involving r_t and theta_l. The correlation of chi and eta depends on the
2687 : ! correlation of r_t and theta_l, as well as the variances of r_t and
2688 : ! theta_l, and other factors. The correlation of chi and eta is subject to
2689 : ! change at every vertical level and model time step, and is calculated as
2690 : ! part of the CLUBB PDF parameters.
2691 :
2692 : ! WARNING: this code is inconsistent with the rest of CLUBB's PDF. This
2693 : ! code is necessary because SILHS is lazy and wussy, and only
2694 : ! wants to declare correlation arrays at the start of the model
2695 : ! run, rather than updating them throughout the model run.
2696 :
2697 :
2698 0 : do k = 1, nz
2699 0 : do i = 1, ngrdcol
2700 :
2701 0 : if ( rc_1(i,k) > rc_tol ) then
2702 0 : corr_chi_eta_1(i,k) = corr_chi_eta_NN_cloud
2703 : else
2704 0 : corr_chi_eta_1(i,k) = corr_chi_eta_NN_below
2705 : end if
2706 : end do
2707 : end do
2708 :
2709 0 : do k = 1, nz
2710 0 : do i = 1, ngrdcol
2711 0 : if ( rc_2(i,k) > rc_tol ) then
2712 0 : corr_chi_eta_2(i,k) = corr_chi_eta_NN_cloud
2713 : else
2714 0 : corr_chi_eta_2(i,k) = corr_chi_eta_NN_below
2715 : end if
2716 : end do
2717 : end do
2718 :
2719 :
2720 :
2721 : ! We cannot have a perfect correlation of chi (old s) and eta (old t) if we
2722 : ! plan to decompose this matrix and we don't want the Cholesky_factor code
2723 : ! to throw a fit.
2724 0 : if ( l_limit_corr_chi_eta ) then
2725 :
2726 0 : do k = 1, nz
2727 0 : do i = 1, ngrdcol
2728 0 : corr_chi_eta_1(i,k) = max( min( corr_chi_eta_1(i,k), max_mag_correlation ), &
2729 0 : -max_mag_correlation )
2730 : end do
2731 : end do
2732 :
2733 0 : do k = 1, nz
2734 0 : do i = 1, ngrdcol
2735 0 : corr_chi_eta_2(i,k) = max( min( corr_chi_eta_2(i,k), max_mag_correlation ), &
2736 0 : -max_mag_correlation )
2737 : end do
2738 : end do
2739 :
2740 : end if
2741 :
2742 0 : return
2743 :
2744 : end subroutine component_corr_chi_eta
2745 :
2746 : !=============================================================================
2747 0 : subroutine component_corr_w_hm_n_ip( nz, ngrdcol, &
2748 0 : corr_w_hm_1_n_in, rc_1, &
2749 0 : corr_w_hm_2_n_in, rc_2, &
2750 : corr_w_hm_n_NL_cloud, &
2751 : corr_w_hm_n_NL_below, &
2752 : l_calc_w_corr, &
2753 0 : corr_w_hm_1_n, &
2754 0 : corr_w_hm_2_n )
2755 :
2756 : ! Description:
2757 : ! Calculates the in-precip correlation of w and the natural logarithm of a
2758 : ! hydrometeor species within the ith PDF component.
2759 :
2760 : ! References:
2761 : !-----------------------------------------------------------------------
2762 :
2763 : use constants_clubb, only: &
2764 : rc_tol
2765 :
2766 : use clubb_precision, only: &
2767 : core_rknd ! Variable(s)
2768 :
2769 : implicit none
2770 :
2771 : ! Input Variables
2772 : integer, intent(in) :: &
2773 : nz, & ! Number of model vertical grid levels
2774 : ngrdcol ! Number of grid columns
2775 :
2776 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(in) :: &
2777 : corr_w_hm_1_n_in, & ! Correlation of w and ln hm (1st PDF comp.) ip [-]
2778 : corr_w_hm_2_n_in, & ! Correlation of w and ln hm (2nd PDF comp.) ip [-]
2779 : rc_1, & ! Mean cloud water mix. ratio (1st PDF comp.) [kg/kg]
2780 : rc_2 ! Mean cloud water mix. ratio (2nd PDF comp.) [kg/kg]
2781 :
2782 : real( kind = core_rknd ), intent(in) :: &
2783 : corr_w_hm_n_NL_cloud, & ! Corr. of w & ln hm (ith PDF comp.) ip; cloud [-]
2784 : corr_w_hm_n_NL_below ! Corr. of w & ln hm (ith PDF comp.) ip; clear [-]
2785 :
2786 : logical, intent(in) :: &
2787 : l_calc_w_corr ! Calculate the correlations between w and the hydrometeors
2788 :
2789 : ! Output Variables
2790 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(out) :: &
2791 : corr_w_hm_1_n, & ! Correlation of w and ln hm (1st PDF component) ip [-]
2792 : corr_w_hm_2_n ! Correlation of w and ln hm (2nd PDF component) ip [-]
2793 :
2794 : ! Local Variables
2795 : integer :: i, k
2796 :
2797 :
2798 : ! Correlation (in-precip) of w and the natural logarithm of the hydrometeor
2799 : ! in the ith PDF component.
2800 0 : if ( l_calc_w_corr ) then
2801 :
2802 0 : corr_w_hm_1_n(:,:) = corr_w_hm_1_n_in(:,:)
2803 0 : corr_w_hm_2_n(:,:) = corr_w_hm_2_n_in(:,:)
2804 :
2805 :
2806 : else
2807 :
2808 0 : do k = 1, nz
2809 0 : do i = 1, ngrdcol
2810 :
2811 0 : if ( rc_1(i,k) > rc_tol ) then
2812 0 : corr_w_hm_1_n(i,k) = corr_w_hm_n_NL_cloud
2813 : else
2814 0 : corr_w_hm_1_n(i,k) = corr_w_hm_n_NL_below
2815 : end if
2816 :
2817 0 : if ( rc_2(i,k) > rc_tol ) then
2818 0 : corr_w_hm_2_n(i,k) = corr_w_hm_n_NL_cloud
2819 : else
2820 0 : corr_w_hm_2_n(i,k) = corr_w_hm_n_NL_below
2821 : end if
2822 : end do
2823 : end do
2824 :
2825 : end if ! l_calc_w_corr
2826 :
2827 0 : return
2828 :
2829 : end subroutine component_corr_w_hm_n_ip
2830 :
2831 : !=============================================================================
2832 0 : subroutine component_corr_x_hm_n_ip( nz, ngrdcol, &
2833 0 : rc_1, &
2834 0 : rc_2, &
2835 : corr_x_hm_n_NL_cloud, &
2836 : corr_x_hm_n_NL_below, &
2837 0 : corr_x_hm_1_n, &
2838 0 : corr_x_hm_2_n )
2839 :
2840 : ! Description:
2841 : ! Calculates the in-precip correlation of x and a hydrometeor species
2842 : ! within the ith PDF component. Here, x is a variable with a normally
2843 : ! distributed individual marginal PDF, such as chi or eta.
2844 :
2845 : ! References:
2846 : !-----------------------------------------------------------------------
2847 :
2848 : use constants_clubb, only: &
2849 : rc_tol
2850 :
2851 : use clubb_precision, only: &
2852 : core_rknd ! Variable(s)
2853 :
2854 : implicit none
2855 :
2856 : ! Input Variables
2857 : integer, intent(in) :: &
2858 : nz, & ! Number of model vertical grid levels
2859 : ngrdcol ! Number of grid columns
2860 :
2861 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(in) :: &
2862 : rc_1, & ! Mean cloud water mixing ratio (1st PDF comp.) [kg/kg]
2863 : rc_2 ! Mean cloud water mixing ratio (2nd PDF comp.) [kg/kg]
2864 :
2865 :
2866 : real( kind = core_rknd ), intent(in) :: &
2867 : corr_x_hm_n_NL_cloud, & ! Corr. of x and ln hm (ith PDF comp.) ip [-]
2868 : corr_x_hm_n_NL_below ! Corr. of x and ln hm (ith PDF comp.) ip [-]
2869 :
2870 : ! Output Variables
2871 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(out) :: &
2872 : corr_x_hm_1_n, & ! Correlation of x and ln hm (1st PDF component) ip [-]
2873 : corr_x_hm_2_n ! Correlation of x and ln hm (2nd PDF component) ip [-]
2874 :
2875 : ! Local Variables
2876 : integer :: i, k
2877 :
2878 0 : do k = 1, nz
2879 0 : do i = 1, ngrdcol
2880 :
2881 0 : if ( rc_1(i,k) > rc_tol ) then
2882 0 : corr_x_hm_1_n(i,k) = corr_x_hm_n_NL_cloud
2883 : else
2884 0 : corr_x_hm_1_n(i,k) = corr_x_hm_n_NL_below
2885 : end if
2886 :
2887 0 : if ( rc_2(i,k) > rc_tol ) then
2888 0 : corr_x_hm_2_n(i,k) = corr_x_hm_n_NL_cloud
2889 : else
2890 0 : corr_x_hm_2_n(i,k) = corr_x_hm_n_NL_below
2891 : end if
2892 :
2893 : end do
2894 : end do
2895 :
2896 0 : return
2897 :
2898 : end subroutine component_corr_x_hm_n_ip
2899 :
2900 : !=============================================================================
2901 0 : subroutine component_corr_hmx_hmy_n_ip( nz, ngrdcol, &
2902 0 : rc_1, &
2903 0 : rc_2, &
2904 : corr_hmx_hmy_n_LL_cloud, &
2905 : corr_hmx_hmy_n_LL_below, &
2906 0 : corr_hmx_hmy_1_n, &
2907 0 : corr_hmx_hmy_2_n )
2908 :
2909 : ! Description:
2910 : ! Calculates the in-precip correlation of the natural logarithms of
2911 : ! hydrometeor x and hydrometeor y within the ith PDF component.
2912 :
2913 : ! References:
2914 : !-----------------------------------------------------------------------
2915 :
2916 : use constants_clubb, only: &
2917 : rc_tol
2918 :
2919 : use clubb_precision, only: &
2920 : core_rknd ! Variable(s)
2921 :
2922 : implicit none
2923 :
2924 : ! Input Variables
2925 : integer, intent(in) :: &
2926 : nz, & ! Number of model vertical grid levels
2927 : ngrdcol ! Number of grid columns
2928 :
2929 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(in) :: &
2930 : rc_1, & ! Mean cloud water mixing ratio (ith PDF comp.) [kg/kg]
2931 : rc_2 ! Mean cloud water mixing ratio (ith PDF comp.) [kg/kg]
2932 :
2933 : real( kind = core_rknd ), intent(in) :: &
2934 : corr_hmx_hmy_n_LL_cloud, & ! Corr.: ln hmx & ln hmy (ith PDF comp.) ip [-]
2935 : corr_hmx_hmy_n_LL_below ! Corr.: ln hmx & ln hmy (ith PDF comp.) ip [-]
2936 :
2937 : ! Output Variable
2938 : real( kind = core_rknd ), dimension(ngrdcol,nz) :: &
2939 : corr_hmx_hmy_1_n, & ! Corr. of ln hmx & ln hmy (ith PDF comp.) ip [-]
2940 : corr_hmx_hmy_2_n ! Corr. of ln hmx & ln hmy (ith PDF comp.) ip [-]
2941 :
2942 : ! Local Variable
2943 : integer :: i, k
2944 :
2945 :
2946 : ! Correlation (in-precip) of the natural logarithms of hydrometeor x and
2947 : ! hydrometeor y in the ith PDF component.
2948 0 : do k = 1, nz
2949 0 : do i = 1, ngrdcol
2950 :
2951 0 : if ( rc_1(i,k) > rc_tol ) then
2952 0 : corr_hmx_hmy_1_n(i,k) = corr_hmx_hmy_n_LL_cloud
2953 : else
2954 0 : corr_hmx_hmy_1_n(i,k) = corr_hmx_hmy_n_LL_below
2955 : end if
2956 :
2957 0 : if ( rc_2(i,k) > rc_tol ) then
2958 0 : corr_hmx_hmy_2_n(i,k) = corr_hmx_hmy_n_LL_cloud
2959 : else
2960 0 : corr_hmx_hmy_2_n(i,k) = corr_hmx_hmy_n_LL_below
2961 : end if
2962 :
2963 : end do
2964 : end do
2965 :
2966 0 : return
2967 :
2968 : end subroutine component_corr_hmx_hmy_n_ip
2969 :
2970 : !=============================================================================
2971 0 : subroutine component_corr_eta_hm_n_ip( nz, ngrdcol, &
2972 0 : corr_chi_eta_1, &
2973 0 : corr_chi_hm_n_1, &
2974 0 : corr_chi_eta_2, &
2975 0 : corr_chi_hm_n_2, &
2976 0 : corr_eta_hm_n_1, &
2977 0 : corr_eta_hm_n_2)
2978 : ! Description:
2979 : ! Estimates the correlation of eta and the natural logarithm of a
2980 : ! hydrometeor species using the correlation of chi and eta and the
2981 : ! correlation of chi and the natural logarithm of the hydrometeor. This
2982 : ! facilities the Cholesky decomposability of the correlation array that will
2983 : ! inevitably be decomposed for SILHS purposes. Without this estimation, we
2984 : ! have found that the resulting correlation matrix cannot be decomposed.
2985 :
2986 : ! References:
2987 : !-----------------------------------------------------------------------
2988 :
2989 : use clubb_precision, only: &
2990 : core_rknd ! Constant
2991 :
2992 : implicit none
2993 :
2994 : ! Input Variables
2995 : integer, intent(in) :: &
2996 : nz, & ! Number of model vertical grid levels
2997 : ngrdcol ! Number of grid columns
2998 :
2999 :
3000 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(in) :: &
3001 : corr_chi_eta_1, & ! Component correlation of chi and eta [-]
3002 : corr_chi_eta_2, & ! Component correlation of chi and eta [-]
3003 : corr_chi_hm_n_1, & ! Component correlation of chi and ln hm [-]
3004 : corr_chi_hm_n_2 ! Component correlation of chi and ln hm [-]
3005 :
3006 : ! Output Variables
3007 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(out) :: &
3008 : corr_eta_hm_n_1, & ! Component correlation of eta and ln hm [-]
3009 : corr_eta_hm_n_2 ! Component correlation of eta and ln hm [-]
3010 :
3011 :
3012 0 : corr_eta_hm_n_1 = corr_chi_eta_1 * corr_chi_hm_n_1
3013 0 : corr_eta_hm_n_2 = corr_chi_eta_2 * corr_chi_hm_n_2
3014 :
3015 :
3016 0 : return
3017 :
3018 : end subroutine component_corr_eta_hm_n_ip
3019 :
3020 : !=============================================================================
3021 0 : subroutine norm_transform_mean_stdev( nz, ngrdcol, &
3022 0 : hm_1, hm_2, &
3023 0 : Ncnm, pdf_dim, &
3024 0 : mu_x_1, mu_x_2, &
3025 0 : sigma_x_1, sigma_x_2, &
3026 0 : sigma2_on_mu2_ip_1, &
3027 0 : sigma2_on_mu2_ip_2, &
3028 : l_const_Nc_in_cloud, &
3029 0 : mu_x_1_n, mu_x_2_n, &
3030 0 : sigma_x_1_n, sigma_x_2_n )
3031 :
3032 : ! Description:
3033 : ! Transforms the means and the standard deviations of PDF variables that
3034 : ! have assumed lognormal distributions -- which are precipitating
3035 : ! hydrometeors (in precipitation) and N_cn -- to normal space for each PDF
3036 : ! component.
3037 :
3038 : ! References:
3039 : !-----------------------------------------------------------------------
3040 :
3041 : use constants_clubb, only: &
3042 : Ncn_tol, & ! Constant(s)
3043 : zero
3044 :
3045 : use pdf_utilities, only: &
3046 : mean_L2N, & ! Procedure(s)
3047 : stdev_L2N
3048 :
3049 : use index_mapping, only: &
3050 : pdf2hydromet_idx ! Procedure(s)
3051 :
3052 : use array_index, only: &
3053 : iiPDF_w, &
3054 : iiPDF_chi, &
3055 : iiPDF_eta, &
3056 : iiPDF_Ncn, & ! Variable(s)
3057 : hydromet_tol ! Variable(s)
3058 :
3059 : use parameters_model, only: &
3060 : hydromet_dim ! Variable(s)
3061 :
3062 : use clubb_precision, only: &
3063 : core_rknd ! Variable(s)
3064 :
3065 : implicit none
3066 :
3067 : ! Input Variables
3068 : integer, intent(in) :: &
3069 : nz, & ! Number of model vertical grid levels
3070 : pdf_dim, & ! Number of variables in CLUBB's PDF
3071 : ngrdcol ! Number of grid columns
3072 :
3073 : real( kind = core_rknd ), dimension(ngrdcol,nz,hydromet_dim), intent(in) :: &
3074 : hm_1, & ! Mean of a precip. hydrometeor (1st PDF component) [units vary]
3075 : hm_2 ! Mean of a precip. hydrometeor (2nd PDF component) [units vary]
3076 :
3077 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(in) :: &
3078 : Ncnm ! Mean cloud nuclei concentration, < N_cn > [num/kg]
3079 :
3080 : real( kind = core_rknd ), dimension(ngrdcol,nz,pdf_dim), intent(in) :: &
3081 : mu_x_1, & ! Mean array of PDF vars. (1st PDF component) [units vary]
3082 : mu_x_2, & ! Mean array of PDF vars. (2nd PDF component) [units vary]
3083 : sigma_x_1, & ! Standard deviation array of PDF vars (comp. 1) [units vary]
3084 : sigma_x_2 ! Standard deviation array of PDF vars (comp. 2) [units vary]
3085 :
3086 : real( kind = core_rknd ), dimension(ngrdcol,nz,pdf_dim), intent(in) :: &
3087 : sigma2_on_mu2_ip_1, & ! Prescribed ratio array: sigma_hm_1^2/mu_hm_1^2 [-]
3088 : sigma2_on_mu2_ip_2 ! Prescribed ratio array: sigma_hm_2^2/mu_hm_2^2 [-]
3089 :
3090 : logical, intent(in) :: &
3091 : l_const_Nc_in_cloud ! Use a constant cloud droplet conc. within cloud (K&K)
3092 :
3093 : ! Output Variables
3094 : real( kind = core_rknd ), dimension(ngrdcol,nz,pdf_dim), intent(out) :: &
3095 : mu_x_1_n, & ! Mean array (normal space): PDF vars. (comp. 1) [un. vary]
3096 : mu_x_2_n, & ! Mean array (normal space): PDF vars. (comp. 2) [un. vary]
3097 : sigma_x_1_n, & ! Std. dev. array (normal space): PDF vars (comp. 1) [u.v.]
3098 : sigma_x_2_n ! Std. dev. array (normal space): PDF vars (comp. 2) [u.v.]
3099 :
3100 : ! Local Variable
3101 : integer :: ivar, hm_idx, k, i ! Indices
3102 :
3103 :
3104 : ! The means and standard deviations in each PDF component of w, chi (old s),
3105 : ! and eta (old t) do not need to be transformed to normal space, since w,
3106 : ! chi, and eta already follow assumed normal distributions in each PDF
3107 : ! component. The normal space means and standard deviations are the same as
3108 : ! the actual means and standard deviations.
3109 0 : do k = 1, nz
3110 0 : mu_x_1_n(:,k,iiPDF_chi) = mu_x_1(:,k,iiPDF_chi)
3111 0 : mu_x_1_n(:,k,iiPDF_eta) = mu_x_1(:,k,iiPDF_eta)
3112 0 : mu_x_1_n(:,k,iiPDF_w) = mu_x_1(:,k,iiPDF_w)
3113 : end do
3114 :
3115 0 : do k = 1, nz
3116 0 : mu_x_2_n(:,k,iiPDF_chi) = mu_x_2(:,k,iiPDF_chi)
3117 0 : mu_x_2_n(:,k,iiPDF_eta) = mu_x_2(:,k,iiPDF_eta)
3118 0 : mu_x_2_n(:,k,iiPDF_w) = mu_x_2(:,k,iiPDF_w)
3119 : end do
3120 :
3121 0 : do k = 1, nz
3122 0 : sigma_x_1_n(:,k,iiPDF_chi) = sigma_x_1(:,k,iiPDF_chi)
3123 0 : sigma_x_1_n(:,k,iiPDF_eta) = sigma_x_1(:,k,iiPDF_eta)
3124 0 : sigma_x_1_n(:,k,iiPDF_w) = sigma_x_1(:,k,iiPDF_w)
3125 : end do
3126 :
3127 0 : do k = 1, nz
3128 0 : sigma_x_2_n(:,k,iiPDF_chi) = sigma_x_2(:,k,iiPDF_chi)
3129 0 : sigma_x_2_n(:,k,iiPDF_eta) = sigma_x_2(:,k,iiPDF_eta)
3130 0 : sigma_x_2_n(:,k,iiPDF_w) = sigma_x_2(:,k,iiPDF_w)
3131 : end do
3132 :
3133 : !!! Transform the mean and standard deviation to normal space in each PDF
3134 : !!! component for variables that have an assumed lognormal distribution,
3135 : !!! given the mean and standard deviation in each PDF component for those
3136 : !!! variables. A precipitating hydrometeor has an assumed lognormal
3137 : !!! distribution in precipitation in each PDF component. Simplified cloud
3138 : !!! nuclei concentration, N_cn, has an assumed lognormal distribution in
3139 : !!! each PDF component, and furthermore, mu_Ncn_1 = mu_Ncn_2 and
3140 : !!! sigma_Ncn_1 = sigma_Ncn_2, so N_cn has an assumed single lognormal
3141 : !!! distribution over the entire domain.
3142 :
3143 : ! Normal space mean of simplified cloud nuclei concentration, N_cn,
3144 : ! in PDF component 1.
3145 0 : do k = 1, nz
3146 0 : do i = 1, ngrdcol
3147 :
3148 0 : if ( Ncnm(i,k) >= Ncn_tol ) then
3149 :
3150 0 : mu_x_1_n(i,k,iiPDF_Ncn) = mean_L2N( mu_x_1(i,k,iiPDF_Ncn), &
3151 0 : sigma2_on_mu2_ip_1(i,k,iiPDF_Ncn) )
3152 :
3153 : else
3154 :
3155 : ! Mean simplified cloud nuclei concentration in PDF component 1 is less
3156 : ! than the tolerance amount. It is considered to have a value of 0.
3157 : ! There are not any cloud nuclei or cloud at this grid level. The value
3158 : ! of mu_Ncn_1_n should be -inf. It will be set to -huge for purposes of
3159 : ! assigning it a value.
3160 0 : mu_x_1_n(i,k,iiPDF_Ncn) = -huge( mu_x_1(i,k,iiPDF_Ncn) )
3161 :
3162 : end if
3163 :
3164 : end do
3165 : end do
3166 :
3167 : ! Normal space mean of simplified cloud nuclei concentration, N_cn,
3168 : ! in PDF component 2.
3169 0 : do k = 1, nz
3170 0 : do i = 1, ngrdcol
3171 :
3172 0 : if ( Ncnm(i,k) >= Ncn_tol ) then
3173 :
3174 0 : mu_x_2_n(i,k,iiPDF_Ncn) = mean_L2N( mu_x_2(i,k,iiPDF_Ncn), &
3175 0 : sigma2_on_mu2_ip_1(i,k,iiPDF_Ncn) )
3176 :
3177 : else
3178 :
3179 : ! Mean simplified cloud nuclei concentration in PDF component 1 is less
3180 : ! than the tolerance amount. It is considered to have a value of 0.
3181 : ! There are not any cloud nuclei or cloud at this grid level. The value
3182 : ! of mu_Ncn_1_n should be -inf. It will be set to -huge for purposes of
3183 : ! assigning it a value.
3184 0 : mu_x_2_n(i,k,iiPDF_Ncn) = -huge( mu_x_2(i,k,iiPDF_Ncn) )
3185 :
3186 : end if
3187 :
3188 : end do
3189 : end do
3190 :
3191 : ! Normal space standard deviation of simplified cloud nuclei concentration,
3192 : ! N_cn, in PDF components 1 and 2.
3193 0 : if ( l_const_Nc_in_cloud ) then
3194 : ! Ncn does not vary in the grid box.
3195 0 : sigma_x_1_n(:,:,iiPDF_Ncn) = zero
3196 0 : sigma_x_2_n(:,:,iiPDF_Ncn) = zero
3197 : else
3198 : ! Ncn (perhaps) varies in the grid box.
3199 0 : sigma_x_1_n(:,:,iiPDF_Ncn) = stdev_L2N( sigma2_on_mu2_ip_1(:,:,iiPDF_Ncn) )
3200 0 : sigma_x_2_n(:,:,iiPDF_Ncn) = stdev_L2N( sigma2_on_mu2_ip_2(:,:,iiPDF_Ncn) )
3201 : end if
3202 :
3203 : ! Normal space precipitating hydrometeor means and standard deviations.
3204 0 : do ivar = iiPDF_Ncn+1, pdf_dim, 1
3205 :
3206 0 : hm_idx = pdf2hydromet_idx(ivar)
3207 :
3208 : ! Normal space mean of a precipitating hydrometeor, hm, in PDF
3209 : ! component 1.
3210 0 : do k = 1, nz
3211 0 : do i = 1, ngrdcol
3212 :
3213 0 : if ( hm_1(i,k,hm_idx) >= hydromet_tol(hm_idx) ) then
3214 :
3215 0 : mu_x_1_n(i,k,ivar) = mean_L2N( mu_x_1(i,k,ivar), &
3216 0 : sigma2_on_mu2_ip_1(i,k,ivar) )
3217 :
3218 : else
3219 :
3220 : ! The mean of a precipitating hydrometeor in PDF component 1 is less
3221 : ! than its tolerance amount. It is considered to have a value of 0.
3222 : ! There is not any of this precipitating hydrometeor in the 1st PDF
3223 : ! component at this grid level. The in-precip mean of this
3224 : ! precipitating hydrometeor (1st PDF component) is also 0. The value
3225 : ! of mu_hm_1_n should be -inf. It will be set to -huge for purposes
3226 : ! of assigning it a value.
3227 0 : mu_x_1_n(i,k,ivar) = -huge( mu_x_1(i,k,ivar) )
3228 :
3229 : end if
3230 :
3231 : end do
3232 : end do
3233 :
3234 : ! Normal space standard deviation of a precipitating hydrometeor, hm, in
3235 : ! PDF component 1.
3236 0 : sigma_x_1_n(:,:,ivar) = stdev_L2N( sigma2_on_mu2_ip_1(:,:,ivar) )
3237 :
3238 : ! Normal space mean of a precipitating hydrometeor, hm, in PDF
3239 : ! component 2.
3240 0 : do k = 1, nz
3241 0 : do i = 1, ngrdcol
3242 :
3243 0 : if ( hm_2(i,k,hm_idx) >= hydromet_tol(hm_idx) ) then
3244 :
3245 : mu_x_2_n(i,k,ivar) = mean_L2N( mu_x_2(i,k,ivar), &
3246 0 : sigma2_on_mu2_ip_2(i,k,ivar) )
3247 :
3248 : else
3249 :
3250 : ! The mean of a precipitating hydrometeor in PDF component 2 is less
3251 : ! than its tolerance amount. It is considered to have a value of 0.
3252 : ! There is not any of this precipitating hydrometeor in the 2nd PDF
3253 : ! component at this grid level. The in-precip mean of this
3254 : ! precipitating hydrometeor (2nd PDF component) is also 0. The value
3255 : ! of mu_hm_2_n should be -inf. It will be set to -huge for purposes
3256 : ! of assigning it a value.
3257 0 : mu_x_2_n(i,k,ivar) = -huge( mu_x_2(i,k,ivar) )
3258 :
3259 : end if
3260 :
3261 : end do
3262 : end do
3263 :
3264 : ! Normal space standard deviation of a precipitating hydrometeor, hm, in
3265 : ! PDF component 2.
3266 0 : sigma_x_2_n(:,:,ivar) = stdev_L2N( sigma2_on_mu2_ip_2(:,:,ivar) )
3267 :
3268 : end do ! ivar = iiPDF_Ncn+1, pdf_dim, 1
3269 :
3270 :
3271 0 : return
3272 :
3273 : end subroutine norm_transform_mean_stdev
3274 :
3275 : !=============================================================================
3276 0 : subroutine denorm_transform_corr( nz, ngrdcol, pdf_dim, &
3277 0 : sigma_x_1_n, sigma_x_2_n, &
3278 0 : sigma2_on_mu2_ip_1, sigma2_on_mu2_ip_2, &
3279 0 : corr_array_1_n, &
3280 0 : corr_array_2_n, &
3281 0 : corr_array_1, corr_array_2 )
3282 :
3283 : ! Description:
3284 : ! Calculates the true or "real-space" correlations between PDF variables,
3285 : ! where at least one of the variables that is part of a correlation has an
3286 : ! assumed lognormal distribution -- which are the precipitating hydrometeors
3287 : ! (in precipitation) and N_cn.
3288 :
3289 : ! References:
3290 : !-----------------------------------------------------------------------
3291 :
3292 : use constants_clubb, only : &
3293 : one
3294 :
3295 : use pdf_utilities, only: &
3296 : corr_NN2NL, & ! Procedure(s)
3297 : corr_NN2LL
3298 :
3299 : use array_index, only: &
3300 : iiPDF_chi, & ! Variable(s)
3301 : iiPDF_eta, &
3302 : iiPDF_w, &
3303 : iiPDF_Ncn
3304 :
3305 : use clubb_precision, only: &
3306 : core_rknd ! Variable(s)
3307 :
3308 : implicit none
3309 :
3310 : ! Input Variables
3311 : integer, intent(in) :: &
3312 : nz, & ! Number of vertical levels
3313 : pdf_dim, & ! Number of variables
3314 : ngrdcol ! Number of grid columns
3315 :
3316 : real( kind = core_rknd ), dimension(ngrdcol,nz,pdf_dim), intent(in) :: &
3317 : sigma_x_1_n, & ! Std. dev. array (normal space): PDF vars (comp. 1) [u.v.]
3318 : sigma_x_2_n ! Std. dev. array (normal space): PDF vars (comp. 2) [u.v.]
3319 :
3320 : real( kind = core_rknd ), dimension(ngrdcol,nz,pdf_dim), intent(in) :: &
3321 : sigma2_on_mu2_ip_1, & ! Ratio array sigma_hm_1^2/mu_hm_1^2 [-]
3322 : sigma2_on_mu2_ip_2 ! Ratio array sigma_hm_2^2/mu_hm_2^2 [-]
3323 :
3324 : real( kind = core_rknd ), dimension(ngrdcol,nz,pdf_dim,pdf_dim), &
3325 : intent(in) :: &
3326 : corr_array_1_n, & ! Corr. array (normal space) of PDF vars. (comp. 1) [-]
3327 : corr_array_2_n ! Corr. array (normal space) of PDF vars. (comp. 2) [-]
3328 :
3329 : ! Output Variables
3330 : real( kind = core_rknd ), dimension(ngrdcol,nz,pdf_dim,pdf_dim), &
3331 : intent(out) :: &
3332 : corr_array_1, & ! Correlation array of PDF vars. (comp. 1) [-]
3333 : corr_array_2 ! Correlation array of PDF vars. (comp. 2) [-]
3334 :
3335 : ! Local Variables
3336 : integer :: ivar, jvar ! Loop indices
3337 :
3338 : ! ----------- Begin Code -----------
3339 :
3340 : ! Initialize diagonal elements to one
3341 0 : do ivar = 1, pdf_dim
3342 0 : corr_array_1(:,:,ivar,ivar) = one
3343 0 : corr_array_2(:,:,ivar,ivar) = one
3344 : end do
3345 :
3346 : ! The correlations in each PDF component between two of w, chi (old s), and
3347 : ! eta (old t) do not need to be transformed to standard space, since w, chi,
3348 : ! and eta follow assumed normal distributions in each PDF component. The
3349 : ! normal space correlations between any two of these variables are the same
3350 : ! as the actual correlations.
3351 0 : corr_array_1(:,:,iiPDF_eta,iiPDF_chi) = corr_array_1_n(:,:,iiPDF_eta,iiPDF_chi)
3352 0 : corr_array_1(:,:,iiPDF_w,iiPDF_chi) = corr_array_1_n(:,:,iiPDF_w,iiPDF_chi)
3353 0 : corr_array_1(:,:,iiPDF_w,iiPDF_eta) = corr_array_1_n(:,:,iiPDF_w,iiPDF_eta)
3354 :
3355 0 : corr_array_2(:,:,iiPDF_eta,iiPDF_chi) = corr_array_2_n(:,:,iiPDF_eta,iiPDF_chi)
3356 0 : corr_array_2(:,:,iiPDF_w,iiPDF_chi) = corr_array_2_n(:,:,iiPDF_w,iiPDF_chi)
3357 0 : corr_array_2(:,:,iiPDF_w,iiPDF_eta) = corr_array_2_n(:,:,iiPDF_w,iiPDF_eta)
3358 :
3359 : !!! Calculate the true correlation of variables that have an assumed normal
3360 : !!! distribution and variables that have an assumed lognormal distribution
3361 : !!! for the ith PDF component, given their normal space correlation and the
3362 : !!! normal space standard deviation of the variable with the assumed
3363 : !!! lognormal distribution.
3364 :
3365 : ! Transform the correlations between chi/eta/w and N_cn to standard space.
3366 :
3367 : ! Transform the correlation of chi (old s) and N_cn to standard space in PDF component 1.
3368 : call corr_NN2NL( nz, ngrdcol, & ! intent(in)
3369 : corr_array_1_n(:,:,iiPDF_Ncn,iiPDF_chi), & ! intent(in)
3370 : sigma_x_1_n(:,:,iiPDF_Ncn), sigma2_on_mu2_ip_1(:,:,iiPDF_Ncn), & ! intent(in)
3371 0 : corr_array_1(:,:,iiPDF_Ncn,iiPDF_chi) ) ! intent(out)
3372 :
3373 : ! Transform the correlation of eta (old t) and N_cn to standard space in PDF component 1.
3374 : call corr_NN2NL( nz, ngrdcol, & ! intent(in)
3375 : corr_array_1_n(:,:,iiPDF_Ncn,iiPDF_eta), & ! intent(in)
3376 : sigma_x_1_n(:,:,iiPDF_Ncn), sigma2_on_mu2_ip_1(:,:,iiPDF_Ncn), & ! intent(in)
3377 0 : corr_array_1(:,:,iiPDF_Ncn,iiPDF_eta) )! intent(out)
3378 :
3379 : ! Transform the correlation of w and N_cn to standard space in PDF component 1.
3380 : call corr_NN2NL( nz, ngrdcol, & ! intent(in)
3381 : corr_array_1_n(:,:,iiPDF_Ncn,iiPDF_w), & ! intent(in)
3382 : sigma_x_1_n(:,:,iiPDF_Ncn), sigma2_on_mu2_ip_1(:,:,iiPDF_Ncn), & ! intent(in)
3383 0 : corr_array_1(:,:,iiPDF_Ncn,iiPDF_w) ) ! intent(out)
3384 :
3385 : ! Transform the correlation of chi (old s) and N_cn to standard space in PDF component 2.
3386 : call corr_NN2NL( nz, ngrdcol, & ! intent(in)
3387 : corr_array_2_n(:,:,iiPDF_Ncn,iiPDF_chi), & ! intent(in)
3388 : sigma_x_2_n(:,:,iiPDF_Ncn), sigma2_on_mu2_ip_1(:,:,iiPDF_Ncn), & ! intent(in)
3389 0 : corr_array_2(:,:,iiPDF_Ncn,iiPDF_chi) ) ! intent(out)
3390 :
3391 : ! Transform the correlation of eta (old t) and N_cn to standard space in PDF component 2.
3392 : call corr_NN2NL( nz, ngrdcol, & ! intent(in)
3393 : corr_array_2_n(:,:,iiPDF_Ncn,iiPDF_eta), & ! intent(in)
3394 : sigma_x_2_n(:,:,iiPDF_Ncn), sigma2_on_mu2_ip_1(:,:,iiPDF_Ncn), & ! intent(in)
3395 0 : corr_array_2(:,:,iiPDF_Ncn,iiPDF_eta) ) ! intent(out)
3396 :
3397 : ! Transform the correlation of w and N_cn to standard space in PDF component 2.
3398 : call corr_NN2NL( nz, ngrdcol, & ! intent(in)
3399 : corr_array_2_n(:,:,iiPDF_Ncn,iiPDF_w), & ! intent(in)
3400 : sigma_x_2_n(:,:,iiPDF_Ncn), sigma2_on_mu2_ip_1(:,:,iiPDF_Ncn), & ! intent(in)
3401 0 : corr_array_2(:,:,iiPDF_Ncn,iiPDF_w) ) ! intent(out)
3402 :
3403 : ! Transform the correlations (in-precip) between chi/eta/w and the
3404 : ! precipitating hydrometeors to standard space.
3405 0 : do ivar = iiPDF_chi, iiPDF_w
3406 0 : do jvar = iiPDF_Ncn+1, pdf_dim
3407 :
3408 : ! Transform the correlation (in-precip) between w, chi, or eta and a
3409 : ! precipitating hydrometeor, hm, to standard space in PDF component 1.
3410 : call corr_NN2NL( nz, ngrdcol, & ! intent(in)
3411 : corr_array_1_n(:,:,jvar,ivar), & ! intent(in)
3412 : sigma_x_1_n(:,:,jvar), sigma2_on_mu2_ip_1(:,:,jvar), & ! intent(in)
3413 0 : corr_array_1(:,:,jvar,ivar) ) ! intent(out)
3414 :
3415 : ! Transform the correlation (in-precip) between w, chi, or eta and a
3416 : ! precipitating hydrometeor, hm, to standard space in PDF component 2.
3417 : call corr_NN2NL( nz, ngrdcol, & ! intent(in)
3418 : corr_array_2_n(:,:,jvar,ivar), & ! intent(in)
3419 : sigma_x_2_n(:,:,jvar), sigma2_on_mu2_ip_2(:,:,jvar), & ! intent(in)
3420 0 : corr_array_2(:,:,jvar,ivar) ) ! intent(out)
3421 :
3422 : end do ! jvar = iiPDF_Ncn+1, pdf_dim
3423 : end do ! ivar = iiPDF_chi, iiPDF_w
3424 :
3425 :
3426 : !!! Calculate the true correlation of two variables that both have an
3427 : !!! assumed lognormal distribution for the ith PDF component, given their
3428 : !!! normal space correlation and both of their normal space standard
3429 : !!! deviations.
3430 :
3431 : ! Transform the correlations (in-precip) between N_cn and the precipitating
3432 : ! hydrometeors to standard space.
3433 0 : do jvar = iiPDF_Ncn+1, pdf_dim
3434 :
3435 : ! Transform the correlation (in-precip) between N_cn and a precipitating
3436 : ! hydrometeor, hm, to standard space in PDF component 1.
3437 : call corr_NN2LL( nz, ngrdcol, & ! intent(in)
3438 : corr_array_1_n(:,:,jvar,iiPDF_Ncn), & ! intent(in)
3439 : sigma_x_1_n(:,:,iiPDF_Ncn), sigma_x_1_n(:,:,jvar), & ! intent(in)
3440 : sigma2_on_mu2_ip_1(:,:,iiPDF_Ncn), sigma2_on_mu2_ip_1(:,:,jvar), & ! in
3441 0 : corr_array_1(:,:,jvar,iiPDF_Ncn)) ! intent(out)
3442 :
3443 : ! Transform the correlation (in-precip) between N_cn and a precipitating
3444 : ! hydrometeor, hm, to standard space in PDF component 2.
3445 : call corr_NN2LL( nz, ngrdcol, & ! intent(in)
3446 : corr_array_2_n(:,:,jvar,iiPDF_Ncn), & ! intent(in)
3447 : sigma_x_2_n(:,:,iiPDF_Ncn), sigma_x_2_n(:,:,jvar), & ! intent(in)
3448 : sigma2_on_mu2_ip_1(:,:,iiPDF_Ncn), sigma2_on_mu2_ip_2(:,:,jvar), & ! in
3449 0 : corr_array_2(:,:,jvar,iiPDF_Ncn)) ! intent(out)
3450 :
3451 : end do ! jvar = ivar+1, pdf_dim
3452 :
3453 : ! Transform the correlations (in-precip) between two precipitating
3454 : ! hydrometeors to standard space.
3455 0 : do ivar = iiPDF_Ncn+1, pdf_dim-1
3456 0 : do jvar = ivar+1, pdf_dim
3457 :
3458 : ! Transform the correlation (in-precip) between two precipitating
3459 : ! hydrometeors (for example, r_r and N_r) to standard space in PDF
3460 : ! component 1.
3461 : call corr_NN2LL( nz, ngrdcol, & ! intent(in)
3462 : corr_array_1_n(:,:,jvar,ivar), & ! intent(in)
3463 : sigma_x_1_n(:,:,ivar), sigma_x_1_n(:,:,jvar), & ! intent(in)
3464 : sigma2_on_mu2_ip_1(:,:,ivar), sigma2_on_mu2_ip_1(:,:,jvar), & ! in
3465 0 : corr_array_1(:,:,jvar,ivar)) ! intent(out)
3466 :
3467 : ! Transform the correlation (in-precip) between two precipitating
3468 : ! hydrometeors (for example, r_r and N_r) to standard space in PDF
3469 : ! component 2.
3470 : call corr_NN2LL( nz, ngrdcol, & ! intent(in)
3471 : corr_array_2_n(:,:,jvar,ivar), & ! intent(in)
3472 : sigma_x_2_n(:,:,ivar), sigma_x_2_n(:,:,jvar), & ! intent(in)
3473 : sigma2_on_mu2_ip_2(:,:,ivar), sigma2_on_mu2_ip_2(:,:,jvar), & ! in
3474 0 : corr_array_2(:,:,jvar,ivar)) ! intent(out)
3475 :
3476 : end do ! jvar = ivar+1, pdf_dim
3477 : end do ! ivar = iiPDF_Ncn+1, pdf_dim-1
3478 :
3479 0 : return
3480 :
3481 : end subroutine denorm_transform_corr
3482 :
3483 : !=============================================================================
3484 0 : elemental subroutine calc_corr_w_hm_n( wm, wphydrometp, &
3485 : mu_w_1, mu_w_2, &
3486 : mu_hm_1, mu_hm_2, &
3487 : sigma_w_1, sigma_w_2, &
3488 : sigma_hm_1, sigma_hm_2, &
3489 : sigma_hm_1_n, sigma_hm_2_n, &
3490 : mixt_frac, precip_frac_1, &
3491 : precip_frac_2, hm_tol, &
3492 : corr_w_hm_1_n, corr_w_hm_2_n )
3493 :
3494 : ! Description:
3495 : ! Calculates the PDF component correlation (in-precip) between vertical
3496 : ! velocity, w, and the natural logarithm of a hydrometeor, ln hm. The
3497 : ! overall covariance of w and hm, <w'hm'> can be written in terms of the PDF
3498 : ! parameters. When both w and hm vary in both PDF components, the equation
3499 : ! is written as:
3500 : !
3501 : ! <w'hm'> = mixt_frac * precip_frac_1
3502 : ! * ( mu_w_1 - <w>
3503 : ! + corr_w_hm_1_n * sigma_w_1 * sigma_hm_1_n ) * mu_hm_1
3504 : ! + ( 1 - mixt_frac ) * precip_frac_2
3505 : ! * ( mu_w_2 - <w>
3506 : ! + corr_w_hm_2_n * sigma_w_2 * sigma_hm_2_n ) * mu_hm_2.
3507 : !
3508 : ! The overall covariance is provided, so the component correlation is solved
3509 : ! by setting corr_w_hm_1_n = corr_w_hm_2_n ( = corr_w_hm_n ). The equation
3510 : ! is:
3511 : !
3512 : ! corr_w_hm_n
3513 : ! = ( <w'hm'>
3514 : ! - mixt_frac * precip_frac_1 * ( mu_w_1 - <w> ) * mu_hm_1
3515 : ! - ( 1 - mixt_frac ) * precip_frac_2 * ( mu_w_2 - <w> ) * mu_hm_2 )
3516 : ! / ( mixt_frac * precip_frac_1 * sigma_w_1 * sigma_hm_1_n * mu_hm_1
3517 : ! + ( 1 - mixt_frac ) * precip_frac_2
3518 : ! * sigma_w_2 * sigma_hm_2_n * mu_hm_2 );
3519 : !
3520 : ! again, where corr_w_hm_1_n = corr_w_hm_2_n = corr_w_hm_n. When either w
3521 : ! or hm is constant in one PDF component, but both w and hm vary in the
3522 : ! other PDF component, the equation for <w'hm'> is written as:
3523 : !
3524 : ! <w'hm'> = mixt_frac * precip_frac_1
3525 : ! * ( mu_w_1 - <w>
3526 : ! + corr_w_hm_1_n * sigma_w_1 * sigma_hm_1_n ) * mu_hm_1
3527 : ! + ( 1 - mixt_frac ) * precip_frac_2
3528 : ! * ( mu_w_2 - <w> ) * mu_hm_2.
3529 : !
3530 : ! In the above equation, either w or hm (or both) is (are) constant in PDF
3531 : ! component 2, but both w and hm vary in PDF component 1. When both w and
3532 : ! hm vary in PDF component 2, but at least one of w or hm is constant in PDF
3533 : ! component 1, the equation is similar. The above equation can be rewritten
3534 : ! to solve for corr_w_hm_1_n, such that:
3535 : !
3536 : ! corr_w_hm_1_n
3537 : ! = ( <w'hm'>
3538 : ! - mixt_frac * precip_frac_1 * ( mu_w_1 - <w> ) * mu_hm_1
3539 : ! - ( 1 - mixt_frac ) * precip_frac_2 * ( mu_w_2 - <w> ) * mu_hm_2 )
3540 : ! / ( mixt_frac * precip_frac_1 * sigma_w_1 * sigma_hm_1_n * mu_hm_1 ).
3541 : !
3542 : ! Since either w or hm is constant in PDF component 2, corr_w_hm_2_n is
3543 : ! undefined. When both w and hm vary in PDF component 2, but at least one
3544 : ! of w or hm is constant in PDF component 1, the equation is similar, but
3545 : ! is in terms of corr_w_hm_2_n, while corr_w_hm_1_n is undefined. When
3546 : ! either w or hm is constant in both PDF components, the equation for
3547 : ! <w'hm'> is:
3548 : !
3549 : ! <w'hm'> = mixt_frac * precip_frac_1
3550 : ! * ( mu_w_1 - <w> ) * mu_hm_1
3551 : ! + ( 1 - mixt_frac ) * precip_frac_2
3552 : ! * ( mu_w_2 - <w> ) * mu_hm_2.
3553 : !
3554 : ! When this is the case, both corr_w_hm_1_n and corr_w_hm_2_n are undefined.
3555 :
3556 : ! References:
3557 : !-----------------------------------------------------------------------
3558 :
3559 : use constants_clubb, only: &
3560 : one, & ! Constant(s)
3561 : zero, &
3562 : max_mag_correlation, &
3563 : w_tol
3564 :
3565 : use clubb_precision, only: &
3566 : core_rknd ! Variable(s)
3567 :
3568 : implicit none
3569 :
3570 : ! Input Variables
3571 : real( kind = core_rknd ), intent(in) :: &
3572 : wm, & ! Mean vertical velocity (overall), <w> [m/s]
3573 : wphydrometp, & ! Covariance of w and hm (overall), <w'hm'> [m/s(hm un)]
3574 : mu_w_1, & ! Mean of w (1st PDF component) [m/s]
3575 : mu_w_2, & ! Mean of w (2nd PDF component) [m/s]
3576 : mu_hm_1, & ! Mean of hm (1st PDF component) in-precip (ip) [hm un]
3577 : mu_hm_2, & ! Mean of hm (2nd PDF component) ip [hm un]
3578 : sigma_w_1, & ! Standard deviation of w (1st PDF component) [m/s]
3579 : sigma_w_2, & ! Standard deviation of w (2nd PDF component) [m/s]
3580 : sigma_hm_1, & ! Standard deviation of hm (1st PDF component) ip [hm un]
3581 : sigma_hm_2, & ! Standard deviation of hm (2nd PDF component) ip [hm un]
3582 : sigma_hm_1_n, & ! Standard deviation of ln hm (1st PDF component) ip [-]
3583 : sigma_hm_2_n, & ! Standard deviation of ln hm (2nd PDF component) ip [-]
3584 : mixt_frac, & ! Mixture fraction [-]
3585 : precip_frac_1, & ! Precipitation fraction (1st PDF component) [-]
3586 : precip_frac_2 ! Precipitation fraction (2nd PDF component) [-]
3587 :
3588 : real( kind = core_rknd ), intent(in) :: &
3589 : hm_tol ! Hydrometeor tolerance value [hm un]
3590 :
3591 : ! Output Variables
3592 : real( kind = core_rknd ), intent(out) :: &
3593 : corr_w_hm_1_n, & ! Correlation of w and ln hm (1st PDF component) ip [-]
3594 : corr_w_hm_2_n ! Correlation of w and ln hm (2nd PDF component) ip [-]
3595 :
3596 : ! Local Variables
3597 : real( kind = core_rknd ) :: &
3598 : corr_w_hm_n ! Correlation of w and ln hm (both PDF components) ip [-]
3599 :
3600 :
3601 : ! Calculate the PDF component correlation of vertical velocity, w, and the
3602 : ! natural logarithm of a hydrometeor, ln hm, in precipitation.
3603 : if ( sigma_w_1 > w_tol .and. sigma_hm_1 > hm_tol .and. &
3604 0 : sigma_w_2 > w_tol .and. sigma_hm_2 > hm_tol ) then
3605 :
3606 : ! Both w and hm vary in both PDF components.
3607 : ! Calculate corr_w_hm_n (where corr_w_hm_1_n = corr_w_hm_2_n
3608 : ! = corr_w_hm_n).
3609 : corr_w_hm_n &
3610 : = ( wphydrometp &
3611 : - mixt_frac * precip_frac_1 * ( mu_w_1 - wm ) * mu_hm_1 &
3612 : - ( one - mixt_frac ) * precip_frac_2 * ( mu_w_2 - wm ) * mu_hm_2 ) &
3613 : / ( mixt_frac * precip_frac_1 * sigma_w_1 * sigma_hm_1_n * mu_hm_1 &
3614 : + ( one - mixt_frac ) * precip_frac_2 &
3615 0 : * sigma_w_2 * sigma_hm_2_n * mu_hm_2 )
3616 :
3617 : ! Check that the PDF component correlations have reasonable values.
3618 0 : if ( corr_w_hm_n > max_mag_correlation ) then
3619 : corr_w_hm_n = max_mag_correlation
3620 0 : elseif ( corr_w_hm_n < -max_mag_correlation ) then
3621 0 : corr_w_hm_n = -max_mag_correlation
3622 : end if
3623 :
3624 : ! The PDF component correlations between w and ln hm (in-precip) are
3625 : ! equal.
3626 0 : corr_w_hm_1_n = corr_w_hm_n
3627 0 : corr_w_hm_2_n = corr_w_hm_n
3628 :
3629 :
3630 0 : elseif ( sigma_w_1 > w_tol .and. sigma_hm_1 > hm_tol ) then
3631 :
3632 : ! Both w and hm vary in PDF component 1, but at least one of w and hm is
3633 : ! constant in PDF component 2.
3634 : ! Calculate the PDF component 1 correlation of w and ln hm (in-precip).
3635 : corr_w_hm_1_n &
3636 : = ( wphydrometp &
3637 : - mixt_frac * precip_frac_1 * ( mu_w_1 - wm ) * mu_hm_1 &
3638 : - ( one - mixt_frac ) * precip_frac_2 * ( mu_w_2 - wm ) * mu_hm_2 ) &
3639 0 : / ( mixt_frac * precip_frac_1 * sigma_w_1 * sigma_hm_1_n * mu_hm_1 )
3640 :
3641 : ! Check that the PDF component 1 correlation has a reasonable value.
3642 0 : if ( corr_w_hm_1_n > max_mag_correlation ) then
3643 0 : corr_w_hm_1_n = max_mag_correlation
3644 0 : elseif ( corr_w_hm_1_n < -max_mag_correlation ) then
3645 0 : corr_w_hm_1_n = -max_mag_correlation
3646 : end if
3647 :
3648 : ! The PDF component 2 correlation is undefined.
3649 0 : corr_w_hm_2_n = zero
3650 :
3651 :
3652 0 : elseif ( sigma_w_2 > w_tol .and. sigma_hm_2 > hm_tol ) then
3653 :
3654 : ! Both w and hm vary in PDF component 2, but at least one of w and hm is
3655 : ! constant in PDF component 1.
3656 : ! Calculate the PDF component 2 correlation of w and ln hm (in-precip).
3657 : corr_w_hm_2_n &
3658 : = ( wphydrometp &
3659 : - mixt_frac * precip_frac_1 * ( mu_w_1 - wm ) * mu_hm_1 &
3660 : - ( one - mixt_frac ) * precip_frac_2 * ( mu_w_2 - wm ) * mu_hm_2 ) &
3661 : / ( ( one - mixt_frac ) * precip_frac_2 &
3662 0 : * sigma_w_2 * sigma_hm_2_n * mu_hm_2 )
3663 :
3664 : ! Check that the PDF component 2 correlation has a reasonable value.
3665 0 : if ( corr_w_hm_2_n > max_mag_correlation ) then
3666 0 : corr_w_hm_2_n = max_mag_correlation
3667 0 : elseif ( corr_w_hm_2_n < -max_mag_correlation ) then
3668 0 : corr_w_hm_2_n = -max_mag_correlation
3669 : end if
3670 :
3671 : ! The PDF component 1 correlation is undefined.
3672 0 : corr_w_hm_1_n = zero
3673 :
3674 :
3675 : else ! sigma_w_1 * sigma_hm_1 = 0 .and. sigma_w_2 * sigma_hm_2 = 0.
3676 :
3677 : ! At least one of w and hm is constant in both PDF components.
3678 :
3679 : ! The PDF component 1 and component 2 correlations are both undefined.
3680 0 : corr_w_hm_1_n = zero
3681 0 : corr_w_hm_2_n = zero
3682 :
3683 :
3684 : end if
3685 :
3686 :
3687 0 : return
3688 :
3689 : end subroutine calc_corr_w_hm_n
3690 :
3691 : !=============================================================================
3692 0 : subroutine pdf_param_hm_stats( nz, pdf_dim, hm_1, hm_2, &
3693 0 : mu_x_1, mu_x_2, &
3694 0 : sigma_x_1, sigma_x_2, &
3695 0 : corr_array_1, corr_array_2, &
3696 : stats_metadata, &
3697 : stats_zt )
3698 :
3699 : ! Description:
3700 : ! Record statistics for standard PDF parameters involving hydrometeors.
3701 :
3702 : ! References:
3703 : !-----------------------------------------------------------------------
3704 :
3705 : use index_mapping, only: &
3706 : pdf2hydromet_idx ! Procedure(s)
3707 :
3708 : use parameters_model, only: &
3709 : hydromet_dim ! Variable(s)
3710 :
3711 : use array_index, only: &
3712 : iiPDF_w, & ! Variable(s)
3713 : iiPDF_chi, &
3714 : iiPDF_eta, &
3715 : iiPDF_Ncn
3716 :
3717 : use clubb_precision, only: &
3718 : core_rknd ! Variable(s)
3719 :
3720 : use stats_type_utilities, only: &
3721 : stat_update_var_pt ! Procedure(s)
3722 :
3723 : use stats_variables, only: &
3724 : stats_metadata_type
3725 :
3726 : use stats_type, only: stats ! Type
3727 :
3728 : implicit none
3729 :
3730 : !--------------------------- Input Variables ---------------------------
3731 : integer, intent(in) :: &
3732 : nz, & ! Number of vertical levels
3733 : pdf_dim ! Number of variables in the correlation array
3734 :
3735 : real( kind = core_rknd ), dimension(nz,hydromet_dim), intent(in) :: &
3736 : hm_1, & ! Mean of a precip. hydrometeor (1st PDF component) [units vary]
3737 : hm_2 ! Mean of a precip. hydrometeor (2nd PDF component) [units vary]
3738 :
3739 : real( kind = core_rknd ), dimension(nz,pdf_dim), intent(in) :: &
3740 : mu_x_1, & ! Mean array of PDF vars. (1st PDF component) [units vary]
3741 : mu_x_2, & ! Mean array of PDF vars. (2nd PDF component) [units vary]
3742 : sigma_x_1, & ! Standard deviation array of PDF vars (comp. 1) [units vary]
3743 : sigma_x_2 ! Standard deviation array of PDF vars (comp. 2) [units vary]
3744 :
3745 : real( kind = core_rknd ), dimension(nz,pdf_dim,pdf_dim), intent(in) :: &
3746 : corr_array_1, & ! Correlation array of PDF vars. (comp. 1) [-]
3747 : corr_array_2 ! Correlation array of PDF vars. (comp. 2) [-]
3748 :
3749 : type (stats_metadata_type), intent(in) :: &
3750 : stats_metadata
3751 :
3752 : !--------------------------- InOut Variable ---------------------------
3753 : type (stats), target, intent(inout) :: &
3754 : stats_zt
3755 :
3756 : !--------------------------- Local Variable ---------------------------
3757 : integer :: ivar, jvar, hm_idx, hm_idx_ivar, hm_idx_jvar, k ! Indices
3758 :
3759 : !--------------------------- Begin Code ---------------------------
3760 :
3761 : !!! Output the statistics for hydrometeor PDF parameters.
3762 :
3763 : ! Statistics
3764 0 : if ( stats_metadata%l_stats_samp ) then
3765 :
3766 : ! Switch back to using stat_update_var once the code is generalized
3767 : ! to pass in the number of vertical levels.
3768 0 : do ivar = 1, hydromet_dim, 1
3769 :
3770 0 : if ( stats_metadata%ihm_1(ivar) > 0 ) then
3771 : ! Mean of the precipitating hydrometeor in PDF component 1.
3772 : ! call stat_update_var( stats_metadata%ihm_1(ivar), hm_1(:,ivar), stats_zt )
3773 0 : do k = 1, nz, 1
3774 0 : call stat_update_var_pt( stats_metadata%ihm_1(ivar), k, hm_1(k,ivar), & ! intent(in)
3775 0 : stats_zt ) ! intent(inout)
3776 : end do ! k = 1, nz, 1
3777 : end if
3778 :
3779 0 : if ( stats_metadata%ihm_2(ivar) > 0 ) then
3780 : ! Mean of the precipitating hydrometeor in PDF component 2.
3781 : ! call stat_update_var( stats_metadata%ihm_2(ivar), hm_2(:,ivar), stats_zt )
3782 0 : do k = 1, nz, 1
3783 0 : call stat_update_var_pt( stats_metadata%ihm_2(ivar), k, hm_2(k,ivar), & ! intent(in)
3784 0 : stats_zt ) ! intent(inout)
3785 : end do ! k = 1, nz, 1
3786 : end if
3787 :
3788 : end do ! ivar = 1, hydromet_dim, 1
3789 :
3790 0 : do ivar = iiPDF_Ncn+1, pdf_dim, 1
3791 :
3792 0 : hm_idx = pdf2hydromet_idx(ivar)
3793 :
3794 : ! Mean of the precipitating hydrometeor (in-precip)
3795 : ! in PDF component 1.
3796 0 : if ( stats_metadata%imu_hm_1(hm_idx) > 0 ) then
3797 : ! call stat_update_var( stats_metadata%imu_hm_1(hm_idx), mu_x_1(ivar,:), stats_zt )
3798 0 : do k = 1, nz, 1
3799 0 : call stat_update_var_pt( stats_metadata%imu_hm_1(hm_idx), k, mu_x_1(k,ivar), & ! intent(in)
3800 0 : stats_zt ) ! intent(inout)
3801 : end do ! k = 1, nz, 1
3802 : end if
3803 :
3804 : ! Mean of the precipitating hydrometeor (in-precip)
3805 : ! in PDF component 2.
3806 0 : if ( stats_metadata%imu_hm_2(hm_idx) > 0 ) then
3807 : ! call stat_update_var( stats_metadata%imu_hm_2(hm_idx), mu_x_2(ivar,:), stats_zt )
3808 0 : do k = 1, nz, 1
3809 0 : call stat_update_var_pt( stats_metadata%imu_hm_2(hm_idx), k, mu_x_2(k,ivar), & ! intent(in)
3810 0 : stats_zt ) ! intent(inout)
3811 : end do ! k = 1, nz, 1
3812 : end if
3813 :
3814 : end do ! ivar = iiPDF_Ncn+1, pdf_dim, 1
3815 :
3816 : ! Mean of cloud nuclei concentration in PDF component 1.
3817 0 : if ( stats_metadata%imu_Ncn_1 > 0 ) then
3818 : ! call stat_update_var( stats_metadata%imu_Ncn_1, mu_x_1(iiPDF_Ncn,:), stats_zt )
3819 0 : do k = 1, nz, 1
3820 0 : call stat_update_var_pt( stats_metadata%imu_Ncn_1, k, mu_x_1(k,iiPDF_Ncn), & ! intent(in)
3821 0 : stats_zt ) ! intent(inout)
3822 : end do ! k = 1, nz, 1
3823 : end if
3824 :
3825 : ! Mean of cloud nuclei concentration in PDF component 2.
3826 0 : if ( stats_metadata%imu_Ncn_2 > 0 ) then
3827 : ! call stat_update_var( stats_metadata%imu_Ncn_2, mu_x_2(iiPDF_Ncn,:), stats_zt )
3828 0 : do k = 1, nz, 1
3829 0 : call stat_update_var_pt( stats_metadata%imu_Ncn_2, k, mu_x_2(k,iiPDF_Ncn), & ! intent(in)
3830 0 : stats_zt ) ! intent(inout)
3831 : end do ! k = 1, nz, 1
3832 : end if
3833 :
3834 0 : do ivar = iiPDF_Ncn+1, pdf_dim, 1
3835 :
3836 0 : hm_idx = pdf2hydromet_idx(ivar)
3837 :
3838 : ! Standard deviation of the precipitating hydrometeor (in-precip)
3839 : ! in PDF component 1.
3840 0 : if ( stats_metadata%isigma_hm_1(hm_idx) > 0 ) then
3841 : ! call stat_update_var( stats_metadata%isigma_hm_1(hm_idx), sigma_x_1(ivar,:), &
3842 : ! stats_zt )
3843 0 : do k = 1, nz, 1
3844 0 : call stat_update_var_pt( stats_metadata%isigma_hm_1(hm_idx), k, sigma_x_1(k,ivar), & ! intent(in)
3845 0 : stats_zt ) ! intent(inout)
3846 : end do ! k = 1, nz, 1
3847 : end if
3848 :
3849 : ! Standard deviation of the precipitating hydrometeor (in-precip)
3850 : ! in PDF component 2.
3851 0 : if ( stats_metadata%isigma_hm_2(hm_idx) > 0 ) then
3852 : ! call stat_update_var( stats_metadata%isigma_hm_2(hm_idx), sigma_x_2(ivar,:), &
3853 : ! stats_zt )
3854 0 : do k = 1, nz, 1
3855 0 : call stat_update_var_pt( stats_metadata%isigma_hm_2(hm_idx), k, sigma_x_2(k,ivar), & ! intent(in)
3856 0 : stats_zt ) ! intent(inout)
3857 : end do ! k = 1, nz, 1
3858 : end if
3859 :
3860 : end do ! ivar = iiPDF_Ncn+1, pdf_dim, 1
3861 :
3862 : ! Standard deviation of cloud nuclei concentration in PDF component 1.
3863 0 : if ( stats_metadata%isigma_Ncn_1 > 0 ) then
3864 : ! call stat_update_var( stats_metadata%isigma_Ncn_1, sigma_x_1(iiPDF_Ncn,:), stats_zt )
3865 0 : do k = 1, nz, 1
3866 0 : call stat_update_var_pt( stats_metadata%isigma_Ncn_1, k, sigma_x_1(k,iiPDF_Ncn), & ! intent(in)
3867 0 : stats_zt ) ! intent(inout)
3868 : end do ! k = 1, nz, 1
3869 : end if
3870 :
3871 : ! Standard deviation of cloud nuclei concentration in PDF component 2.
3872 0 : if ( stats_metadata%isigma_Ncn_2 > 0 ) then
3873 : ! call stat_update_var( stats_metadata%isigma_Ncn_2, sigma_x_2(iiPDF_Ncn,:), stats_zt )
3874 0 : do k = 1, nz, 1
3875 0 : call stat_update_var_pt( stats_metadata%isigma_Ncn_2, k, sigma_x_2(k,iiPDF_Ncn), & ! intent(in)
3876 0 : stats_zt ) ! intent(inout)
3877 : end do ! k = 1, nz, 1
3878 : end if
3879 :
3880 : ! Correlation of w and chi (old s) in PDF component 1 found in the
3881 : ! correlation array.
3882 : ! The true correlation of w and chi in each PDF component is solved for
3883 : ! by an equation and is part of CLUBB's PDF parameters. However, there
3884 : ! is an option in CLUBB, l_fix_w_chi_eta_correlations, that sets the
3885 : ! component correlation of w and chi to a constant, prescribed value
3886 : ! because of SILHS. The correlation of w and chi in PDF component 1
3887 : ! that is calculated by an equation is stored in stats as "corr_w_chi_1".
3888 : ! Here, "corr_w_chi_1_ca" outputs whatever value is found in the
3889 : ! correlation array, whether or not it matches "corr_w_chi_1".
3890 0 : if ( stats_metadata%icorr_w_chi_1_ca > 0 ) then
3891 : ! call stat_update_var( stats_metadata%icorr_w_chi_1_ca, &
3892 : ! corr_array_1(iiPDF_w,iiPDF_chi,:), stats_zt )
3893 0 : do k = 1, nz, 1
3894 : call stat_update_var_pt( stats_metadata%icorr_w_chi_1_ca, k, &
3895 0 : corr_array_1(k,iiPDF_w,iiPDF_chi), & ! intent(in)
3896 0 : stats_zt ) ! intent(inout)
3897 : end do ! k = 1, nz, 1
3898 : end if
3899 :
3900 : ! Correlation of w and chi (old s) in PDF component 2 found in the
3901 : ! correlation array.
3902 : ! The true correlation of w and chi in each PDF component is solved for
3903 : ! by an equation and is part of CLUBB's PDF parameters. However, there
3904 : ! is an option in CLUBB, l_fix_w_chi_eta_correlations, that sets the
3905 : ! component correlation of w and chi to a constant, prescribed value
3906 : ! because of SILHS. The correlation of w and chi in PDF component 2
3907 : ! that is calculated by an equation is stored in stats as "corr_w_chi_2".
3908 : ! Here, "corr_w_chi_2_ca" outputs whatever value is found in the
3909 : ! correlation array, whether or not it matches "corr_w_chi_2".
3910 0 : if ( stats_metadata%icorr_w_chi_2_ca > 0 ) then
3911 : ! call stat_update_var( stats_metadata%icorr_w_chi_2_ca, &
3912 : ! corr_array_2(iiPDF_w,iiPDF_chi,:), stats_zt )
3913 0 : do k = 1, nz, 1
3914 : call stat_update_var_pt( stats_metadata%icorr_w_chi_2_ca, k, & ! intent(in)
3915 0 : corr_array_2(k,iiPDF_w,iiPDF_chi), & ! intent(in)
3916 0 : stats_zt ) ! intent(inout)
3917 : end do ! k = 1, nz, 1
3918 : end if
3919 :
3920 : ! Correlation of w and eta (old t) in PDF component 1 found in the
3921 : ! correlation array.
3922 : ! The true correlation of w and eta in each PDF component is solved for
3923 : ! by an equation and is part of CLUBB's PDF parameters. However, there
3924 : ! is an option in CLUBB, l_fix_w_chi_eta_correlations, that sets the
3925 : ! component correlation of w and eta to a constant, prescribed value
3926 : ! because of SILHS. The correlation of w and eta in PDF component 1
3927 : ! that is calculated by an equation is stored in stats as "corr_w_eta_1".
3928 : ! Here, "corr_w_eta_1_ca" outputs whatever value is found in the
3929 : ! correlation array, whether or not it matches "corr_w_eta_1".
3930 0 : if ( stats_metadata%icorr_w_eta_1_ca > 0 ) then
3931 : ! call stat_update_var( stats_metadata%icorr_w_eta_1_ca, &
3932 : ! corr_array_1(iiPDF_w,iiPDF_eta,:), stats_zt )
3933 0 : do k = 1, nz, 1
3934 : call stat_update_var_pt( stats_metadata%icorr_w_eta_1_ca, k, & ! intent(in)
3935 0 : corr_array_1(k,iiPDF_w,iiPDF_eta), & ! intent(in)
3936 0 : stats_zt ) ! intent(inout)
3937 : end do ! k = 1, nz, 1
3938 : end if
3939 :
3940 : ! Correlation of w and eta (old t) in PDF component 2 found in the
3941 : ! correlation array.
3942 : ! The true correlation of w and eta in each PDF component is solved for
3943 : ! by an equation and is part of CLUBB's PDF parameters. However, there
3944 : ! is an option in CLUBB, l_fix_w_chi_eta_correlations, that sets the
3945 : ! component correlation of w and eta to a constant, prescribed value
3946 : ! because of SILHS. The correlation of w and eta in PDF component 2
3947 : ! that is calculated by an equation is stored in stats as "corr_w_eta_2".
3948 : ! Here, "corr_w_eta_2_ca" outputs whatever value is found in the
3949 : ! correlation array, whether or not it matches "corr_w_eta_2".
3950 0 : if ( stats_metadata%icorr_w_eta_2_ca > 0 ) then
3951 : ! call stat_update_var( stats_metadata%icorr_w_eta_2_ca, &
3952 : ! corr_array_2(iiPDF_w,iiPDF_eta,:), stats_zt )
3953 0 : do k = 1, nz, 1
3954 : call stat_update_var_pt( stats_metadata%icorr_w_eta_2_ca, k, & ! intent(in)
3955 0 : corr_array_2(k,iiPDF_w,iiPDF_eta), & ! intent(in)
3956 0 : stats_zt ) ! intent(inout)
3957 : end do ! k = 1, nz, 1
3958 : end if
3959 :
3960 0 : do ivar = iiPDF_Ncn+1, pdf_dim, 1
3961 :
3962 0 : hm_idx = pdf2hydromet_idx(ivar)
3963 :
3964 : ! Correlation (in-precip) of w and the precipitating hydrometeor
3965 : ! in PDF component 1.
3966 0 : if ( stats_metadata%icorr_w_hm_1(hm_idx) > 0 ) then
3967 : ! call stat_update_var( stats_metadata%icorr_w_hm_1(hm_idx), &
3968 : ! corr_array_1(ivar,iiPDF_w,:), stats_zt )
3969 0 : do k = 1, nz, 1
3970 : call stat_update_var_pt( stats_metadata%icorr_w_hm_1(hm_idx), k, & ! intent(in)
3971 0 : corr_array_1(k,ivar,iiPDF_w), & ! intent(in)
3972 0 : stats_zt ) ! intent(inout)
3973 : end do ! k = 1, nz, 1
3974 : end if
3975 :
3976 : ! Correlation (in-precip) of w and the precipitating hydrometeor
3977 : ! in PDF component 2.
3978 0 : if ( stats_metadata%icorr_w_hm_2(hm_idx) > 0 ) then
3979 : ! call stat_update_var( stats_metadata%icorr_w_hm_2(hm_idx), &
3980 : ! corr_array_2(ivar,iiPDF_w,:), stats_zt )
3981 0 : do k = 1, nz, 1
3982 : call stat_update_var_pt( stats_metadata%icorr_w_hm_2(hm_idx), k, & ! intent(in)
3983 0 : corr_array_2(k,ivar,iiPDF_w), & ! intent(in)
3984 0 : stats_zt ) ! intent(inout)
3985 : end do ! k = 1, nz, 1
3986 : end if
3987 :
3988 : end do ! ivar = iiPDF_Ncn+1, pdf_dim, 1
3989 :
3990 : ! Correlation of w and N_cn in PDF component 1.
3991 0 : if ( stats_metadata%icorr_w_Ncn_1 > 0 ) then
3992 : ! call stat_update_var( stats_metadata%icorr_w_Ncn_1, &
3993 : ! corr_array_1(iiPDF_Ncn,iiPDF_w,:), stats_zt )
3994 0 : do k = 1, nz, 1
3995 : call stat_update_var_pt( stats_metadata%icorr_w_Ncn_1, k, & ! intent(in)
3996 0 : corr_array_1(k,iiPDF_Ncn,iiPDF_w), & ! intent(in)
3997 0 : stats_zt ) ! intent(inout)
3998 : end do ! k = 1, nz, 1
3999 : end if
4000 :
4001 : ! Correlation of w and N_cn in PDF component 2.
4002 0 : if ( stats_metadata%icorr_w_Ncn_2 > 0 ) then
4003 : ! call stat_update_var( stats_metadata%icorr_w_Ncn_2, &
4004 : ! corr_array_2(iiPDF_Ncn,iiPDF_w,:), stats_zt )
4005 0 : do k = 1, nz, 1
4006 : call stat_update_var_pt( stats_metadata%icorr_w_Ncn_2, k, & ! intent(in)
4007 0 : corr_array_2(k,iiPDF_Ncn,iiPDF_w), & ! intent(in)
4008 0 : stats_zt ) ! intent(inout)
4009 : end do ! k = 1, nz, 1
4010 : end if
4011 :
4012 : ! Correlation of chi (old s) and eta (old t) in PDF component 1 found in
4013 : ! the correlation array.
4014 : ! The true correlation of chi and eta in each PDF component is solved for
4015 : ! by an equation and is part of CLUBB's PDF parameters. However, there
4016 : ! is an option in CLUBB, l_fix_w_chi_eta_correlations, that sets the
4017 : ! component correlation of chi and eta to a constant, prescribed value
4018 : ! because of SILHS. The correlation of chi and eta in PDF component 1
4019 : ! that is calculated by an equation is stored in stats as
4020 : ! "corr_chi_eta_1". Here, "corr_chi_eta_1_ca" outputs whatever value is
4021 : ! found in the correlation array, whether or not it matches
4022 : ! "corr_chi_eta_1".
4023 0 : if ( stats_metadata%icorr_chi_eta_1_ca > 0 ) then
4024 : ! call stat_update_var( stats_metadata%icorr_chi_eta_1_ca, &
4025 : ! corr_array_1(iiPDF_eta,iiPDF_chi,:), stats_zt )
4026 0 : do k = 1, nz, 1
4027 : call stat_update_var_pt( stats_metadata%icorr_chi_eta_1_ca, k, & ! intent(in)
4028 0 : corr_array_1(k,iiPDF_eta,iiPDF_chi), & ! intent(in)
4029 0 : stats_zt ) ! intent(inout)
4030 : end do ! k = 1, nz, 1
4031 : end if
4032 :
4033 : ! Correlation of chi (old s) and eta (old t) in PDF component 2 found in
4034 : ! the correlation array.
4035 : ! The true correlation of chi and eta in each PDF component is solved for
4036 : ! by an equation and is part of CLUBB's PDF parameters. However, there
4037 : ! is an option in CLUBB, l_fix_w_chi_eta_correlations, that sets the
4038 : ! component correlation of chi and eta to a constant, prescribed value
4039 : ! because of SILHS. The correlation of chi and eta in PDF component 2
4040 : ! that is calculated by an equation is stored in stats as
4041 : ! "corr_chi_eta_2". Here, "corr_chi_eta_2_ca" outputs whatever value is
4042 : ! found in the correlation array, whether or not it matches
4043 : ! "corr_chi_eta_2".
4044 0 : if ( stats_metadata%icorr_chi_eta_2_ca > 0 ) then
4045 : ! call stat_update_var( stats_metadata%icorr_chi_eta_2_ca, &
4046 : ! corr_array_2(iiPDF_eta,iiPDF_chi,:), stats_zt )
4047 0 : do k = 1, nz, 1
4048 : call stat_update_var_pt( stats_metadata%icorr_chi_eta_2_ca, k, & ! intent(in)
4049 0 : corr_array_2(k,iiPDF_eta,iiPDF_chi), & ! intent(in)
4050 0 : stats_zt ) ! intent(inout)
4051 : end do ! k = 1, nz, 1
4052 : end if
4053 :
4054 0 : do ivar = iiPDF_Ncn+1, pdf_dim, 1
4055 :
4056 0 : hm_idx = pdf2hydromet_idx(ivar)
4057 :
4058 : ! Correlation (in-precip) of chi (old s) and the precipitating
4059 : ! hydrometeor in PDF component 1.
4060 0 : if ( stats_metadata%icorr_chi_hm_1(hm_idx) > 0 ) then
4061 : ! call stat_update_var( stats_metadata%icorr_chi_hm_1(hm_idx), &
4062 : ! corr_array_1(ivar,iiPDF_chi,:), stats_zt )
4063 0 : do k = 1, nz, 1
4064 : call stat_update_var_pt( stats_metadata%icorr_chi_hm_1(hm_idx), k, & ! intent(in)
4065 0 : corr_array_1(k,ivar,iiPDF_chi), & ! intent(in)
4066 0 : stats_zt ) ! intent(inout)
4067 : end do ! k = 1, nz, 1
4068 : end if
4069 :
4070 : ! Correlation (in-precip) of chi (old s) and the precipitating
4071 : ! hydrometeor in PDF component 2.
4072 0 : if ( stats_metadata%icorr_chi_hm_2(hm_idx) > 0 ) then
4073 : ! call stat_update_var( stats_metadata%icorr_chi_hm_2(hm_idx), &
4074 : ! corr_array_2(ivar,iiPDF_chi,:), stats_zt )
4075 0 : do k = 1, nz, 1
4076 : call stat_update_var_pt( stats_metadata%icorr_chi_hm_2(hm_idx), k, & ! intent(in)
4077 0 : corr_array_2(k,ivar,iiPDF_chi), & ! intent(in)
4078 0 : stats_zt ) ! intent(inout)
4079 : end do ! k = 1, nz, 1
4080 : end if
4081 :
4082 : end do ! ivar = iiPDF_Ncn+1, pdf_dim, 1
4083 :
4084 : ! Correlation of chi (old s) and N_cn in PDF component 1.
4085 0 : if ( stats_metadata%icorr_chi_Ncn_1 > 0 ) then
4086 : ! call stat_update_var( stats_metadata%icorr_chi_Ncn_1, &
4087 : ! corr_array_1(iiPDF_Ncn,iiPDF_chi,:), stats_zt )
4088 0 : do k = 1, nz, 1
4089 : call stat_update_var_pt( stats_metadata%icorr_chi_Ncn_1, k, & ! intent(in)
4090 0 : corr_array_1(k,iiPDF_Ncn,iiPDF_chi), & ! intent(inout)
4091 0 : stats_zt ) ! intent(in)
4092 : end do ! k = 1, nz, 1
4093 : end if
4094 :
4095 : ! Correlation of chi (old s) and N_cn in PDF component 2.
4096 0 : if ( stats_metadata%icorr_chi_Ncn_2 > 0 ) then
4097 : ! call stat_update_var( stats_metadata%icorr_chi_Ncn_2, &
4098 : ! corr_array_2(iiPDF_Ncn,iiPDF_chi,:), stats_zt )
4099 0 : do k = 1, nz, 1
4100 : call stat_update_var_pt( stats_metadata%icorr_chi_Ncn_2, k, & ! intent(in)
4101 0 : corr_array_2(k,iiPDF_Ncn,iiPDF_chi), & ! intent(in)
4102 0 : stats_zt ) ! intent(inout)
4103 : end do ! k = 1, nz, 1
4104 : end if
4105 :
4106 0 : do ivar = iiPDF_Ncn+1, pdf_dim, 1
4107 :
4108 0 : hm_idx = pdf2hydromet_idx(ivar)
4109 :
4110 : ! Correlation (in-precip) of eta (old t) and the precipitating
4111 : ! hydrometeor in PDF component 1.
4112 0 : if ( stats_metadata%icorr_eta_hm_1(hm_idx) > 0 ) then
4113 : ! call stat_update_var( stats_metadata%icorr_eta_hm_1(hm_idx), &
4114 : ! corr_array_1(ivar,iiPDF_eta,:), stats_zt )
4115 0 : do k = 1, nz, 1
4116 : call stat_update_var_pt( stats_metadata%icorr_eta_hm_1(hm_idx), k, & ! intent(in)
4117 0 : corr_array_1(k,ivar,iiPDF_eta), & ! intent(in)
4118 0 : stats_zt ) ! intent(inout)
4119 : end do ! k = 1, nz, 1
4120 : end if
4121 :
4122 : ! Correlation (in-precip) of eta (old t) and the precipitating
4123 : ! hydrometeor in PDF component 2.
4124 0 : if ( stats_metadata%icorr_eta_hm_2(hm_idx) > 0 ) then
4125 : ! call stat_update_var( stats_metadata%icorr_eta_hm_2(hm_idx), &
4126 : ! corr_array_2(ivar,iiPDF_eta,:), stats_zt )
4127 0 : do k = 1, nz, 1
4128 : call stat_update_var_pt( stats_metadata%icorr_eta_hm_2(hm_idx), k, & ! intent(in)
4129 0 : corr_array_2(k,ivar,iiPDF_eta), & ! intent(in)
4130 0 : stats_zt ) ! intent(inout)
4131 : end do ! k = 1, nz, 1
4132 : end if
4133 :
4134 : end do ! ivar = iiPDF_Ncn+1, pdf_dim, 1
4135 :
4136 : ! Correlation of eta (old t) and N_cn in PDF component 1.
4137 0 : if ( stats_metadata%icorr_eta_Ncn_1 > 0 ) then
4138 : ! call stat_update_var( stats_metadata%icorr_eta_Ncn_1, &
4139 : ! corr_array_1(iiPDF_Ncn,iiPDF_eta,:), stats_zt )
4140 0 : do k = 1, nz, 1
4141 : call stat_update_var_pt( stats_metadata%icorr_eta_Ncn_1, k, & ! intent(in)
4142 0 : corr_array_1(k,iiPDF_Ncn,iiPDF_eta), & ! intent(in)
4143 0 : stats_zt ) ! intent(inout)
4144 : end do ! k = 1, nz, 1
4145 : end if
4146 :
4147 : ! Correlation of eta (old t) and N_cn in PDF component 2.
4148 0 : if ( stats_metadata%icorr_eta_Ncn_2 > 0 ) then
4149 : ! call stat_update_var( stats_metadata%icorr_eta_Ncn_2, &
4150 : ! corr_array_2(iiPDF_Ncn,iiPDF_eta,:), stats_zt )
4151 0 : do k = 1, nz, 1
4152 : call stat_update_var_pt( stats_metadata%icorr_eta_Ncn_2, k, & ! intent(in)
4153 0 : corr_array_2(k,iiPDF_Ncn,iiPDF_eta), & ! intent(in)
4154 0 : stats_zt ) ! intent(inout)
4155 : end do ! k = 1, nz, 1
4156 : end if
4157 :
4158 0 : do ivar = iiPDF_Ncn+1, pdf_dim, 1
4159 :
4160 0 : hm_idx = pdf2hydromet_idx(ivar)
4161 :
4162 : ! Correlation (in-precip) of N_cn and the precipitating
4163 : ! hydrometeor in PDF component 1.
4164 0 : if ( stats_metadata%icorr_Ncn_hm_1(hm_idx) > 0 ) then
4165 : ! call stat_update_var( stats_metadata%icorr_Ncn_hm_1(hm_idx), &
4166 : ! corr_array_1(ivar,iiPDF_Ncn,:), stats_zt )
4167 0 : do k = 1, nz, 1
4168 : call stat_update_var_pt( stats_metadata%icorr_Ncn_hm_1(hm_idx), k, & ! intent(in)
4169 0 : corr_array_1(k,ivar,iiPDF_Ncn), & ! intent(in)
4170 0 : stats_zt ) ! intent(inout)
4171 : end do ! k = 1, nz, 1
4172 : end if
4173 :
4174 : ! Correlation (in-precip) of N_cn and the precipitating
4175 : ! hydrometeor in PDF component 2.
4176 0 : if ( stats_metadata%icorr_Ncn_hm_2(hm_idx) > 0 ) then
4177 : ! call stat_update_var( stats_metadata%icorr_Ncn_hm_2(hm_idx), &
4178 : ! corr_array_2(ivar,iiPDF_Ncn,:), stats_zt )
4179 0 : do k = 1, nz, 1
4180 : call stat_update_var_pt( stats_metadata%icorr_Ncn_hm_2(hm_idx), k, & ! intent(in)
4181 0 : corr_array_2(k,ivar,iiPDF_Ncn), & ! intent(in)
4182 0 : stats_zt ) ! intent(inout)
4183 : end do ! k = 1, nz, 1
4184 : end if
4185 :
4186 : end do ! ivar = iiPDF_Ncn+1, pdf_dim, 1
4187 :
4188 0 : do ivar = iiPDF_Ncn+1, pdf_dim, 1
4189 :
4190 0 : hm_idx_ivar = pdf2hydromet_idx(ivar)
4191 :
4192 0 : do jvar = ivar+1, pdf_dim, 1
4193 :
4194 0 : hm_idx_jvar = pdf2hydromet_idx(jvar)
4195 :
4196 : ! Correlation (in-precip) of two different hydrometeors (hmx and
4197 : ! hmy) in PDF component 1.
4198 0 : if ( stats_metadata%icorr_hmx_hmy_1(hm_idx_jvar,hm_idx_ivar) > 0 ) then
4199 : ! call stat_update_var( stats_metadata%icorr_hmx_hmy_1(hm_idx_jvar,hm_idx_ivar), &
4200 : ! corr_array_1(jvar,ivar,:), stats_zt )
4201 0 : do k = 1, nz, 1
4202 : call stat_update_var_pt( stats_metadata%icorr_hmx_hmy_1(hm_idx_jvar,hm_idx_ivar), k, & ! in
4203 0 : corr_array_1(k,jvar,ivar), & ! intent(in)
4204 0 : stats_zt ) ! intent(inout)
4205 : end do ! k = 1, nz, 1
4206 : end if
4207 :
4208 : ! Correlation (in-precip) of two different hydrometeors (hmx and
4209 : ! hmy) in PDF component 2.
4210 0 : if ( stats_metadata%icorr_hmx_hmy_2(hm_idx_jvar,hm_idx_ivar) > 0 ) then
4211 : ! call stat_update_var( stats_metadata%icorr_hmx_hmy_2(hm_idx_jvar,hm_idx_ivar), &
4212 : ! corr_array_2(jvar,ivar,:), stats_zt )
4213 0 : do k = 1, nz, 1
4214 : call stat_update_var_pt( stats_metadata%icorr_hmx_hmy_2(hm_idx_jvar,hm_idx_ivar), k, & ! in
4215 0 : corr_array_2(k,jvar,ivar), & ! intent(in)
4216 0 : stats_zt ) ! intent(inout)
4217 : end do ! k = 1, nz, 1
4218 : end if
4219 :
4220 : end do ! jvar = ivar+1, pdf_dim, 1
4221 : end do ! ivar = iiPDF_Ncn+1, pdf_dim, 1
4222 :
4223 : end if ! stats_metadata%l_stats_samp
4224 :
4225 :
4226 0 : return
4227 :
4228 : end subroutine pdf_param_hm_stats
4229 :
4230 : !=============================================================================
4231 0 : subroutine pdf_param_ln_hm_stats( nz, pdf_dim, mu_x_1_n, &
4232 0 : mu_x_2_n, sigma_x_1_n, &
4233 0 : sigma_x_2_n, corr_array_1_n, &
4234 0 : corr_array_2_n, &
4235 : stats_metadata, &
4236 : stats_zt )
4237 :
4238 : ! Description:
4239 : ! Record statistics for normal space PDF parameters involving hydrometeors.
4240 :
4241 : ! References:
4242 : !-----------------------------------------------------------------------
4243 :
4244 : use index_mapping, only: &
4245 : pdf2hydromet_idx ! Procedure(s)
4246 :
4247 : use array_index, only: &
4248 : iiPDF_w, & ! Variable(s)
4249 : iiPDF_chi, &
4250 : iiPDF_eta, &
4251 : iiPDF_Ncn
4252 :
4253 : use clubb_precision, only: &
4254 : core_rknd ! Variable(s)
4255 :
4256 : use stats_type_utilities, only: &
4257 : stat_update_var_pt ! Procedure(s)
4258 :
4259 : use stats_type, only: &
4260 : stats ! Type
4261 :
4262 : use stats_variables, only: &
4263 : stats_metadata_type
4264 :
4265 : implicit none
4266 :
4267 : !------------------------ Input Variables ------------------------
4268 : integer, intent(in) :: &
4269 : nz, & ! Number of vertical levels
4270 : pdf_dim ! Number of variables in the correlation array
4271 :
4272 : real( kind = core_rknd ), dimension(nz,pdf_dim), intent(in) :: &
4273 : mu_x_1_n, & ! Mean array (normal space): PDF vars. (comp. 1) [un. vary]
4274 : mu_x_2_n, & ! Mean array (normal space): PDF vars. (comp. 2) [un. vary]
4275 : sigma_x_1_n, & ! Std. dev. array (normal space): PDF vars (comp. 1) [u.v.]
4276 : sigma_x_2_n ! Std. dev. array (normal space): PDF vars (comp. 2) [u.v.]
4277 :
4278 : real( kind = core_rknd ), dimension(nz,pdf_dim,pdf_dim), &
4279 : intent(in) :: &
4280 : corr_array_1_n, & ! Corr. array (normal space) of PDF vars. (comp. 1) [-]
4281 : corr_array_2_n ! Corr. array (normal space) of PDF vars. (comp. 2) [-]
4282 :
4283 : type (stats_metadata_type), intent(in) :: &
4284 : stats_metadata
4285 :
4286 : !------------------------ InOut Variables ------------------------
4287 : type (stats), target, intent(inout) :: &
4288 : stats_zt
4289 :
4290 : !------------------------ Local Variables ------------------------
4291 : real( kind = core_rknd ), dimension(nz) :: &
4292 0 : mu_hm_1_n, & ! Mean of ln hm (1st PDF component) [units vary]
4293 0 : mu_hm_2_n, & ! Mean of ln hm (2nd PDF component) [units vary]
4294 0 : mu_Ncn_1_n, & ! Mean of ln Ncn (1st PDF component) [ln(num/kg)]
4295 0 : mu_Ncn_2_n ! Mean of ln Ncn (2nd PDF component) [ln(num/kg)]
4296 :
4297 : integer :: ivar, jvar, hm_idx, hm_idx_ivar, hm_idx_jvar, k ! Indices
4298 :
4299 : !------------------------ Begin Code ------------------------
4300 :
4301 : !!! Output the statistics for normal space hydrometeor PDF parameters.
4302 :
4303 : ! Statistics
4304 0 : if ( stats_metadata%l_stats_samp ) then
4305 :
4306 : ! Switch back to using stat_update_var once the code is generalized
4307 : ! to pass in the number of vertical levels.
4308 0 : do ivar = iiPDF_Ncn+1, pdf_dim, 1
4309 :
4310 0 : hm_idx = pdf2hydromet_idx(ivar)
4311 :
4312 : ! Mean (in-precip) of ln hm in PDF component 1.
4313 0 : if ( stats_metadata%imu_hm_1_n(hm_idx) > 0 ) then
4314 0 : where ( mu_x_1_n(:,ivar) > real( -huge( 0.0 ), kind = core_rknd ) )
4315 0 : mu_hm_1_n = mu_x_1_n(:,ivar)
4316 : elsewhere
4317 : ! When hm_1 is 0 (or below tolerance value), mu_hm_1_n is -inf,
4318 : ! and is set to -huge for the default CLUBB kind. Some
4319 : ! compilers have issues outputting to stats files (in single
4320 : ! precision) when the default CLUBB kind is in double precision.
4321 : ! Set to -huge for single precision.
4322 : mu_hm_1_n = real( -huge( 0.0 ), kind = core_rknd )
4323 : endwhere
4324 : ! call stat_update_var( stats_metadata%imu_hm_1_n(hm_idx), mu_hm_1_n, stats_zt )
4325 0 : do k = 1, nz, 1
4326 0 : call stat_update_var_pt( stats_metadata%imu_hm_1_n(hm_idx), k, mu_hm_1_n(k), & ! intent(in)
4327 0 : stats_zt ) ! intent(inout)
4328 : end do ! k = 1, nz, 1
4329 : end if
4330 :
4331 : ! Mean (in-precip) of ln hm in PDF component 2.
4332 0 : if ( stats_metadata%imu_hm_2_n(hm_idx) > 0 ) then
4333 0 : where ( mu_x_2_n(:,ivar) > real( -huge( 0.0 ), kind = core_rknd ) )
4334 0 : mu_hm_2_n = mu_x_2_n(:,ivar)
4335 : elsewhere
4336 : ! When hm_2 is 0 (or below tolerance value), mu_hm_2_n is -inf,
4337 : ! and is set to -huge for the default CLUBB kind. Some
4338 : ! compilers have issues outputting to stats files (in single
4339 : ! precision) when the default CLUBB kind is in double precision.
4340 : ! Set to -huge for single precision.
4341 : mu_hm_2_n = real( -huge( 0.0 ), kind = core_rknd )
4342 : endwhere
4343 : ! call stat_update_var( stats_metadata%imu_hm_2_n(hm_idx), mu_hm_2_n, stats_zt )
4344 0 : do k = 1, nz, 1
4345 0 : call stat_update_var_pt( stats_metadata%imu_hm_2_n(hm_idx), k, mu_hm_2_n(k), & ! intent(in)
4346 0 : stats_zt ) ! intent(inout)
4347 : end do ! k = 1, nz, 1
4348 : end if
4349 :
4350 : end do ! ivar = iiPDF_Ncn+1, pdf_dim, 1
4351 :
4352 : ! Mean of ln N_cn in PDF component 1.
4353 0 : if ( stats_metadata%imu_Ncn_1_n > 0 ) then
4354 : where ( mu_x_1_n(:,iiPDF_Ncn) &
4355 0 : > real( -huge( 0.0 ), kind = core_rknd ) )
4356 0 : mu_Ncn_1_n = mu_x_1_n(:,iiPDF_Ncn)
4357 : elsewhere
4358 : ! When Ncnm is 0 (or below tolerance value), mu_Ncn_1_n is -inf,
4359 : ! and is set to -huge for the default CLUBB kind. Some compilers
4360 : ! have issues outputting to stats files (in single precision) when
4361 : ! the default CLUBB kind is in double precision.
4362 : ! Set to -huge for single precision.
4363 : mu_Ncn_1_n = real( -huge( 0.0 ), kind = core_rknd )
4364 : endwhere
4365 : ! call stat_update_var( stats_metadata%imu_Ncn_1_n, mu_Ncn_1_n, stats_zt )
4366 0 : do k = 1, nz, 1
4367 0 : call stat_update_var_pt( stats_metadata%imu_Ncn_1_n, k, mu_Ncn_1_n(k), & ! intent(in)
4368 0 : stats_zt ) ! intent(inout)
4369 : end do ! k = 1, nz, 1
4370 : end if
4371 :
4372 : ! Mean of ln N_cn in PDF component 2.
4373 0 : if ( stats_metadata%imu_Ncn_2_n > 0 ) then
4374 : where ( mu_x_2_n(:,iiPDF_Ncn) &
4375 0 : > real( -huge( 0.0 ), kind = core_rknd ) )
4376 0 : mu_Ncn_2_n = mu_x_2_n(:,iiPDF_Ncn)
4377 : elsewhere
4378 : ! When Ncnm is 0 (or below tolerance value), mu_Ncn_2_n is -inf,
4379 : ! and is set to -huge for the default CLUBB kind. Some compilers
4380 : ! have issues outputting to stats files (in single precision) when
4381 : ! the default CLUBB kind is in double precision.
4382 : ! Set to -huge for single precision.
4383 : mu_Ncn_2_n = real( -huge( 0.0 ), kind = core_rknd )
4384 : endwhere
4385 : ! call stat_update_var( stats_metadata%imu_Ncn_2_n, mu_Ncn_2_n, stats_zt )
4386 0 : do k = 1, nz, 1
4387 0 : call stat_update_var_pt( stats_metadata%imu_Ncn_2_n, k, mu_Ncn_2_n(k), & ! intent(in)
4388 0 : stats_zt ) ! intent(inout)
4389 : end do ! k = 1, nz, 1
4390 : end if
4391 :
4392 0 : do ivar = iiPDF_Ncn+1, pdf_dim, 1
4393 :
4394 0 : hm_idx = pdf2hydromet_idx(ivar)
4395 :
4396 : ! Standard deviation (in-precip) of ln hm in PDF component 1.
4397 0 : if ( stats_metadata%isigma_hm_1_n(hm_idx) > 0 ) then
4398 : ! call stat_update_var( stats_metadata%isigma_hm_1_n(hm_idx), sigma_x_1_n(ivar,:), &
4399 : ! stats_zt )
4400 0 : do k = 1, nz, 1
4401 : call stat_update_var_pt( stats_metadata%isigma_hm_1_n(hm_idx), k, & ! intent(in)
4402 0 : sigma_x_1_n(k,ivar), & ! intent(in)
4403 0 : stats_zt ) ! intent(inout)
4404 : end do ! k = 1, nz, 1
4405 : end if
4406 :
4407 : ! Standard deviation (in-precip) of ln hm in PDF component 2.
4408 0 : if ( stats_metadata%isigma_hm_2_n(hm_idx) > 0 ) then
4409 : ! call stat_update_var( stats_metadata%isigma_hm_2_n(hm_idx), sigma_x_2_n(ivar,:), &
4410 : ! stats_zt )
4411 0 : do k = 1, nz, 1
4412 : call stat_update_var_pt( stats_metadata%isigma_hm_2_n(hm_idx), k, & ! intent(in)
4413 0 : sigma_x_2_n(k,ivar), & ! intent(in)
4414 0 : stats_zt ) ! intent(inout)
4415 : end do ! k = 1, nz, 1
4416 : end if
4417 :
4418 : end do ! ivar = iiPDF_Ncn+1, pdf_dim, 1
4419 :
4420 : ! Standard deviation of ln N_cn in PDF component 1.
4421 0 : if ( stats_metadata%isigma_Ncn_1_n > 0 ) then
4422 : ! call stat_update_var( stats_metadata%isigma_Ncn_1_n, sigma_x_1_n(iiPDF_Ncn,:), &
4423 : ! stats_zt )
4424 0 : do k = 1, nz, 1
4425 : call stat_update_var_pt( stats_metadata%isigma_Ncn_1_n, k, & ! intent(in)
4426 0 : sigma_x_1_n(k,iiPDF_Ncn), & ! intent(in)
4427 0 : stats_zt ) ! intent(inout)
4428 : end do ! k = 1, nz, 1
4429 : end if
4430 :
4431 : ! Standard deviation of ln N_cn in PDF component 2.
4432 0 : if ( stats_metadata%isigma_Ncn_2_n > 0 ) then
4433 : ! call stat_update_var( stats_metadata%isigma_Ncn_2_n, sigma_x_2_n(iiPDF_Ncn,:), &
4434 : ! stats_zt )
4435 0 : do k = 1, nz, 1
4436 : call stat_update_var_pt( stats_metadata%isigma_Ncn_2_n, k, & ! intent(in)
4437 0 : sigma_x_2_n(k,iiPDF_Ncn), & ! intent(in)
4438 0 : stats_zt ) ! intent(inout)
4439 : end do ! k = 1, nz, 1
4440 : end if
4441 :
4442 0 : do ivar = iiPDF_Ncn+1, pdf_dim, 1
4443 :
4444 0 : hm_idx = pdf2hydromet_idx(ivar)
4445 :
4446 : ! Correlation (in-precip) of w and ln hm in PDF component 1.
4447 0 : if ( stats_metadata%icorr_w_hm_1_n(hm_idx) > 0 ) then
4448 : ! call stat_update_var( stats_metadata%icorr_w_hm_1_n(hm_idx), &
4449 : ! corr_array_1_n(ivar,iiPDF_w,:), stats_zt )
4450 0 : do k = 1, nz, 1
4451 : call stat_update_var_pt( stats_metadata%icorr_w_hm_1_n(hm_idx), k, & ! intent(in)
4452 0 : corr_array_1_n(k,ivar,iiPDF_w), & ! intent(in)
4453 0 : stats_zt ) ! intent(inout)
4454 : end do ! k = 1, nz, 1
4455 : end if
4456 :
4457 : ! Correlation (in-precip) of w and ln hm in PDF component 2.
4458 0 : if ( stats_metadata%icorr_w_hm_2_n(hm_idx) > 0 ) then
4459 : ! call stat_update_var( stats_metadata%icorr_w_hm_2_n(hm_idx), &
4460 : ! corr_array_2_n(ivar,iiPDF_w,:), stats_zt )
4461 0 : do k = 1, nz, 1
4462 : call stat_update_var_pt( stats_metadata%icorr_w_hm_2_n(hm_idx), k, & ! intent(in)
4463 0 : corr_array_2_n(k,ivar,iiPDF_w), & ! intent(in)
4464 0 : stats_zt ) ! intent(inout)
4465 : end do ! k = 1, nz, 1
4466 : end if
4467 :
4468 : end do ! ivar = iiPDF_Ncn+1, pdf_dim, 1
4469 :
4470 : ! Correlation of w and ln N_cn in PDF component 1.
4471 0 : if ( stats_metadata%icorr_w_Ncn_1_n > 0 ) then
4472 : ! call stat_update_var( stats_metadata%icorr_w_Ncn_1_n, &
4473 : ! corr_array_1_n(iiPDF_Ncn,iiPDF_w,:), stats_zt )
4474 0 : do k = 1, nz, 1
4475 : call stat_update_var_pt( stats_metadata%icorr_w_Ncn_1_n, k, & ! intent(in)
4476 0 : corr_array_1_n(k,iiPDF_Ncn,iiPDF_w), & ! intent(in)
4477 0 : stats_zt ) ! intent(inout)
4478 : end do ! k = 1, nz, 1
4479 : end if
4480 :
4481 : ! Correlation of w and ln N_cn in PDF component 2.
4482 0 : if ( stats_metadata%icorr_w_Ncn_2_n > 0 ) then
4483 : ! call stat_update_var( stats_metadata%icorr_w_Ncn_2_n, &
4484 : ! corr_array_2_n(iiPDF_Ncn,iiPDF_w,:), stats_zt )
4485 0 : do k = 1, nz, 1
4486 : call stat_update_var_pt( stats_metadata%icorr_w_Ncn_2_n, k, & ! intent(in)
4487 0 : corr_array_2_n(k,iiPDF_Ncn,iiPDF_w), & ! intent(in)
4488 0 : stats_zt ) ! intent(inout)
4489 : end do ! k = 1, nz, 1
4490 : end if
4491 :
4492 0 : do ivar = iiPDF_Ncn+1, pdf_dim, 1
4493 :
4494 0 : hm_idx = pdf2hydromet_idx(ivar)
4495 :
4496 : ! Correlation (in-precip) of chi (old s) and ln hm in PDF component 1.
4497 0 : if ( stats_metadata%icorr_chi_hm_1_n(hm_idx) > 0 ) then
4498 : ! call stat_update_var( stats_metadata%icorr_chi_hm_1_n(hm_idx), &
4499 : ! corr_array_1_n(ivar,iiPDF_chi,:), stats_zt )
4500 0 : do k = 1, nz, 1
4501 : call stat_update_var_pt( stats_metadata%icorr_chi_hm_1_n(hm_idx), k, & ! intent(in)
4502 0 : corr_array_1_n(k,ivar,iiPDF_chi), & ! intent(in)
4503 0 : stats_zt ) ! intent(inout)
4504 : end do ! k = 1, nz, 1
4505 : end if
4506 :
4507 : ! Correlation (in-precip) of chi( old s) and ln hm in PDF component 2.
4508 0 : if ( stats_metadata%icorr_chi_hm_2_n(hm_idx) > 0 ) then
4509 : ! call stat_update_var( stats_metadata%icorr_chi_hm_2_n(hm_idx), &
4510 : ! corr_array_2_n(ivar,iiPDF_chi,:), stats_zt )
4511 0 : do k = 1, nz, 1
4512 : call stat_update_var_pt( stats_metadata%icorr_chi_hm_2_n(hm_idx), k, & ! intent(in)
4513 0 : corr_array_2_n(k,ivar,iiPDF_chi), & ! intent(in)
4514 0 : stats_zt ) ! intent(inout)
4515 : end do ! k = 1, nz, 1
4516 : end if
4517 :
4518 : end do ! ivar = iiPDF_Ncn+1, pdf_dim, 1
4519 :
4520 : ! Correlation of chi (old s) and ln N_cn in PDF component 1.
4521 0 : if ( stats_metadata%icorr_chi_Ncn_1_n > 0 ) then
4522 : ! call stat_update_var( stats_metadata%icorr_chi_Ncn_1_n, &
4523 : ! corr_array_1_n(iiPDF_Ncn,iiPDF_chi,:), &
4524 : ! stats_zt )
4525 0 : do k = 1, nz, 1
4526 : call stat_update_var_pt( stats_metadata%icorr_chi_Ncn_1_n, k, & ! intent(in)
4527 0 : corr_array_1_n(k,iiPDF_Ncn,iiPDF_chi), & ! intent(in)
4528 0 : stats_zt ) ! intent(inout)
4529 : end do ! k = 1, nz, 1
4530 : end if
4531 :
4532 : ! Correlation of chi(old s) and ln N_cn in PDF component 2.
4533 0 : if ( stats_metadata%icorr_chi_Ncn_2_n > 0 ) then
4534 : ! call stat_update_var( stats_metadata%icorr_chi_Ncn_2_n, &
4535 : ! corr_array_2_n(iiPDF_Ncn,iiPDF_chi,:), &
4536 : ! stats_zt )
4537 0 : do k = 1, nz, 1
4538 : call stat_update_var_pt( stats_metadata%icorr_chi_Ncn_2_n, k, & ! intent(in)
4539 0 : corr_array_2_n(k,iiPDF_Ncn,iiPDF_chi), & ! intent(in)
4540 0 : stats_zt ) ! intent(inout)
4541 : end do ! k = 1, nz, 1
4542 : end if
4543 :
4544 0 : do ivar = iiPDF_Ncn+1, pdf_dim, 1
4545 :
4546 0 : hm_idx = pdf2hydromet_idx(ivar)
4547 :
4548 : ! Correlation (in-precip) of eta (old t) and ln hm in PDF component 1.
4549 0 : if ( stats_metadata%icorr_eta_hm_1_n(hm_idx) > 0 ) then
4550 : ! call stat_update_var( stats_metadata%icorr_eta_hm_1_n(hm_idx), &
4551 : ! corr_array_1_n(ivar,iiPDF_eta,:), stats_zt )
4552 0 : do k = 1, nz, 1
4553 : call stat_update_var_pt( stats_metadata%icorr_eta_hm_1_n(hm_idx), k, & ! intent(in)
4554 0 : corr_array_1_n(k,ivar,iiPDF_eta), & ! intent(in)
4555 0 : stats_zt ) ! intent(inout)
4556 : end do ! k = 1, nz, 1
4557 : end if
4558 :
4559 : ! Correlation (in-precip) of eta (old t) and ln hm in PDF component 2.
4560 0 : if ( stats_metadata%icorr_eta_hm_2_n(hm_idx) > 0 ) then
4561 : ! call stat_update_var( stats_metadata%icorr_eta_hm_2_n(hm_idx), &
4562 : ! corr_array_2_n(ivar,iiPDF_eta,:), stats_zt )
4563 0 : do k = 1, nz, 1
4564 : call stat_update_var_pt( stats_metadata%icorr_eta_hm_2_n(hm_idx), k, & ! intent(in)
4565 0 : corr_array_2_n(k,ivar,iiPDF_eta), & ! intent(in)
4566 0 : stats_zt ) ! intent(inout)
4567 : end do ! k = 1, nz, 1
4568 : end if
4569 :
4570 : end do ! ivar = iiPDF_Ncn+1, pdf_dim, 1
4571 :
4572 : ! Correlation of eta (old t) and ln N_cn in PDF component 1.
4573 0 : if ( stats_metadata%icorr_eta_Ncn_1_n > 0 ) then
4574 : ! call stat_update_var( stats_metadata%icorr_eta_Ncn_1_n, &
4575 : ! corr_array_1_n(iiPDF_Ncn,iiPDF_eta,:), &
4576 : ! stats_zt )
4577 0 : do k = 1, nz, 1
4578 : call stat_update_var_pt( stats_metadata%icorr_eta_Ncn_1_n, k, & ! intent(in)
4579 0 : corr_array_1_n(k,iiPDF_Ncn,iiPDF_eta), & ! intent(in)
4580 0 : stats_zt ) ! intent(inout)
4581 : end do ! k = 1, nz, 1
4582 : end if
4583 :
4584 : ! Correlation of eta (old t) and ln N_cn in PDF component 2.
4585 0 : if ( stats_metadata%icorr_eta_Ncn_2_n > 0 ) then
4586 : ! call stat_update_var( stats_metadata%icorr_eta_Ncn_2_n, &
4587 : ! corr_array_2_n(iiPDF_Ncn,iiPDF_eta,:), &
4588 : ! stats_zt )
4589 0 : do k = 1, nz, 1
4590 : call stat_update_var_pt( stats_metadata%icorr_eta_Ncn_2_n, k, & ! intent(in)
4591 0 : corr_array_2_n(k,iiPDF_Ncn,iiPDF_eta), & ! intent(in)
4592 0 : stats_zt ) ! intent(inout)
4593 : end do ! k = 1, nz, 1
4594 : end if
4595 :
4596 0 : do ivar = iiPDF_Ncn+1, pdf_dim, 1
4597 :
4598 0 : hm_idx = pdf2hydromet_idx(ivar)
4599 :
4600 : ! Correlation (in-precip) of ln N_cn and ln hm in PDF
4601 : ! component 1.
4602 0 : if ( stats_metadata%icorr_Ncn_hm_1_n(hm_idx) > 0 ) then
4603 : ! call stat_update_var( stats_metadata%icorr_Ncn_hm_1_n(hm_idx), &
4604 : ! corr_array_1_n(ivar,iiPDF_Ncn,:), stats_zt )
4605 0 : do k = 1, nz, 1
4606 : call stat_update_var_pt( stats_metadata%icorr_Ncn_hm_1_n(hm_idx), k, & ! intent(in)
4607 0 : corr_array_1_n(k,ivar,iiPDF_Ncn), & ! intent(in)
4608 0 : stats_zt ) ! intent(inout)
4609 : end do ! k = 1, nz, 1
4610 : end if
4611 :
4612 : ! Correlation (in-precip) of ln N_cn and ln hm in PDF
4613 : ! component 2.
4614 0 : if ( stats_metadata%icorr_Ncn_hm_2_n(hm_idx) > 0 ) then
4615 : ! call stat_update_var( stats_metadata%icorr_Ncn_hm_2_n(hm_idx), &
4616 : ! corr_array_2_n(ivar,iiPDF_Ncn,:), stats_zt )
4617 0 : do k = 1, nz, 1
4618 : call stat_update_var_pt( stats_metadata%icorr_Ncn_hm_2_n(hm_idx), k, & ! intent(in)
4619 0 : corr_array_2_n(k,ivar,iiPDF_Ncn), & ! intent(in)
4620 0 : stats_zt )! intent(inout)
4621 : end do ! k = 1, nz, 1
4622 : end if
4623 :
4624 : end do ! ivar = iiPDF_Ncn+1, pdf_dim, 1
4625 :
4626 0 : do ivar = iiPDF_Ncn+1, pdf_dim, 1
4627 :
4628 0 : hm_idx_ivar = pdf2hydromet_idx(ivar)
4629 :
4630 0 : do jvar = ivar+1, pdf_dim, 1
4631 :
4632 0 : hm_idx_jvar= pdf2hydromet_idx(jvar)
4633 :
4634 : ! Correlation (in-precip) of ln hmx and ln hmy (two different
4635 : ! hydrometeors) in PDF component 1.
4636 0 : if ( stats_metadata%icorr_hmx_hmy_1_n(hm_idx_jvar,hm_idx_ivar) > 0 ) then
4637 : ! call stat_update_var( &
4638 : ! stats_metadata%icorr_hmx_hmy_1_n(hm_idx_jvar,hm_idx_ivar), &
4639 : ! corr_array_1_n(jvar,ivar,:), stats_zt )
4640 0 : do k = 1, nz, 1
4641 : call stat_update_var_pt( &
4642 : stats_metadata%icorr_hmx_hmy_1_n(hm_idx_jvar,hm_idx_ivar), k, & ! intent(in)
4643 0 : corr_array_1_n(k,jvar,ivar), & ! intent(in)
4644 0 : stats_zt ) ! intent(inout)
4645 : end do ! k = 1, nz, 1
4646 : end if
4647 :
4648 : ! Correlation (in-precip) of ln hmx and ln hmy (two different
4649 : ! hydrometeors) in PDF component 2.
4650 0 : if ( stats_metadata%icorr_hmx_hmy_2_n(hm_idx_jvar,hm_idx_ivar) > 0 ) then
4651 : ! call stat_update_var( &
4652 : ! stats_metadata%icorr_hmx_hmy_2_n(hm_idx_jvar,hm_idx_ivar), &
4653 : ! corr_array_2_n(jvar,ivar,:), stats_zt )
4654 0 : do k = 1, nz, 1
4655 : call stat_update_var_pt( &
4656 : stats_metadata%icorr_hmx_hmy_2_n(hm_idx_jvar,hm_idx_ivar), k, & ! intent(in)
4657 0 : corr_array_2_n(k,jvar,ivar), & ! intent(in)
4658 0 : stats_zt ) ! intent(inout)
4659 : end do ! k = 1, nz, 1
4660 : end if
4661 :
4662 : end do ! jvar = ivar+1, pdf_dim, 1
4663 : end do ! ivar = iiPDF_Ncn+1, pdf_dim, 1
4664 :
4665 : end if ! stats_metadata%l_stats_samp
4666 :
4667 :
4668 0 : return
4669 :
4670 : end subroutine pdf_param_ln_hm_stats
4671 :
4672 : !=============================================================================
4673 0 : subroutine pack_hydromet_pdf_params( nz, ngrdcol, hm_1, hm_2, pdf_dim, mu_x_1, & ! In
4674 0 : mu_x_2, sigma_x_1, sigma_x_2, & ! In
4675 0 : corr_array_1, corr_array_2, & ! In
4676 0 : hydromet_pdf_params ) ! Out
4677 :
4678 : ! Description:
4679 : ! Pack the standard means and variances involving hydrometeors, as well as a
4680 : ! few other variables, into the structure hydromet_pdf_params.
4681 :
4682 : ! References:
4683 : !-----------------------------------------------------------------------
4684 :
4685 : use constants_clubb, only: &
4686 : one ! Constant(s)
4687 :
4688 : use hydromet_pdf_parameter_module, only: &
4689 : hydromet_pdf_parameter ! Variable(s)
4690 :
4691 : use index_mapping, only: &
4692 : hydromet2pdf_idx ! Procedure(s)
4693 :
4694 : use parameters_model, only: &
4695 : hydromet_dim ! Variable(s)
4696 :
4697 : use array_index, only: &
4698 : iiPDF_w, & ! Variable(s)
4699 : iiPDF_chi, &
4700 : iiPDF_eta, &
4701 : iiPDF_Ncn
4702 :
4703 : use clubb_precision, only: &
4704 : core_rknd ! Variable(s)
4705 :
4706 : implicit none
4707 :
4708 : ! Input Variables
4709 : integer, intent(in) :: &
4710 : nz, & ! Number of vertical grid levels
4711 : ngrdcol ! Number of grid columns
4712 :
4713 : real( kind = core_rknd ), dimension(ngrdcol,nz,hydromet_dim), intent(in) :: &
4714 : hm_1, & ! Mean of a precip. hydrometeor (1st PDF component) [units vary]
4715 : hm_2 ! Mean of a precip. hydrometeor (2nd PDF component) [units vary]
4716 :
4717 : integer, intent(in) :: &
4718 : pdf_dim ! Number of variables in the mean/stdev arrays
4719 :
4720 : real( kind = core_rknd ), dimension(ngrdcol,nz,pdf_dim), intent(in) :: &
4721 : mu_x_1, & ! Mean array of PDF vars. (1st PDF component) [units vary]
4722 : mu_x_2, & ! Mean array of PDF vars. (2nd PDF component) [units vary]
4723 : sigma_x_1, & ! Standard deviation array of PDF vars (comp. 1) [units vary]
4724 : sigma_x_2 ! Standard deviation array of PDF vars (comp. 2) [units vary]
4725 :
4726 : real( kind = core_rknd ), dimension(ngrdcol,nz,pdf_dim,pdf_dim), intent(in) :: &
4727 : corr_array_1, & ! Correlation array of PDF vars. (comp. 1) [-]
4728 : corr_array_2 ! Correlation array of PDF vars. (comp. 2) [-]
4729 :
4730 : ! Output Variable
4731 : type(hydromet_pdf_parameter), dimension(ngrdcol,nz), intent(out) :: &
4732 : hydromet_pdf_params ! Hydrometeor PDF parameters [units vary]
4733 :
4734 : ! Local Variables
4735 : integer :: ivar, jvar, pdf_idx ! Indices
4736 :
4737 :
4738 : ! Pack remaining means and standard deviations into hydromet_pdf_params.
4739 0 : do ivar = 1, hydromet_dim, 1
4740 :
4741 0 : pdf_idx = hydromet2pdf_idx(ivar)
4742 :
4743 : ! Mean of a hydrometeor (overall) in the 1st PDF component.
4744 0 : hydromet_pdf_params(:,:)%hm_1(ivar) = hm_1(:,:,ivar)
4745 : ! Mean of a hydrometeor (overall) in the 2nd PDF component.
4746 0 : hydromet_pdf_params(:,:)%hm_2(ivar) = hm_2(:,:,ivar)
4747 :
4748 : ! Mean of a hydrometeor (in-precip) in the 1st PDF component.
4749 0 : hydromet_pdf_params(:,:)%mu_hm_1(ivar) = mu_x_1(:,:,pdf_idx)
4750 : ! Mean of a hydrometeor (in-precip) in the 2nd PDF component.
4751 0 : hydromet_pdf_params(:,:)%mu_hm_2(ivar) = mu_x_2(:,:,pdf_idx)
4752 :
4753 : ! Standard deviation of a hydrometeor (in-precip) in the
4754 : ! 1st PDF component.
4755 0 : hydromet_pdf_params(:,:)%sigma_hm_1(ivar) = sigma_x_1(:,:,pdf_idx)
4756 : ! Standard deviation of a hydrometeor (in-precip) in the
4757 : ! 2nd PDF component.
4758 0 : hydromet_pdf_params(:,:)%sigma_hm_2(ivar) = sigma_x_2(:,:,pdf_idx)
4759 :
4760 : ! Correlation (in-precip) of w and a hydrometeor in the 1st PDF
4761 : ! component.
4762 0 : hydromet_pdf_params(:,:)%corr_w_hm_1(ivar) = corr_array_1(:,:,pdf_idx,iiPDF_w)
4763 :
4764 : ! Correlation (in-precip) of w and a hydrometeor in the 2nd PDF
4765 : ! component.
4766 0 : hydromet_pdf_params(:,:)%corr_w_hm_2(ivar) = corr_array_2(:,:,pdf_idx,iiPDF_w)
4767 :
4768 : ! Correlation (in-precip) of chi and a hydrometeor in the 1st PDF
4769 : ! component.
4770 0 : hydromet_pdf_params(:,:)%corr_chi_hm_1(ivar) &
4771 0 : = corr_array_1(:,:,pdf_idx,iiPDF_chi)
4772 :
4773 : ! Correlation (in-precip) of chi and a hydrometeor in the 2nd PDF
4774 : ! component.
4775 0 : hydromet_pdf_params(:,:)%corr_chi_hm_2(ivar) &
4776 0 : = corr_array_2(:,:,pdf_idx,iiPDF_chi)
4777 :
4778 : ! Correlation (in-precip) of eta and a hydrometeor in the 1st PDF
4779 : ! component.
4780 0 : hydromet_pdf_params(:,:)%corr_eta_hm_1(ivar) &
4781 0 : = corr_array_1(:,:,pdf_idx,iiPDF_eta)
4782 :
4783 : ! Correlation (in-precip) of eta and a hydrometeor in the 2nd PDF
4784 : ! component.
4785 0 : hydromet_pdf_params(:,:)%corr_eta_hm_2(ivar) &
4786 0 : = corr_array_2(:,:,pdf_idx,iiPDF_eta)
4787 :
4788 : ! Correlation (in-precip) of two hydrometeors, hmx and hmy, in the 1st
4789 : ! PDF component.
4790 0 : hydromet_pdf_params(:,:)%corr_hmx_hmy_1(ivar,ivar) = one
4791 :
4792 0 : do jvar = ivar+1, hydromet_dim, 1
4793 :
4794 0 : hydromet_pdf_params(:,:)%corr_hmx_hmy_1(jvar,ivar) &
4795 0 : = corr_array_1(:,:,hydromet2pdf_idx(jvar),pdf_idx)
4796 :
4797 0 : hydromet_pdf_params(:,:)%corr_hmx_hmy_1(ivar,jvar) &
4798 0 : = hydromet_pdf_params(:,:)%corr_hmx_hmy_1(jvar,ivar)
4799 :
4800 : end do ! jvar = ivar+1, hydromet_dim, 1
4801 :
4802 : ! Correlation (in-precip) of two hydrometeors, hmx and hmy, in the 2nd
4803 : ! PDF component.
4804 0 : hydromet_pdf_params(:,:)%corr_hmx_hmy_2(ivar,ivar) = one
4805 :
4806 0 : do jvar = ivar+1, hydromet_dim, 1
4807 :
4808 0 : hydromet_pdf_params(:,:)%corr_hmx_hmy_2(jvar,ivar) &
4809 0 : = corr_array_2(:,:,hydromet2pdf_idx(jvar),pdf_idx)
4810 :
4811 0 : hydromet_pdf_params(:,:)%corr_hmx_hmy_2(ivar,jvar) &
4812 0 : = hydromet_pdf_params(:,:)%corr_hmx_hmy_2(jvar,ivar)
4813 :
4814 : end do ! jvar = ivar+1, hydromet_dim, 1
4815 :
4816 : end do ! ivar = 1, hydromet_dim, 1
4817 :
4818 : ! Mean of Ncn (overall) in the 1st PDF component.
4819 0 : hydromet_pdf_params(:,:)%mu_Ncn_1 = mu_x_1(:,:,iiPDF_Ncn)
4820 : ! Mean of Ncn (overall) in the 2nd PDF component.
4821 0 : hydromet_pdf_params(:,:)%mu_Ncn_2 = mu_x_2(:,:,iiPDF_Ncn)
4822 :
4823 : ! Standard deviation of Ncn (overall) in the 1st PDF component.
4824 0 : hydromet_pdf_params(:,:)%sigma_Ncn_1 = sigma_x_1(:,:,iiPDF_Ncn)
4825 : ! Standard deviation of Ncn (overall) in the 2nd PDF component.
4826 0 : hydromet_pdf_params(:,:)%sigma_Ncn_2 = sigma_x_2(:,:,iiPDF_Ncn)
4827 :
4828 :
4829 0 : return
4830 :
4831 : end subroutine pack_hydromet_pdf_params
4832 :
4833 : !=============================================================================
4834 0 : elemental function compute_rtp2_from_chi( sigma_chi_1, sigma_chi_2, &
4835 : sigma_eta_1, sigma_eta_2, &
4836 : rt_1, rt_2, &
4837 : crt_1, crt_2, &
4838 : mixt_frac, &
4839 : corr_chi_eta_1, corr_chi_eta_2 ) &
4840 : result( rtp2_zt_from_chi )
4841 :
4842 : ! Description:
4843 : ! Compute the variance of rt from the distribution of chi and eta. The
4844 : ! resulting variance will be consistent with CLUBB's extended PDF
4845 : ! involving chi and eta, including if l_fix_w_chi_eta_correlations = .true..
4846 :
4847 : ! References:
4848 : ! None
4849 : !-----------------------------------------------------------------------
4850 :
4851 : use clubb_precision, only: &
4852 : core_rknd ! Constant
4853 :
4854 : use pdf_utilities, only: &
4855 : compute_variance_binormal ! Procedure
4856 :
4857 : use constants_clubb, only: &
4858 : one_half, & ! Constant(s)
4859 : one, &
4860 : two
4861 :
4862 : implicit none
4863 :
4864 : ! Input Variables
4865 : real( kind = core_rknd ), intent(in) :: &
4866 : sigma_chi_1, & ! Standard deviation of chi (1st PDF comp.) [kg/kg]
4867 : sigma_chi_2, & ! Standard deviation of chi (2nd PDF comp.) [kg/kg]
4868 : sigma_eta_1, & ! Standard deviation of eta (1st PDF comp.) [kg/kg]
4869 : sigma_eta_2, & ! Standard deviation of eta (2nd PDF comp.) [kg/kg]
4870 : crt_1, & ! Coef. of r_t in chi/eta eqns. (1st comp.) [-]
4871 : crt_2, & ! Coef. of r_t in chi/eta eqns. (2nd comp.) [-]
4872 : rt_1, & ! Mean of rt (1st PDF component) [kg/kg]
4873 : rt_2, & ! Mean of rt (2nd PDF component) [kg/kg]
4874 : mixt_frac ! Weight of 1st gaussian PDF component [-]
4875 :
4876 : real( kind = core_rknd ), intent(in) :: &
4877 : corr_chi_eta_1, & ! Correlation of chi and eta in 1st PDF component [-]
4878 : corr_chi_eta_2 ! Correlation of chi and eta in 2nd PDF component [-]
4879 :
4880 : ! Output Variable
4881 : real( kind = core_rknd ) :: &
4882 : rtp2_zt_from_chi ! Grid-box variance of rtp2 on thermo. levels [kg/kg]
4883 :
4884 : ! Local Variables
4885 : real( kind = core_rknd ) :: &
4886 : varnce_rt_1_zt_from_chi, varnce_rt_2_zt_from_chi
4887 :
4888 : real( kind = core_rknd ) :: &
4889 : rtm, & ! Mean of rt (overall) [kg/kg]
4890 : sigma_rt_1_from_chi, & ! Standard deviation of rt (1st PDF comp.) [kg/kg]
4891 : sigma_rt_2_from_chi ! Standard deviation of rt (2nd PDF comp.) [kg/kg]
4892 :
4893 :
4894 : !-----------------------------------------------------------------------
4895 :
4896 : !----- Begin Code -----
4897 :
4898 : varnce_rt_1_zt_from_chi &
4899 : = ( corr_chi_eta_1 * sigma_chi_1 * sigma_eta_1 &
4900 : + one_half * sigma_chi_1**2 + one_half * sigma_eta_1**2 ) &
4901 0 : / ( two * crt_1**2 )
4902 :
4903 : varnce_rt_2_zt_from_chi &
4904 : = ( corr_chi_eta_2 * sigma_chi_2 * sigma_eta_2 &
4905 : + one_half * sigma_chi_2**2 + one_half * sigma_eta_2**2 ) &
4906 0 : / ( two * crt_2**2 )
4907 :
4908 0 : rtm = mixt_frac*rt_1 + (one-mixt_frac)*rt_2
4909 :
4910 0 : sigma_rt_1_from_chi = sqrt( varnce_rt_1_zt_from_chi )
4911 0 : sigma_rt_2_from_chi = sqrt( varnce_rt_2_zt_from_chi )
4912 :
4913 : rtp2_zt_from_chi &
4914 : = compute_variance_binormal( rtm, rt_1, rt_2, sigma_rt_1_from_chi, &
4915 0 : sigma_rt_2_from_chi, mixt_frac )
4916 :
4917 :
4918 : return
4919 :
4920 : end function compute_rtp2_from_chi
4921 :
4922 : !===============================================================================
4923 :
4924 : end module setup_clubb_pdf_params
|