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 matrix and return a ready-to-use solver.
Offline algorithm (Buzbee, Golub & Nielson 1970):
- Detect inner boundary — find the N_b mask-interior cells that are
4-connected to at least one exterior cell (using
scipy.ndimage.binary_dilationwith a cross-shaped structuring element). - Delegate to gaussx — :class:
gaussx.CapacitanceSolvercomputes the Green's functions (one rectangular base solve per boundary point), the capacitance matrix, and its inverse.
Complexity¶
- Offline (this function): O(N_b · Ny · Nx · log(Ny·Nx)) time, O(N_b · Ny · Nx) memory for the Green's function matrix.
- Online (
CapacitanceSolver.__call__): O(N_b² + Ny · Nx · log(Ny·Nx)) time per solve.
Parameters¶
mask : np.ndarray of bool, shape (Ny, Nx)
Physical domain mask. True = interior (ocean/fluid),
False = exterior (land/walls).
Inner-boundary points are computed as wet (True) cells that are
4-connected to at least one dry (False) cell.
dx : float
Grid spacing in x.
dy : float
Grid spacing in y.
lambda_ : float
Helmholtz parameter λ. Use 0.0 for pure Poisson.
base_bc : {"fft", "dst", "dct"}
Rectangular spectral solver used as the base.
Returns¶
CapacitanceSolver A callable equinox Module wrapping the precomputed gaussx solver.
Raises¶
ValueError If the mask has no inner-boundary points (e.g. all-ones mask).
Source code in spectraldiffx/_src/fourier/capacitance.py
149 150 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 | |
CapacitanceSolver
¶
Bases: Module
Spectral Poisson/Helmholtz solver for masked irregular domains.
Uses the capacitance matrix method (Buzbee, Golub & Nielson 1970) to extend a fast rectangular spectral solver to a domain defined by a binary mask.
The algorithm (Buzbee, Golub & Nielson 1970):
- Solve the PDE on the full rectangle using a fast spectral solver
(DST/DCT/FFT), ignoring the mask. Call this
u. ugenerally violates ψ = 0 at inner-boundary points. Correct it:ψ = u − Σ_k α_k g_k, whereg_kare precomputed Green's functions (rectangular-domain response to δ-sources at each boundary point b_k).- The coefficients α are found by requiring ψ(b_k) = 0 at all
N_b boundary points, giving the linear system
C α = u[B]whereC[k,l] = g_l(b_k)is the capacitance matrix.
The capacitance correction is delegated to :class:gaussx.CapacitanceSolver;
this class adds the field reshaping and the exterior masking. Construct with
:func:build_capacitance_solver.
Attributes¶
solver : gaussx.CapacitanceSolver
The generic capacitance solver operating on flat vectors.
mask : Float[Array, "Ny Nx"]
Domain mask (1.0 = interior, 0.0 = exterior). Applied to the output
so that values outside the physical domain are exactly zero.
shape : tuple[int, int]
Grid shape (Ny, Nx).
dx : float
Grid spacing in x.
dy : float
Grid spacing in y.
lambda_ : float
Helmholtz parameter.
base_bc : str
Spectral solver used as the rectangular base.
Source code in spectraldiffx/_src/fourier/capacitance.py
Functions¶
__call__(rhs)
¶
Solve (∇² − λ)ψ = rhs on the masked domain.
The generic solver enforces ψ = 0 at the inner-boundary points and returns the corrected field; this method reshapes between fields and flat vectors and zeroes the exterior via the mask.
Parameters¶
rhs : Float[Array, "Ny Nx"] Right-hand side on the full rectangular grid. Values outside the physical domain (mask = False) are ignored.
Returns¶
Float[Array, "Ny Nx"] Solution ψ on the full rectangular grid. Exactly zero outside the mask, and ψ ≈ 0 at inner-boundary points.