5from scipy.special
import legendre
7from .compute_coag
import *
8from .generate_flux_intflux
import *
12from .generate_tabflux_tabintflux
import *
15from .utils_polynomials
import *
18def iterate_coag(kernel, K0, nbins, kpol, dthydro, ndthydro, coeff_CFL, Q, eps, massgrid, massbins):
20 Function to iterate coagulation solver to reach the time ndthydro x dthydro
22 DG scheme k=0, piecewise constant approximation
26 kernel : scalar, type -> integer
27 select the collisional kernel function
28 K0 : scalar, type -> float
29 constant value of the kernel function (used to adapt to code unit)
30 nbins : scalar, type -> integer
32 kpol : scalar, type -> integer
33 degree of polynomials for approximation
34 dthydro : scalar, type -> float
35 hydro timestep, used as timestep to reach for coagulation process
36 ndthydro : scalar, type -> integer
37 number of hydro timestep
38 coeff_CFL : scalar, type -> float
39 timestep coefficient for stability of the SSPRK order 3 scheme
40 Q : scalar, type -> integer
41 number of points for Gauss-Legendre quadrature
42 eps : scalar, type -> float
43 minimum value for mass distribution approximation gij
44 massgrid : 1D array (dim = nbins+1), type -> float
45 grid of masses given borders value of mass bins
46 massbins : 1D array (dim = nbins), type -> float
47 arithmetic mean value of massgrid for each mass bins
52 gij_init : 1D array (dim = nbins) or 2D array (dim = (nbins.kpol+1)), type -> float
53 initial components of g on the polynomial basis
54 gij : 1D array (dim = nbins) or 2D array (dim = (nbins.kpol+1)), type -> float
55 evolved components of g on the polynomial basis
56 time_coag : scalar, type -> float
57 final time ndthydro x dthydro
61 vecnodes, vecweights = np.polynomial.legendre.leggauss(Q)
64 mat_coeffs_leg = np.zeros((kpol + 1, kpol + 1))
65 mat_coeffs_leg = legendre_coeffs(kpol)
72 tensor_tabflux_coag = np.zeros((nbins, nbins, nbins))
81 compute_coagtabflux_k0_numba(
94 tensor_tabflux_coag = np.zeros((nbins, nbins, nbins, kpol + 1, kpol + 1))
103 compute_coagtabflux_numba(
116 tensor_tabintflux_coag = np.zeros(
117 (nbins, kpol + 1, nbins, nbins, kpol + 1, kpol + 1)
126 compute_coagtabintflux_numba(
136 tensor_tabintflux_coag,
142 return "Need to choose a kernel in the list among values 0,1,2."
148 print(
"Tensor tabflux generated in %.5f s" % (finish - start))
150 print(
"Tensor tabflux tabintflux generated in %.5f s" % (finish - start))
156 gij = L2projDL_k0(eps, nbins, massgrid, massbins, Q, vecnodes, vecweights)
158 gij = L2projDL(eps, nbins, kpol, massgrid, massbins, Q, vecnodes, vecweights)
161 tabgamma = gammafunction(eps, nbins, kpol, massgrid, massbins, gij)
162 gij[:, 1:] = np.transpose(tabgamma * np.transpose(gij[:, 1:]))
165 if gij[:, 0][gij[:, 0] < 0.0].any():
169 gij[:, 0][gij[:, 0] < eps] = eps
170 gij[:, 1:][gij[:, 0] < eps] = 0.0
173 gij_init = np.copy(gij)
174 print(
"gij generated in %.5f s" % (finish - start))
175 print(
"gij t0 =", gij)
179 M1_t0 = np.sum((massgrid[1:] - massgrid[0:nbins]) * gij)
181 M1_t0 = np.sum((massgrid[1:] - massgrid[0:nbins]) * gij[:, 0])
182 print(
"M1 t0 = ", M1_t0)
187 print(
"Time solver in progress")
197 for i
in range(ndthydro):
198 gij, nsub, ndt = compute_coag_k0(
199 eps, coeff_CFL, nbins, massgrid, gij, tensor_tabflux_coag, dthydro
206 for i
in range(ndthydro):
207 gij, nsub, ndt = compute_coag(
216 tensor_tabintflux_coag,
228 return "Need to choose a kernel in the list."
233 print(
"total nsub =", tot_nsub)
234 print(
"total ndt =", tot_ndt)
235 print(
"total number time-steps =", tot_ndt + tot_nsub)
238 print(
"gij tend =", gij)
241 M1_tend = np.sum((massgrid[1:] - massgrid[0:nbins]) * gij)
243 M1_tend = np.sum((massgrid[1:] - massgrid[0:nbins]) * gij[:, 0])
244 print(
"M1 t0 = ", M1_t0)
245 print(
"M1 tend = ", M1_tend)
246 print(
"diff M1 = ", M1_tend - M1_t0)
248 print(
"Time solver in %.5f" % (finish - start))
250 return gij_init, gij, time_coag
254 kernel, K0, nbins, kpol, dthydro, ndthydro, coeff_CFL, Q, eps, massgrid, massbins, dv
257 Function to iterate coagulation solver to reach the time ndthydro x dthydro
259 Function for ballistic kernel with differential velocities dv
261 DG scheme k=0, piecewise constant approximation
265 kernel : scalar, type -> integer
266 select the collisional kernel function
267 K0 : scalar, type -> float
268 constant value of the kernel function (used to adapt to code unit)
269 nbins : scalar, type -> integer
271 kpol : scalar, type -> integer
272 degree of polynomials for approximation
273 dthydro : scalar, type -> float
274 hydro timestep, used as timestep to reach for coagulation process
275 ndthydro : scalar, type -> integer
276 number of hydro timestep
277 coeff_CFL : scalar, type -> float
278 timestep coefficient for stability of the SSPRK order 3 scheme
279 Q : scalar, type -> integer
280 number of points for Gauss-Legendre quadrature
281 eps : scalar, type -> float
282 minimum value for mass distribution approximation gij
283 massgrid : 1D array (dim = nbins+1), type -> float
284 grid of masses given borders value of mass bins
285 massbins : 1D array (dim = nbins), type -> float
286 arithmetic mean value of massgrid for each mass bins
287 dv : 2D array (dim = (nbins,nbins)), type -> float
288 array of the differential velocity between grains
293 gij_init : 1D array (dim = nbins) or 2D array (dim = (nbins.kpol+1)), type -> float
294 initial components of g on the polynomial basis
295 gij : 1D array (dim = nbins) or 2D array (dim = (nbins.kpol+1)), type -> float
296 evolved components of g on the polynomial basis
297 time_coag : scalar, type -> float
298 final time ndthydro x dthydro
302 vecnodes, vecweights = np.polynomial.legendre.leggauss(Q)
305 mat_coeffs_leg = np.zeros((kpol + 1, kpol + 1))
306 mat_coeffs_leg = legendre_coeffs(kpol)
313 tensor_tabflux_coag = np.zeros((nbins, nbins, nbins))
322 compute_coagtabflux_k0_numba(
335 tensor_tabflux_coag = np.zeros((nbins, nbins, nbins, kpol + 1, kpol + 1))
344 compute_coagtabflux_numba(
357 tensor_tabintflux_coag = np.zeros((nbins, kpol + 1, nbins, nbins, kpol + 1, kpol + 1))
365 compute_coagtabintflux_numba(
375 tensor_tabintflux_coag,
379 print(
"Need to choose a kernel = 3 for ballistic kernel with dv array.")
384 print(
"Tensor tabflux generated in %.5f s" % (finish - start))
386 print(
"Tensor tabflux tabintflux generated in %.5f s" % (finish - start))
392 gij = L2projDL_k0(eps, nbins, massgrid, massbins, Q, vecnodes, vecweights)
394 gij = L2projDL(eps, nbins, kpol, massgrid, massbins, Q, vecnodes, vecweights)
399 tabgamma = gammafunction(eps, nbins, kpol, massgrid, massbins, gij)
401 gij[:, 1:] = np.transpose(tabgamma * np.transpose(gij[:, 1:]))
406 if gij[:, 0][gij[:, 0] < 0.0].any():
410 gij[:, 0][gij[:, 0] < eps] = eps
411 gij[:, 1:][gij[:, 0] < eps] = 0.0
414 gij_init = np.copy(gij)
415 print(
"gij generated in %.5f s" % (finish - start))
416 print(
"gij t0 =", gij)
431 M1_t0 = np.sum((massgrid[1:] - massgrid[0:nbins]) * gij)
433 M1_t0 = np.sum((massgrid[1:] - massgrid[0:nbins]) * gij[:, 0])
434 print(
"M1 t0 = ", M1_t0)
439 print(
"Time solver in progress")
447 for i
in range(ndthydro):
448 gij, nsub, ndt = compute_coag_k0_kdv(
449 eps, coeff_CFL, nbins, massgrid, gij, tensor_tabflux_coag, dv, dthydro
457 for i
in range(ndthydro):
458 gij, nsub, ndt = compute_coag_kdv(
467 tensor_tabintflux_coag,
480 print(
"Need to choose a kernel = 3 for ballistic kernel with dv array.")
486 print(
"total nsub =", tot_nsub)
487 print(
"total ndt =", tot_ndt)
488 print(
"total number time-steps =", tot_ndt + tot_nsub)
491 print(
"gij tend =", gij)
494 M1_tend = np.sum((massgrid[1:] - massgrid[0:nbins]) * gij)
496 M1_tend = np.sum((massgrid[1:] - massgrid[0:nbins]) * gij[:, 0])
497 print(
"M1 t0 = ", M1_t0)
498 print(
"M1 tend = ", M1_tend)
499 print(
"diff M1 = ", M1_tend - M1_t0)
501 print(
"Time solver in %.5f" % (finish - start))
503 return gij_init, gij, time_coag