4from scipy.special
import eval_legendre
6from .utils_polynomials
import *
10def L2proj_k0(eps, nbins, N0, m0, massgrid, massbins, Q, vecnodes, vecweights):
12 Function to compute the initial gij coefficient from the initial function g(m) = m*N0/m0*exp(-m/m0)
14 DG scheme k=0, piecewise constant approximation
18 eps : scalar, type -> float
19 minimum value for mass distribution approximation gij
20 nbins : scalar, type -> integer
22 N0 : scalar, type -> float
23 initial total number density of grains
24 m0 : scalar, type -> float
25 initial mean mass of grains
26 massgrid : 1D array (dim = nbins+1), type -> float
27 grid of masses given borders value of mass bins
28 massbins : 1D array (dim = nbins), type -> float
29 arithmetic mean value of massgrid for each mass bins
30 Q : scalar, type -> integer
31 number of points for Gauss-Legendre quadrature
32 vecnodes : 1D array (dim = Q), type -> float
33 nodes of the Legendre polynomials
34 vecweights : 1D array (dim = Q), type -> float
35 weights coefficients for the Gauss-Legendre polynomials
40 gij : 1D array (dim = nbins), type -> float
41 initial components of g on the polynomial basis
45 mat_vecweights = np.outer(np.ones(nbins), vecweights)
46 mat_xjalpha = np.outer(massbins, np.ones(Q)) + np.outer(
47 (massgrid[1:] - massgrid[0:nbins]) / 2.0, vecnodes
50 term_sum = np.sum(mat_vecweights * N0 * mat_xjalpha / m0 * np.exp(-mat_xjalpha / m0), axis=1)
52 gij = term_sum / coeff_norm_leg(0)
58def L2projDL_k0(eps, nbins, massgrid, massbins, Q, vecnodes, vecweights):
60 Function to compute the initial gij coefficient from the dimensionless initial function g(x)=x*exp(-x)
62 DG scheme k=0, piecewise constant approximation
66 eps : scalar, type -> float
67 minimum value for mass distribution approximation gij
68 nbins : scalar, type -> integer
70 massgrid : 1D array (dim = nbins+1), type -> float
71 grid of masses given borders value of mass bins
72 massbins : 1D array (dim = nbins), type -> float
73 arithmetic mean value of massgrid for each mass bins
74 Q : scalar, type -> integer
75 number of points for Gauss-Legendre quadrature
76 vecnodes : 1D array (dim = Q), type -> float
77 nodes of the Legendre polynomials
78 vecweights : 1D array (dim = Q), type -> float
79 weights coefficients for the Gauss-Legendre polynomials
84 gij : 1D array (dim = nbins), type -> float
85 initial components of g on the polynomial basis
88 mat_vecweights = np.outer(np.ones(nbins), vecweights)
89 mat_xjalpha = np.outer(massbins, np.ones(Q)) + np.outer(
90 (massgrid[1:] - massgrid[0:nbins]) / 2.0, vecnodes
93 term_sum = np.sum(mat_vecweights * mat_xjalpha * np.exp(-mat_xjalpha), axis=1)
95 gij = term_sum / coeff_norm_leg(0)
102def L2proj(eps, nbins, kpol, N0, m0, massgrid, massbins, Q, vecnodes, vecweights):
104 Function to compute the initial gij coefficient from the initial function g(m) = m*N0/m0*exp(-m/m0)
106 DG scheme k>0, piecewise polynomial approximation
110 eps : scalar, type -> float
111 minimum value for mass distribution approximation gij
112 nbins : scalar, type -> integer
114 kpol : scalar, type -> integer
115 degree of polynomials for approximation
116 N0 : scalar, type -> float
117 initial total number density of grains
118 m0 : scalar, type -> float
119 initial mean mass of grains
120 massgrid : 1D array (dim = nbins+1), type -> float
121 grid of masses given borders value of mass bins
122 massbins : 1D array (dim = nbins), type -> float
123 arithmetic mean value of massgrid for each mass bins
124 Q : scalar, type -> integer
125 number of points for Gauss-Legendre quadrature
126 vecnodes : 1D array (dim = Q), type -> float
127 nodes of the Legendre polynomials
128 vecweights : 1D array (dim = Q), type -> float
129 weights coefficients for the Gauss-Legendre polynomials
134 gij : 2D array (dim = (nbins,kpol+1)), type -> float
135 initial components of g on the polynomial basis
139 gij = np.zeros((nbins, kpol + 1))
140 for j
in range(nbins):
142 hj = massgrid[j + 1] - massgrid[j]
144 for k
in range(kpol + 1):
146 for alpha
in range(Q):
147 xjalpha = xj + hj * vecnodes[alpha] / 2.0
154 * np.exp(-xjalpha / m0)
155 * eval_legendre(k, vecnodes[alpha])
158 gij[j, k] = term_sum / coeff_norm_leg(k)
160 if gij[:, 0][gij[:, 0] < 0.0].any():
162 raise ValueError(f
"gij has negative values: {gij}")
164 gij[:, 1:][gij[:, 0] < eps] = 0.0
165 gij[:, 0][gij[:, 0] < eps] = eps
170def L2projDL(eps, nbins, kpol, massgrid, massbins, Q, vecnodes, vecweights):
172 Function to compute the initial gij coefficient from the dimensionless initial function g(x)=x*exp(-x)
174 DG scheme k>0, piecewise polynomial approximation
178 eps : scalar, type -> float
179 minimum value for mass distribution approximation gij
180 nbins : scalar, type -> integer
182 kpol : scalar, type -> integer
183 degree of polynomials for approximation
184 massgrid : 1D array (dim = nbins+1), type -> float
185 grid of masses given borders value of mass bins
186 massbins : 1D array (dim = nbins), type -> float
187 arithmetic mean value of massgrid for each mass bins
188 Q : scalar, type -> integer
189 number of points for Gauss-Legendre quadrature
190 vecnodes : 1D array (dim = Q), type -> float
191 nodes of the Legendre polynomials
192 vecweights : 1D array (dim = Q), type -> float
193 weights coefficients for the Gauss-Legendre polynomials
198 gij : 2D array (dim = (nbins,kpol+1)), type -> float
199 initial components of g on the polynomial basis
203 gij = np.zeros((nbins, kpol + 1))
204 for j
in range(nbins):
206 hj = massgrid[j + 1] - massgrid[j]
208 for k
in range(kpol + 1):
210 for alpha
in range(Q):
211 xjalpha = xj + hj * vecnodes[alpha] / 2.0
217 * eval_legendre(k, vecnodes[alpha])
220 gij[j, k] = term_sum / coeff_norm_leg(k)
222 if gij[:, 0][gij[:, 0] < 0.0].any():
226 gij[:, 1:][gij[:, 0] < eps] = 0.0
227 gij[:, 0][gij[:, 0] < eps] = eps