pystencils.grids.patch.Patch#
- class pystencils.grids.patch.Patch(name: str, x_max: tuple[Any, ...], /, *, num_vertices: Iterable[Basic] | None = None, num_cells: Iterable[Basic] | None = None)#
- class pystencils.grids.patch.Patch(name: str, x_min: tuple[Any, ...], x_max: tuple[Any, ...], /, *, num_vertices: Iterable[Basic] | None = None, num_cells: Iterable[Basic] | None = None)
Cuboid volume of space, discretized by a cartesian grid.
Patches are algebraic objects representing (patches of) simulation domains in pystencils. A patch \(\Omega\) is an \(m\)-dimensional multi-interval \([\ell_1, u_1] \times \cdots \times [\ell_m, u_m]\) given by its lower and upper corners \((\ell_1, \dots, \ell_m)\) and \((u_1, \dots, u_m)\).
Each patch is host to a numerical grid of \(N_1 \times \cdots \times N_m\) vertices (points), with spacings \(h_k = \frac{u_k - \ell_k}{N_k - 1}\) in each dimension. The grid vertices are
\[\mathrm{vertices} (\Omega) = \left\{ (i_k \cdot h_k)_{k = 1, \dots, m} \; \vert \; (i_k = 0, \dots, N_k - 1)_{k = 1, \dots, m} \right\}.\]The cuboid spaces enclosed by adjacent vertices are the grid’s cells. Each cell encloses a volume \(h_1 \times \cdots \times h_m\) according to the grid spacing; cell \(\mathsf{c}_{\boldsymbol{i}}\) therefore claims the multi-interval
\[\mathsf{c}_{\boldsymbol{i}} = \prod_{k=1}^m [i_k \cdot h_k, (i_k + 1) \cdot h_k].\]There are one fewer cells than vertices in each dimension; the grid’s cells are therefore
\[\mathrm{cells} (\Omega) = \left\{ \mathsf{c}_{(i_1, \dots, i_m)} \; \vert \; (i_k = 0, \dots, N_k - 2)_{k = 1, \dots, m} \right\}.\]The
Patchclass models these patches algebraically, and allows for the definition of fields on its vertex and cell grids. All its attributes are symbolic expressions.- Parameters:
name (
str) – Name of the patchx_min – Lower corner \((\ell_1, \dots, \ell_m)\) of the patch. Can be omitted; in this case, the lower corner is set to the origin.
x_max – Upper corner \((u_1, \dots, u_k)\) of the patch.
num_vertices (
Optional[Iterable[Basic]]) – Number of vertices in each dimension. If given,num_cellsis inferred; do not specify both.num_cells (
Optional[Iterable[Basic]]) – Number of cells in each dimension. If given,num_verticesis inferred; do not specify both.corners (tuple[Any, ...])
- property x_min: ImmutableDenseMatrix#
Lower corner as a SymPy matrix
- property x_max: ImmutableDenseMatrix#
Upper corner as a SymPy matrix
- property extents: ImmutableDenseMatrix#
Total extents of the patch as a SymPy matrix
- property spacing: ImmutableDenseMatrix#
Vertex spacing as a SymPy matrix
- property num_vertices: ImmutableDenseMatrix#
Number of vertices as a SymPy matrix
- property num_cells: ImmutableDenseMatrix#
Number of cells as a SymPy matrix
- property cells: PatchGrid#
Proxy indicating the patch’s cell grid; use to associate algebraic fields with the patch’s cells.
- property vertices: PatchGrid#
Proxy indicating the patch’s vertex grid; use to associate algebraic fields with the patch’s vertices.
- vertex(*idcs)#
Coordinates of a vertex identified by the given relative indices.
Like for field accesses, indices are interpreted relative to the current iteration point.
Examples
Coordinates of the current vertex:
patch.vertex()
Coordinates of the north-east neighbor vertex on a 2D patch:
patch.vertex(-1, 1)
- Return type:
- Parameters:
idcs (SupportsIndex | Basic)
- cell_center(*idcs)#
Coordinates of the center of a cell identified by the given relative indices.
Like for field accesses, indices are interpreted relative to the current iteration point.
Examples
Coordinates of the current cell’s center:
patch.cell_center()
Coordinates of the center of the north-east neighbor cell on a 2D patch:
patch.cell_center(-1, 1)
- Return type:
- Parameters:
idcs (SupportsIndex | Basic)