Boundary conditions belong to the operation
A finite grid ends while the physical function may continue into the surrounding space. To approximate derivatives and solves near that edge, you therefore need a boundary condition describing the continuation. The appropriate choice depends on the field involved: a known analytical function can supply its face values, an unknown bound orbital needs an approximation to its decay, and a source-generated potential has its own exterior behaviour. Keeping these roles distinct makes the boundary calls below easier to interpret.
Known functions and sampled arrays
For a known function, sample its actual values on the outer face:
import numpy as np
from flodi import RadialGrid
grid = RadialGrid.uniform(n_r=100, r_max=4.0)
f = grid.sample(lambda c: np.exp(-c.r**2))
lap_f = grid.laplacian(f)
An array provides only centre values. Supply a scalar, a face-shaped
array, or a coordinate callable through outer_boundary:
f_array = grid.sample(
np.exp(-grid.r**2),
outer_boundary=lambda c: np.exp(-c.r**2),
)
np.testing.assert_allclose(grid.laplacian(f_array).values, lap_f.values)
The shape of the boundary follows the geometry: it is a scalar for a
radial field and retains the remaining angular indices on an angular grid.
This is why field.boundary is stored separately from
field.values[-1]. The latter is a row of centres inside the domain,
whereas the former describes the face beyond that row.
Unknown orbitals
When the orbital is unknown, the eigensolver imposes zero values on the outer face to approximate the decay of a localized bound state. This is a finite-domain approximation whose influence you assess by extending the domain and comparing the quantity of interest. The last centre remains an unknown inside the domain, so its value can be nonzero even when the face beyond it is fixed at zero.
For an analytical derivative test, retain the known function’s true face
values. You can explicitly override them with outer_boundary=0 when
testing a zero-face boundary problem, but that is a different numerical
problem. Changing the boundary and changing the stencil should be tested
separately.
Potentials generated by a source
A localized source generates a potential that can extend well beyond the
source itself. The default grid.poisson(source) accounts for this by
matching the potential and its flux to a source-free exterior that decays
at infinity. In radial geometry, the resulting outer value is the
integrated source divided by the outer radius, which generally remains
nonzero on a finite grid.
This exterior treatment assumes that the omitted source is negligible, so the domain must be large enough for that assumption to be reasonable. The source field’s own face values describe its density at the edge; they do not prescribe the potential there. FLODI consequently keeps those two kinds of boundary information separate.
For a manufactured solution, grid.poisson(source, outer_boundary=...)
can instead prescribe known potential face values. See From a source to a potential
for a Gaussian reference and residual check.
Other faces and repeated differentiation
The other faces are treated according to the geometry’s regularity and periodicity. At the radial origin, for example, the flux treatment allows a regular physical field whose value need not vanish; on a full spherical grid, the azimuthal direction joins periodically. Prolate fields with nonzero angular sectors use the regularity appropriate to their sector.
Boundary information also needs attention when composing operations. A Laplacian provides the derivative at cell centres, but those values do not determine its outer-face behaviour. You can immediately multiply or integrate the returned field, whereas differentiating it again requires a boundary condition for this new function. Supplying zero is appropriate only when that additional mathematical assumption is justified.