iwopy.utils.discretization.RegularDiscretizationGrid¶
- class iwopy.utils.discretization.RegularDiscretizationGrid[source]¶
Bases:
object
A lightweight regular grid in n dimensions, without points storage.
- Parameters:
origin (array-like) – The origin point, len: n_dims
deltas (array-like) – The step sizes, len: n_dims.
n_steps (array-like) – The number of steps, len: n_dims. Use INT_INF for infinite.
interpolation (str) – The interpolation method: None, nearest, linear
tol (list of float, optional) – The tolerances for grid bounds, default is 0, shape: (n_dims,)
digits (int) – The grid point precision
- origin¶
The origin point, shape: (n_dims,)
- Type:
- deltas¶
The step sizes, shape: (n_dims,)
- Type:
- n_steps¶
The number of steps, shape: (n_dims,)
- Type:
- tol¶
The tolerances for grid bounds, shape: (n_dims,), or None
- Type:
Methods
__init__
(origin, deltas, n_steps[, ...])all_gridpoints
(pts[, allow_outer])Checks if all points are on grid.
apply_tol
(p)Get tolerance corrected point
apply_tols
(pts)Get tolerance corrected points
deriv_coeffs
(pts, var[, order, orderb])Calculates the derivative coefficients at points.
deriv_coeffs_gridpoints
(inds, var[, order, ...])Calculates the derivative coefficients at grid points.
find_grid_inds
(inds)Finds indices that are on grid
find_gridpoints
(pts[, allow_outer, ret_inds])Finds points that are on grid.
find_ingrid
(pts)Finds points that are on grid.
get_cell
(p)Get the grid cell that contains a point.
get_cells
(pts)Get the grid cells that contain the given points, one cell per point.
get_corner
(p[, allow_outer])Get the lower-left grid corner of a point.
get_corners
(pts[, allow_outer])Get the lower-left grid corners of points.
gp2i
(gp[, allow_outer, error])Get grid index of a grid point
gpts2inds
(gpts[, allow_outer, error])Get grid indices of grid points.
grad_coeffs
(pts, vars[, order, orderb])Calculates the gradient coefficients at grid points.
grad_coeffs_gridpoints
(inds, vars[, order, ...])Calculates the gradient coefficients at grid points.
i2gp
(inds[, error])Translates grid point indices to grid point.
in_grid
(p)Checks if a point is located within the grid.
inds2gpts
(inds)Translates grid point indices to grid points.
Get the interpolation coefficients for a point.
interpolation_coeffs_points
(pts[, ret_pmap])Get the interpolation coefficients for a set of points.
is_gridi
(inds)Checks if grid indices are valid
is_gridpoint
(p[, allow_outer, ret_inds])Checks if a point is on grid.
print_info
([spaces])Prints basic information
Attributes
INT_INF
The number of dimensions
The number of points in each dimension
The maximal grid point values
The minimal grid point values
- all_gridpoints(pts, allow_outer=True)[source]¶
Checks if all points are on grid.
- Parameters:
pts (numpy.ndarray) – The points space, shape: (n_pts, n_dims)
allow_outer (bool) – Allow outermost point indices, else reduce those to lower-left cell corner
- Returns:
True if all points on grid
- Return type:
- apply_tol(p)[source]¶
Get tolerance corrected point
- Parameters:
p (numpy.ndarray) – The point, shape: (n_dims,)
- Returns:
q – The corrected point, shape: (n_dims,)
- Return type:
- apply_tols(pts)[source]¶
Get tolerance corrected points
- Parameters:
pts (numpy.ndarray) – The points, shape: (n_pts, n_dims)
- Returns:
q – The corrected points, shape: (n_pts, n_dims)
- Return type:
- deriv_coeffs(pts, var, order=2, orderb=1)[source]¶
Calculates the derivative coefficients at points.
- Parameters:
pts (numpy.ndarray) – The evaluation points, shape: (n_pts, n_dims)
var (int) – The dimension representing the variable wrt which to differentiate
order (int) – The finite difference order, 1 = forward, -1 = backward, 2 = centre
orderb (int) – The finite difference order at boundary points
- Returns:
gpts (numpy.ndarray) – The grid points relevant for coeffs, shape: (n_gpts, n_dims)
coeffs (numpy.ndarray) – The gradient coefficients, shape: (n_pts, n_gpts)
- deriv_coeffs_gridpoints(inds, var, order=2, orderb=1)[source]¶
Calculates the derivative coefficients at grid points.
- Parameters:
inds (numpy.ndarray) – The integer grid point indices, shape: (n_inds, n_dims)
var (int) – The dimension representing the variable wrt which to differentiate
order (int) – The finite difference order, 1 = forward, -1 = backward, 2 = centre
orderb (int) – The finite difference order at boundary points
- Returns:
gpts (numpy.ndarray) – The grid points relevant for coeffs, shape: (n_gpts, n_dims)
coeffs (numpy.ndarray) – The gradient coefficients, shape: (n_inds, n_gpts)
- find_grid_inds(inds)[source]¶
Finds indices that are on grid
- Parameters:
inds (numpy.ndarray) – The grid point index candidates, shape: (n_inds, n_dims)
- Returns:
sel_grid – Subset selection of on-grid indices, shape: (n_inds, n_dims)
- Return type:
- find_gridpoints(pts, allow_outer=True, ret_inds=False)[source]¶
Finds points that are on grid.
- Parameters:
pts (numpy.ndarray) – The points, shape: (n_pts, n_dims)
allow_outer (bool) – Allow outermost point indices, else reduce those to lower-left cell corner
ret_inds (bool) – Additionally return indices
- Returns:
sel_grid (numpy.ndarray of bool) – Subset selection of points that are on grid, shape: (n_pts, n_dims)
inds (numpy.ndarray, optional) – The grid point indices, shape: (n_gpts, n_dims)
- find_ingrid(pts)[source]¶
Finds points that are on grid.
- Parameters:
pts (numpy.ndarray) – The points, shape: (n_pts, n_dims)
- Returns:
sel_grid – Subset selection of points that are in grid, shape: (n_pts, n_dims)
- Return type:
- get_cell(p)[source]¶
Get the grid cell that contains a point.
- Parameters:
p (numpy.ndarray) – The point, shape: (n_dims,)
- Returns:
cell – The min and max values of each dimension. Shape: (n_dims, 2)
- Return type:
- get_cells(pts)[source]¶
Get the grid cells that contain the given points, one cell per point.
- Parameters:
pts (numpy.ndarray) – The points, shape: (n_pts, n_dims)
- Returns:
cells – The min and max values of each dimension. Shape: (n_pts, n_dims, 2)
- Return type:
- get_corner(p, allow_outer=True)[source]¶
Get the lower-left grid corner of a point.
- Parameters:
p (numpy.ndarray) – The point, shape: (n_dims,)
allow_outer (bool) – Allow outermost point indices, else reduce those to lower-left cell corner
- Returns:
p0 – The lower-left grid corner point, shape: (n_dims,)
- Return type:
- get_corners(pts, allow_outer=True)[source]¶
Get the lower-left grid corners of points.
- Parameters:
pts (numpy.ndarray) – The points space, shape: (n_pts, n_dims)
allow_outer (bool) – Allow outermost point indices, else reduce those to lower-left cell corner
- Returns:
p0 – The lower-left grid corner points, shape: (n_pts, n_dims)
- Return type:
- gp2i(gp, allow_outer=True, error=True)[source]¶
Get grid index of a grid point
- Parameters:
gp (numpy.ndarray) – The point, shape: (n_dims,)
allow_outer (bool) – Allow outermost point indices, else reduce those to lower-left cell corner
error (bool) – Flag for throwing error if off-grid, else return None in that case
- Returns:
inds – The lower-left grid corner point indices, shape: (n_dims,)
- Return type:
- gpts2inds(gpts, allow_outer=True, error=True)[source]¶
Get grid indices of grid points.
- Parameters:
gpts (numpy.ndarray) – The grid points, shape: (n_gpts, n_dims)
allow_outer (bool) – Allow outermost point indices, else reduce those to lower-left cell corner
error (bool) – Flag for throwing error if off-grid, else return None in that case
- Returns:
inds – The lower-left grid corner indices, shape: (n_gpts, n_dims)
- Return type:
- grad_coeffs(pts, vars, order=2, orderb=1)[source]¶
Calculates the gradient coefficients at grid points.
- Parameters:
pts (numpy.ndarray) – The evaluation points, shape: (n_pts, n_dims)
vars (list of int, optional) – The dimensions representing the variables wrt which to differentiate, shape: (n_vars,). Default is all dimensions
order (int list of int) – The finite difference order, 1 = forward, -1 = backward, 2 = centre
orderb (int list of int) – The finite difference order at boundary points
- Returns:
gpts (numpy.ndarray) – The grid points relevant for coeffs, shape: (n_gpts, n_dims)
coeffs (numpy.ndarray) – The gradient coefficients, shape: (n_pts, n_vars, n_gpts)
- grad_coeffs_gridpoints(inds, vars, order=2, orderb=1)[source]¶
Calculates the gradient coefficients at grid points.
- Parameters:
inds (numpy.ndarray) – The integer grid point indices, shape: (n_inds, n_dims)
vars (list of int, optional) – The dimensions representing the variables wrt which to differentiate, shape: (n_vars,). Default is all dimensions
order (int or list of int) – The finite difference order, 1 = forward, -1 = backward, 2 = centre
orderb (int list of int) – The finite difference order at boundary points
- Returns:
gpts (numpy.ndarray) – The grid points relevant for coeffs, shape: (n_gpts, n_dims)
coeffs (numpy.ndarray) – The gradient coefficients, shape: (n_inds, n_vars, n_gpts)
- i2gp(inds, error=True)[source]¶
Translates grid point indices to grid point.
- Parameters:
- Returns:
gp – The grid point, shape: (n_dims,)
- Return type:
- in_grid(p)[source]¶
Checks if a point is located within the grid.
- Parameters:
p (numpy.ndarray) – The point, shape: (n_dims,)
- Returns:
True if within grid
- Return type:
- inds2gpts(inds)[source]¶
Translates grid point indices to grid points.
- Parameters:
inds (array-like) – The integer grid point indices, shape: (n_gpts, dims)
- Returns:
gpts – The grid points, shape: (n_gpts, n_dims)
- Return type:
- interpolation_coeffs_point(p)[source]¶
Get the interpolation coefficients for a point.
Example
>>> g = RegularDiscretizationGrid(...) >>> p = ... >>> gpts, c = g.interpolation_coeffs_point(p) >>> ratg = ... calc results at gpts, shape (n_gpts, x) ... >>> ires = np.einsum('gx,g->x', ratg, c)
- Parameters:
p (numpy.ndarray) – The point, shape: (n_dims,)
- Returns:
gpts (numpy.ndarray) – The grid points relevant for coeffs, shape: (n_gpts, n_dims)
coeffs (numpy.ndarray) – The interpolation coefficients, shape: (n_gpts,)
- interpolation_coeffs_points(pts, ret_pmap=False)[source]¶
Get the interpolation coefficients for a set of points.
Example
>>> g = RegularDiscretizationGrid(...) >>> pts = ... >>> gpts, c = g.interpolation_coeffs_points(pts) >>> ratg = ... calc results at gpts, shape (n_gpts, x) ... >>> ires = np.einsum('gx,pg->px', ratg, c)
- Parameters:
pts (numpy.ndarray) – The points, shape: (n_pts, n_dims)
ret_pmap (bool) – Additionally return the map from pts to gpts
- Returns:
gpts (numpy.ndarray) – The grid points relevant for coeffs, shape: (n_gpts, n_dims)
coeffs (numpy.ndarray) – The interpolation coefficients, shape: (n_pts, n_gpts)
pmap (numpy.ndarray, optional) – The map from pts to gpts, shape: (n_pts, n_gp)
- is_gridpoint(p, allow_outer=True, ret_inds=False)[source]¶
Checks if a point is on grid.
- Parameters:
p (numpy.ndarray) – The point, shape: (n_dims,)
allow_outer (bool) – Allow outermost point indices, else reduce those to lower-left cell corner
ret_inds (bool) – Additionally return indices
- Returns:
bool – True if on grid
inds (numpy.ndarray, optional) – The grid point indices, shape: (n_dims,)
- property n_points¶
The number of points in each dimension
- Returns:
The number of points in each dimension, shape: (n_dims,)
- Return type:
- property p_max¶
The maximal grid point values
- Returns:
The maximal grid point values, shape: (n_dims,)
- Return type:
- property p_min¶
The minimal grid point values
- Returns:
The minimal grid point values, shape: (n_dims,)
- Return type: