3from .generate_flux_intflux
import (
4 compute_flux_coag_frag_k0_kdv,
5 compute_flux_coag_k0_kdv,
6 compute_flux_frag_k0_kdv,
10def coala_coag_source_term_k0(nbins, massgrid, rhodust, rhodust_eps, tensor_tabflux_coag, v_dust):
12 Function to compute the source for coagulation in continuity equation for piecewise constant approximation (see Lombart et al., 2021)
13 Function for ballistic kernel with differential velocities dv
14 Used to evaluate the source term, then hydro code applies time solver
16 /!\ Only coagulation so far
20 nbins : scalar, type -> integer
22 massgrid : 1D array (dim = nbins+1), type -> float
23 grid of masses given borders value of mass bins
24 rhodust : 1D array (dim = nbins), type -> float
25 dust density for each grain size
26 rhodust_eps : scalar, type -> float
27 threshold value for rhodust
28 tensor_tabflux_coag : 3D array (dim = (nbins,nbins,nbins)), type -> float
29 array to evaluate coagulation flux
30 v_dust : 1D array (dim = (nbins)), type -> float
31 array of the dust velocities (could also be delta_v in monofluid since it is a delta)
35 S_coag : 1D array (dim = nbins), type -> float
36 Source term for dust coagulation in continuity equation
37 DG operator for piecewise constant approximation in each binls
43 for j
in range(nbins):
44 if rhodust[j] > rhodust_eps:
45 gij[j] = rhodust[j] / (massgrid[j + 1] - massgrid[j])
48 dv = np.zeros((nbins, nbins))
49 for i
in range(nbins):
50 for j
in range(nbins):
51 delta_v = v_dust[j] - v_dust[i]
52 dv[i, j] = np.sqrt(delta_v[0] ** 2 + delta_v[1] ** 2 + delta_v[2] ** 2)
55 flux = compute_flux_coag_k0_kdv(gij, tensor_tabflux_coag, dv)
57 S_coag = np.zeros(nbins)
59 S_coag[1:] = flux[:-1] - flux[1:]
64def coala_frag_source_term_k0(
70 tensor_tabflux_frag_T1,
71 tensor_tabflux_frag_T2,
75 Function to compute the source for fragmentation in continuity equation for piecewise constant approximation (see Lombart et al., 2024)
76 Function for ballistic kernel with differential velocities dv
77 Used to evaluate the source term, then hydro code applies time solver
79 /!\ Only fragmentation
83 nbins : scalar, type -> integer
85 massgrid : 1D array (dim = nbins+1), type -> float
86 grid of masses given borders value of mass bins
87 rhodust : 1D array (dim = nbins), type -> float
88 dust density for each grain size
89 rhodust_eps : scalar, type -> float
90 threshold value for rhodust
91 tensor_tabflux_coag : 3D array (dim = (nbins,nbins,nbins)), type -> float
92 array to evaluate coagulation term in fragmentation flux
93 tensor_tabflux_frag_T1 : 3D array (dim = (nbins,nbins,nbins)), type -> float
94 array to evaluate the term 1 for fragmentation flux
95 tensor_tabflux_frag_T2 : 3D array (dim = (nbins,nbins,nbins)), type -> float
96 array to evaluate the term 2 for fragmentation flux
97 v_dust : 1D array (dim = (nbins)), type -> float
98 array of the dust velocities (could also be delta_v in monofluid since it is a delta)
102 S_frag : 1D array (dim = nbins), type -> float
103 Source term for dust coagulation in continuity equation
104 DG operator for piecewise constant approximation in each bins
109 gij = np.zeros(nbins)
110 for j
in range(nbins):
111 if rhodust[j] > rhodust_eps:
112 gij[j] = rhodust[j] / (massgrid[j + 1] - massgrid[j])
115 dv = v_dust[
None, :] - v_dust[:,
None]
118 flux = compute_flux_frag_k0_kdv(
119 gij, tensor_tabflux_coag, tensor_tabflux_frag_T1, tensor_tabflux_frag_T2, dv
122 S_frag = np.zeros(nbins)
124 S_frag[1:] = flux[:-1] - flux[1:]
129def coala_coag_frag_source_term_k0(
135 tensor_tabflux_frag_T1,
136 tensor_tabflux_frag_T2,
141 Function to compute the source for coagulation and fragmentation in continuity equation for piecewise constant approximation (see Lombart et al., 2021)
142 Function for ballistic kernel with differential velocities dv
143 Used to evaluate the source term, then hydro code applies time solver
145 /!\ You can relaxed, coagulation and fragmentation are ready to use
149 nbins : scalar, type -> integer
151 massgrid : 1D array (dim = nbins+1), type -> float
152 grid of masses given borders value of mass bins
153 rhodust : 1D array (dim = nbins), type -> float
154 dust density for each grain size
155 rhodust_eps : scalar, type -> float
156 threshold value for rhodust
157 tensor_tabflux_coag : 3D array (dim = (nbins,nbins,nbins)), type -> float
158 array to evaluate coagulation term in fragmentation flux
159 tensor_tabflux_frag_T1 : 3D array (dim = (nbins,nbins,nbins)), type -> float
160 array to evaluate the term 1 for fragmentation flux
161 tensor_tabflux_frag_T2 : 3D array (dim = (nbins,nbins,nbins)), type -> float
162 array to evaluate the term 2 for fragmentation flux
163 v_dust : 1D array (dim = (nbins)), type -> float
164 array of the dust velocities (could also be delta_v in monofluid since it is a delta)
165 threshold_vfrag : scalar, type -> float
166 threshold velocity value for fragmentation
170 S_coag_frag : 1D array (dim = nbins), type -> float
171 Source term for dust coagulation + fragmentation in continuity equation
172 DG operator for piecewise constant approximation in each bins
177 gij = np.zeros(nbins)
178 for j
in range(nbins):
179 if rhodust[j] > rhodust_eps:
180 gij[j] = rhodust[j] / (massgrid[j + 1] - massgrid[j])
183 dv = v_dust[
None, :] - v_dust[:,
None]
186 proba_frag = (1.5 * (threshold_vfrag / dv) ** 2 + 1.0) * np.exp(
187 -1.5 * (threshold_vfrag / dv) ** 2
189 proba_coag = 1.0 - proba_frag
192 flux = compute_flux_coag_frag_k0_kdv(
195 tensor_tabflux_frag_T1,
196 tensor_tabflux_frag_T2,
202 S_coag_frag = np.zeros(nbins)
203 S_coag_frag[0] = -flux[0]
204 S_coag_frag[1:] = flux[:-1] - flux[1:]
211from scipy.special
import legendre
213from .generate_tabflux_tabintflux
import (
214 compute_coagtabflux_k0_numba,
215 compute_fragtabflux_k0_numba,
217from .utils_polynomials
import legendre_coeffs
220def coala_precalc_tabflux_coag(K0, nbins, Q, massgrid):
222 Function to iterate coagulation solver to reach the time ndthydro x dthydro
224 Function for ballistic kernel with differential velocities dv
226 DG scheme k=0, piecewise constant approximation
230 K0 : scalar, type -> float
231 constant value of the kernel function (used to adapt to code unit)
232 nbins : scalar, type -> integer
234 Q : scalar, type -> integer
235 number of points for Gauss-Legendre quadrature
236 massgrid : 1D array (dim = nbins+1), type -> float
237 grid of masses given borders value of mass bins
242 gij_init : 1D array (dim = nbins) or 2D array (dim = (nbins.kpol+1)), type -> float
243 initial components of g on the polynomial basis
244 gij : 1D array (dim = nbins) or 2D array (dim = (nbins.kpol+1)), type -> float
245 evolved components of g on the polynomial basis
246 time_coag : scalar, type -> float
247 final time ndthydro x dthydro
254 vecnodes, vecweights = np.polynomial.legendre.leggauss(Q)
257 mat_coeffs_leg = np.zeros((kpol + 1, kpol + 1))
258 mat_coeffs_leg = legendre_coeffs(kpol)
261 tensor_tabflux_coag = np.zeros((nbins, nbins, nbins))
263 compute_coagtabflux_k0_numba(
276 print(
"Tensor tabflux generated in %.5f s" % (finish - start))
278 return tensor_tabflux_coag
281def coala_precalc_tabflux_frag(K0, nbins, Q, massgrid, frac_mass_fragments, beta):
283 Function to iterate coagulation solver to reach the time ndthydro x dthydro
285 Function for ballistic kernel with differential velocities dv
287 DG scheme k=0, piecewise constant approximation
291 K0 : scalar, type -> float
292 constant value of the kernel function (used to adapt to code unit)
293 nbins : scalar, type -> integer
295 Q : scalar, type -> integer
296 number of points for Gauss-Legendre quadrature
297 massgrid : 1D array (dim = nbins+1), type -> float
298 grid of masses given borders value of mass bins
299 frac_mass_fragments : scalar, type -> float
300 mass fraction of total mass (u+v) represented by fragments, m_frag = frac_mass_fragments*(u+v)
301 beta : scalar, type -> float
302 coefficient for power law fragment distribution in mass range [xmin,mfrag]
307 gij_init : 1D array (dim = nbins) or 2D array (dim = (nbins.kpol+1)), type -> float
308 initial components of g on the polynomial basis
309 gij : 1D array (dim = nbins) or 2D array (dim = (nbins.kpol+1)), type -> float
310 evolved components of g on the polynomial basis
311 time_coag : scalar, type -> float
312 final time ndthydro x dthydro
319 vecnodes, vecweights = np.polynomial.legendre.leggauss(Q)
322 mat_coeffs_leg = np.zeros((kpol + 1, kpol + 1))
323 mat_coeffs_leg = legendre_coeffs(kpol)
326 tensor_tabflux_frag_T1 = np.zeros((nbins, nbins, nbins))
327 tensor_tabflux_frag_T2 = np.zeros((nbins, nbins, nbins))
329 compute_fragtabflux_k0_numba(
340 tensor_tabflux_frag_T1,
341 tensor_tabflux_frag_T2,
345 print(
"Tensor tabflux frag generated in %.5f s" % (finish - start))
347 return tensor_tabflux_frag_T1, tensor_tabflux_frag_T2