grid.ngrid module
Grid for N particle functions.
- class Ngrid(grid_list=None, n=None, **kwargs)[source]
Bases:
Grid
Grid class for integration of N argument functions.
This class is used for integrating functions of N arguments.
- ..math::
idotsint f(x_1, x_2, …, x_N) dx_1 dx_2 … dx_N
The function to integrate must have all arguments \(\{x_i\}\) with the same dimension as the points of the corresponding grids (i.e. each of the arguments corresponds to a different grid). For example for a function of the form f((x1,y1,z1), (x2,y2)) -> float the first argument must be described by a 3D grid and the second argument by a 2D grid.
- __init__(grid_list=None, n=None, **kwargs)[source]
Initialize n particle grid.
At least one grid must be specified. If only one grid is specified, and a value for n bigger than one is specified, the same grid will copied n times and one grid will used for each particle. If more than one grid is specified, n will be ignored. In all cases, The function to integrate must be a function with all arguments with the same dimension as the grid points and must depend on a number of particles equal to the number of grids. For example, a function of the form f((x1,y1,z1), (x2,y2,z2), …, (xn, yn, zn)) -> float where (xi, yi, zi) are the coordinates of the i-th particle and n is the number of particles.
- Parameters
grid_list (list of Grid) – List of grids, one Grid for each particle.
n (int) – Number of particles.
- get_localgrid(center, radius)[source]
Create a grid containing 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(callable, **call_kwargs)[source]
Integrate callable on the N particle grid.
- Parameters
callable (callable) – Callable to integrate. It must take a list of arguments (one for each particle) with the same dimension as the grid points and return a float (e.g. a function of the form f([x1,y1,z1], [x2,y2,z2]) -> float).
call_kwargs (dict) – Keyword arguments that will be passed to callable.
- Returns
Integral of callable.
- 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 function, 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)[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,)