Finite-cluster solvers
spectrum_dispersion keeps dense in-place LU as its default. For large homogeneous-host clusters, select matrix-free restarted GMRES explicitly. The physical equation and cross-section normalization do not change. Infinite-array Ewald/Bloch routines remain local research experiments, not part of the published package; no production periodic boundary condition is introduced.
Choosing a solver
| Selection | Positions | Interaction storage / work per action |
|---|---|---|
method="direct" | Arbitrary | Quadratic matrix storage; shared LU for all RHS |
method="gmres", interaction="pairwise" | Arbitrary | Linear operator storage; quadratic summation |
method="gmres", interaction="fft" | Axis-aligned Cartesian xy grid | Linear padded-grid storage; FFT convolution |
method="oos" retains the existing dense order-of-scattering expansion. It is not the matrix-free GMRES option.
Where the FFT acts
The FFT is only ever used inside method="gmres" with interaction="fft", and it appears in exactly two places:
- The operator action (matrix–vector product). Each GMRES iteration must evaluate
F x = x + G₀ (α x)without storingF. On a regular Cartesian xy grid the dipole–dipole propagationG₀is block-Toeplitz in the two lattice indices, so its action is an aperiodic discrete convolution. It is evaluated exactly by zero-padding the particle polarizations to a2nx × 2nygrid, multiplying by the precomputed Fourier symbol of the kernel (nine tensor channels acting on three field components), and transforming back. This changes where the pairwise sum is computed — Fourier space instead of a double loop — not its value, to rounding. No periodic images are introduced by the padding. - The Chan preconditioner application (see below), which uses a separate unpadded
nx × nycirculant operator diagonalized by FFT.
The FFT is not used by method="direct", by interaction="pairwise", by cross-section assembly, or by incident-field construction. Selecting it does not periodize the array: the physical model remains the same finite cluster solved by the dense path.
Rectangular grids, translated grids, shuffled particle storage, vacancies and heterogeneous lab-frame 3x3 tensors are supported. Distinct occupied x/y coordinates must form uniformly spaced coordinate axes. Completely missing intermediate coordinate rows/columns are not inferred; use an explicitly represented grid or the pairwise backend. At least two coordinate values are required per axis.
Rotated planes, positional disorder, interfaces and sphere-mediated coupling are not supported by this FFT backend. Invalid grids are rejected, not snapped. The pairwise backend handles off-grid positions but is not FMM: low storage alone does not make an arbitrary 160000-particle calculation fast. The high-level GMRES path currently rejects interfaces and sphere coupling. spectrum_oa accepts the same method="gmres", interaction, preconditioner and solver_* options for orientation-averaged cross-sections and dichroism, with return_diagnostics=true returning (average, dichroism, diagnostics). See Many right-hand sides below for why the direct path usually remains preferable for orientation averaging. Other high-level workflows retain their existing solvers.
Preconditioning and convergence
Choose preconditioner="none" (default), "chan", "nearfield", or "circulant1d". Chan requires the FFT backend — or, for position-disordered arrays, the pairwise backend plus preconditioner_positions (see the disorder discussion below). "nearfield" and "circulant1d" require the pairwise backend. All preconditioners are built from primal values, applied as right preconditioners, and never change the converged answer — only the iteration count.
What Chan is. The lattice part of the operator is block-Toeplitz; T. F. Chan's construction replaces it with the nearest circulant operator (the weighted average of kernel diagonals), here extended to two grid axes and 3×3 dyadic blocks. A circulant operator is diagonalized by the FFT, so (I + C ᾱ) can be inverted cheaply block-by-block in Fourier space, where ᾱ is the arithmetic mean local lab-frame tensor over the cluster — one shared reference response, which is why heterogeneity degrades the approximation only through that mean.
How it is applied. As a right preconditioner inside GMRES: the solver iterates on F M⁻¹ y = b and recovers x = M⁻¹ y, so the reported residual remains the residual of the original physical equation. Setup (once per wavelength and solve) builds and inverts nx × ny Fourier-space 3×3 blocks; each application costs one additional forward/inverse FFT pair plus blockwise 3×3 multiplies, roughly doubling the per-iteration cost — worthwhile when it reduces iterations by more (typically ~25–40 % fewer iterations on resonant arrays).
Off-grid preconditioners. The system F = I + G₀ α has unit diagonal, so point-Jacobi is the identity (equivalent to "none"), and incomplete factorizations (ILU) need an assembled sparse matrix that the matrix-free operator deliberately avoids. Two structured options cover common off-grid geometries:
"nearfield"— geometry-agnostic block-Jacobi over contiguous storage-index groups ofpreconditioner_blocksizeparticles (default 32): each diagonal block ofF, including its intra-group coupling, is factorized densely and applied independently. Effective when storage order is spatially coherent (chains, helices, growth order); useless when storage is shuffled, since index neighbours are then not spatial neighbours."circulant1d"— a one-dimensional Chan-style circulant for clusters that are (approximately) block-Toeplitz in the particle index after transforming to a co-rotating frame. A uniform helix with angular step δ has a discrete screw symmetry, making this exact withpreconditioner_rotation = RotZ(δ); a straight chain uses the identity (nothing). The Toeplitz blocks are read from the first block column/row in the rotated frame, averaged into Chan's optimal circulant, diagonalized by a 1D FFT of length N, and combined with the mean rotated-frame tensor.
Remaining candidates — sparse approximate inverses, auxiliary-grid (precorrected-FFT) embeddings that would also accelerate the matvec — are not implemented.
Chan is not the physical infinite-lattice Green tensor, and changing the preconditioner does not change the finite residual equation.
Disorder: two distinct cases. On-grid disorder — heterogeneous sizes, materials or local 3×3 tensors, and vacancies — leaves positions on the lattice: FFT propagation stays exact, and Chan remains fully usable, degrading only through its mean-tensor reference (gracefully: ±30 % radius disorder costs about one extra iteration in the bundled notebook study). Positional disorder moves particles off the lattice: the FFT operator rejects such geometries (no snapping), so the exact solve must use the pairwise operator. A nominal-grid Chan preconditioner remains available there: pass preconditioner="chan" with interaction="pairwise" and preconditioner_positions set to the perfect-lattice positions (same length and storage order). Any nonsingular approximate inverse is an admissible right preconditioner; only its effectiveness fades with growing jitter — the bundled notebook quantifies how much displacement makes it useless. The mean-response Chan choice also differs from the fixed nominal-response preconditioner used in earlier local research benchmarks of on-grid radius disorder; benchmark results should not be assumed identical.
Every RHS starts from zero and must satisfy:
\[\|b-Fx\| \leq \mathrm{atol}+\mathrm{rtol}\|b\|.\]
Nonconvergence or nonfinite residuals throw; spectra are not returned as if successful. Near resonances, tighten tolerance and check field/observable stability: a small residual is not a universal forward-error bound. GMRES restart length also matters for memory: its basis stores approximately restart + 1 complex field vectors. FFT plans/scratch belong to the solve; do not share an internal workspace across concurrent solves.
Many right-hand sides
Each wavelength couples one interaction matrix to possibly many incident fields: two linear polarizations per incidence direction in spectrum_dispersion, and two circular polarizations for each of the N_inc cubature directions in spectrum_oa (2N_inc right-hand sides). The two solver families treat this very differently:
- Direct LU factorizes once per wavelength and reuses the factors for every RHS; each extra RHS costs only a cheap triangular solve.
- Sequential GMRES (the default
rhs_strategy) restarts from zero for every RHS, rebuilding a Krylov subspace each time;mright-hand sides cost close tomindependent solves.
Consequently, orientation averaging strongly favours the direct path until the dense matrix no longer fits in memory — unless the block strategy is selected:
rhs_strategy="block"(implemented) runs a right-preconditioned restarted block GMRES: all right-hand sides share one block Arnoldi basis per cycle, so each operator action — in particular each O(N²) pairwise kernel sweep — serves every column at once, and the shared search space is richer than any single-vector space. With this strategysolver_restartcounts block Arnoldi steps per cycle (memory grows as approximately(restart+1) × nrhsfield vectors) andsolver_maxitercaps total block steps. Convergence is still enforced per RHS through the same true-residual targets, and nonconvergence throws. Blocks at least as wide as the system (nrhs ≥ 3N) silently fall back to the sequential strategy.- Subspace recycling / deflation (e.g. GCRO-DR) — extracting approximate spectral information from one solve to deflate subsequent solves against the same matrix — remains not implemented.
For orientation-averaged quantities, prefer method="direct" while the matrix fits in memory, and rhs_strategy="block" whenever the iterative path is required.
Runnable example
This small example runs in the documentation build. Both linear polarizations are calculated at oblique incidence. The rendered notebook 17 — Finite solvers extends it with the diffractive-array studies: direct-vs-iterative crossover, preconditioner behaviour under disorder, array-size scaling, and helix orientation-averaged CD with block multi-RHS solves.
using CoupledDipole, Rotations, LinearAlgebra
cl = cluster_array(25, 450.0, 50.0, 50.0, 50.0)
mat = Material([598.5, 617.0], Dict("Au" => epsilon_Au, "medium" => _ -> 1.33))
incidence = [RotMatrix(RotZYZ(0.2, 0.3, 0.0))]
direct = spectrum_dispersion(cl, mat, incidence; N_sca=8)
iterative = spectrum_dispersion(cl, mat, incidence;
N_sca=8, method="gmres", interaction="fft", preconditioner="chan",
solver_rtol=1e-10, return_diagnostics=true)
relative_error = norm(iterative.cross_sections.extinction-direct.extinction) /
norm(direct.extinction)
@assert relative_error < 1e-7
(relative_error, maximum(d.iterations for d in iterative.diagnostics))(8.002139141310074e-13, 14)The default return remains CrossSections, normalized per particle. return_diagnostics=true returns (cross_sections, diagnostics). GMRES records wavelength, backend/preconditioner, RHS index, true residual, target, iteration count, matvec count (excluding final residual check), solve time including that check, operator and preconditioner setup times, and stop reason. Setup is shared and repeated in each RHS diagnostic; do not sum it over RHS. Direct/OOS diagnostics are currently empty.
Use the lower-level function when only fields or extinction are required:
CoupledDipole.solve_fields — Function
solve_fields(k, positions, alpha_blocks, incident; method="direct",
interaction="pairwise", preconditioner="none", rtol=1e-8,
atol=0.0, restart=50, maxiter=300, rhs_strategy="sequential",
preconditioner_positions=nothing, preconditioner_rotation=nothing,
preconditioner_blocksize=32)Solve the homogeneous-host finite electric-dipole field equation. incident is a 3N x nrhs matrix; alpha_blocks contains local lab-frame 3x3 tensors. Return fields, polarizations, diagnostics and operator setup time. Direct LU uses private dense scratch; GMRES does not allocate a dense interaction matrix. FFT requires an axis-aligned xy Cartesian grid. Chan uses the mean local tensor as its reference response. Unsupported combinations and nonconvergence throw.
Preconditioners: "none", "chan" (FFT grid, or interaction="pairwise" with preconditioner_positions supplying the nominal grid for a position-disordered array), "nearfield" (block-Jacobi over contiguous storage-index groups of preconditioner_blocksize particles; geometry agnostic), and "circulant1d" (index-Toeplitz circulant in a frame co-rotating with preconditioner_rotation, e.g. RotZ(δ) for a uniform helix with angular step δ; identity when nothing). Preconditioners are built from primal values and never change the converged answer.
rhs_strategy="block" solves all right-hand sides with one shared block Arnoldi basis per restart cycle, evaluating each (pairwise) kernel sweep once for all columns; restart then counts block steps (memory ~(restart+1)*nrhs field vectors) and maxiter caps total block steps. Blocks at least as wide as the system (nrhs >= 3N) silently fall back to the sequential strategy.
GMRES: Saad & Schultz (1986), doi:10.1137/0907058, via IterativeSolvers.jl. Chan: doi:10.1137/0909051. See docs/src/finite_solvers.md for boundaries, autodiff support and dependency licences.
Its input tensors and incident fields are already in the laboratory frame. It does not build illumination or perform angular scattering quadrature. It returns fields, polarizations, diagnostics and operator setup time. The spectrum wrapper still computes extinction, absorption and integrated scattering; its full runtime is not just the GMRES solve time.
Autodiff
Load ForwardDiff to activate the package extension. Direct LU retains its generic-number behavior. The iterative extension uses implicit differentiation:
\[F E=B,\qquad F\,dE=dB-(dF)E.\]
It solves primal and tangent equations, rather than differentiating stopping decisions or a truncated GMRES iteration history. The primal preconditioner is reused; its derivative is not part of the physical equation. Both primal and tangent true residuals are checked and reported.
First-order ForwardDiff supports multiple active directions through local responses, grid spacing, wavelength, host/material parameters and incident fields. Dual-valued FFTs are evaluated by transforming primal and tangent components separately in ordinary FFTW buffers. The physical response and kernel derivatives are not discarded.
using CoupledDipole, ForwardDiff, Rotations
mat = Material([610.0], Dict("Au" => _ -> -10.0+1.0im, "medium" => _ -> 1.33))
incidence = [RotMatrix(RotZYZ(0.0, 0.2, 0.0))]
function objective(radius)
cl = cluster_array(9, 450.0, radius, radius, radius)
sum(spectrum_dispersion(cl, mat, incidence; N_sca=8,
method="gmres", interaction="fft", preconditioner="chan",
solver_rtol=1e-11, solver_atol=1e-13).extinction)
end
ForwardDiff.derivative(objective, 30.0)789.6465574272856Grid topology must remain fixed. FFT derivatives that independently displace one particle off the lattice are rejected even when the primal positions still lie on the grid; use the pairwise backend for positional derivatives. Nested duals/higher derivatives and reverse-mode rules are not supported by the new GMRES extension. FFT numeric types are ComplexF32/ComplexF64 and their first-order ForwardDiff forms. Choose positive absolute tolerance when near-zero tangent RHS would make relative-only convergence impractical. Check gradient stability under tolerance refinement near resonance.
Algorithm sources and software provenance
- Saad & Schultz (1986), GMRES: A Generalized Minimal Residual Algorithm for Solving Nonsymmetric Linear Systems, doi:10.1137/0907058. GMRES is provided by IterativeSolvers.jl, not copied into this package.
- T. F. Chan (1988), An Optimal Circulant Preconditioner for Toeplitz Systems, doi:10.1137/0909051. The independent implementation here extends the weighting to two axes and dyadic blocks. It approximates the finite Toeplitz operator; it does not minimize iteration counts or guarantee convergence.
- Finite zero-padded convolution follows the Toeplitz-to-circulant embedding: signed offsets are placed modulo the padded lengths, with zero self coupling and restriction to occupied target sites. The shared dipole kernel uses the package's existing sign/normalization convention.
- The implicit derivative identity above is obtained by differentiating the physical field equation. The extension is independently implemented; no external custom derivative rule was copied.
CoupledDipole's independent source remains MIT licensed. IterativeSolvers.jl and the FFTW.jl Julia wrapper are MIT licensed dependencies. The native FFTW library is separately GPL licensed, with commercial licensing also available upstream; the locally checked FFTW_jll 3.3.12 artifact includes GPL version 2 text in share/licenses/FFTW/COPYING. The wrapper licence does not replace native-library terms. Consult the actual resolved artifact/ provider notices when redistributing binaries. See the FFTW licensing FAQ. No third-party source is vendored in these new solvers. Any future adapted code must identify upstream authors/version/licence and preserve notices.