Capacitance Solver¶
Capacitance matrix method for elliptic PDEs on masked/irregular domains. See the theory page for the algorithm.
build_capacitance_solver(mask, dx, dy, lambda_=0.0, base_bc='fft')
¶
Pre-compute the capacitance factorisation and return a solver.
- Classify cells — the inner boundary is every wet cell that is
4-connected to a dry cell; with
base_bc="fft"neighbours wrap around the periodic rectangle. The remaining wet cells are the interior unknowns. - Delegate to gaussx —
gaussx.MaskedOperatorover the rectangular base operator, with the inner boundary as its coupling set, factorises theN_b × N_bcapacitance matrix once.
Complexity
- Offline (this function):
N_brectangular solves, O(N_b · Ny·Nx · log(Ny·Nx)) time, O(N_b² + Ny·Nx) memory. - Online (
CapacitanceSolver.__call__): two rectangular solves plus an O(N_b²) back-substitution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
np.ndarray of bool, shape (Ny, Nx)
|
Physical domain mask. |
required |
dx
|
float
|
Grid spacings in x and y. |
required |
dy
|
float
|
Grid spacings in x and y. |
required |
lambda_
|
float
|
Helmholtz parameter λ. |
0.0
|
base_bc
|
('fft', 'dst', 'dct')
|
Rectangular base operator: periodic, Dirichlet (DST-I) or Neumann (DCT-II) on the enclosing rectangle. |
"fft"
|
Returns:
| Type | Description |
|---|---|
CapacitanceSolver
|
Callable equinox Module with the factorisation baked in. |
Raises:
| Type | Description |
|---|---|
ValueError
|
For an unknown |
Source code in spectraldiffx/_src/fourier/capacitance.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
CapacitanceSolver
¶
Bases: Module
Spectral Poisson/Helmholtz solver for masked irregular domains.
Solves (∇² − λ) ψ = f on the wet cells of mask with ψ = 0 on
the inner boundary (wet cells adjacent to a dry cell) and outside the
mask, using the five-point finite-difference Laplacian.
Method (Buzbee, Golub & Nielson 1970, via gaussx)
Let B be the rectangular operator (periodic / Dirichlet / Neumann by
base_bc), I the interior cells (wet, not on the inner boundary)
and C the inner-boundary cells, which are exactly the cells outside
I that the stencil of I reaches. The masked problem is
B[I][:, I] ψ_I = f_I. The capacitance method solves it with two fast
rectangular solves per call: find y with y[C] = 0 and
(B y)_k = f_k for every k ∉ C (point sources on C absorb the
constraints, via an |C| × |C| capacitance matrix factorised once at
construction). For a singular base (fft/dct with λ = 0) the
constant null vector is included in the capacitance system, so the PDE
holds exactly in the interior (gh-87).
Construct with :func:build_capacitance_solver.
Attributes:
| Name | Type | Description |
|---|---|---|
operator |
MaskedOperator
|
|
interior_indices |
Int[Array, 'Ni']
|
Flat (row-major) indices of the interior cells |
shape |
tuple[int, int]
|
Grid shape |
dx, dy |
float
|
Grid spacings (static; baked into |
lambda_ |
float
|
Helmholtz parameter (static). |
base_bc |
str
|
Rectangular base: |
Source code in spectraldiffx/_src/fourier/capacitance.py
Functions¶
__call__(rhs)
¶
Solve (∇² − λ)ψ = rhs on the masked domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Float[Array, 'Ny Nx']
|
Right-hand side on the full rectangular grid. Only the interior cells are used; values on the inner boundary and outside the mask are ignored. |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, 'Ny Nx']
|
Solution ψ on the full grid: the masked solve on the interior, exactly zero on the inner boundary and outside the mask. |