grid.onedgrid module
1D integration grid.
- class ClenshawCurtis(npoints)[source]
Bases:
OneDGrid
Clenshaw-Curtis integral quadrature class.
The definition of this quadrature is:
\[\begin{split}\theta_i &= \pi (i - 1) / (n - 1) \\ x_i &= \cos (\theta_i) \\ w_i &= \frac{c_k}{n} \bigg(1 - \sum_{j=1}^{\lfloor n/2 \rfloor} \frac{b_j}{4j^2 - 1} \cos(2j\theta_i) \bigg) \\ b_j &= \begin{cases} 1 & \text{if } j = n/2 \\ 2 & \text{if } j < n/2 \end{cases} \\ c_j &= \begin{cases} 1 & \text{if } k = 0, n\\ 2 & else \end{cases}\end{split}\]where \(k=0,\cdots ,n\).
If discontinuous, it is recommended to break the intervals at the discontinuities and handled separately.
- __init__(npoints)[source]
Generate grid on \([-1,1]\) interval based on Clenshaw-Curtis method.
- Parameters
npoints (int) – Number of points in the grid.
- Returns
One-dimensional grid instance.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Clenshaw-Curtis'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class ExpExp(npoints, h=0.1)[source]
Bases:
OneDGrid
Exponential-Exponential quadrature class.
The definition of this quadrature is:
\[\begin{split}\int_{0}^{\infty} f(x) dx \approx \sum_{k=-n}^n w_k f(x_k). \\ x_k = e^{kh} e^{-e^{-kh}} \\ w_k = h e^{-e^{-kh}}\left( e^{kh} + 1 \right)\end{split}\]Warning
Using this quadrature requires heavy parameter-tuning in-order to work.
- __init__(npoints, h=0.1)[source]
Generate 1D grid on \((0, \infty)\) interval based on exp-exp quadrature.
- Parameters
npoints (int) – Number of grid points.
h (float) – Value of parameter :math: h which control the quadrature.
- Returns
One-dimensional grid instance.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Exponential-Exponential'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class ExpSinh(npoints, h=1.0)[source]
Bases:
OneDGrid
Exponential-Hyperbolic Sine quadrature class.
The definition of this quadrature is:
\[\begin{split}\int_{0}^{\infty} f(x) dx \approx \sum_{k=-n}^n w_k f(x_k). \\ x_k = \exp \left(\frac{\pi}{2}\sinh(k h) \right) \\ w_k = \exp \left(\frac{\pi}{2}\sinh(k h) \right)\left(\frac{\pi h}{2} \cosh(k h) \right)\end{split}\]Warning
Using this quadrature requires heavy parameter-tuning in-order to work.
- __init__(npoints, h=1.0)[source]
Generate 1D grid on \((0, \infty)\) interval based on exp-sinh quadrature.
- Parameters
npoints (int) – Number of grid points.
h (float) – Value of parameter :math: h wich control the quadrature.
- Returns
One-dimensional grid instance.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Exponential-Hyperbolic-Sine'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class FejerFirst(npoints)[source]
Bases:
OneDGrid
Fejer first integral quadrature class.
The definition of this quadrature is:
\[\begin{split}\theta_i &= \frac{(2i - 1)\pi}{2n}, \\ x_i &= \cos(\theta_i), \\ w_i &= \frac{2}{n}\bigg(1 - 2 \sum_{j=1}^{\lfloor n/2 \rfloor} \frac{\cos(2j \theta_j)}{4 j^2 - 1} \bigg),\end{split}\]where \(k=1,\cdots, n\). It uses the zeros of the Chebyshev polynomial. If discontinuous, it is recommended to break the intervals at the discontinuities and handled separately.
- __init__(npoints)[source]
Generate 1D grid on \((-1,1)\) interval based on Fejer’s first rule.
- Parameters
npoints (int) – Number of points in the grid.
- Returns
One-dimensional grid instance.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Fejer-First'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class FejerSecond(npoints)[source]
Bases:
OneDGrid
Fejer Second integral quadrature class.
The definition of this quadrature is:
\[\begin{split}\theta_i &= k \pi / n \\ x_i &= \cos(\theta_i) \\ w_i &= \frac{4 \sin(\theta_i)}{n} \sum_{j=1}^{\lfloor n/2 \rfloor} \frac{\sin(2j - 1)\theta_i}{2j - 1}\\\end{split}\]where \(k=1, \cdots n - 1\) and \(n\) is the number of points. This method is considered more practical than the first method. If discontinuous, it is recommended to break the intervals at the discontinuities and handled separately.
- __init__(npoints)[source]
Generate grid on \((-1,1)\) interval based on Fejer’s second rule.
- Parameters
npoints (int) – Number of points in the grid.
- Returns
One-dimensional grid instance.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Fejer-Second'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class GaussChebyshev(npoints)[source]
Bases:
OneDGrid
Gauss-Chebyshev integral quadrature class.
The fundamental definition of Gauss-Chebyshev quadrature is:
\[\begin{split}\int_{-1}^{1} \frac{f(x)}{\sqrt{1-x^2}} dx \approx& \sum_{i=1}^n w_i f(x_i) \\ x_i =& \cos\left( \frac{2i-1}{2n}\pi \right) \\ w_i =& \frac{\pi}{n}\end{split}\]However, to integrate a given function \(g(x)\) over \([-1, 1]\), this is re-written as:
\[\int_{-1}^{1}g(x)dx \approx \sum_{i=1}^n \left(w_i\sqrt{1-x_i^2}\right)g(x_i) = \sum_{i=1}^n w_i'g(x_i)\]- __init__(npoints)[source]
Generate grid on \([-1, 1]\) interval based on Gauss-Chebyshev quadrature.
- Parameters
npoints (int) – Number of grid points.
- Returns
A 1-D grid instance containing points and weights.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Gauss-Chebyshev'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class GaussChebyshevLobatto(npoints)[source]
Bases:
OneDGrid
Gauss Chebyshev Lobatto integral quadrature class.
The definition of Gauss-Chebyshev-Lobato quadrature is:
\[\begin{split}\int_{-1}^{1} \frac{f(x)}{\sqrt{1-x^2}} dx \approx& \sum_{i=1}^n w_i f(x_i) \\ x_i =& \cos\left( \frac{(i-1)}{n-1}\pi \right) \\ w_{1} = w_{n} =& \frac{\pi}{2(n-1)} \\ w_{i\neq 1,n} =& \frac{\pi}{n-1}\end{split}\]However, to integrate a given function \(g(x)\) over \([-1, 1]\), this is re-written as:
\[\int_{-1}^{1}g(x) dx \approx \sum_{i=1}^n \left(w_i \sqrt{1-x_i^2}\right) g(x_i) = \sum_{i=1}^n w_i' g(x_i)\]- __init__(npoints)[source]
Generate grid on \([-1, 1]\) interval based on Gauss-Chebyshev-Lobatto quadrature.
- Parameters
npoints (int) – Number of grid points.
- Returns
A 1-D grid instance containing points and weights.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Gauss-Chebyshev-Lobatto'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class GaussChebyshevType2(npoints)[source]
Bases:
OneDGrid
Gauss Chebyshev Type2 integral quadrature class.
The definition of the Gauss-Chebyshev of the second kind quadrature is:
\[\begin{split}\int_{-1}^{1} f(x) \sqrt{1-x^2} dx \approx& \sum_{i=1}^n w_i f(x_i) \\ x_i =& \cos\left( \frac{i}{n+1} \pi \right) \\ w_i =& \frac{\pi}{n+1} \sin^2 \left( \frac{i}{n+1} \pi \right)\end{split}\]However, to integrate a given function \(g(x)\) over \([-1, 1]\), this is re-written as:
\[\int_{-1}^{1} g(x) dx \approx \sum_{i=1}^n \left(\frac{w_i}{\sqrt{1-x_i^2}}\right) g(x_i) = \sum_{i=1}^n w_i' g(x_i)\]- __init__(npoints)[source]
Generate grid on \([-1, 1]\) interval based on Gauss-Chebyshev Type 2.
- Parameters
npoints (int) – Number of grid points.
- Returns
A 1-D grid instance containing points and weights.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Gauss-Chebyshev-Type2'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class GaussLaguerre(npoints, alpha=0)[source]
Bases:
OneDGrid
Gauss Laguerre integral quadrature class.
The definition of generalized Gauss-Laguerre quadrature is:
\[\int_{0}^{\infty} x^\alpha e^{-x} f(x) dx \approx \sum_{i=1}^n w_i f(x_i),\]where \(\alpha > -1\).
However, to integrate function \(g(x)\) over \([0, \infty)\), this is re-written as:
\[\int_{0}^{\infty} g(x)dx \approx \sum_{i=1}^n \left(\frac{w_i}{x_i^\alpha e^{-x_i}}\right) g(x_i) = \sum_{i=1}^n w_i' g(x_i)\]- __init__(npoints, alpha=0)[source]
Generate grid on \([0, \infty)\) based on generalized Gauss-Laguerre quadrature.
- Parameters
npoints (int) – Number of grid points.
alpha (float, optional) – Value of the parameter \(alpha\) which must be larger than -1.
- Returns
A 1-D grid instance containing points and weights.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Gauss-Laguerre'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class GaussLegendre(npoints)[source]
Bases:
OneDGrid
Gauss-Legendre integral quadrature class.
The definition of Gauss-Legendre quadrature is:
\[\int_{-1}^{1} f(x) dx \approx \sum_{i=1}^n w_i f(x_i),\]where \(w_i\) are the quadrature weights and \(x_i\) are the roots of the nth Legendre polynomial.
- __init__(npoints)[source]
Generate grid on \([-1, 1]\) interval based on Gauss-Legendre quadrature.
- Parameters
npoints (int) – Number of grid points.
- Returns
A 1-D grid instance containing points and weights.
- Return type
Notes
Only known to be accurate up to `npoints`=100 and may cause problems after
that amount.
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Gauss-Legendre'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class LogExpSinh(npoints, h=0.1)[source]
Bases:
OneDGrid
Logarithm-Exponential-Hyperbolic Sine quadrature class.
The definition of this quadrature is:
\[\begin{split}\int_{0}^{\infty} f(x) dx \approx \sum_{k=-n}^n w_k f(x_k). \\ x_k = \log \left( \exp \left(\frac{\pi}{2}\sinh(kh) \right) + 1\right) \\ w_k = \frac{\pi h\cosh(kh)\exp(\frac{\pi}{2}\sinh(kh))} {2(\exp(\frac{\pi}{2}\sinh(kh))+1)}.\end{split}\]Warning
Using this quadrature requires heavy parameter-tuning in-order to work.
- __init__(npoints, h=0.1)[source]
Generate 1D grid on \((0, \infty)\) interval based on log-exp-sinh quadrature.
- Parameters
npoints (int) – Number of grid points.
h (float) – Value of parameter :math: h wich control the quadrature.
- Returns
One-dimensional grid instance.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Logarithm-Exponential-Hyperbolic-Sine'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class MidPoint(npoints)[source]
Bases:
OneDGrid
MidPoint integral quadrature class.
The definition of this quadrature is:
\[\begin{split}\int_{-1}^{1} f(x) dx \approx& \sum_{i=1}^n w_i f(x_i) \\ x_i =& -1 + \frac{2i + 1}{n} \\ w_i =& \frac{2}{n}\end{split}\]- __init__(npoints)[source]
Generate grid on \([-1, 1]\) interval based on Mid-Point rule.
- Parameters
npoints (int) – Number of grid points.
- Returns
One-dimensional grid instance containing points and weights.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'MidPoint'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class RectangleRuleSineEndPoints(npoints)[source]
Bases:
OneDGrid
Rectangle-Rule Sine end points integral quadrature class.
\[\begin{split}\int_{-1}^{1} f(x) dx \approx& \sum_{i=1}^n w_i f(x_i) \\ x_i =& \frac{i}{n+1} \\ w_i =& \frac{2}{n+1} \sum_{m=1}^n \frac{\sin(m \pi x_i)(1-\cos(m \pi))}{m \pi}\end{split}\]For consistency with other 1-D grids, the integration range is modified by \(q=2x-1\) to the interval \([-1, 1]\), so that
\[2 \int_{0}^{1} f(x) dx = \int_{-1}^{1} f(q) dq\]References
- 1
Boyd, John P. Chebyshev and Fourier spectral methods. Courier Corporation, 2001.
- __init__(npoints)[source]
Generate grid on \([-1, 1]\) using rectangle rule for Sine Series (with endpoints).
- Parameters
npoints (int) – Number of grid points.
- Returns
One-dimensional grid instance containing points and weights.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Rectangle-Rule-Sine'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class Simpson(npoints)[source]
Bases:
OneDGrid
Simpson integral quadrature class.
The definition of this quadrature is:
\[\int_{-1}^{1} f(x) dx \approx \sum_{i=1}^n w_i f(x_i),\]where
\[\begin{split}x_i &= -1 + 2 \left(\frac{i-1}{n-1}\right), w_i &= \begin{cases} 2 / (3(N - 1)) & i = 0 \\ 8 / (3(N - 1)) & i \geq 1 \text{and is odd}, \\ 4 / (3(N - 1)) & i \geq 2 \text{and is even}. \end{cases}\end{split}\]- __init__(npoints)[source]
Generate grid on \([-1,1]\) interval based on Simpson rule.
- Parameters
npoints (int) – Number of points in the grid.
- Returns
One-dimensional grid instance.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Simpson'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class SingleArcSinhExp(npoints, h=0.1)[source]
Bases:
OneDGrid
Single Arc Hyperbolic Sine-Exponential quadrature class.
The definition of this quadrature is:
\[\begin{split}\int_{0}^{\infty} f(x) dx \approx \sum_{k=-n}^n w_k f(x_k). \\ x_k = \mbox{arcsinh}(e^{kh}) \\ w_k = \frac{h e^{kh}}{\sqrt{e^{2kh} + 1}}\end{split}\]Warning
Using this quadrature requires heavy parameter-tuning in-order to work.
- __init__(npoints, h=0.1)[source]
Generate 1D grid on \((0, \infty)\) interval based on tanh-sinh quadrature.
- Parameters
npoints (int) – Number of grid points.
h (float) – Value of parameter :math: h which control the quadrature.
- Returns
One-dimensional grid instance.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Single-Arc-Hyperbolic-Sine-Exponential'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class SingleExp(npoints, h=0.1)[source]
Bases:
OneDGrid
Single exponential quadrature class.
The definition of this quadrature is:
\[\begin{split}\int_{0}^{\infty} f(x) dx \approx \sum_{k=-n}^n w_k f(x_k). \\ x_k = e^{kh} \\ w_k = h e^{kh}.\end{split}\]Warning
Using this quadrature requires heavy parameter-tuning in-order to work.
- __init__(npoints, h=0.1)[source]
Generate 1D grid on \((0, \infty)\) interval based on exponential quadrature.
- Parameters
npoints (int) – Number of grid points.
h (float) – Value of parameter :math: h which control the quadrature.
- Returns
One-dimensional grid instance.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Single-Exponential'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class SingleTanh(npoints, h=0.1)[source]
Bases:
OneDGrid
Hyperbolic Tan quadrature class.
The definition of this quadrature is:
\[\begin{split}\int_{-1}^{1} f(x) dx \approx \sum_{k=-n}^n w_k f(x_k). \\ x_k = \tanh{kh} \\ w_k = \frac{h}{\cosh^2(kh)}\end{split}\]- __init__(npoints, h=0.1)[source]
Generate 1D grid on \((-1, +1)\) interval based on tanh-sinh quadrature.
- Parameters
npoints (int) – Number of grid points.
h (float) – Value of parameter :math: h which control the quadrature.
- Returns
One-dimensional grid instance.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Hyperbolic-Tan'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class TanhSinh(npoints, delta=0.1)[source]
Bases:
OneDGrid
Tanh Sinh integral quadrature class.
The definition of the quadrature is:
\[\begin{split}\int_{-1}^{1} f(x) dx \approx& \sum_{i=-\frac{1}{2}(n-1)}^{\frac{1}{2}(n-1)} w_i f(x_i) \\ x_i =& \tanh\left( \frac{\pi}{2} \sinh(i\delta) \right) \\ w_i =& \frac{\frac{\pi}{2}\delta \cosh(i\delta)}{\cosh^2(\frac{\pi}{2}\sinh(i\delta))}\end{split}\]This quadrature is useful when singularities or infinite derivatives exist on the endpoints of \([-1, 1]\).
- __init__(npoints, delta=0.1)[source]
Generate grid on \([-1, 1]\) interval based on Tanh-Sinh rule.
- Parameters
npoints (int) – Number of grid points, which should be an odd integer.
delta (float) – The value of parameter \(\delta\), which is related with the size.
- Returns
One-dimensional grid instance containing points and weights.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Tanh-Sinh'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class Trapezoidal(npoints)[source]
Bases:
OneDGrid
Trapezoidal Lobatto integral quadrature class.
The fundamental definition of Trapezoidal rule is:
\[\begin{split}\int_{-1}^{1} f(x) dx \approx& \sum_{i=1}^n w_i f(x_i) \\ x_i =& -1 + 2 \left(\frac{i-1}{n-1}\right) \\ w_1 = w_n =& \frac{1}{n} \\ w_{i\neq 1,n} =& \frac{2}{n}\end{split}\]- __init__(npoints)[source]
Generate grid on [-1, 1] interval based on Trapezoidal (Euler-Maclaurin) rule.
- Parameters
npoints (int) – Number of grid points.
- Returns
One-dimensional grid instance containing points and weights.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Trapezoidal-Lobatto'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class TrefethenCC(npoints, d=9)[source]
Bases:
OneDGrid
Trefethen polynomial transformation of Clenshaw-Curtis integral quadrature class.
References
- 2
Hale, Nicholas, and Lloyd N. Trefethen. “New quadrature formulas from conformal maps.” SIAM Journal on Numerical Analysis 46.2 (2008): 930-948.
- __init__(npoints, d=9)[source]
Generate 1D grid on \([-1,1]\) interval based on Trefethen-Clenshaw-Curtis.
- Parameters
npoints (int) – Number of points in the grid.
d (
int
) – Odd degree of the Taylor series polynomial of \(\sin^{-1}\). Only d=1,5,9 are supported.
- Returns
One-dimensional grid instance.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Trefethen-Polynomial-Transformation-Clenshaw-Curtis'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class TrefethenGC2(npoints, d=9)[source]
Bases:
OneDGrid
Trefethen polynomial transformation of Gauss-Chebyshev of the second kind quadrature.
References
- 3
Hale, Nicholas, and Lloyd N. Trefethen. “New quadrature formulas from conformal maps.” SIAM Journal on Numerical Analysis 46.2 (2008): 930-948.
- __init__(npoints, d=9)[source]
Generate 1D grid on [-1,1] interval based on Trefethen-Gauss-Chebyshev.
- Parameters
npoints (int) – Number of points in the grid.
d (int) – Odd degree of the Taylor series polynomial of \(\sin^{-1}\). Only d=1,5,9 are supported.
- Returns
One-dimensional grid instance.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Trefethen-Polynomial-Transformation-Gauss-Chebyshev-Type2'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class TrefethenGeneral(npoints, quadrature, d=9)[source]
Bases:
OneDGrid
Trefethen polynomial transformation of a general integral quadrature class.
References
- 4
Hale, Nicholas, and Lloyd N. Trefethen. “New quadrature formulas from conformal maps.” SIAM Journal on Numerical Analysis 46.2 (2008): 930-948.
- __init__(npoints, quadrature, d=9)[source]
Generate 1D grid on \([-1,1]\) interval based on Trefethen-General.
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Trefethen-Polynomial'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class TrefethenStripCC(npoints, rho=1.1)[source]
Bases:
OneDGrid
Trefethen strip transformation of Clenshaw-Curtis quadrature.
References
- 5
Hale, Nicholas, and Lloyd N. Trefethen. “New quadrature formulas from conformal maps.” SIAM Journal on Numerical Analysis 46.2 (2008): 930-948.
- __init__(npoints, rho=1.1)[source]
Generate grid on \([-1,1]\) interval based on Trefethen-Clenshaw-Curtis.
- Parameters
npoints (int) – Number of points in the grid.
- Returns
One-dimensional grid instance.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Trefethen-Strip-Transformation-Clenshaw-Curtis'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class TrefethenStripGC2(npoints, rho=1.1)[source]
Bases:
OneDGrid
Trefethen strip transformation of the Gauss-Chebyshev of the second kind quadrature.
References
- 6
Hale, Nicholas, and Lloyd N. Trefethen. “New quadrature formulas from conformal maps.” SIAM Journal on Numerical Analysis 46.2 (2008): 930-948.
- __init__(npoints, rho=1.1)[source]
Generate grid on \([-1,1]\) interval based on Trefethen-Gauss-Chebyshev.
- Parameters
npoints (int) – Number of points in the grid.
- Returns
One-dimensional grid instance.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Trefethen-Strip-Transformation-Gauss-Chebyshev-Type2'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class TrefethenStripGeneral(npoints, quadrature, rho=1.1)[source]
Bases:
OneDGrid
Trefethen Strip General integral quadrature class.
References
- 7
Hale, Nicholas, and Lloyd N. Trefethen. “New quadrature formulas from conformal maps.” SIAM Journal on Numerical Analysis 46.2 (2008): 930-948.
- __init__(npoints, quadrature, rho=1.1)[source]
Generate grid on \([-1,1]\) interval based on Trefethen-General.
- Parameters
npoints (int) – Number of points in the grid.
- Returns
One-dimensional grid instance.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Trefethen-Strip-General'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)
- class UniformInteger(npoints)[source]
Bases:
OneDGrid
HORTON2 integral quadrature (HortonLinear) class.
\[\begin{split}\int_{0}^{n} f(x) dx \approx& \sum_{i=1}^n w_i f(x_i) \\ x_i =& i - 1 \\ w_i =& 1.0\end{split}\]- __init__(npoints)[source]
Generate grid on [0, npoints] interval using equally spaced uniform distribution.
- Parameters
npoints (int) – Number of grid points.
- Returns
One-dimensional grid instance containing points and weights.
- Return type
- property domain
the range of grid points.
- Type
(float, float)
- get_localgrid(center, radius)[source]
Create a grid contain points within the given radius of center.
- Parameters
center (float or np.array(M,)) – Cartesian coordinates of the center of the local grid.
radius (float) – Radius of sphere around the center. When equal to np.inf, the local grid coincides with the whole grid, which can be useful for debugging.
- Returns
Instance of LocalGrid.
- Return type
- integrate(*value_arrays)[source]
Integrate over the whole grid for given multiple value arrays.
Product of all value_arrays will be computed element-wise then integrated on the grid with its weights:
\[\int w(x) \prod_i f_i(x) dx.\]- Parameters
*value_arrays (np.ndarray(N, )) – One or multiple value array to integrate.
- Returns
The calculated integral over given integrand or function
- Return type
float
- moments(orders, centers, func_vals, type_mom='cartesian', return_orders=False)[source]
Compute the multipole moment integral of a function over centers.
The Cartesian type moments are:
\[m_{n_x, n_y, n_z} = \int (x - X_c)^{n_x} (y - Y_c)^{n_y} (z - Z_c)^{n_z} f(r) dr,\]where \(\textbf{R}_c = (X_c, Y_c, Z_c)\) is the center of the moment, \(\f(r)\) is the density, and \((n_x, n_y, n_z)\) are the Cartesian orders.
The spherical/pure moments with \((l, m)\) parameter are:
\[m_{lm} = \int | \textbf{r} - \textbf{R}_c|^l S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r},\]where \(S_l^m\) is a regular, real solid harmonic.
The radial moments with \(n\) parameter are:
\[m_n = \int | \textbf{r} - \textbf{R}_c|^{n} f(\textbf{r}) d\textbf{r}\]The radial combined with spherical/pure moments \((n, l, m)\) are:
\[m_{nlm} = \int | \textbf{r} - \textbf{R}_c|^{n+1} S_l^m(\theta, \phi) f(\textbf{r}) d\textbf{r}\]- Parameters
orders (int) – Generates all orders with Horton order depending on the type of the multipole moment type_mom.
centers (ndarray(M, 3)) – The centers \(\textbf{R}_c\) of the moments to compute from.
func_vals (ndarray(N,)) – The function \(f\) values evaluated on all \(N\) points on the integration grid.
type_mom (str) – The type of multipole moments: “cartesian”, “pure”, “radial” and “pure-radial”.
return_orders (bool) – If true, it will also return a list of size \(L\) of the orders corresponding to each integral/row of the output.
- Returns
Computes the moment integral of the function on the m`th center for all orders. If `return_orders is true, then this also returns a list that describes what each row/order is, e.g. for Cartesian, [(0, 0, 0), (1, 0, 0) ,…].
- Return type
ndarray(L, M), or (ndarray(L, M), list)
- name = 'Uniform-Integer'
- property points
Positions of the grid points.
- Type
np.ndarray(N,) or np.ndarray(N, M)
- save(filename)[source]
Save the points and weights as a npz file.
- Parameters
filename (str) – The path/name of the .npz file.
- property size
the total number of points on the grid.
- Type
int
- property weights
the weights of each grid point.
- Type
np.ndarray(N,)