Boundary Conditions
Boundary condition primitives and helpers for staggered C-grid fields.
BC Atoms (1-D)
finitevolx.Dirichlet1D
Bases: Module
Apply a Dirichlet value on one domain face.
For a cell-centred field (point="T", the default) the value is
imposed at the physical wall between the first interior cell and the
ghost cell:
phi_boundary = 0.5 * (phi_interior + phi_ghost),
i.e. phi_ghost = 2 * value - phi_interior.
For a node on the wall (the normal velocity U on west / east or
V on south / north, any X field) the wall node is set to
value directly. A closed wall for the normal velocity is therefore
Dirichlet1D("east", 0.0, point="U"); without point="U" the east
wall face U[:, Nx-2] is left untouched and mass leaks through it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
face
|
Literal['south', 'north', 'west', 'east']
|
Domain face to update. |
required |
value
|
float
|
Target boundary value. |
required |
point
|
Literal['T', 'U', 'V', 'X']
|
C-grid point the field lives on (default |
required |
Examples:
No normal flow through the west and east walls of a U-field:
>>> u = jnp.ones((6, 6))
>>> u = Dirichlet1D("west", 0.0, point="U")(u, dx=1.0, dy=1.0)
>>> u = Dirichlet1D("east", 0.0, point="U")(u, dx=1.0, dy=1.0)
>>> float(u[2, 0]), float(u[2, -2]) # the two wall faces
(0.0, 0.0)
Source code in finitevolx/_src/boundary/bc_1d.py
__call__(field, dx, dy)
Return field with one Dirichlet ghost face (or wall node) updated.
Source code in finitevolx/_src/boundary/bc_1d.py
finitevolx.Neumann1D
Bases: Module
Apply an outward-normal gradient on one domain face.
The gradient is interpreted as dphi/dn along the outward normal,
evaluated over the one-cell distance between the first interior node
and the boundary node: the ghost node for a cell-centred field (the
difference is centred on the wall face), the wall node itself for a
node on the wall (a one-sided difference; the outside slot then makes
the centred difference across the wall node equal value too).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
face
|
Literal['south', 'north', 'west', 'east']
|
Domain face to update. |
required |
value
|
float
|
Outward-normal gradient. Defaults to |
required |
point
|
Literal['T', 'U', 'V', 'X']
|
C-grid point the field lives on (default |
required |
Source code in finitevolx/_src/boundary/bc_1d.py
__call__(field, dx, dy)
Return field with one Neumann ghost face updated.
Source code in finitevolx/_src/boundary/bc_1d.py
finitevolx.Periodic1D
Bases: Module
Apply periodic wrapping on one domain face.
Periodic wrapping copies the interior line one period away, which is the
right ghost value for every C-grid point (U[:, 0] is the same face as
U[:, Nx-2]), so this atom takes no point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
face
|
Literal['south', 'north', 'west', 'east']
|
Domain face to update. |
required |
Source code in finitevolx/_src/boundary/bc_1d.py
__call__(field, dx, dy)
Return field with one periodic ghost face updated.
Source code in finitevolx/_src/boundary/bc_1d.py
finitevolx.Reflective1D
Bases: Module
Apply an even-symmetry reflective boundary on one face.
This mirrors the nearest interior values into the ghost cells, which is appropriate for scalar tracers or tangential components with reflective symmetry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
face
|
Literal['south', 'north', 'west', 'east']
|
Domain face to update. |
required |
point
|
Literal['T', 'U', 'V', 'X']
|
C-grid point the field lives on (default |
required |
Source code in finitevolx/_src/boundary/bc_1d.py
__call__(field, dx, dy)
Return field with one reflective ghost face updated.
Source code in finitevolx/_src/boundary/bc_1d.py
finitevolx.Slip1D
Bases: Module
Slip boundary condition for tangential velocity at a solid wall.
Controls the tangential velocity at the wall via a slip coefficient
a in [0, 1]:
a = 1.0— free-slip: ghost = +interior (zero gradient, frictionless wall).a = 0.0— no-slip: ghost = -interior (zero tangential velocity at wall).0 < a < 1— partial-slip: linear interpolation between the two.
The ghost cell is set using:
phi_ghost = (2*a - 1) * phi_interior
so that the extrapolated wall value
phi_wall = 0.5 * (phi_ghost + phi_interior) = a * phi_interior
smoothly varies from zero (no-slip) to the interior value (free-slip).
For a node on the wall (e.g. an X-point field) the wall node is set
to a * phi_interior directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
face
|
Literal['south', 'north', 'west', 'east']
|
Domain face to update. |
required |
coefficient
|
float
|
Slip parameter |
required |
point
|
Literal['T', 'U', 'V', 'X']
|
C-grid point the field lives on (default |
required |
Examples:
Free-slip on the west wall (tangential velocity preserved):
No-slip on the north wall (tangential velocity -> 0):
Partial-slip on the south wall:
Source code in finitevolx/_src/boundary/bc_1d.py
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 | |
__call__(field, dx, dy)
Return field with one slip ghost face updated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Float[Array, '*batch Ny Nx']
|
Input array with ghost-cell ring. |
required |
dx
|
float
|
Grid spacing in x (unused, kept for interface consistency). |
required |
dy
|
float
|
Grid spacing in y (unused, kept for interface consistency). |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, '*batch Ny Nx']
|
Field with the ghost face set according to the slip coefficient. |
Source code in finitevolx/_src/boundary/bc_1d.py
finitevolx.Outflow1D
Bases: Module
Apply a one-face outflow boundary condition.
Outflow is modelled here as a zero-gradient copy from the nearest interior cell into the ghost ring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
face
|
Literal['south', 'north', 'west', 'east']
|
Domain face to update. |
required |
point
|
Literal['T', 'U', 'V', 'X']
|
C-grid point the field lives on (default |
required |
Source code in finitevolx/_src/boundary/bc_1d.py
__call__(field, dx, dy)
Return field with one outflow ghost face updated.
Source code in finitevolx/_src/boundary/bc_1d.py
finitevolx.Sponge1D
Bases: Module
Relax one ghost face toward a background value.
The ghost cells are updated as:
phi_ghost = (1 - weight) * phi_interior + weight * background
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
face
|
Literal['south', 'north', 'west', 'east']
|
Domain face to update. |
required |
background
|
float
|
Background state toward which the ghost cells relax. |
required |
weight
|
float
|
Relaxation weight in |
required |
point
|
Literal['T', 'U', 'V', 'X']
|
C-grid point the field lives on (default |
required |
Source code in finitevolx/_src/boundary/bc_1d.py
__call__(field, dx, dy)
Return field with one sponge ghost face updated.
Source code in finitevolx/_src/boundary/bc_1d.py
BC Composition
finitevolx.BoundaryConditionSet
Bases: Module
Apply a different boundary condition on each domain face.
The application order is south, north, west, then east, so west/east updates overwrite the corner values written by south/north updates.
Each atom carries its own point (the C-grid point of the field); the
closed / open constructors pass one point to all four faces.
A closed basin for the velocity is BoundaryConditionSet.closed(point="U")
for u and closed(point="V") for v: zero normal velocity on the
wall faces and no-slip (ghost = -interior) on the tangential walls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
south
|
BoundaryCondition1D | None
|
Boundary condition for the south ghost row. |
required |
north
|
BoundaryCondition1D | None
|
Boundary condition for the north ghost row. |
required |
west
|
BoundaryCondition1D | None
|
Boundary condition for the west ghost column. |
required |
east
|
BoundaryCondition1D | None
|
Boundary condition for the east ghost column. |
required |
mask
|
Mask2D or Float[Array, '*batch Ny Nx'] or None
|
Domain mask. When provided, solvers can extract it from the
BCSet instead of requiring a separate |
required |
Source code in finitevolx/_src/boundary/bc_set.py
__call__(field, dx, dy)
Return field with all configured ghost faces updated.
Boundary conditions are applied in south, north, west, east order, so west/east updates overwrite the corner values written by south/north.
Source code in finitevolx/_src/boundary/bc_set.py
closed(mask=None, point='T')
classmethod
Return a zero-Dirichlet boundary-condition set on all faces.
point is the C-grid point of the field ("T", "U", "V"
or "X"); see :class:Dirichlet1D.
Source code in finitevolx/_src/boundary/bc_set.py
open(point='T')
classmethod
Return a zero-gradient boundary-condition set on all faces.
point is the C-grid point of the field; see :class:Outflow1D.
Source code in finitevolx/_src/boundary/bc_set.py
periodic()
classmethod
Return a fully periodic boundary-condition set.
Source code in finitevolx/_src/boundary/bc_set.py
finitevolx.FieldBCSet
Bases: Module
Dispatch per-face boundary conditions across multiple fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bc_map
|
dict[str, BoundaryConditionSet]
|
Mapping from state-variable name to per-face boundary conditions. |
required |
default
|
BoundaryConditionSet | None
|
Boundary-condition set used when a variable is not present in
|
required |
Source code in finitevolx/_src/boundary/bc_field.py
__call__(state, dx, dy)
Return a new state dictionary with boundary conditions applied.
Source code in finitevolx/_src/boundary/bc_field.py
Helpers
finitevolx.enforce_periodic(field)
Fill the ghost-cell ring with periodic boundary conditions.
Copies the last interior row/column into the opposite ghost row/column::
ghost south <- last interior row (row Ny-2)
ghost north <- first interior row (row 1 )
ghost west <- last interior col (col Nx-2)
ghost east <- first interior col (col 1 )
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Float[Array, '*batch Ny Nx']
|
Input array of shape [Ny, Nx]. |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, '*batch Ny Nx']
|
Array with periodic ghost cells. |
Source code in finitevolx/_src/boundary/boundary.py
finitevolx.pad_interior(field, mode='edge')
Extract physical interior and re-pad to original size.
Strips the ghost-cell ring, then re-pads using the requested mode. Useful for enforcing boundary conditions by re-filling the ghost ring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Float[Array, '*batch Ny Nx']
|
Input array of shape [Ny, Nx]. |
required |
mode
|
str
|
Padding mode passed to |
'edge'
|
Returns:
| Type | Description |
|---|---|
Float[Array, '*batch Ny Nx']
|
Array of shape [Ny, Nx] with ghost cells re-filled. |
Examples: