Line data Source code
1 : ! $Id$
2 : !===============================================================================
3 : module new_hybrid_pdf_main
4 :
5 : ! Description:
6 : ! The portion of CLUBB's multivariate, two-component PDF that is the
7 : ! multivariate, two-component normal PDF of vertical velocity (w), total water
8 : ! mixing ratio (rt), liquid water potential temperature (thl), and optionally,
9 : ! the west-east horizontal wind component (u), the south-north horizontal wind
10 : ! component (v), and passive scalars (sclr).
11 :
12 : ! References:
13 : !-------------------------------------------------------------------------
14 :
15 : implicit none
16 :
17 : public :: new_hybrid_pdf_driver ! Procedure(s)
18 :
19 : private :: calc_responder_driver, & ! Procedure(s)
20 : calc_F_w_zeta_w
21 :
22 : private
23 :
24 : contains
25 :
26 : !=============================================================================
27 0 : subroutine new_hybrid_pdf_driver( nz, ngrdcol, wm, rtm, thlm, um, vm, & ! In
28 0 : wp2, rtp2, thlp2, up2, vp2, & ! In
29 0 : Skw, wprtp, wpthlp, upwp, vpwp, & ! In
30 0 : sclrm, sclrp2, wpsclrp, & ! In
31 0 : gamma_Skw_fnc, & ! In
32 : slope_coef_spread_DG_means_w, & ! In
33 : pdf_component_stdev_factor_w, & ! In
34 0 : Skrt, Skthl, Sku, Skv, Sksclr, & ! I/O
35 0 : mu_w_1, mu_w_2, & ! Out
36 0 : mu_rt_1, mu_rt_2, & ! Out
37 0 : mu_thl_1, mu_thl_2, & ! Out
38 0 : mu_u_1, mu_u_2, mu_v_1, mu_v_2, & ! Out
39 0 : sigma_w_1_sqd, sigma_w_2_sqd, & ! Out
40 0 : sigma_rt_1_sqd, sigma_rt_2_sqd, & ! Out
41 0 : sigma_thl_1_sqd, sigma_thl_2_sqd, & ! Out
42 0 : sigma_u_1_sqd, sigma_u_2_sqd, & ! Out
43 0 : sigma_v_1_sqd, sigma_v_2_sqd, & ! Out
44 0 : mu_sclr_1, mu_sclr_2, & ! Out
45 0 : sigma_sclr_1_sqd, sigma_sclr_2_sqd, & ! Out
46 0 : mixt_frac, & ! Out
47 : pdf_implicit_coefs_terms, & ! Out
48 0 : F_w, min_F_w, max_F_w ) ! Out
49 :
50 :
51 : ! Description:
52 : ! Calculate the PDF parameters for w (including mixture fraction), rt,
53 : ! theta-l, and optionally, u, v, and passive scalar variables.
54 :
55 : ! References:
56 : !-----------------------------------------------------------------------
57 :
58 : use constants_clubb, only: &
59 : zero, & ! Constant(s)
60 : fstderr
61 :
62 : use new_hybrid_pdf, only: &
63 : calculate_w_params, & ! Procedure(s)
64 : calculate_coef_wp4_implicit, &
65 : calc_coef_wp2xp_implicit, &
66 : calc_coefs_wpxp2_semiimpl, &
67 : calc_coefs_wpxpyp_semiimpl
68 :
69 : use pdf_parameter_module, only: &
70 : implicit_coefs_terms ! Variable Type
71 :
72 : use model_flags, only: &
73 : l_explicit_turbulent_adv_wp3, & ! Variable(s)
74 : l_explicit_turbulent_adv_wpxp, &
75 : l_explicit_turbulent_adv_xpyp
76 :
77 : use parameters_model, only: &
78 : sclr_dim
79 :
80 : use clubb_precision, only: &
81 : core_rknd ! Variable(s)
82 :
83 : implicit none
84 :
85 : integer, intent(in) :: &
86 : nz, &
87 : ngrdcol
88 :
89 : ! Input Variables
90 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(in) :: &
91 : wm, & ! Mean of w (overall) [m/s]
92 : rtm, & ! Mean of rt (overall) [kg/kg]
93 : thlm, & ! Mean of thl (overall) [K]
94 : um, & ! Mean of u (overall) [m/s]
95 : vm, & ! Mean of v (overall) [m/s]
96 : wp2, & ! Variance of w (overall) [m^2/s^2]
97 : rtp2, & ! Variance of rt (overall) [kg^2/kg^2]
98 : thlp2, & ! Variance of thl (overall) [K^2]
99 : up2, & ! Variance of u (overall) [m^2/s^2]
100 : vp2, & ! Variance of v (overall) [m^2/s^2]
101 : Skw, & ! Skewness of w (overall) [-]
102 : wprtp, & ! Covariance of w and rt (overall) [(m/s)kg/kg]
103 : wpthlp, & ! Covariance of w and thl (overall) [(m/s)K]
104 : upwp, & ! Covariance of u and w (overall) [m^2/s^2]
105 : vpwp ! Covariance of v and w (overall) [m^2/s^2]
106 :
107 : real( kind = core_rknd ), dimension(ngrdcol,nz,sclr_dim), intent(in) :: &
108 : sclrm, & ! Mean of sclr (overall) [units vary]
109 : sclrp2, & ! Variance of sclr (overall) [(units vary)^2]
110 : wpsclrp ! Covariance of w and sclr (overall) [(m/s)(units vary)]
111 :
112 : ! Tunable parameter gamma.
113 : ! When gamma goes to 0, the standard deviations of w in each PDF component
114 : ! become small, and the spread between the two PDF component means of w
115 : ! becomes large. F_w goes to min_F_w.
116 : ! When gamma goes to 1, the standard deviations of w in each PDF component
117 : ! become large, and the spread between the two PDF component means of w
118 : ! becomes small. F_w goes to max_F_w.
119 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(in) :: &
120 : gamma_Skw_fnc ! Value of parameter gamma from tunable Skw function [-]
121 :
122 : real( kind = core_rknd ), intent(in) :: &
123 : ! Slope coefficient for the spread between the PDF component means of w.
124 : slope_coef_spread_DG_means_w, &
125 : ! Parameter to adjust the PDF component standard deviations of w.
126 : pdf_component_stdev_factor_w
127 :
128 : ! Input/Output Variables
129 : ! These variables are input/output because their values may be clipped.
130 : ! Otherwise, as long as it is not necessary to clip them, their values
131 : ! will stay the same.
132 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(inout) :: &
133 : Skrt, & ! Skewness of rt (overall) [-]
134 : Skthl, & ! Skewness of thl (overall) [-]
135 : Sku, & ! Skewness of u (overall) [-]
136 : Skv ! Skewness of v (overall) [-]
137 :
138 : real( kind = core_rknd ), dimension(ngrdcol,nz,sclr_dim), intent(inout) :: &
139 : Sksclr ! Skewness of sclr (overall) [-]
140 :
141 : ! Output Variables
142 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(out) :: &
143 : mu_w_1, & ! Mean of w (1st PDF component) [m/s]
144 : mu_w_2, & ! Mean of w (2nd PDF component) [m/s]
145 : mu_rt_1, & ! Mean of rt (1st PDF component) [kg/kg]
146 : mu_rt_2, & ! Mean of rt (2nd PDF component) [kg/kg]
147 : mu_thl_1, & ! Mean of thl (1st PDF component) [K]
148 : mu_thl_2, & ! Mean of thl (2nd PDF component) [K]
149 : mu_u_1, & ! Mean of u (1st PDF component) [m/s]
150 : mu_u_2, & ! Mean of u (2nd PDF component) [m/s]
151 : mu_v_1, & ! Mean of v (1st PDF component) [m/s]
152 : mu_v_2, & ! Mean of v (2nd PDF component) [m/s]
153 : sigma_w_1_sqd, & ! Variance of w (1st PDF component) [m^2/s^2]
154 : sigma_w_2_sqd, & ! Variance of w (2nd PDF component) [m^2/s^2]
155 : sigma_rt_1_sqd, & ! Variance of rt (1st PDF component) [kg^2/kg^2]
156 : sigma_rt_2_sqd, & ! Variance of rt (2nd PDF component) [kg^2/kg^2]
157 : sigma_thl_1_sqd, & ! Variance of thl (1st PDF component) [K^2]
158 : sigma_thl_2_sqd, & ! Variance of thl (2nd PDF component) [K^2]
159 : sigma_u_1_sqd, & ! Variance of u (1st PDF component) [m^2/s^2]
160 : sigma_u_2_sqd, & ! Variance of u (2nd PDF component) [m^2/s^2]
161 : sigma_v_1_sqd, & ! Variance of v (1st PDF component) [m^2/s^2]
162 : sigma_v_2_sqd, & ! Variance of v (2nd PDF component) [m^2/s^2]
163 : mixt_frac ! Mixture fraction [-]
164 :
165 : real( kind = core_rknd ), dimension(ngrdcol,nz,sclr_dim), intent(out) :: &
166 : mu_sclr_1, & ! Mean of sclr (1st PDF component) [units vary]
167 : mu_sclr_2, & ! Mean of sclr (2nd PDF component) [units vary]
168 : sigma_sclr_1_sqd, & ! Variance of sclr (1st PDF component) [(un. vary)^2]
169 : sigma_sclr_2_sqd ! Variance of sclr (2nd PDF component) [(un. vary)^2]
170 :
171 : type(implicit_coefs_terms), intent(inout) :: &
172 : pdf_implicit_coefs_terms ! Implicit coefs / explicit terms [units vary]
173 :
174 : ! Output only for recording statistics.
175 : real( kind = core_rknd ), dimension(ngrdcol,nz), intent(out) :: &
176 : F_w, & ! Parameter for the spread of the PDF component means of w [-]
177 : min_F_w, & ! Minimum allowable value of parameter F_w [-]
178 : max_F_w ! Maximum allowable value of parameter F_w [-]
179 :
180 : ! Local Variables
181 : real( kind = core_rknd ), dimension(nz) :: &
182 0 : sigma_w_1, & ! Standard deviation of w (1st PDF component) [m/s]
183 0 : sigma_w_2 ! Standard deviation of w (2nd PDF component) [m/s]
184 :
185 : real( kind = core_rknd ), dimension(nz) :: &
186 0 : coef_sigma_w_1_sqd, & ! sigma_w_1^2 = coef_sigma_w_1_sqd * <w'^2> [-]
187 0 : coef_sigma_w_2_sqd, & ! sigma_w_2^2 = coef_sigma_w_2_sqd * <w'^2> [-]
188 0 : coef_sigma_rt_1_sqd, & ! sigma_rt_1^2 = coef_sigma_rt_1_sqd * <rt'^2> [-]
189 0 : coef_sigma_rt_2_sqd, & ! sigma_rt_2^2 = coef_sigma_rt_2_sqd * <rt'^2> [-]
190 0 : coef_sigma_thl_1_sqd, & ! sigma_thl_1^2=coef_sigma_thl_1_sqd*<thl'^2> [-]
191 0 : coef_sigma_thl_2_sqd, & ! sigma_thl_2^2=coef_sigma_thl_2_sqd*<thl'^2> [-]
192 0 : coef_sigma_u_1_sqd, & ! sigma_u_1^2 = coef_sigma_u_1_sqd * <u'^2> [-]
193 0 : coef_sigma_u_2_sqd, & ! sigma_u_2^2 = coef_sigma_u_2_sqd * <u'^2> [-]
194 0 : coef_sigma_v_1_sqd, & ! sigma_v_1^2 = coef_sigma_v_1_sqd * <v'^2> [-]
195 0 : coef_sigma_v_2_sqd ! sigma_v_2^2 = coef_sigma_v_2_sqd * <v'^2> [-]
196 :
197 : ! sigma_sclr_1^2 = coef_sigma_sclr_1_sqd * <sclr'^2>
198 : ! sigma_sclr_2^2 = coef_sigma_sclr_2_sqd * <sclr'^2>
199 : real( kind = core_rknd ), dimension(nz,sclr_dim) :: &
200 0 : coef_sigma_sclr_1_sqd, & ! Coefficient that is multiplied by <sclr'^2> [-]
201 0 : coef_sigma_sclr_2_sqd ! Coefficient that is multiplied by <sclr'^2> [-]
202 :
203 : real( kind = core_rknd ), dimension(nz) :: &
204 0 : zeta_w ! Parameter for the PDF component variances of w [-]
205 :
206 : real( kind = core_rknd ), dimension(nz) :: &
207 : ! Slope coefficient for the spread between the PDF component means of w.
208 0 : slope_coef_spread_DG_means_w_in, &
209 : ! Parameter to adjust the PDF component standard deviations of w.
210 0 : pdf_component_stdev_factor_w_in
211 :
212 : real( kind = core_rknd ), dimension(nz) :: &
213 0 : coef_wp4_implicit, & ! <w'^4> = coef_wp4_implicit * <w'^2>^2 [-]
214 0 : coef_wp2rtp_implicit, & ! <w'^2 rt'> = coef_wp2rtp_implicit*<w'rt'> [m/s]
215 0 : coef_wp2thlp_implicit, & ! <w'^2 thl'>=coef_wp2thlp_implicit*<w'thl'>[m/s]
216 0 : coef_wp2up_implicit, & ! <w'^2 u'> = coef_wp2up_implicit * <u'w'> [m/s]
217 0 : coef_wp2vp_implicit ! <w'^2 v'> = coef_wp2vp_implicit * <v'w'> [m/s]
218 :
219 : ! <w'^2 sclr'> = coef_wp2sclrp_implicit * <w'sclr'>
220 : real( kind = core_rknd ), dimension(nz,sclr_dim) :: &
221 0 : coef_wp2sclrp_implicit ! Coef. that is multiplied by <w'sclr'> [m/s]
222 :
223 : ! <w'rt'^2> = coef_wprtp2_implicit * <rt'^2> + term_wprtp2_explicit
224 : real( kind = core_rknd ), dimension(nz) :: &
225 0 : coef_wprtp2_implicit, & ! Coefficient that is multiplied by <rt'^2> [m/s]
226 0 : term_wprtp2_explicit ! Term that is on the RHS [m/s kg^2/kg^2]
227 :
228 : ! <w'thl'^2> = coef_wpthlp2_implicit * <thl'^2> + term_wpthlp2_explicit
229 : real( kind = core_rknd ), dimension(nz) :: &
230 0 : coef_wpthlp2_implicit, & ! Coef. that is multiplied by <thl'^2> [m/s]
231 0 : term_wpthlp2_explicit ! Term that is on the RHS [m/s K^2]
232 :
233 : ! <w'rt'thl'> = coef_wprtpthlp_implicit*<rt'thl'> + term_wprtpthlp_explicit
234 : real( kind = core_rknd ), dimension(nz) :: &
235 0 : coef_wprtpthlp_implicit, & ! Coef. that is multiplied by <rt'thl'> [m/s]
236 0 : term_wprtpthlp_explicit ! Term that is on the RHS [m/s(kg/kg)K]
237 :
238 : ! <w'u'^2> = coef_wpup2_implicit * <u'^2> + term_wpup2_explicit
239 : real( kind = core_rknd ), dimension(nz) :: &
240 0 : coef_wpup2_implicit, & ! Coefficient that is multiplied by <u'^2> [m/s]
241 0 : term_wpup2_explicit ! Term that is on the RHS [m^3/s^3]
242 :
243 : ! <w'v'^2> = coef_wpvp2_implicit * <v'^2> + term_wpvp2_explicit
244 : real( kind = core_rknd ), dimension(nz) :: &
245 0 : coef_wpvp2_implicit, & ! Coefficient that is multiplied by <v'^2> [m/s]
246 0 : term_wpvp2_explicit ! Term that is on the RHS [m^3/s^3]
247 :
248 : ! <w'sclr'^2> = coef_wpsclrp2_implicit * <sclr'^2> + term_wpsclrp2_explicit
249 : real( kind = core_rknd ), dimension(nz,sclr_dim) :: &
250 0 : coef_wpsclrp2_implicit, & ! Coef. that is multiplied by <sclr'^2> [m/s]
251 0 : term_wpsclrp2_explicit ! Term that is on the RHS [m/s(units vary)^2]
252 :
253 : ! <w'rt'sclr'> = coef_wprtpsclrp_implicit * <sclr'rt'>
254 : ! + term_wprtpsclrp_explicit
255 : real( kind = core_rknd ), dimension(nz,sclr_dim) :: &
256 0 : coef_wprtpsclrp_implicit, & ! Coef. that is multiplied by <sclr'rt'> [m/s]
257 0 : term_wprtpsclrp_explicit ! Term that is on the RHS [m/s(kg/kg)(un. v.)]
258 :
259 : ! <w'thl'sclr'> = coef_wpthlpsclrp_implicit * <sclr'thl'>
260 : ! + term_wpthlpsclrp_explicit
261 : real( kind = core_rknd ), dimension(nz,sclr_dim) :: &
262 0 : coef_wpthlpsclrp_implicit, & ! Coef. that is mult. by <sclr'thl'> [m/s]
263 0 : term_wpthlpsclrp_explicit ! Term that is on the RHS [(m/s)K(un. vary)]
264 :
265 : ! Variables to interface with code for the jth scalar
266 : real( kind = core_rknd ), dimension(nz) :: &
267 0 : sclrjm, & ! Mean of sclr j (overall) [units vary]
268 0 : sclrjp2, & ! Variance of sclr j (overall) [(units vary)^2]
269 0 : wpsclrjp, & ! Covariance of w and sclr j (overall) [(m/s)(units vary)]
270 0 : Sksclrj ! Skewness of rt (overall) [-]
271 :
272 : real( kind = core_rknd ), dimension(nz) :: &
273 0 : mu_sclrj_1, & ! Mean of sclr j (1st PDF component) [units vary]
274 0 : mu_sclrj_2, & ! Mean of sclr j (2nd PDF component) [units vary]
275 0 : sigma_sclrj_1_sqd, & ! Variance of sclr j (1st PDF comp.) [(units vary)^2]
276 0 : sigma_sclrj_2_sqd ! Variance of sclr j (2nd PDF comp.) [(units vary)^2]
277 :
278 : ! sigma_sclrj_1^2 = coef_sigma_sclrj_1_sqd * <sclrj'^2>
279 : ! sigma_sclrj_2^2 = coef_sigma_sclrj_2_sqd * <sclrj'^2>
280 : real( kind = core_rknd ), dimension(nz) :: &
281 0 : coef_sigma_sclrj_1_sqd, & ! Coef. that is multiplied by <sclrj'^2> [-]
282 0 : coef_sigma_sclrj_2_sqd ! Coef. that is multiplied by <sclrj'^2> [-]
283 :
284 : ! <w'sclrj'^2> = coef_wpsclrjp2_implicit * <sclrj'^2>
285 : ! + term_wpsclrjp2_explicit
286 : real( kind = core_rknd ), dimension(nz) :: &
287 0 : coef_wpsclrjp2_implicit, & ! Coef. that is multiplied by <sclrj'^2> [m/s]
288 0 : term_wpsclrjp2_explicit ! Term that is on the RHS [m/s(units vary)^2]
289 :
290 : ! <w'rt'sclrj'> = coef_wprtpsclrjp_implicit * <sclrj'rt'>
291 : ! + term_wprtpsclrjp_explicit
292 : real( kind = core_rknd ), dimension(nz) :: &
293 0 : coef_wprtpsclrjp_implicit, & ! Coef. that is mult. by <sclr'rt'> [m/s]
294 0 : term_wprtpsclrjp_explicit ! Term that is on the RHS [m/s(kg/kg)(un.v.)]
295 :
296 : ! <w'thl'sclrj'> = coef_wpthlpsclrjp_implicit * <sclrj'thl'>
297 : ! + term_wpthlpsclrjp_explicit
298 : real( kind = core_rknd ), dimension(nz) :: &
299 0 : coef_wpthlpsclrjp_implicit, & ! Coef. that is mult. by <sclrj'thl'> [m/s]
300 0 : term_wpthlpsclrjp_explicit ! Term that is on the RHS [(m/s)K(un. vary)]
301 :
302 : real( kind = core_rknd ), dimension(nz) :: &
303 0 : max_corr_w_sclr_sqd ! Max value of wpsclrp^2 / ( wp2 * sclrp2 ) [-]
304 :
305 : real( kind = core_rknd ), dimension(nz) :: &
306 0 : zeros ! Vector of 0s (size nz) [-]
307 :
308 : real( kind = core_rknd ), dimension(nz,sclr_dim) :: &
309 0 : zero_array ! Array of 0s (size nz x sclr_dim) [-]
310 :
311 : integer :: i, k, j ! Loop indices
312 :
313 0 : do i = 1, ngrdcol
314 :
315 : ! Calculate the maximum value of the square of the correlation of w and a
316 : ! scalar when scalars are used.
317 : ! Initialize max_corr_w_sclr_sqd to 0. It needs to retain this value even
318 : ! when sclr_dim = 0.
319 0 : max_corr_w_sclr_sqd = zero
320 0 : if ( sclr_dim > 0 ) then
321 0 : do k = 1, nz, 1
322 0 : do j = 1, sclr_dim, 1
323 0 : if ( wp2(i,k) * sclrp2(i,k,j) > zero ) then
324 : max_corr_w_sclr_sqd(k) = max( wpsclrp(i,k,j)**2 &
325 : / ( wp2(i,k) * sclrp2(i,k,j) ), &
326 0 : max_corr_w_sclr_sqd(k) )
327 : endif ! wp2(k) * sclrp2(k,j) > 0
328 : enddo ! j = 1, sclr_dim, 1
329 : enddo ! k = 1, nz, 1
330 : endif ! sclr_dim > 0
331 :
332 0 : slope_coef_spread_DG_means_w_in = slope_coef_spread_DG_means_w
333 0 : pdf_component_stdev_factor_w_in = pdf_component_stdev_factor_w
334 :
335 : ! Calculate the values of PDF tunable parameters F_w and zeta_w.
336 : ! Vertical velocity, w, will always be the setter variable.
337 0 : call calc_F_w_zeta_w( Skw(i,:), wprtp(i,:), wpthlp(i,:), upwp(i,:), vpwp(i,:), & ! In
338 : wp2(i,:), rtp2(i,:), thlp2(i,:), up2(i,:), vp2(i,:), & ! In
339 : gamma_Skw_fnc(i,:), & ! In
340 : slope_coef_spread_DG_means_w_in, & ! In
341 : pdf_component_stdev_factor_w_in, & ! In
342 : max_corr_w_sclr_sqd, & ! In
343 0 : F_w(i,:), zeta_w, min_F_w(i,:), max_F_w(i,:) ) ! Out
344 :
345 : ! Calculate the PDF parameters, including mixture fraction, for the
346 : ! setter variable, w.
347 : call calculate_w_params( wm(i,:), wp2(i,:), Skw(i,:), F_w(i,:), zeta_w, & ! In
348 : mu_w_1(i,:), mu_w_2(i,:), sigma_w_1, & ! Out
349 : sigma_w_2, mixt_frac(i,:), & ! Out
350 : coef_sigma_w_1_sqd, & ! Out
351 0 : coef_sigma_w_2_sqd ) ! Out
352 :
353 0 : sigma_w_1_sqd(i,:) = sigma_w_1**2
354 0 : sigma_w_2_sqd(i,:) = sigma_w_2**2
355 :
356 0 : if ( any( mixt_frac(i,:) < zero ) ) then
357 0 : write(fstderr,*) "Mixture fraction cannot be calculated."
358 : write(fstderr,*) "The value of F_w must be greater than 0 when " &
359 0 : // "| Skw | > 0."
360 0 : error stop
361 : endif
362 :
363 : ! Calculate the PDF parameters for responder variable rt.
364 : call calc_responder_driver( rtm(i,:), rtp2(i,:), wprtp(i,:), wp2(i,:), & ! In
365 : mixt_frac(i,:), F_w(i,:), & ! In
366 : Skrt(i,:), & ! In/Out
367 : mu_rt_1(i,:), mu_rt_2(i,:), & ! Out
368 : sigma_rt_1_sqd(i,:), & ! Out
369 : sigma_rt_2_sqd(i,:), & ! Out
370 : coef_sigma_rt_1_sqd, & ! Out
371 0 : coef_sigma_rt_2_sqd ) ! Out
372 :
373 : ! Calculate the PDF parameters for responder variable thl.
374 : call calc_responder_driver( thlm(i,:), thlp2(i,:), wpthlp(i,:), wp2(i,:), & ! In
375 : mixt_frac(i,:), F_w(i,:), & ! In
376 : Skthl(i,:), & ! In/Out
377 : mu_thl_1(i,:), mu_thl_2(i,:), & ! Out
378 : sigma_thl_1_sqd(i,:), & ! Out
379 : sigma_thl_2_sqd(i,:), & ! Out
380 : coef_sigma_thl_1_sqd, & ! Out
381 0 : coef_sigma_thl_2_sqd ) ! Out
382 :
383 : ! Calculate the PDF parameters for responder variable u.
384 : call calc_responder_driver( um(i,:), up2(i,:), upwp(i,:), wp2(i,:), & ! In
385 : mixt_frac(i,:), F_w(i,:), & ! In
386 : Sku(i,:), & ! In/Out
387 : mu_u_1(i,:), mu_u_2(i,:), & ! Out
388 : sigma_u_1_sqd(i,:), & ! Out
389 : sigma_u_2_sqd(i,:), & ! Out
390 : coef_sigma_u_1_sqd, & ! Out
391 0 : coef_sigma_u_2_sqd ) ! Out
392 :
393 : ! Calculate the PDF parameters for responder variable v.
394 : call calc_responder_driver( vm(i,:), vp2(i,:), vpwp(i,:), wp2(i,:), & ! In
395 : mixt_frac(i,:), F_w(i,:), & ! In
396 : Skv(i,:), & ! In/Out
397 : mu_v_1(i,:), mu_v_2(i,:), & ! Out
398 : sigma_v_1_sqd(i,:), & ! Out
399 : sigma_v_2_sqd(i,:), & ! Out
400 : coef_sigma_v_1_sqd, & ! Out
401 0 : coef_sigma_v_2_sqd ) ! Out
402 :
403 : ! Calculate the PDF parameters for responder variable sclr.
404 0 : if ( sclr_dim > 0 ) then
405 :
406 0 : do j = 1, sclr_dim, 1
407 :
408 0 : do k = 1, nz, 1
409 0 : sclrjm(k) = sclrm(i,k,j)
410 0 : sclrjp2(k) = sclrp2(i,k,j)
411 0 : wpsclrjp(k) = wpsclrp(i,k,j)
412 0 : Sksclrj(k) = Sksclr(i,k,j)
413 : enddo ! k = 1, nz, 1
414 :
415 : call calc_responder_driver( sclrjm, sclrjp2, wpsclrjp, wp2(i,:), & ! In
416 : mixt_frac(i,:), F_w(i,:), & ! In
417 : Sksclrj, & ! In/Out
418 : mu_sclrj_1, mu_sclrj_2, & ! Out
419 : sigma_sclrj_1_sqd, & ! Out
420 : sigma_sclrj_2_sqd, & ! Out
421 : coef_sigma_sclrj_1_sqd, & ! Out
422 0 : coef_sigma_sclrj_2_sqd ) ! Out
423 :
424 0 : do k = 1, nz, 1
425 0 : Sksclr(i,k,j) = Sksclrj(k)
426 0 : mu_sclr_1(i,k,j) = mu_sclrj_1(k)
427 0 : mu_sclr_2(i,k,j) = mu_sclrj_2(k)
428 0 : sigma_sclr_1_sqd(i,k,j) = sigma_sclrj_1_sqd(k)
429 0 : sigma_sclr_2_sqd(i,k,j) = sigma_sclrj_2_sqd(k)
430 0 : coef_sigma_sclr_1_sqd(k,j) = coef_sigma_sclrj_1_sqd(k)
431 0 : coef_sigma_sclr_2_sqd(k,j) = coef_sigma_sclrj_2_sqd(k)
432 : enddo ! k = 1, nz, 1
433 :
434 : enddo ! j = 1, sclr_dim, 1
435 :
436 : endif ! sclr_dim > 0
437 :
438 :
439 : if ( .not. l_explicit_turbulent_adv_wp3 ) then
440 :
441 : ! Turbulent advection of <w'^3> is being handled implicitly.
442 :
443 : ! <w'^4> = coef_wp4_implicit * <w'^2>^2.
444 : coef_wp4_implicit &
445 : = calculate_coef_wp4_implicit( mixt_frac(i,:), F_w(i,:), &
446 : coef_sigma_w_1_sqd, &
447 0 : coef_sigma_w_2_sqd )
448 :
449 : else ! l_explicit_turbulent_adv_wp3
450 :
451 : ! Turbulent advection of <w'^3> is being handled explicitly.
452 : coef_wp4_implicit = zero
453 :
454 : endif ! .not. l_explicit_turbulent_adv_wp3
455 :
456 : if ( .not. l_explicit_turbulent_adv_wpxp ) then
457 :
458 : ! Turbulent advection of <w'rt'>, <w'thl'>, <u'w'>, <v'w'>, and <w'sclr'>
459 : ! are all being handled implicitly.
460 :
461 : ! <w'^2 rt'> = coef_wp2rtp_implicit * <w'rt'>
462 : coef_wp2rtp_implicit = calc_coef_wp2xp_implicit( wp2(i,:), mixt_frac(i,:), F_w(i,:), &
463 : coef_sigma_w_1_sqd, &
464 0 : coef_sigma_w_2_sqd )
465 :
466 : ! <w'^2 thl'> = coef_wp2thlp_implicit * <w'thl'>;
467 : ! <w'^2 u'> = coef_wp2up_implicit * <u'w'>; and
468 : ! <w'^2 v'> = coef_wp2vp_implicit * <v'w'>;
469 : ! where each coef_wp2xp_implicit is the same as coef_wp2rtp_implicit.
470 0 : coef_wp2thlp_implicit = coef_wp2rtp_implicit
471 0 : coef_wp2up_implicit = coef_wp2rtp_implicit
472 0 : coef_wp2vp_implicit = coef_wp2rtp_implicit
473 :
474 : ! <w'^2 sclr'> = coef_wp2sclrp_implicit * <w'sclr'>;
475 : ! where each coef_wp2xp_implicit is the same as coef_wp2rtp_implicit.
476 0 : if ( sclr_dim > 0 ) then
477 0 : do k = 1, nz, 1
478 0 : do j = 1, sclr_dim, 1
479 0 : coef_wp2sclrp_implicit(k,j) = coef_wp2rtp_implicit(k)
480 : enddo ! j = 1, sclr_dim, 1
481 : enddo ! k = 1, nz, 1
482 : endif ! sclr_dim > 0
483 :
484 : else ! l_explicit_turbulent_adv_wpxp
485 :
486 : ! Turbulent advection of <w'rt'>, <w'thl'>, <u'w'>, <v'w'>, and <w'sclr'>
487 : ! are all being handled explicitly.
488 : coef_wp2rtp_implicit = zero
489 : coef_wp2thlp_implicit = zero
490 : coef_wp2up_implicit = zero
491 : coef_wp2vp_implicit = zero
492 : if ( sclr_dim > 0 ) then
493 : coef_wp2sclrp_implicit = zero
494 : endif ! sclr_dim > 0
495 :
496 : endif ! .not. l_explicit_turbulent_adv_wpxp
497 :
498 : if ( .not. l_explicit_turbulent_adv_xpyp ) then
499 :
500 : ! Turbulent advection of <rt'^2>, <thl'^2>, <rt'thl'>, <u'^2>, <v'^2>,
501 : ! <sclr'^2>, <sclr'rt'>, and <sclr'thl'> are all being handled
502 : ! semi-implicitly.
503 :
504 : ! <w'rt'^2> = coef_wprtp2_implicit * <rt'^2> + term_wprtp2_explicit
505 : call calc_coefs_wpxp2_semiimpl( wp2(i,:), wprtp(i,:), & ! In
506 : mixt_frac(i,:), F_w(i,:), & ! In
507 : coef_sigma_rt_1_sqd, & ! In
508 : coef_sigma_rt_2_sqd, & ! In
509 : coef_wprtp2_implicit, & ! Out
510 0 : term_wprtp2_explicit ) ! Out
511 :
512 : ! <w'thl'^2> = coef_wpthlp2_implicit * <thl'^2> + term_wprtp2_explicit
513 : call calc_coefs_wpxp2_semiimpl( wp2(i,:), wpthlp(i,:), & ! In
514 : mixt_frac(i,:), F_w(i,:), & ! In
515 : coef_sigma_thl_1_sqd, & ! In
516 : coef_sigma_thl_2_sqd, & ! In
517 : coef_wpthlp2_implicit, & ! Out
518 0 : term_wpthlp2_explicit ) ! Out
519 :
520 : ! <w'rt'thl'> = coef_wprtpthlp_implicit * <rt'thl'>
521 : ! + term_wprtpthlp_explicit
522 : call calc_coefs_wpxpyp_semiimpl( wp2(i,:), wprtp(i,:), wpthlp(i,:), & ! In
523 : mixt_frac(i,:), F_w(i,:), & ! In
524 : coef_sigma_rt_1_sqd, & ! In
525 : coef_sigma_rt_2_sqd, & ! In
526 : coef_sigma_thl_1_sqd, & ! In
527 : coef_sigma_thl_2_sqd, & ! In
528 : coef_wprtpthlp_implicit, & ! Out
529 0 : term_wprtpthlp_explicit ) ! Out
530 :
531 : ! <w'u'^2> = coef_wpup2_implicit * <u'^2> + term_wpup2_explicit
532 : call calc_coefs_wpxp2_semiimpl( wp2(i,:), upwp(i,:), & ! In
533 : mixt_frac(i,:), F_w(i,:), & ! In
534 : coef_sigma_u_1_sqd, & ! In
535 : coef_sigma_u_2_sqd, & ! In
536 : coef_wpup2_implicit, & ! Out
537 0 : term_wpup2_explicit ) ! Out
538 :
539 : ! <w'v'^2> = coef_wpvp2_implicit * <v'^2> + term_wpvp2_explicit
540 : call calc_coefs_wpxp2_semiimpl( wp2(i,:), vpwp(i,:), & ! In
541 : mixt_frac(i,:), F_w(i,:), & ! In
542 : coef_sigma_v_1_sqd, & ! In
543 : coef_sigma_v_2_sqd, & ! In
544 : coef_wpvp2_implicit, & ! Out
545 0 : term_wpvp2_explicit ) ! Out
546 :
547 0 : if ( sclr_dim > 0 ) then
548 :
549 0 : do j = 1, sclr_dim, 1
550 :
551 0 : do k = 1, nz, 1
552 0 : wpsclrjp(k) = wpsclrp(i,k,j)
553 0 : coef_sigma_sclrj_1_sqd(k) = coef_sigma_sclr_1_sqd(k,j)
554 0 : coef_sigma_sclrj_2_sqd(k) = coef_sigma_sclr_2_sqd(k,j)
555 : enddo ! k = 1, nz, 1
556 :
557 : ! <w'sclr'^2> = coef_wpsclrp2_implicit * <sclr'^2>
558 : ! + term_wpsclrp2_explicit
559 : call calc_coefs_wpxp2_semiimpl( wp2(i,:), wpsclrjp, & ! In
560 : mixt_frac(i,:), F_w(i,:), & ! In
561 : coef_sigma_sclrj_1_sqd, & ! In
562 : coef_sigma_sclrj_2_sqd, & ! In
563 : coef_wpsclrjp2_implicit, & ! Out
564 0 : term_wpsclrjp2_explicit ) ! Out
565 :
566 : ! <w'rt'sclr'> = coef_wprtpsclrp_implicit * <sclr'rt'>
567 : ! + term_wprtpsclrp_explicit
568 : call calc_coefs_wpxpyp_semiimpl( wp2(i,:), wprtp(i,:), wpsclrjp, & ! In
569 : mixt_frac(i,:), F_w(i,:), & ! In
570 : coef_sigma_rt_1_sqd, & ! In
571 : coef_sigma_rt_2_sqd, & ! In
572 : coef_sigma_sclrj_1_sqd, & ! In
573 : coef_sigma_sclrj_2_sqd, & ! In
574 : coef_wprtpsclrjp_implicit, & ! Out
575 0 : term_wprtpsclrjp_explicit ) ! Out
576 :
577 : ! <w'thl'sclr'> = coef_wpthlpsclrp_implicit * <sclr'thl'>
578 : ! + term_wpthlpsclrp_explicit
579 : call calc_coefs_wpxpyp_semiimpl( wp2(i,:), wpthlp(i,:), wpsclrjp, & ! In
580 : mixt_frac(i,:), F_w(i,:), & ! In
581 : coef_sigma_thl_1_sqd, & ! In
582 : coef_sigma_thl_2_sqd, & ! In
583 : coef_sigma_sclrj_1_sqd, & ! In
584 : coef_sigma_sclrj_2_sqd, & ! In
585 : coef_wpthlpsclrjp_implicit, & ! Out
586 0 : term_wpthlpsclrjp_explicit ) ! Out
587 :
588 0 : do k = 1, nz, 1
589 0 : coef_wpsclrp2_implicit(k,j) = coef_wpsclrjp2_implicit(k)
590 0 : term_wpsclrp2_explicit(k,j) = term_wpsclrjp2_explicit(k)
591 0 : coef_wprtpsclrp_implicit(k,j) = coef_wprtpsclrjp_implicit(k)
592 0 : term_wprtpsclrp_explicit(k,j) = term_wprtpsclrjp_explicit(k)
593 0 : coef_wpthlpsclrp_implicit(k,j) = coef_wpthlpsclrjp_implicit(k)
594 0 : term_wpthlpsclrp_explicit(k,j) = term_wpthlpsclrjp_explicit(k)
595 : enddo ! k = 1, nz, 1
596 :
597 : enddo ! j = 1, sclr_dim, 1
598 :
599 : endif ! sclr_dim > 0
600 :
601 : else ! l_explicit_turbulent_adv_xpyp
602 :
603 : ! Turbulent advection of <rt'^2>, <thl'^2>, <rt'thl'>, <u'^2>, <v'^2>,
604 : ! <sclr'^2>, <sclr'rt'>, and <sclr'thl'> are being handled explicitly.
605 : coef_wprtp2_implicit = zero
606 : term_wprtp2_explicit = zero
607 : coef_wpthlp2_implicit = zero
608 : term_wpthlp2_explicit = zero
609 : coef_wprtpthlp_implicit = zero
610 : term_wprtpthlp_explicit = zero
611 : coef_wpup2_implicit = zero
612 : term_wpup2_explicit = zero
613 : coef_wpvp2_implicit = zero
614 : term_wpvp2_explicit = zero
615 : if ( sclr_dim > 0 ) then
616 : coef_wpsclrp2_implicit = zero
617 : term_wpsclrp2_explicit = zero
618 : coef_wprtpsclrp_implicit = zero
619 : term_wprtpsclrp_explicit = zero
620 : coef_wpthlpsclrp_implicit = zero
621 : term_wpthlpsclrp_explicit = zero
622 : endif ! sclr_dim > 0
623 :
624 : endif ! .not. l_explicit_turbulent_adv_xpyp
625 :
626 : ! Set up a vector of 0s and an array of 0s to help write results back to
627 : ! type variable pdf_implicit_coefs_terms.
628 0 : zeros = zero
629 0 : zero_array = zero
630 :
631 : ! Pack the implicit coefficients and explicit terms into a single type
632 : ! variable for output.
633 0 : pdf_implicit_coefs_terms%coef_wp4_implicit(i,:) = coef_wp4_implicit
634 0 : pdf_implicit_coefs_terms%coef_wp2rtp_implicit(i,:) = coef_wp2rtp_implicit
635 0 : pdf_implicit_coefs_terms%term_wp2rtp_explicit(i,:) = zeros
636 0 : pdf_implicit_coefs_terms%coef_wp2thlp_implicit(i,:) = coef_wp2thlp_implicit
637 0 : pdf_implicit_coefs_terms%term_wp2thlp_explicit(i,:) = zeros
638 0 : pdf_implicit_coefs_terms%coef_wp2up_implicit(i,:) = coef_wp2up_implicit
639 0 : pdf_implicit_coefs_terms%term_wp2up_explicit(i,:) = zeros
640 0 : pdf_implicit_coefs_terms%coef_wp2vp_implicit(i,:) = coef_wp2vp_implicit
641 0 : pdf_implicit_coefs_terms%term_wp2vp_explicit(i,:) = zeros
642 0 : pdf_implicit_coefs_terms%coef_wprtp2_implicit(i,:) = coef_wprtp2_implicit
643 0 : pdf_implicit_coefs_terms%term_wprtp2_explicit(i,:) = term_wprtp2_explicit
644 0 : pdf_implicit_coefs_terms%coef_wpthlp2_implicit(i,:) = coef_wpthlp2_implicit
645 0 : pdf_implicit_coefs_terms%term_wpthlp2_explicit(i,:) = term_wpthlp2_explicit
646 0 : pdf_implicit_coefs_terms%coef_wprtpthlp_implicit(i,:) = coef_wprtpthlp_implicit
647 0 : pdf_implicit_coefs_terms%term_wprtpthlp_explicit(i,:) = term_wprtpthlp_explicit
648 0 : pdf_implicit_coefs_terms%coef_wpup2_implicit(i,:) = coef_wpup2_implicit
649 0 : pdf_implicit_coefs_terms%term_wpup2_explicit(i,:) = term_wpup2_explicit
650 0 : pdf_implicit_coefs_terms%coef_wpvp2_implicit(i,:) = coef_wpvp2_implicit
651 0 : pdf_implicit_coefs_terms%term_wpvp2_explicit(i,:) = term_wpvp2_explicit
652 0 : if ( sclr_dim > 0 ) then
653 0 : pdf_implicit_coefs_terms%coef_wp2sclrp_implicit(i,:,:) = coef_wp2sclrp_implicit
654 0 : pdf_implicit_coefs_terms%term_wp2sclrp_explicit(i,:,:) = zero_array
655 0 : pdf_implicit_coefs_terms%coef_wpsclrp2_implicit(i,:,:) = coef_wpsclrp2_implicit
656 0 : pdf_implicit_coefs_terms%term_wpsclrp2_explicit(i,:,:) = term_wpsclrp2_explicit
657 0 : pdf_implicit_coefs_terms%coef_wprtpsclrp_implicit(i,:,:) &
658 0 : = coef_wprtpsclrp_implicit
659 0 : pdf_implicit_coefs_terms%term_wprtpsclrp_explicit(i,:,:) &
660 0 : = term_wprtpsclrp_explicit
661 0 : pdf_implicit_coefs_terms%coef_wpthlpsclrp_implicit(i,:,:) &
662 0 : = coef_wpthlpsclrp_implicit
663 0 : pdf_implicit_coefs_terms%term_wpthlpsclrp_explicit(i,:,:) &
664 0 : = term_wpthlpsclrp_explicit
665 : endif ! sclr_dim > 0
666 :
667 : end do
668 :
669 0 : return
670 :
671 : end subroutine new_hybrid_pdf_driver
672 :
673 : !=============================================================================
674 0 : elemental subroutine calc_responder_driver( xm, xp2, wpxp, wp2, & ! In
675 : mixt_frac, F_w, & ! In
676 : Skx, & ! In/Out
677 : mu_x_1, mu_x_2, & ! Out
678 : sigma_x_1_sqd, & ! Out
679 : sigma_x_2_sqd, & ! Out
680 : coef_sigma_x_1_sqd, & ! Out
681 : coef_sigma_x_2_sqd ) ! Out
682 :
683 : ! Description:
684 : ! This is the sub-driver for a responder variable. The limits of the range
685 : ! of values of Skx that the PDF is able to represent are calculated, and
686 : ! Skx is clipped when it exceeds the upper or lower limit. Then, the PDF
687 : ! parameters for responder variable x are calculated.
688 :
689 : ! References:
690 : !-----------------------------------------------------------------------
691 :
692 : use constants_clubb, only: &
693 : three, & ! Constant(s)
694 : two, &
695 : three_halves, &
696 : one, &
697 : zero
698 :
699 : use new_hybrid_pdf, only: &
700 : calculate_responder_params ! Procedure(s)
701 :
702 : use clubb_precision, only: &
703 : core_rknd ! Variable(s)
704 :
705 : implicit none
706 :
707 : ! Input Variables
708 : real( kind = core_rknd ), intent(in) :: &
709 : xm, & ! Mean of x (overall) [units vary]
710 : xp2, & ! Variance of x (overall) [(units vary)^2]
711 : wpxp, & ! Covariance of w and x (overall) [m/s (units vary)]
712 : wp2, & ! Variance of w (overall) [m^2/s^2]
713 : mixt_frac, & ! Mixture fraction [-]
714 : F_w ! Parameter for the spread of the PDF comp. means of w [-]
715 :
716 : ! Input/Output Variable
717 : real( kind = core_rknd ), intent(inout) :: &
718 : Skx ! Skewness of x (overall) [-]
719 :
720 : ! Output Variables
721 : real( kind = core_rknd ), intent(out) :: &
722 : mu_x_1, & ! Mean of x (1st PDF component) [units vary]
723 : mu_x_2, & ! Mean of x (2nd PDF component) [units vary]
724 : sigma_x_1_sqd, & ! Variance of x (1st PDF component) [(units vary)^2]
725 : sigma_x_2_sqd ! Variance of x (2nd PDF component) [(units vary)^2]
726 :
727 : real( kind = core_rknd ), intent(out) :: &
728 : coef_sigma_x_1_sqd, & ! sigma_x_1^2 = coef_sigma_x_1_sqd * <x'^2> [-]
729 : coef_sigma_x_2_sqd ! sigma_x_2^2 = coef_sigma_x_2_sqd * <x'^2> [-]
730 :
731 : ! Local Variables
732 : real( kind = core_rknd ) :: &
733 : corr_w_x, & ! Correlation (overall) of w and x [-]
734 : min_Skx, & ! Minimum Skx that can be represented by the PDF [-]
735 : max_Skx ! Maximum Skx that can be represented by the PDF [-]
736 :
737 :
738 : ! Calculate the limits of Skx.
739 0 : if ( F_w > zero ) then
740 :
741 : ! Calculate the overall correlation of w and x.
742 0 : if ( wp2 * xp2 > zero ) then
743 :
744 : ! The overall correlation of w and x is:
745 : !
746 : ! corr_w_x = <w'x'> / sqrt( <w'^2> * <x'^2> ).
747 0 : corr_w_x = wpxp / sqrt( wp2 * xp2 )
748 :
749 : else ! <w'^2> * <x'^2> = 0
750 :
751 : ! When <w'^2> = 0 or <x'^2> = 0, <w'x'> = 0. The correlation of w
752 : ! and x is undefined, however, since <w'x'> = 0, Skx = 0. Setting
753 : ! corr_w_x = 0 in this scenario will set max_Skx = min_Skx = 0.
754 : corr_w_x = zero
755 :
756 : endif
757 :
758 0 : if ( wpxp >= zero ) then
759 :
760 : min_Skx = ( one + mixt_frac ) &
761 : / sqrt( mixt_frac * ( one - mixt_frac ) ) &
762 : * corr_w_x**3 / F_w**three_halves &
763 : - sqrt( mixt_frac / ( one - mixt_frac ) ) &
764 0 : * three * corr_w_x / sqrt( F_w )
765 :
766 : max_Skx = ( mixt_frac - two ) &
767 : / sqrt( mixt_frac * ( one - mixt_frac ) ) &
768 : * corr_w_x**3 / F_w**three_halves &
769 : + sqrt( ( one - mixt_frac ) / mixt_frac ) &
770 0 : * three * corr_w_x / sqrt( F_w )
771 :
772 : else ! <w'x'> < 0
773 :
774 : min_Skx = ( mixt_frac - two ) &
775 : / sqrt( mixt_frac * ( one - mixt_frac ) ) &
776 : * corr_w_x**3 / F_w**three_halves &
777 : + sqrt( ( one - mixt_frac ) / mixt_frac ) &
778 0 : * three * corr_w_x / sqrt( F_w )
779 :
780 : max_Skx = ( one + mixt_frac ) &
781 : / sqrt( mixt_frac * ( one - mixt_frac ) ) &
782 : * corr_w_x**3 / F_w**three_halves &
783 : - sqrt( mixt_frac / ( one - mixt_frac ) ) &
784 0 : * three * corr_w_x / sqrt( F_w )
785 :
786 : endif ! <w'x'> >= 0
787 :
788 : else ! F_w > 0
789 :
790 : ! When F_w = 0, <w'x'> = 0, and Skx = 0.
791 : min_Skx = zero
792 : max_Skx = zero
793 :
794 : endif ! F_w > 0
795 :
796 : ! Limit Skx so that min_Skx <= Skx <= max_Skx.
797 0 : if ( Skx > max_Skx ) then
798 0 : Skx = max_Skx
799 0 : elseif ( Skx < min_Skx ) then
800 0 : Skx = min_Skx
801 : endif ! Skx >= max_Skx
802 :
803 : ! Calculate the PDF parameters for responder variable x.
804 : call calculate_responder_params( xm, xp2, Skx, wpxp, & ! In
805 : wp2, F_w, mixt_frac, & ! In
806 : mu_x_1, mu_x_2, & ! Out
807 : sigma_x_1_sqd, & ! Out
808 : sigma_x_2_sqd, & ! Out
809 : coef_sigma_x_1_sqd, & ! Out
810 0 : coef_sigma_x_2_sqd ) ! Out
811 :
812 :
813 0 : return
814 :
815 : end subroutine calc_responder_driver
816 :
817 : !=============================================================================
818 0 : elemental subroutine calc_F_w_zeta_w( Skw, wprtp, wpthlp, upwp, vpwp, & ! In
819 : wp2, rtp2, thlp2, up2, vp2, & ! In
820 : gamma_Skw_fnc, & ! In
821 : slope_coef_spread_DG_means_w, & ! In
822 : pdf_component_stdev_factor_w, & ! In
823 : max_corr_w_sclr_sqd, & ! In
824 : F_w, zeta_w, min_F_w, max_F_w ) ! Out
825 :
826 : ! Description:
827 : ! Calculates the values of F_w and zeta_w for w, which is the setter
828 : ! variable (which is the variable that sets the mixture fraction).
829 : !
830 : ! Based purely on the PDF of w and not considering restrictions caused by
831 : ! other variables in the multivariate PDF, the value of F_w is calculated
832 : ! between 0 (min_F_w) and 1 (max_F_w). However, other variables in the PDF
833 : ! place restrictions on the minimum value of F_w. The range of acceptible
834 : ! values for F_w is given by:
835 : !
836 : ! max( <w'x'>^2 / ( <w'^2> * <x'^2> ), for all variables x ) <= F_w <= 1.
837 : !
838 : ! Additionally, the value of F_w should still increase with an increasing
839 : ! magnitude of Skw. The value of F_w can be 0 only when Skw = 0 (as well as
840 : ! all <w'x'> = 0, as well). The F_w skewness equation used is:
841 : !
842 : ! F_w = max_F_w + ( min_F_w - max_F_w )
843 : ! * exp{ -|Skw|^lambda / slope_coef_spread_DG_means_w };
844 : !
845 : ! where lambda > 0 and slope_coef_spread_DG_means_w > 0. As |Skw| goes
846 : ! toward 0, the value of F_w goes toward min_F_w, and as |Skw| becomes
847 : ! large, the value of F_w goes toward max_F_w. When the value of
848 : ! slope_coef_spread_DG_means_w is small, the value of F_w tends toward
849 : ! max_F_w, and when the value of slope_coef_spread_DG_means_w is large, the
850 : ! value of F_w tends toward min_F_w. When lambda is small, the value of F_w
851 : ! is less dependent on Skw, and when lambda is large, the value of F_w is
852 : ! more dependent on Skw.
853 : !
854 : ! Mathematically, this equation will always produce a value of F_w that
855 : ! falls between min_F_w and max_F_w. However, in order to prevent a value
856 : ! of F_w from being calculated outside the bounds of min_F_w and max_F_w
857 : ! owing to numerical underflow or loss of precision, this equation can be
858 : ! rewritten as:
859 : !
860 : ! F_w
861 : ! = min_F_w * exp{ -|Skw|^lambda / slope_coef_spread_DG_means_w }
862 : ! + max_F_w * ( 1 - exp{ -|Skw|^lambda / slope_coef_spread_DG_means_w } ).
863 : !
864 : ! The value of zeta_w used to adjust the PDF component standard devations:
865 : !
866 : ! 1 + zeta_w = ( mixt_frac * sigma_w_1^2 )
867 : ! / ( ( 1 - mixt_frac ) * sigma_w_2^2 );
868 : !
869 : ! where zeta_w > -1. The sign of zeta_w is used to easily determine if
870 : ! mixt_frac * sigma_w_1^2 is greater than ( 1 - mixt_frac ) * sigma_w_2^2
871 : ! (when zeta_w is positive), mixt_frac * sigma_w_1^2 is less than
872 : ! ( 1 - mixt_frac ) * sigma_w_2^2 (when zeta_w is negative), or
873 : ! mixt_frac * sigma_w_1^2 is equal to ( 1 - mixt_frac ) * sigma_w_2^2 (when
874 : ! zeta_w is 0).
875 : !
876 : ! In order to allow for a tunable parameter that is the pure ratio of
877 : ! mixt_frac * sigma_w_1^2 to ( 1 - mixt_frac ) * sigma_w_2^2, zeta_w is
878 : ! related to the parameter pdf_component_stdev_factor_w, where:
879 : !
880 : ! 1 + zeta_w = pdf_component_stdev_factor_w.
881 :
882 : ! References:
883 : !-----------------------------------------------------------------------
884 :
885 : use constants_clubb, only: &
886 : one, & ! Variable(s)
887 : zero, &
888 : max_mag_correlation_flux
889 :
890 : use clubb_precision, only: &
891 : core_rknd ! Variable(s)
892 :
893 : implicit none
894 :
895 : ! Input Variables
896 : real( kind = core_rknd ), intent(in) :: &
897 : Skw, & ! Skewness of w (overall) [-]
898 : wprtp, & ! Covariance (overall) of w and rt [m/s (kg/kg)]
899 : wpthlp, & ! Covariance (overall) of w and thl [m/s K]
900 : upwp, & ! Covariance (overall) of u and w [m^2/s^2]
901 : vpwp, & ! Covariance (overall) of u and v [m^2/s^2]
902 : wp2, & ! Variance (overall) of w [m^2/s^2]
903 : rtp2, & ! Variance (overall) of rt [(kg/kg)^2]
904 : thlp2, & ! Variance (overall) of thl [K^2]
905 : up2, & ! Variance (overall) of u [m^2/s^2]
906 : vp2 ! Variance (overall) of v [m^2/s^2]
907 :
908 : ! Tunable parameter gamma.
909 : ! When gamma goes to 0, the standard deviations of w in each PDF component
910 : ! become small, and the spread between the two PDF component means of w
911 : ! becomes large. F_w goes to min_F_w.
912 : ! When gamma goes to 1, the standard deviations of w in each PDF component
913 : ! become large, and the spread between the two PDF component means of w
914 : ! becomes small. F_w goes to max_F_w.
915 : real( kind = core_rknd ), intent(in) :: &
916 : gamma_Skw_fnc ! Value of parameter gamma from tunable Skw function [-]
917 :
918 : real( kind = core_rknd ), intent(in) :: &
919 : ! Slope coefficient for the spread between the PDF component means of w.
920 : slope_coef_spread_DG_means_w, &
921 : ! Parameter to adjust the PDF component standard deviations of w.
922 : pdf_component_stdev_factor_w
923 :
924 : real( kind = core_rknd ), intent(in) :: &
925 : max_corr_w_sclr_sqd ! Max value of wpsclrp^2 / ( wp2 * sclrp2 ) [-]
926 :
927 : ! Output Variables
928 : real( kind = core_rknd ), intent(out) :: &
929 : F_w, & ! Parameter for the spread of the PDF component means of w [-]
930 : zeta_w, & ! Parameter for the PDF component variances of w [-]
931 : min_F_w, & ! Minimum allowable value of parameter F_w [-]
932 : max_F_w ! Maximum allowable value of parameter F_w [-]
933 :
934 : ! Local Variables
935 : real( kind = core_rknd ) :: &
936 : corr_w_rt_sqd, & ! Value of wprtp^2 / ( wp2 * rtp2 ) [-]
937 : corr_w_thl_sqd, & ! Value of wpthlp^2 / ( wp2 * thlp2 ) [-]
938 : corr_u_w_sqd, & ! Value of upwp^2 / ( up2 * wp2 ) [-]
939 : corr_v_w_sqd, & ! Value of vpwp^2 / ( vp2 * wp2 ) [-]
940 : max_corr_w_x_sqd ! Max. val. of wpxp^2/(wp2*xp2) for all vars. x [-]
941 :
942 : real( kind = core_rknd ) :: &
943 : exp_Skw_interp_factor, & ! Function to interp. between min. and max. [-]
944 : zeta_w_star
945 :
946 : real( kind = core_rknd ), parameter :: &
947 : lambda = 0.5_core_rknd ! Parameter for Skw dependence [-]
948 :
949 :
950 : ! Find the maximum value of <w'x'>^2 / ( <w'^2> * <x'^2> ) for all
951 : ! variables x that are Double Gaussian PDF responder variables. This
952 : ! includes rt and theta-l. When l_predict_upwp_vpwp is enabled, u and v are
953 : ! also calculated as part of the PDF, and they are included as well.
954 : ! Additionally, when sclr_dim > 0, passive scalars (sclr) are also included.
955 :
956 : ! Calculate the squared value of the correlation of w and rt.
957 0 : if ( wp2 * rtp2 > zero ) then
958 0 : corr_w_rt_sqd = wprtp**2 / ( wp2 * rtp2 )
959 : else
960 : corr_w_rt_sqd = zero
961 : endif
962 :
963 : ! Calculate the squared value of the correlation of w and thl.
964 0 : if ( wp2 * thlp2 > zero ) then
965 0 : corr_w_thl_sqd = wpthlp**2 / ( wp2 * thlp2 )
966 : else
967 : corr_w_thl_sqd = zero
968 : endif
969 :
970 : ! Calculate the squared value of the correlation of u and w.
971 0 : if ( up2 * wp2 > zero ) then
972 0 : corr_u_w_sqd = upwp**2 / ( up2 * wp2 )
973 : else
974 : corr_u_w_sqd = zero
975 : endif
976 :
977 : ! Calculate the squared value of the correlation of v and w.
978 0 : if ( vp2 * wp2 > zero ) then
979 0 : corr_v_w_sqd = vpwp**2 / ( vp2 * wp2 )
980 : else
981 : corr_v_w_sqd = zero
982 : endif
983 :
984 : ! Calculate the maximum value of corr_w_rt^2, corr_w_thl^2, corr_u_w^2, and
985 : ! corr_v_w^2 in the calculation of max(corr_w_x^2). Include the maximum
986 : ! value of corr_w_sclr^2 (for all sclrs) when scalars are found.
987 : max_corr_w_x_sqd = max( corr_w_rt_sqd, corr_w_thl_sqd, &
988 0 : corr_u_w_sqd, corr_v_w_sqd, max_corr_w_sclr_sqd )
989 :
990 0 : max_corr_w_x_sqd = min( max_corr_w_x_sqd, max_mag_correlation_flux**2 )
991 :
992 : ! Calculate min_F_w and set max_F_w to 1.
993 0 : if ( abs( Skw ) > zero ) then
994 0 : min_F_w = max( max_corr_w_x_sqd, 1.0e-3_core_rknd )
995 : else
996 0 : min_F_w = max_corr_w_x_sqd
997 : endif
998 0 : max_F_w = one
999 :
1000 : ! F_w must have a value between min_F_w and max_F_w.
1001 : exp_Skw_interp_factor &
1002 : = exp( -abs(Skw)**lambda / slope_coef_spread_DG_means_w )
1003 :
1004 : ! F_w = min_F_w * exp_Skw_interp_factor &
1005 : ! + max_F_w * ( one - exp_Skw_interp_factor )
1006 :
1007 : ! For now, use a formulation similar to what is used for ADG1.
1008 : ! Tunable parameter gamma.
1009 : ! When gamma goes to 0, the standard deviations of w in each PDF component
1010 : ! become small, and the spread between the two PDF component means of w
1011 : ! becomes large. F_w goes to min_F_w.
1012 : ! When gamma goes to 1, the standard deviations of w in each PDF component
1013 : ! become large, and the spread between the two PDF component means of w
1014 : ! becomes small. F_w goes to max_F_w.
1015 0 : F_w = max_F_w - gamma_Skw_fnc * ( max_F_w - min_F_w )
1016 :
1017 : ! The value of zeta_w must be greater than -1.
1018 0 : zeta_w_star = pdf_component_stdev_factor_w - one
1019 :
1020 : ! Make the PDF of w symmetric. In other words, the PDF at a value of
1021 : ! positive skewness will look like a mirror image of the PDF at the
1022 : ! opposite value of negative skewness.
1023 0 : if ( Skw >= zero ) then
1024 0 : zeta_w = zeta_w_star
1025 : else ! Skw < 0
1026 0 : zeta_w = - zeta_w_star / ( zeta_w_star + one )
1027 : endif
1028 :
1029 :
1030 0 : return
1031 :
1032 : end subroutine calc_F_w_zeta_w
1033 :
1034 : !=============================================================================
1035 :
1036 : end module new_hybrid_pdf_main
|