BoundaryConditions¶
BoundaryConditions stores node-indexed boundary rows for a rectangular
SourceGrid.
from gbmsc_pde import BoundaryConditions
boundary_conditions = BoundaryConditions(grid)
Dirichlet Conditions¶
Dirichlet rows impose:
u_i = value_i
Example:
nodes = grid.boundary_indices()["all"]
boundary_conditions.add_dirichlet(nodes, 0.0)
Values may be scalar or an array with one entry per node.
Neumann Conditions¶
Neumann rows impose:
du/dn = flux
Example:
left = grid.boundary_indices()["left"]
boundary_conditions.add_neumann(
left,
outwardnormal=(-1.0, 0.0),
fluxes=0.0,
)
The normal may contain scalar components or arrays matching the node count.
Robin Conditions¶
Robin rows impose:
alpha * u + beta * du/dn = value
Example:
right = grid.boundary_indices()["right"]
boundary_conditions.add_robin(
right,
outwardnormal=(1.0, 0.0),
alphas=1.0,
betas=0.5,
values=0.0,
)
alphas, betas, and values may be scalars or arrays with one entry per
node.
Applying Conditions Manually¶
Most users apply boundary conditions through LinearSolver. To apply them manually:
A, b, Mx, My, Mxx, Myy = pde.assemble()
A_bc, b_bc = boundary_conditions.apply(A, b, Mx, My)
Dirichlet rows replace the matrix row by an identity row. Neumann and Robin rows use the derivative matrices:
n_x Mx[i, :] + n_y My[i, :]
Second Neumann Rows¶
The compatibility method add_neumann_as_second_condition can impose Neumann
equations on user-selected matrix rows:
boundary_conditions.add_neumann_as_second_condition(
nodes,
outwardnormal=(nx, ny),
fluxes=flux,
rows=rows,
)
This is intended for augmented systems where a Neumann equation should be added as a separate row rather than replacing the row associated with the source node.