Boundary Conditions¶
Boundary conditions can be applied to solution arrays and to the sparse
matrix systems that arise from discretised differential equations. Numgrids
supports Dirichlet, Neumann, and Robin boundary conditions.
BoundaryFace identifies which face of the domain a
condition is imposed on, and apply_bcs() applies a collection
of conditions in a single call.
- class numgrids.BoundaryFace(grid: Grid, axis_index: int, side: str)[source]¶
A selection of boundary points on one face of a grid.
For an N-dimensional grid, each non-periodic axis contributes two faces:
"low"(index 0 along that axis) and"high"(last index).- Parameters:
- property mask: ndarray[tuple[Any, ...], dtype[_ScalarT]]¶
Boolean mask of shape
grid.shape, True on this face.
- class numgrids.DirichletBC(face: BoundaryFace, value=0.0)[source]¶
Dirichlet boundary condition: \(u = g\) on a boundary face.
- Parameters:
face (BoundaryFace) – The boundary face.
value (float, NDArray, or callable) – The prescribed boundary value g.
- apply(u: ndarray[tuple[Any, ...], dtype[_ScalarT]]) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]¶
Set u to g on the boundary face (in-place).
- Returns:
The modified array (same object as u).
- Return type:
NDArray
- apply_to_system(L: spmatrix, rhs: ndarray[tuple[Any, ...], dtype[_ScalarT]]) tuple[spmatrix, ndarray[tuple[Any, ...], dtype[_ScalarT]]][source]¶
Replace boundary rows in L with identity rows and set rhs = g.
- Parameters:
L (spmatrix) – System matrix of shape
(grid.size, grid.size).rhs (NDArray) – Right-hand side vector of shape
(grid.size,).
- Returns:
Modified
(L, rhs).- Return type:
tuple of (spmatrix, NDArray)
- class numgrids.NeumannBC(face: BoundaryFace, value=0.0)[source]¶
Neumann boundary condition: \(\partial u / \partial n = g\).
The outward normal derivative is
sign * du/d(axis)where sign is+1on the"high"face and-1on the"low"face.- Parameters:
face (BoundaryFace) – The boundary face.
value (float, NDArray, or callable) – The prescribed normal-derivative value g.
- class numgrids.RobinBC(face: BoundaryFace, a: float, b: float, value=0.0)[source]¶
Robin boundary condition: \(a\,u + b\,\partial u/\partial n = g\).
- Parameters:
face (BoundaryFace) – The boundary face.
a (float) – Coefficient of u.
b (float) – Coefficient of the normal derivative.
value (float, NDArray, or callable) – The prescribed value g.
- numgrids.apply_bcs(bcs: list[BoundaryCondition], L: spmatrix, rhs: ndarray[tuple[Any, ...], dtype[_ScalarT]]) tuple[spmatrix, ndarray[tuple[Any, ...], dtype[_ScalarT]]][source]¶
Apply a sequence of boundary conditions to a linear system.
Conditions are applied in list order; for overlapping points (e.g. corners) the last condition wins.