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

  • shape (tuple of int) – Grid shape as (nx, ny, nz).

  • dims (tuple of float) – Cell dimensions as (dx, dy, dz).

  • 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

cx

cy

cz

dx

dy

dz

nx

ny

nz

theta

phi

psi

bounding_box_vertices_coordinates

Return the coordinates of the 8 rotated bounding-box vertices.

bounds

Return the bounds [[xmin, xmax], [ymin, ymax], [zmin, zmax]].

center_coords

Return the grid meshes center coordinates with shape (3, nx, ny, nz).

center_coords_2d

Return the coordinates of the voxel centers for an xy slice.

dims

gamma_ij_x_m2

Return the surface of the frontiers along the x axis in m2

gamma_ij_y_m2

Return the surface of the frontiers along the y axis in m2

gamma_ij_z_m2

Return the surface of the frontiers along the z axis in m2

grid_cell_volume_m3

Return the volume of one grid cell in m3.

indices

Return the grid indices with shape (3, nx, ny, nz).

n_grid_cells

Return the number of grid cells.

non_rot_center_coords

Return the non rotated grid cell center coords with shape (3, nx, ny, nz).

non_rot_center_coords_2d

Return the non rotated coordinates of the voxel centers for an xy slice.

origin

Corner origin in WORLD space (smallest corner after rotation).

origin_coords

Return the grid meshes origin coordinates with shape (3, nx, ny, nz).

rot_center

Rotation pivot — always the grid centre.

shape

total_volume_m3

Return the total grid volume in m3.

x0

x_extent

Return the x extent in meters.

x_indices

Return the grid meshes x-indices as 1D array.

xmax

Return the maximum x of the grid.

xmin

Return the minimum x of the grid.

y0

y_extent

Return the y extent in meters.

y_indices

Return the grid meshes y-indices as 1D array.

ymax

Return the maximum y of the grid.

ymin

Return the minimum y of the grid.

z0

z_extent

Return the z extent in meters.

z_indices

Return the grid meshes z-indices as 1D array.

zmax

Return the maximum z of the grid.

zmin

Return the minimum z of the grid.

Methods

copy

Return a deepcopy of the instance.

make_spatial_gradient_matrices

Make the matrix which gives the spatial gradient of a field.

make_spatial_permutation_matrices

Make the matrix which gives the spatial permutation of a field.

to_pyvista

Convert the grid to a PyVista dataset.

to_shapely

Return a 2d regular grid to 2d shapely polygons.