Rectilinear2DGrid

class petres.grids.Rectilinear2DGrid[source]

Bases: object

Represent a 2D structured rectilinear grid.

The class stores vertex coordinates in each axis and computes cell-center coordinates and coordinate meshes on demand.

Parameters:
  • x_vertex (ArrayLike) – 1D vertex coordinates along x of length ni+1.

  • y_vertex (ArrayLike) – 1D vertex coordinates along y of length nj+1.

  • active (ArrayLike) – Boolean mask of shape (nj, ni) indicating active cells.

Raises:

ValueError – If active does not match the expected shape (nj, ni).

Notes

Coordinate meshes are cached lazily and reused after first computation.

Initialize the rectilinear grid and validate input shapes.

Raises:

ValueError – If active does not match the expected shape (nj, ni).

__init__(x_vertex, y_vertex, active)[source]

Initialize the rectilinear grid and validate input shapes.

Raises:

ValueError – If active does not match the expected shape (nj, ni).

x_vertex: ndarray[tuple[Any, ...], dtype[float64]]
y_vertex: ndarray[tuple[Any, ...], dtype[float64]]
active: ndarray[tuple[Any, ...], dtype[bool]]
__post_init__()[source]

Validate normalized arrays and enforce the activity-mask shape.

Raises:

ValueError – If active does not match the expected cell shape (nj, ni).

Notes

This method assumes arrays were already converted to NumPy arrays by __init__().

property cell_shape: tuple[int, int]

Get the number of cells along j and i.

Returns:

Cell grid shape as (nj, ni).

Return type:

tuple of int

property vertex_shape: tuple[int, int]

Get the number of vertices along j and i.

Returns:

Vertex grid shape as (nj + 1, ni + 1).

Return type:

tuple of int

property niv: int

Get the number of vertices in the i-direction.

Returns:

Number of x-direction vertices, equivalent to ni + 1.

Return type:

int

property njv: int

Get the number of vertices in the j-direction.

Returns:

Number of y-direction vertices, equivalent to nj + 1.

Return type:

int

property ni: int

Get the number of cells in the i-direction.

Returns:

Number of i-direction cells.

Return type:

int

property nj: int

Get the number of cells in the j-direction.

Returns:

Number of j-direction cells.

Return type:

int

property x_center: ndarray[tuple[Any, ...], dtype[float64]]

Get 1D x cell-center coordinates.

Returns:

Array of length ni containing x center coordinates.

Return type:

numpy.ndarray

property y_center: ndarray[tuple[Any, ...], dtype[float64]]

Get 1D y cell-center coordinates.

Returns:

Array of length nj containing y center coordinates.

Return type:

numpy.ndarray

property xx_vertex: ndarray[tuple[Any, ...], dtype[float64]]

Get x coordinates on the 2D vertex mesh.

Returns:

2D array with shape (nj + 1, ni + 1).

Return type:

numpy.ndarray

property yy_vertex: ndarray[tuple[Any, ...], dtype[float64]]

Get y coordinates on the 2D vertex mesh.

Returns:

2D array with shape (nj + 1, ni + 1).

Return type:

numpy.ndarray

property xx_center: ndarray[tuple[Any, ...], dtype[float64]]

Get x coordinates on the 2D cell-center mesh.

Returns:

2D array with shape (nj, ni).

Return type:

numpy.ndarray

property yy_center: ndarray[tuple[Any, ...], dtype[float64]]

Get y coordinates on the 2D cell-center mesh.

Returns:

2D array with shape (nj, ni).

Return type:

numpy.ndarray