# grid.onedgrid module¶

1D integration grid.

class ClenshawCurtis(npoints)

Bases: OneDGrid

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)

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

OneDGrid

property domain

the range of grid points.

Type

(float, float)

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

LocalGrid

integrate(*value_arrays)

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)

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 mth 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)

property points

Positions of the grid points.

Type

np.ndarray(N,) or np.ndarray(N, M)

save(filename)

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)

Bases: OneDGrid

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)

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

OneDGrid

property domain

the range of grid points.

Type

(float, float)

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

LocalGrid

integrate(*value_arrays)

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)

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 mth 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)

property points

Positions of the grid points.

Type

np.ndarray(N,) or np.ndarray(N, M)

save(filename)

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)

Bases: OneDGrid

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)

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

OneDGrid

property domain

the range of grid points.

Type

(float, float)

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

LocalGrid

integrate(*value_arrays)

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)

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 mth 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)

property points

Positions of the grid points.

Type

np.ndarray(N,) or np.ndarray(N, M)

save(filename)

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)

Bases: OneDGrid

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)

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

OneDGrid

property domain

the range of grid points.

Type

(float, float)

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

LocalGrid

integrate(*value_arrays)

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)

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 mth 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)

property points

Positions of the grid points.

Type

np.ndarray(N,) or np.ndarray(N, M)

save(filename)

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)

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)

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

OneDGrid

property domain

the range of grid points.

Type

(float, float)

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

LocalGrid

integrate(*value_arrays)

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)

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 mth 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)

property points

Positions of the grid points.

Type

np.ndarray(N,) or np.ndarray(N, M)

save(filename)

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)

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)

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

OneDGrid

property domain

the range of grid points.

Type

(float, float)

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

LocalGrid

integrate(*value_arrays)

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)

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 mth 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)

property points

Positions of the grid points.

Type

np.ndarray(N,) or np.ndarray(N, M)

save(filename)

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)

Bases: OneDGrid

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)

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

OneDGrid

property domain

the range of grid points.

Type

(float, float)

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

LocalGrid

integrate(*value_arrays)

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)

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 mth 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)

property points

Positions of the grid points.

Type

np.ndarray(N,) or np.ndarray(N, M)

save(filename)

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)

Bases: OneDGrid

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)

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

OneDGrid

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)

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

LocalGrid

integrate(*value_arrays)

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)

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 mth 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)

property points

Positions of the grid points.

Type

np.ndarray(N,) or np.ndarray(N, M)

save(filename)

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)

Bases: OneDGrid

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)

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

OneDGrid

property domain

the range of grid points.

Type

(float, float)

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

LocalGrid

integrate(*value_arrays)

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)

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 mth 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)

property points

Positions of the grid points.

Type

np.ndarray(N,) or np.ndarray(N, M)

save(filename)

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)

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)

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

OneDGrid

property domain

the range of grid points.

Type

(float, float)

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

LocalGrid

integrate(*value_arrays)

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)

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 mth 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)

property points

Positions of the grid points.

Type

np.ndarray(N,) or np.ndarray(N, M)

save(filename)

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)

Bases: OneDGrid

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)

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

OneDGrid

property domain

the range of grid points.

Type

(float, float)

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

LocalGrid

integrate(*value_arrays)

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)

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 mth 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)

property points

Positions of the grid points.

Type

np.ndarray(N,) or np.ndarray(N, M)

save(filename)

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)

Bases: OneDGrid

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)

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

OneDGrid

property domain

the range of grid points.

Type

(float, float)

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

LocalGrid

integrate(*value_arrays)

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)

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 mth 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)

property points

Positions of the grid points.

Type

np.ndarray(N,) or np.ndarray(N, M)

save(filename)

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)

Bases: OneDGrid

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)

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

OneDGrid

property domain

the range of grid points.

Type

(float, float)

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

LocalGrid

integrate(*value_arrays)

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)

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 mth 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)

property points

Positions of the grid points.

Type

np.ndarray(N,) or np.ndarray(N, M)

save(filename)

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)

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)

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

OneDGrid

property domain

the range of grid points.

Type

(float, float)

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

LocalGrid

integrate(*value_arrays)

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)

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 mth 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)

property points

Positions of the grid points.

Type

np.ndarray(N,) or np.ndarray(N, M)

save(filename)

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)

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)

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

OneDGrid

property domain

the range of grid points.

Type

(float, float)

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

LocalGrid

integrate(*value_arrays)

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)

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 mth 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)

property points

Positions of the grid points.

Type

np.ndarray(N,) or np.ndarray(N, M)

save(filename)

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,)

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.

Generate 1D grid on $$[-1,1]$$ interval based on Trefethen-General.

Parameters
• npoints (int) – Number of points in the grid.

• quadrature (OneDGrid) – General one-dimensional grid.

• d – Odd degree of the Taylor series polynomial of $$\sin^{-1}$$. Only d=1,5,9 are supported.

Returns

One-dimensional grid instance.

Return type

OneDGrid

property domain

the range of grid points.

Type

(float, float)

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

LocalGrid

integrate(*value_arrays)

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)

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 mth 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)

property points

Positions of the grid points.

Type

np.ndarray(N,) or np.ndarray(N, M)

save(filename)

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)

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)

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

OneDGrid

property domain

the range of grid points.

Type

(float, float)

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

LocalGrid

integrate(*value_arrays)

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)

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 mth 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)

property points

Positions of the grid points.

Type

np.ndarray(N,) or np.ndarray(N, M)

save(filename)

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)

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)

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

OneDGrid

property domain

the range of grid points.

Type

(float, float)

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

LocalGrid

integrate(*value_arrays)

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)

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 mth 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)

property points

Positions of the grid points.

Type

np.ndarray(N,) or np.ndarray(N, M)

save(filename)

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,)

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.

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

OneDGrid

property domain

the range of grid points.

Type

(float, float)

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

LocalGrid

integrate(*value_arrays)

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)

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 mth 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)

property points

Positions of the grid points.

Type

np.ndarray(N,) or np.ndarray(N, M)

save(filename)

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)

Bases: OneDGrid

$\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)

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

OneDGrid

property domain

the range of grid points.

Type

(float, float)

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

LocalGrid

integrate(*value_arrays)

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)

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 mth 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)

property points

Positions of the grid points.

Type

np.ndarray(N,) or np.ndarray(N, M)

save(filename)

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,)