6from scipy.special
import legendre
8from ..kernel_collision
import *
9from ..utils_polynomials
import *
12def func_coag_flux(kernel, K0, ai, aip, u, v, xilp, xil):
14 Function to evaluate the integrand of the coagulation flux, i.e. integrand of the double integral
18 kernel : scalar, type -> integer
19 select the collisional kernel function
20 K0 : scalar, type -> float
21 constant value of the kernel function (used to adapt to code unit)
22 ai : 1D array (dim = i+1), type -> float
23 coefficients of polynomial of degree i
24 aip : 1D array (dim = ip+1), type - > float
25 coefficients of polynomial of degree ip
26 u : scalar, type -> float
27 mass variable (colliding grain of mass u)
28 v : scalar, type -> float
29 mass variable (colliding grain of mass v)
30 xilp : scalar, type -> float
31 variable mapping the mass bin lp in [-1,1], needed for Legendre polynomials
32 xil : scalar, type -> float
33 variable mapping the mass bin l in [-1,1], need for Legendre polynomials
37 func_coag_flux : scalar, type -> float
38 integrand of cogulation flux evaluated at u,v,xilp,xil
42 return func_kernel(kernel, K0, u, v) * phi_pol(aip, xilp) * phi_pol(ai, xil) / v
46 kernel, K0, Q, vecnodes, vecweights, nbins, massgrid, mat_coeffs_leg, j, lp, l, ip, i
49 Function to evaluate the double integral depending only masses with Gauss-Legendre quadrature method.
50 This function is used to calculate the array for the coagulation flux as precomputation.
54 kernel : scalar, type -> integer
55 select the collisional kernel function
56 K0 : scalar, type -> float
57 constant value of the kernel function (used to adapt to code unit)
58 Q : scalar, type -> integer
59 number of points for Gauss-Legendre quadrature
60 vecnodes : 1D array (dim = Q), type -> float
61 nodes of the Legendre polynomials
62 vecweights : 1D array (dim = Q), type -> float
63 weights coefficients for the Gauss-Legendre polynomials
64 nbins : scalar, type -> integer
66 massgrid : 1D array (dim = nbins+1), type -> float
67 grid of masses given borders value of mass bins
68 mat_coeffs_leg : 2D array (dmin = (kpol+1,kpol+1)), type -> float
69 array containing on each line Legendre polynomial coefficients from degree 0 to kpol inclusive
70 on each line coefficients are ordered from low to high orders
71 j : scalar, type -> integer
72 index corresponding to the mass of the new formed grain
73 lp : scarlar, type -> integer
74 index corresponding to the mass of one colliding grain
75 l : scarlar, type -> integer
76 index corresponding to the mass of the second colliding grain
77 ip : scalar, type -> integer
78 degree of polynomials for approximation in bin lp
79 i : scalar, type -> integer
80 degree of polynomials for approximation in bin l
85 coagfluxfunction : scalar, type -> float
86 double integral for the coagulation flux evaluated at j,lp,l,ip,i
91 xlgridr = massgrid[l + 1]
93 xlpgridl = massgrid[lp]
94 xlpgridr = massgrid[lp + 1]
96 hlp = xlpgridr - xlpgridl
97 xlp = 0.5 * (xlpgridr + xlpgridl)
99 hl = xlgridr - xlgridl
100 xl = 0.5 * (xlgridr + xlgridl)
102 xjgridr = massgrid[j + 1]
109 aip = mat_coeffs_leg[ip, : ip + 1]
110 ai = mat_coeffs_leg[i, : i + 1]
116 for alpha_u
in range(Q):
117 ulp_alpha = xlp + 0.5 * hlp * vecnodes[alpha_u]
118 xilp = vecnodes[alpha_u]
121 for alpha_v
in range(Q):
122 a_vl = np.max([xjgridr - ulp_alpha + xmin, xlgridl])
123 b_vl = np.min([xmax - ulp_alpha + xmin, xlgridr])
124 vl_alpha = 0.5 * (b_vl + a_vl) + 0.5 * (b_vl - a_vl) * vecnodes[alpha_v]
125 xil = 2.0 * (vl_alpha - xl) / hl
127 if xmax - ulp_alpha + xmin > xlgridl
and xlgridr > xjgridr - ulp_alpha + xmin:
132 * vecweights[alpha_u]
133 * vecweights[alpha_v]
134 * func_coag_flux(kernel, K0, ai, aip, ulp_alpha, vl_alpha, xilp, xil)
141def func_coag_flux_numba(kernel, K0, ai, aip, u, v, xilp, xil):
143 Function to evaluate the integrand of the coagulation flux, i.e. integrand of the double integral
148 kernel : scalar, type -> integer
149 select the collisional kernel function
150 K0 : scalar, type -> float
151 constant value of the kernel function (used to adapt to code unit)
152 ai : 1D array (dim = i+1), type -> float
153 coefficients of polynomial of degree i
154 aip : 1D array (dim = ip+1), type - > float
155 coefficients of polynomial of degree ip
156 u : scalar, type -> float
157 mass variable (colliding grain of mass u)
158 v : scalar, type -> float
159 mass variable (colliding grain of mass v)
160 xilp : scalar, type -> float
161 variable mapping the mass bin lp in [-1,1], needed for Legendre polynomials
162 xil : scalar, type -> float
163 variable mapping the mass bin l in [-1,1], need for Legendre polynomials
167 func_coag_flux : scalar, type -> float
168 integrand of cogulation flux evaluated at u,v,xilp,xil
172 return func_kernel_numba(kernel, K0, u, v) * phi_pol(aip, xilp) * phi_pol(ai, xil) / v
176def coagfluxfunction_numba(
177 kernel, K0, Q, vecnodes, vecweights, nbins, massgrid, mat_coeffs_leg, j, lp, l, ip, i
180 Function to evaluate the double integral depending only masses with Gauss-Legendre quadrature method.
181 This function is used to calculate the array for the coagulation flux as precomputation.
186 kernel : scalar, type -> integer
187 select the collisional kernel function
188 K0 : scalar, type -> float
189 constant value of the kernel function (used to adapt to code unit)
190 Q : scalar, type -> integer
191 number of points for Gauss-Legendre quadrature
192 vecnodes : 1D array (dim = Q), type -> float
193 nodes of the Legendre polynomials
194 vecweights : 1D array (dim = Q), type -> float
195 weights coefficients for the Gauss-Legendre polynomials
196 nbins : scalar, type -> integer
198 massgrid : 1D array (dim = nbins+1), type -> float
199 grid of masses given borders value of mass bins
200 mat_coeffs_leg : 2D array (dmin = (kpol+1,kpol+1)), type -> float
201 array containing on each line Legendre polynomial coefficients from degree 0 to kpol inclusive
202 on each line coefficients are ordered from low to high orders
203 j : scalar, type -> integer
204 index corresponding to the mass of the new formed grain
205 lp : scarlar, type -> integer
206 index corresponding to the mass of one colliding grain
207 l : scarlar, type -> integer
208 index corresponding to the mass of the second colliding grain
209 ip : scalar, type -> integer
210 degree of polynomials for approximation in bin lp
211 i : scalar, type -> integer
212 degree of polynomials for approximation in bin l
217 coagfluxfunction : scalar, type -> float
218 double integral for the coagulation flux evaluated at j,lp,l,ip,i
223 xlgridr = massgrid[l + 1]
224 xlgridl = massgrid[l]
225 xlpgridl = massgrid[lp]
226 xlpgridr = massgrid[lp + 1]
228 hlp = xlpgridr - xlpgridl
229 xlp = 0.5 * (xlpgridr + xlpgridl)
231 hl = xlgridr - xlgridl
232 xl = 0.5 * (xlgridr + xlgridl)
234 xjgridr = massgrid[j + 1]
241 aip = mat_coeffs_leg[ip, : ip + 1]
242 ai = mat_coeffs_leg[i, : i + 1]
248 for alpha_u
in range(Q):
249 ulp_alpha = xlp + 0.5 * hlp * vecnodes[alpha_u]
250 xilp = vecnodes[alpha_u]
253 for alpha_v
in range(Q):
254 a_vl = max(xjgridr - ulp_alpha + xmin, xlgridl)
255 b_vl = min(xmax - ulp_alpha + xmin, xlgridr)
256 vl_alpha = 0.5 * (b_vl + a_vl) + 0.5 * (b_vl - a_vl) * vecnodes[alpha_v]
257 xil = 2.0 * (vl_alpha - xl) / hl
259 if xmax - ulp_alpha + xmin > xlgridl
and xlgridr > xjgridr - ulp_alpha + xmin:
264 * vecweights[alpha_u]
265 * vecweights[alpha_v]
266 * func_coag_flux_numba(kernel, K0, ai, aip, ulp_alpha, vl_alpha, xilp, xil)
272def func_coag_intflux(kernel, K0, ak, ai, aip, hj, u, v, xij, xilp, xil):
274 Function to evaluate the integrand of the term including the integral of the coagulation flux, i.e. integrand of the triple integral.
275 See discontinuous galerkin scheme.
279 kernel : scalar, type -> integer
280 select the collisional kernel function
281 K0 : scalar, type -> float
282 constant value of the kernel function (used to adapt to code unit)
283 ak : 1D array (dim = kpol+1), type -> float
284 coefficients of polynomial of degree k
285 ai : 1D array (dim = kpol+1), type -> float
286 coefficients of polynomial of degree i
287 aip : 1D array (dim = kpol+1), type -> float
288 coefficients of polynomial of degree ip
289 hj : scalar, type -> float
291 u : scalar, type -> float
292 mass variable (colliding grain of mass u)
293 v : scalar, type -> float
294 mass variable (colliding grain of mass v)
295 xij : scalar, type -> float
296 variable mapping the mass bin j in [-1,1], needed for Legendre polynomials
297 xilp : scalar, type -> float
298 variable mapping the mass bin lp in [-1,1], needed for Legendre polynomials
299 xil : scalar, type -> float
300 variable mapping the mass bin l in [-1,1], need for Legendre polynomials
304 func_coag_intflux : scalar, type -> float
305 integrand of the triple integral evaluated at u,v,xij,xilp,xil
311 * func_kernel(kernel, K0, u, v)
318def coagintfluxfunction(
319 kernel, K0, Q, vecnodes, vecweights, nbins, massgrid, mat_coeffs_leg, j, k, lp, l, ip, i
322 Function to evaluate the triple integral for coagulation (term in DG scheme) depending only masses with Gauss-Legendre quadrature method.
323 This function is used to calculate the array for the term including the integral of the coagulation flux as precomputation.
327 kernel : scalar, type -> integer
328 select the collisional kernel function
329 K0 : scalar, type -> float
330 constant value of the kernel function (used to adapt to code unit)
331 Q : scalar, type -> integer
332 number of points for Gauss-Legendre quadrature
333 vecnodes : 1D array (dim = Q), type -> float
334 nodes of the Legendre polynomials
335 vecweights : 1D array (dim = Q), type -> float
336 weights coefficients for the Gauss-Legendre polynomials
337 nbins : scalar, type -> integer
339 massgrid : 1D array (dim = nbins+1), type -> float
340 grid of masses given borders value of mass bins
341 mat_coeffs_leg : 2D array (dmin = (kpol+1,kpol+1)), type -> float
342 array containing on each line Legendre polynomial coefficients from degree 0 to kpol inclusive
343 on each line coefficients are ordered from low to high orders
344 j : scalar, type -> integer
345 index corresponding to the mass of the new formed grain
346 k : scalar, type -> integer
347 degree of polynomials for approximation in bin j
348 lp : scarlar, type -> integer
349 index corresponding to the mass of one colliding grain
350 l : scarlar, type -> integer
351 index corresponding to the mass of the second colliding grain
352 ip : scalar, type -> integer
353 degree of polynomials for approximation in bin lp
354 i : scalar, type -> integer
355 degree of polynomials for approximation in bin l
360 coagintfluxfunction : scalar, type -> float
361 triple integral for the term including the integral of coagulation flux evaluated at j,k,lp,l,ip,i
366 xlgridr = massgrid[l + 1]
367 xlgridl = massgrid[l]
368 xlpgridl = massgrid[lp]
369 xlpgridr = massgrid[lp + 1]
371 xjgridr = massgrid[j + 1]
372 xjgridl = massgrid[j]
374 hlp = xlpgridr - xlpgridl
375 xlp = 0.5 * (xlpgridr + xlpgridl)
377 hl = xlgridr - xlgridl
378 xl = 0.5 * (xlgridr + xlgridl)
380 hj = xjgridr - xjgridl
381 xj = 0.5 * (xjgridr + xjgridl)
388 aip = mat_coeffs_leg[ip, : ip + 1]
389 ai = mat_coeffs_leg[i, : i + 1]
390 ak = mat_coeffs_leg[k, : k + 1]
395 for alpha_x
in range(Q):
396 xj_alpha = xj + 0.5 * hj * vecnodes[alpha_x]
397 xij = vecnodes[alpha_x]
400 for alpha_u
in range(Q):
401 a_ulp = np.max([xmin, xlpgridl])
402 b_ulp = np.min([xj_alpha, xlpgridr])
403 ulp_alpha = 0.5 * (b_ulp + a_ulp) + 0.5 * (b_ulp - a_ulp) * vecnodes[alpha_u]
404 xilp = 2.0 * (ulp_alpha - xlp) / hlp
407 for alpha_v
in range(Q):
408 a_vl = np.max([xj_alpha - ulp_alpha + xmin, xlgridl])
409 b_vl = np.min([xmax - ulp_alpha + xmin, xlgridr])
410 vl_alpha = 0.5 * (b_vl + a_vl) + 0.5 * (b_vl - a_vl) * vecnodes[alpha_v]
411 xil = 2.0 * (vl_alpha - xl) / hl
413 if xmax - ulp_alpha + xmin > xlgridl
and xlgridr > xj_alpha - ulp_alpha + xmin:
419 * vecweights[alpha_x]
420 * vecweights[alpha_u]
421 * vecweights[alpha_v]
423 kernel, K0, ak, ai, aip, hj, ulp_alpha, vl_alpha, xij, xilp, xil
431def func_coag_intflux_numba(kernel, K0, ak, ai, aip, hj, u, v, xij, xilp, xil):
432 dphik_val = dphik(ak, hj, xij)
433 kernel_val = func_kernel_numba(kernel, K0, u, v)
434 phi_aip_val = phi_pol(aip, xilp)
435 phi_ai_val = phi_pol(ai, xil)
437 return dphik_val * kernel_val * phi_aip_val * phi_ai_val / v
441def coagintfluxfunction_numba(
442 kernel, K0, Q, vecnodes, vecweights, nbins, massgrid, mat_coeffs_leg, j, k, lp, l, ip, i
445 Function to evaluate the triple integral for coagulation (term in DG scheme) depending only masses with Gauss-Legendre quadrature method.
446 This function is used to calculate the array for the term including the integral of the coagulation flux as precomputation.
450 kernel : scalar, type -> integer
451 select the collisional kernel function
452 K0 : scalar, type -> float
453 constant value of the kernel function (used to adapt to code unit)
454 Q : scalar, type -> integer
455 number of points for Gauss-Legendre quadrature
456 vecnodes : 1D array (dim = Q), type -> float
457 nodes of the Legendre polynomials
458 vecweights : 1D array (dim = Q), type -> float
459 weights coefficients for the Gauss-Legendre polynomials
460 nbins : scalar, type -> integer
462 massgrid : 1D array (dim = nbins+1), type -> float
463 grid of masses given borders value of mass bins
464 mat_coeffs_leg : 2D array (dmin = (kpol+1,kpol+1)), type -> float
465 array containing on each line Legendre polynomial coefficients from degree 0 to kpol inclusive
466 on each line coefficients are ordered from low to high orders
467 j : scalar, type -> integer
468 index corresponding to the mass of the new formed grain
469 k : scalar, type -> integer
470 degree of polynomials for approximation in bin j
471 lp : scarlar, type -> integer
472 index corresponding to the mass of one colliding grain
473 l : scarlar, type -> integer
474 index corresponding to the mass of the second colliding grain
475 ip : scalar, type -> integer
476 degree of polynomials for approximation in bin lp
477 i : scalar, type -> integer
478 degree of polynomials for approximation in bin l
483 coagintfluxfunction : scalar, type -> float
484 triple integral for the term including the integral of coagulation flux evaluated at j,k,lp,l,ip,i
489 xlgridr = massgrid[l + 1]
490 xlgridl = massgrid[l]
491 xlpgridl = massgrid[lp]
492 xlpgridr = massgrid[lp + 1]
494 xjgridr = massgrid[j + 1]
495 xjgridl = massgrid[j]
497 hlp = xlpgridr - xlpgridl
498 xlp = 0.5 * (xlpgridr + xlpgridl)
500 hl = xlgridr - xlgridl
501 xl = 0.5 * (xlgridr + xlgridl)
503 hj = xjgridr - xjgridl
504 xj = 0.5 * (xjgridr + xjgridl)
511 aip = mat_coeffs_leg[ip, : ip + 1]
512 ai = mat_coeffs_leg[i, : i + 1]
513 ak = mat_coeffs_leg[k, : k + 1]
518 for alpha_x
in range(Q):
519 xj_alpha = xj + 0.5 * hj * vecnodes[alpha_x]
520 xij = vecnodes[alpha_x]
523 for alpha_u
in range(Q):
524 a_ulp = max(xmin, xlpgridl)
525 b_ulp = min(xj_alpha, xlpgridr)
526 ulp_alpha = 0.5 * (b_ulp + a_ulp) + 0.5 * (b_ulp - a_ulp) * vecnodes[alpha_u]
527 xilp = 2.0 * (ulp_alpha - xlp) / hlp
530 for alpha_v
in range(Q):
531 a_vl = max(xj_alpha - ulp_alpha + xmin, xlgridl)
532 b_vl = min(xmax - ulp_alpha + xmin, xlgridr)
533 vl_alpha = 0.5 * (b_vl + a_vl) + 0.5 * (b_vl - a_vl) * vecnodes[alpha_v]
534 xil = 2.0 * (vl_alpha - xl) / hl
536 if xmax - ulp_alpha + xmin > xlgridl
and xlgridr > xj_alpha - ulp_alpha + xmin:
542 * vecweights[alpha_x]
543 * vecweights[alpha_u]
544 * vecweights[alpha_v]
545 * func_coag_intflux_numba(
546 kernel, K0, ak, ai, aip, hj, ulp_alpha, vl_alpha, xij, xilp, xil