quickpaver.RectilinearGrid#
- class quickpaver.RectilinearGrid(cx: float = 0.0, cy: float = 0.0, cz: float = 0.0, dx: float = 1.0, dy: float = 1.0, dz: float = 1.0, nx: int = 1, ny: int = 1, nz: int = 1, theta: float = 0.0, phi: float = 0.0, psi: float = 0.0)[source]#
Represent a rectilinear 3D grid.
A rectilinear grid is defined by its centre coordinates, cell dimensions, number of cells along each axis, and optional Euler-angle rotations. The grid is initially constructed in a local, axis-aligned coordinate system and can be rotated around its centre to obtain world-space coordinates.
The grid stores cell-based information, not vertex-based information. Grid indices therefore refer to cells/voxels, and flattened node numbers follow the regular-grid indexing convention used by
rlg_idx_to_nn().- Parameters:
cx (float, optional) – X coordinate of the grid centre in world space, by default 0.0.
cy (float, optional) – Y coordinate of the grid centre in world space, by default 0.0.
cz (float, optional) – Z coordinate of the grid centre in world space, by default 0.0.
dx (float, optional) – Cell size along the local x-axis, in metres, by default 1.0.
dy (float, optional) – Cell size along the local y-axis, in metres, by default 1.0.
dz (float, optional) – Cell size along the local z-axis, in metres, by default 1.0.
nx (int, optional) – Number of cells along the local x-axis, by default 1.
ny (int, optional) – Number of cells along the local y-axis, by default 1.
nz (int, optional) – Number of cells along the local z-axis, by default 1.
theta (float, optional) – Rotation angle around the z-axis, in degrees, by default 0.0.
phi (float, optional) – Rotation angle around the y-axis, in degrees, by default 0.0.
psi (float, optional) – Rotation angle around the x-axis, in degrees, by default 0.0.
- Variables:
rot_center (tuple of float) – Rotation centre of the grid. This is always equal to
(cx, cy, cz).n_grid_cells (int) – Total number of grid cells, equal to
nx * ny * nz.origin (tuple of float) – World-space coordinates of the rotated lower corner of the grid.
origin_coords (NDArrayFloat) – World-space coordinates of all cell lower corners, with shape
(3, nx, ny, nz).center_coords (NDArrayFloat) – World-space coordinates of all cell centres, with shape
(3, nx, ny, nz).bounds (NDArrayFloat) – Axis-aligned world-space bounds of the rotated grid, with shape
(3, 2)and rows[[xmin, xmax], [ymin, ymax], [zmin, zmax]].
Notes
The rotation order applied by
_rotate_coords()is:R_x(psi) @ R_y(phi) @ R_z(theta)where angles are provided in degrees and internally converted to radians. Because matrix multiplication is applied from right to left, coordinates are first rotated around the z-axis, then around the y-axis, and finally around the x-axis.
The rotation pivot is always the grid centre
(cx, cy, cz).This class uses
__slots__and therefore does not expose an instance__dict__. Only the attributes listed in__slots__can be assigned.- __init__(cx: float = 0.0, cy: float = 0.0, cz: float = 0.0, dx: float = 1.0, dy: float = 1.0, dz: float = 1.0, nx: int = 1, ny: int = 1, nz: int = 1, theta: float = 0.0, phi: float = 0.0, psi: float = 0.0) None[source]#
Initialize the instance.
- Parameters:
cx (float) – Grid centre X (world space).
cy (float) – Grid centre Y (world space).
cz (float) – Grid centre Z (world space).
dx (float) – Mesh size along the x axis in meters.
dy (float) – Mesh size along the y axis in meters.
dz (float) – Mesh size along the z axis in meters.
nx (int) – Number of meshes along the x axis.
ny (int) – Number of meshes along the y axis.
nz (int) – Number of meshes along the v axis.
theta (float) – z-axis rotation angle in degrees with (cx, cy, cz) as origin.
phi (float) – y-axis-rotation angle in degrees with (cx, cy, cz) as origin.
psi (float) – x-axis-rotation angle in degrees with (cx, cy, cz) as origin.
Properties
Return the coordinates of the 8 rotated bounding-box vertices.
Return the bounds [[xmin, xmax], [ymin, ymax], [zmin, zmax]].
Return the grid meshes center coordinates with shape (3, nx, ny, nz).
Return the coordinates of the voxel centers for an xy slice.
Return the surface of the frontiers along the x axis in m2
Return the surface of the frontiers along the y axis in m2
Return the surface of the frontiers along the z axis in m2
Return the volume of one grid cell in m3.
Return the grid indices with shape (3, nx, ny, nz).
Return the number of grid cells.
Return the non rotated grid cell center coords with shape (3, nx, ny, nz).
Return the non rotated coordinates of the voxel centers for an xy slice.
Corner origin in WORLD space (smallest corner after rotation).
Return the grid meshes origin coordinates with shape (3, nx, ny, nz).
Rotation pivot — always the grid centre.
Return the total grid volume in m3.
Return the x extent in meters.
Return the grid meshes x-indices as 1D array.
Return the maximum x of the grid.
Return the minimum x of the grid.
Return the y extent in meters.
Return the grid meshes y-indices as 1D array.
Return the maximum y of the grid.
Return the minimum y of the grid.
Return the z extent in meters.
Return the grid meshes z-indices as 1D array.
Return the maximum z of the grid.
Return the minimum z of the grid.
Methods
Return a deepcopy of the instance.
Make the matrix which gives the spatial gradient of a field.
Make the matrix which gives the spatial permutation of a field.
Convert the grid to a PyVista dataset.
Return a 2d regular grid to 2d shapely polygons.