Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
interface_coala_shamrock.py
1import numpy as np
2
3from .generate_flux_intflux import compute_flux_coag_k0_kdv
4
5
6def coala_source_term_k0(nbins, massgrid, rhodust, rhodust_eps, tensor_tabflux_coag, v_dust):
7 r"""
8 Function to compute the source for coagulation and fragmentation in continuity equation for piecewise constant approximation (see Lombart et al., 2021)
9 Function for ballistic kernel with differential velocities dv
10 Used to evaluate the source term, then hydro code applies time solver
11
12 /!\ Only coagulation so far
13
14 Parameters
15 ----------
16 nbins : scalar, type -> integer
17 number of dust bins
18 massgrid : 1D array (dim = nbins+1), type -> float
19 grid of masses given borders value of mass bins
20 rhodust : 1D array (dim = nbins), type -> float
21 dust density for each grain size
22 rhodust_eps : scalar, type -> float
23 threshold value for rhodust
24 tensor_tabflux_coag : 3D array (dim = (nbins,nbins,nbins)), type -> float
25 array to evaluate coagulation flux
26 v_dust : 1D array (dim = (nbins)), type -> float
27 array of the dust velocities (could also be delta_v in monofluid since it is a delta)
28
29 Returns
30 -------
31 S_coag : 1D array (dim = nbins), type -> float
32 Source term for dust coagulation in continuity equation
33 DG operator for piecewise constant approximation in each binls
34
35 """
36
37 # compute gij from rhodust for coala k=0
38 gij = np.zeros(nbins) # shape is 1D with k0
39 for j in range(nbins):
40 if rhodust[j] > rhodust_eps:
41 gij[j] = rhodust[j] / (massgrid[j + 1] - massgrid[j])
42
43 # dv_ij = \vec{v_dust}_j - \vec{v_dust}_i
44 dv = np.zeros((nbins, nbins))
45 for i in range(nbins):
46 for j in range(nbins):
47 delta_v = v_dust[j] - v_dust[i]
48 dv[i, j] = np.sqrt(delta_v[0] ** 2 + delta_v[1] ** 2 + delta_v[2] ** 2)
49
50 # compute flux for all dust bins
51 flux = compute_flux_coag_k0_kdv(gij, tensor_tabflux_coag, dv)
52
53 S_coag = np.zeros(nbins)
54 S_coag[0] = -flux[0]
55 S_coag[1:] = flux[:-1] - flux[1:]
56
57 return S_coag
58
59
60import time
61
62from scipy.special import legendre
63
64from .generate_tabflux_tabintflux import compute_coagtabflux_k0_numba
65from .utils_polynomials import legendre_coeffs
66
67
68def coala_precalc_tabflux_coag(K0, nbins, Q, massgrid):
69 """
70 Function to iterate coagulation solver to reach the time ndthydro x dthydro
71
72 Function for ballistic kernel with differential velocities dv
73
74 DG scheme k=0, piecewise constant approximation
75
76 Parameters
77 ----------
78 K0 : scalar, type -> float
79 constant value of the kernel function (used to adapt to code unit)
80 nbins : scalar, type -> integer
81 number of dust bins
82 Q : scalar, type -> integer
83 number of points for Gauss-Legendre quadrature
84 massgrid : 1D array (dim = nbins+1), type -> float
85 grid of masses given borders value of mass bins
86
87
88 Returns
89 -------
90 gij_init : 1D array (dim = nbins) or 2D array (dim = (nbins.kpol+1)), type -> float
91 initial components of g on the polynomial basis
92 gij : 1D array (dim = nbins) or 2D array (dim = (nbins.kpol+1)), type -> float
93 evolved components of g on the polynomial basis
94 time_coag : scalar, type -> float
95 final time ndthydro x dthydro
96
97 """
98
99 kernel = 3
100 kpol = 0
101
102 vecnodes, vecweights = np.polynomial.legendre.leggauss(Q)
103
104 # Legendre polynomial coefficients
105 mat_coeffs_leg = np.zeros((kpol + 1, kpol + 1))
106 mat_coeffs_leg = legendre_coeffs(kpol)
107
108 start = time.time()
109 tensor_tabflux_coag = np.zeros((nbins, nbins, nbins))
110
111 compute_coagtabflux_k0_numba(
112 kernel,
113 K0,
114 Q,
115 vecnodes,
116 vecweights,
117 nbins,
118 massgrid,
119 mat_coeffs_leg,
120 tensor_tabflux_coag,
121 )
122
123 finish = time.time()
124 print("Tensor tabflux generated in %.5f s" % (finish - start))
125
126 return tensor_tabflux_coag