hp-FEM
Adaptive hp-FEM suite for nano-optics
Loading...
Searching...
No Matches
Classes | Enumerations | Functions
hpfem::solvers Namespace Reference

Classes

struct  ComplexEigenResult
 Result of complex_eigenpairs_near: eigenvalues ordered by distance to the shift. More...
 
class  DeviceArnoldi
 
class  DeviceMatrix
 
class  DeviceStepper
 
struct  EigenOptions
 
struct  EigenResult
 
class  LinearSolver
 Factorise once, solve for many right-hand sides. More...
 
struct  MemoryEstimate
 
class  ReducedBasis
 

Enumerations

enum class  DirectSolverBackend { kAuto , kSparseLu , kMumps , kCudss }
 Direct solver backends. More...
 
enum class  Symmetry { kGeneral , kComplexSymmetric , kDetect }
 

Functions

EigenResult gauged_curl_curl_eigenpairs (const SparseMatrix &stiffness, const SparseMatrix &mass, const SparseMatrix &gradient, std::span< const Index > free_nedelec, std::span< const Index > free_h1, const EigenOptions &options={}, DirectSolverBackend backend=DirectSolverBackend::kAuto)
 
EigenResult generalized_eigenpairs_near (const SparseMatrix &a, const SparseMatrix &b, Real sigma, const EigenOptions &options={}, DirectSolverBackend backend=DirectSolverBackend::kAuto)
 
ComplexEigenResult complex_eigenpairs_near (const SparseMatrix &a, const SparseMatrix &b, Complex sigma, const EigenOptions &options={}, DirectSolverBackend backend=DirectSolverBackend::kAuto)
 
ComplexEigenResult complex_eigenpairs_near_gauged (const SparseMatrix &a, const SparseMatrix &b, const SparseMatrix &gradient, Complex sigma, const EigenOptions &options={}, DirectSolverBackend backend=DirectSolverBackend::kAuto)
 
Index gpu_min_unknowns ()
 
bool available (DirectSolverBackend backend) noexcept
 True if the backend can be used in this build (kAuto always).
 
std::vector< DirectSolverBackend > available_backends ()
 All backends usable in this build.
 
std::string backend_name (DirectSolverBackend backend)
 
std::unique_ptr< LinearSolver > make_sparse_lu (Symmetry symmetry=Symmetry::kGeneral)
 
std::unique_ptr< LinearSolver > make_mumps (Symmetry symmetry=Symmetry::kGeneral)
 
std::unique_ptr< LinearSolver > make_cudss (Symmetry symmetry=Symmetry::kGeneral)
 
std::string cudss_status ()
 
std::unique_ptr< LinearSolver > make_direct_solver (DirectSolverBackend backend=DirectSolverBackend::kAuto, Symmetry symmetry=Symmetry::kGeneral)
 
Vector solve_direct (const SparseMatrix &matrix, const Vector &rhs, DirectSolverBackend backend=DirectSolverBackend::kAuto, Symmetry symmetry=Symmetry::kGeneral)
 Factorise and solve in one go.
 
SparseMatrix upper_triangle (const SparseMatrix &matrix)
 Upper triangle (column ≥ row) of a square matrix, compressed; the input of the LDLᵀ paths.
 
Real asymmetry (const SparseMatrix &matrix)
 
Symmetry detect_symmetry (const SparseMatrix &matrix, Real tolerance=1e-12)
 
bool exploit_symmetry (Symmetry symmetry, const SparseMatrix &matrix, const char *backend)
 
template<int Dim>
MemoryEstimate estimate_memory (const fespace::NedelecDofMap< Dim > &dofs, DirectSolverBackend backend=DirectSolverBackend::kAuto, bool condensed=true, const fespace::DofMap< Dim > *longitudinal=nullptr)
 
template<int Dim>
MemoryEstimate estimate_memory (const mesh::Mesh< Dim > &mesh, int order, DirectSolverBackend backend=DirectSolverBackend::kAuto, bool conical=false)
 
std::string format_bytes (std::size_t bytes)
 Human-readable byte count, "1.2 GB" / "230 MB" / "12 kB".
 

Enumeration Type Documentation

◆ DirectSolverBackend

Direct solver backends.

Enumerator
kAuto 

cuDSS for systems of at least gpu_min_unknowns() unknowns when its library and a GPU are present, otherwise MUMPS if compiled in, otherwise SparseLU; chosen in factorize from the size of the matrix

kSparseLu 

Eigen SparseLU, always available.

kMumps 

MUMPS (multifrontal, zmumps), needs HPFEM_ENABLE_MUMPS

kCudss 

NVIDIA cuDSS on the GPU, needs HPFEM_ENABLE_CUDA and the hpfem_gpu library.

◆ Symmetry

enum class hpfem::solvers::Symmetry
strong

Structure of the system matrix that a backend may exploit. The caller guarantees it: a complex-symmetric matrix (A = Aᵀ, not Hermitian — the curl–curl operators with symmetric material tensors, PML and Dirichlet elimination, also after static condensation and hanging-node constraints; not with Bloch phases) lets cuDSS and MUMPS factorise one triangle (LDLᵀ, about half the work and memory). SparseLU ignores it.

Enumerator
kGeneral 

no structure assumed (LU)

kComplexSymmetric 

A = Aᵀ with complex entries; only the upper triangle is used.

kDetect 

the backend checks asymmetry(A) <= 1e-12 in factorize (once per matrix, only cuDSS and MUMPS, which can exploit it) and takes the LDLᵀ path if it holds; what the problem classes pass

Function Documentation

◆ asymmetry()

Real hpfem::solvers::asymmetry ( const SparseMatrix &  matrix)

Largest |a_ij − a_ji| relative to the largest |a_ij| (0 for a symmetric matrix); one pass over the nonzeros with a binary search of the mirrored entry per row, no copy.

◆ available()

bool hpfem::solvers::available ( DirectSolverBackend  backend)
noexcept

True if the backend can be used in this build (kAuto always).

◆ available_backends()

std::vector< DirectSolverBackend > hpfem::solvers::available_backends ( )

All backends usable in this build.

◆ backend_name()

std::string hpfem::solvers::backend_name ( DirectSolverBackend  backend)

◆ complex_eigenpairs_near()

ComplexEigenResult hpfem::solvers::complex_eigenpairs_near ( const SparseMatrix &  a,
const SparseMatrix &  b,
Complex  sigma,
const EigenOptions &  options = {},
DirectSolverBackend  backend = DirectSolverBackend::kAuto 
)

Eigenpairs of the complex pencil \( A x = \lambda B x \) closest to a complex shift σ: shift-invert Arnoldi on \( (A - \sigma B)^{-1} B \) with a direct factorisation (backend), modified Gram–Schmidt, explicit restarts from the wanted Ritz vectors and the relative residual \( |h_{m+1,m}\,y_m| / | heta| \) as convergence test. Lossy media, PML and complex frequencies are allowed: this is the solver of the resonance (quasi-normal mode) problems. Both matrices are scaled to O(1) internally. options.shift is ignored (σ is the argument). Eigenvectors are B-independent unit 2-norm vectors.

Exceptions
InvalidArgumentfor mismatched matrices, Error if the factorisation fails or no eigenvalue converges within max_iterations restarts.

◆ complex_eigenpairs_near_gauged()

ComplexEigenResult hpfem::solvers::complex_eigenpairs_near_gauged ( const SparseMatrix &  a,
const SparseMatrix &  b,
const SparseMatrix &  gradient,
Complex  sigma,
const EigenOptions &  options = {},
DirectSolverBackend  backend = DirectSolverBackend::kAuto 
)

As complex_eigenpairs_near with the gradient kernel removed: every Arnoldi vector is projected B-orthogonally onto the complement of range(G), \( P = I - G (G^H B G)^{-1} G^H B \), so the eigenvalues at zero of a curl–curl pencil (gradients of the H1 space, possibly Bloch-reduced) never appear. For Bloch-periodic band structures with complex Hermitian matrices (physics::BandStructure).

Exceptions
Errorif \( G^H B G \) is singular.

◆ cudss_status()

std::string hpfem::solvers::cudss_status ( )

Why the cuDSS backend is (un)available in this process: library path, versions and device if usable, otherwise the loading error. Never throws.

◆ detect_symmetry()

Symmetry hpfem::solvers::detect_symmetry ( const SparseMatrix &  matrix,
Real  tolerance = 1e-12 
)

kComplexSymmetric if asymmetry(matrix) <= tolerance, otherwise kGeneral: what the problem classes pass to the direct solvers, so that symmetric curl–curl systems take the LDLᵀ paths and systems with Bloch phases or non-symmetric material tensors do not. Costs one pass over the nonzeros (O(nnz log n), far below a factorisation).

◆ estimate_memory() [1/2]

template<int Dim>
MemoryEstimate hpfem::solvers::estimate_memory ( const fespace::NedelecDofMap< Dim > &  dofs,
DirectSolverBackend  backend = DirectSolverBackend::kAuto,
bool  condensed = true,
const fespace::DofMap< Dim > *  longitudinal = nullptr 
)

Estimate for the system of a Nédélec map (the in-plane Maxwell operator), optionally with an H1 map coupled block-wise (the conical solver, longitudinal), on the backend; condensed drops the cell-interior DoFs as Scattering does by default (not available with a longitudinal map). The matrix nonzeros are \( r_{d,p}\sum_K n_K^2 \) with the overlap ratio r of the H(curl) pattern, the factor entries \( c\,N\log_2N \) (2D) and \( c\,N^{4/3} \) (3D) for the nested-dissection backends and \( c_p N^{1.25} \) (2D), \( c_p N^{1.63} \) (3D) for SparseLU with COLAMD.

Exceptions
InvalidArgumentif condensed is combined with a longitudinal map or the maps live on different meshes.

◆ estimate_memory() [2/2]

template<int Dim>
MemoryEstimate hpfem::solvers::estimate_memory ( const mesh::Mesh< Dim > &  mesh,
int  order,
DirectSolverBackend  backend = DirectSolverBackend::kAuto,
bool  conical = false 
)

The same for a uniform order on the mesh: the in-plane solver (condensed) or, with conical, the conical solver (Nédélec + H1, not condensed).

Exceptions
InvalidArgumentfor order < 1.

◆ exploit_symmetry()

bool hpfem::solvers::exploit_symmetry ( Symmetry  symmetry,
const SparseMatrix &  matrix,
const char *  backend 
)

Backend helper: whether a factorisation with the given request takes the symmetric path (kDetect measures the matrix and logs the result at debug level; kComplexSymmetric is verified in Debug builds, kGeneral is never checked).

Exceptions
InvalidArgumentin Debug builds if kComplexSymmetric was requested for a non-symmetric matrix.

◆ format_bytes()

std::string hpfem::solvers::format_bytes ( std::size_t  bytes)

Human-readable byte count, "1.2 GB" / "230 MB" / "12 kB".

◆ gauged_curl_curl_eigenpairs()

EigenResult hpfem::solvers::gauged_curl_curl_eigenpairs ( const SparseMatrix &  stiffness,
const SparseMatrix &  mass,
const SparseMatrix &  gradient,
std::span< const Index >  free_nedelec,
std::span< const Index >  free_h1,
const EigenOptions &  options = {},
DirectSolverBackend  backend = DirectSolverBackend::kAuto 
)

Smallest eigenpairs of \( S x = \lambda M x \) on the free DoFs, with the gradient kernel removed: every Lanczos vector is projected M-orthogonally onto the complement of range(G) ( \( P = I - G (G^T M G)^{-1} G^T M \)), so the zero eigenvalues of the curl operator never appear and the returned values are the physical resonances. Shift-invert Lanczos (Spectra) with a direct factorisation of \( S - \sigma M \): backend kAuto and kSparseLu keep Eigen's real SparseLU (real arithmetic, half the memory), kMumps / kCudss factorise the complexified shifted matrix with that backend (one factorisation, one solve per Lanczos step; the gauge matrix \( G^T M G \) stays with SparseLU).

S, M, G are the full matrices (Nédélec × Nédélec, Nédélec × H1); free_nedelec and free_h1 list the unconstrained DoFs (PEC removes the tangential DoFs of the Nédélec space and the corresponding H1 boundary DoFs). Lossless media only: the imaginary parts of S and M must vanish.

Exceptions
InvalidArgumentfor complex matrices, Error if the iteration fails to converge.

◆ generalized_eigenpairs_near()

EigenResult hpfem::solvers::generalized_eigenpairs_near ( const SparseMatrix &  a,
const SparseMatrix &  b,
Real  sigma,
const EigenOptions &  options = {},
DirectSolverBackend  backend = DirectSolverBackend::kAuto 
)

Eigenpairs of \( A x = \lambda B x \) closest to σ for real sparse A and B, where B may be indefinite and A singular (waveguide mode pencils): Arnoldi (Spectra) on the real nonsymmetric operator \( (A - \sigma B)^{-1} B \) with a direct factorisation (backend as in gauged_curl_curl_eigenpairs: kAuto keeps the real SparseLU), eigenvalues \( \lambda = \sigma + 1/\nu \). Results are real (imaginary parts of the Ritz values must be negligible, otherwise Error); eigenvectors have unit 2-norm and the size of A. options.shift is ignored (σ is the argument).

Exceptions
InvalidArgumentfor complex or mismatched matrices, Error on non-convergence.

◆ gpu_min_unknowns()

Index hpfem::solvers::gpu_min_unknowns ( )

Size from which kAuto prefers cuDSS: the CMake cache variable HPFEM_GPU_MIN_UNKNOWNS (default 10000, where the GPU factorisation draws level with sequential MUMPS on the RTX 3090, ADR-0008), overridden at run time by the environment variable of the same name; 0 means always cuDSS, a negative value never. Read on every call.

◆ make_cudss()

std::unique_ptr< LinearSolver > hpfem::solvers::make_cudss ( Symmetry  symmetry = Symmetry::kGeneral)

NVIDIA cuDSS (LU on the GPU, factors stay on the device): the backend for many solves of one factorisation (time stepping, Arnoldi, sweeps). The solver lives in the separately built hpfem_gpu library (gpu/README.md), found through HPFEM_GPU_DLL. With kComplexSymmetric only the upper triangle goes to the device (cuDSS LDLᵀ).

Exceptions
Errorif the library was not compiled with HPFEM_ENABLE_CUDA, the hpfem_gpu library cannot be loaded or no CUDA device is present.

◆ make_direct_solver()

std::unique_ptr< LinearSolver > hpfem::solvers::make_direct_solver ( DirectSolverBackend  backend = DirectSolverBackend::kAuto,
Symmetry  symmetry = Symmetry::kGeneral 
)

The requested backend; kAuto returns a solver that picks the backend in factorize (name() reports "auto" before and "auto: <backend>" after the choice). The GPU library is only loaded when cuDSS is actually chosen.

Exceptions
Errorif the backend is not available.

◆ make_mumps()

std::unique_ptr< LinearSolver > hpfem::solvers::make_mumps ( Symmetry  symmetry = Symmetry::kGeneral)

MUMPS multifrontal LU (sequential build, complex double, automatic ordering; SYM = 2 LDLᵀ on the upper triangle for kComplexSymmetric); the backend of choice for 3D and for many right-hand sides.

Exceptions
Errorif the library was not compiled in.

◆ make_sparse_lu()

std::unique_ptr< LinearSolver > hpfem::solvers::make_sparse_lu ( Symmetry  symmetry = Symmetry::kGeneral)

Eigen's supernodal sparse LU with COLAMD ordering; general (non-symmetric) complex matrices, O(fill) memory. Adequate up to a few 10^5 unknowns in 2D.

◆ solve_direct()

Vector hpfem::solvers::solve_direct ( const SparseMatrix &  matrix,
const Vector &  rhs,
DirectSolverBackend  backend = DirectSolverBackend::kAuto,
Symmetry  symmetry = Symmetry::kGeneral 
)

Factorise and solve in one go.

◆ upper_triangle()

SparseMatrix hpfem::solvers::upper_triangle ( const SparseMatrix &  matrix)

Upper triangle (column ≥ row) of a square matrix, compressed; the input of the LDLᵀ paths.