Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
reconstruction_g.py
1import numpy as np
2
3from .utils_polynomials import *
4
5
6def recons_g(massgrid, massbins, kpol, gij, j, x):
7 """
8 Function to reconstruct the approximation of g using the components gij and the Legendre polynomial basis
9
10 only for DG scheme k>0, piecewise polynomial approximation
11
12 Parameters
13 ----------
14 massgrid : 1D array (dim = nbins+1), type -> float
15 grid of masses given borders value of mass bins
16 massbins : 1D array (dim = nbins), type -> float
17 arithmetic mean value of massgrid for each mass bins
18 kpol : scalar, type -> integer
19 degree of polynomials for approximation
20 gij : 2D array (dim = (nbins,kpol+1)), type -> float
21 components of g on the polynomial basis
22 j : scalar, type -> integer
23 index of the bin for reconstruction
24 x : scalar, type -> float
25 mass value to evaluate the reconstruction of g
26
27
28 Returns
29 -------
30 res : scalar, type -> float
31 reconstruction of g evaluated at x
32
33 """
34
35 # to map bin j onto [-1,1]
36 xij = 2.0 / (massgrid[j + 1] - massgrid[j]) * (x - massbins[j])
37 if kpol == 0:
38 res = np.polynomial.legendre.legval(xij, gij[j])
39 else:
40 res = np.polynomial.legendre.legval(xij, gij[j, :])
41
42 return res