4from scipy.optimize
import minimize_scalar
6from .reconstruction_g
import *
9def minval_approx_g(nbins, kpol, massgrid, massbins, gij):
11 Function to compute the minimum value of the approximation of g in each bin
13 only for DG scheme k>0, piecewise polynomial approximation
17 nbins : scalar, type -> integer
19 kpol : scalar, type -> integer
20 degree of polynomials for approximation
21 massgrid : 1D array (dim = nbins+1), type -> float
22 grid of masses given borders value of mass bins
23 massbins : 1D array (dim = nbins), type -> float
24 arithmetic mean value of massgrid for each mass bins
25 gij : 2D array (dim = (nbins,kpol+1)), type -> float
26 components of g on the polynomial basis
31 tab_minval_recons_g : 1D array (dim = nbins), type -> float
32 minimum value of the approximation of in each bin
36 tab_minval_recons_g = np.zeros(nbins)
39 for j
in range(nbins):
41 tab_minval_recons_g[j] = min(
42 recons_g(massgrid, massbins, kpol, gij, j, massgrid[j]),
43 recons_g(massgrid, massbins, kpol, gij, j, massgrid[j + 1]),
47 for j
in range(nbins):
50 return recons_g(massgrid, massbins, kpol, gij, j, x)
53 xjgridr = massgrid[j + 1]
60 res = minimize_scalar(func_pol, bounds=(xjgridl, xjgridr), method=
"bounded")
61 tab_minval_recons_g[j] = np.min(
62 [res.fun, func_pol(xjgridl), func_pol(xjgridr)]
65 return tab_minval_recons_g
68def gammafunction(eps, nbins, kpol, massgrid, massbins, gij):
70 Function to compute the limiter coefficient to ensure positivity of the numerical solution (Zhang and Shu 2010)
72 only for DG scheme k>0, piecewise polynomial approximation
76 eps : scalar, type -> float
77 minimum value for mass distribution approximation gij
78 nbins : scalar, type -> integer
80 kpol : scalar, type -> integer
81 degree of polynomials for approximation
82 massgrid : 1D array (dim = nbins+1), type -> float
83 grid of masses given borders value of mass bins
84 massbins : 1D array (dim = nbins), type -> float
85 arithmetic mean value of massgrid for each mass bins
86 gij : 2D array (dim = (nbins,kpol+1)), type -> float
87 components of g on the polynomial basis
92 tab_gamma : 1D array (dim = nbins), type -> float
93 limiter coefficient in each bin
98 min_approx_g = minval_approx_g(nbins, kpol, massgrid, massbins, gij)
102 tab_gamma = np.asarray(
104 np.min([1.0, np.abs((eps - gij[j, 0]) / (gij[j, 0] - min_approx_g[j]))])
105 if gij[j, 0] != min_approx_g[j]
107 for j
in range(nbins)