Solver module (solver.h)
Functions
-
PetscErrorCode solveCsemSystem(const DM dm, const Mat A, const Mat B, const Mat G, const PetscInt order, Mat *X)
Solves the linear system A·X = B using PETSc KSP.
When A is a MATIS matrix and G is provided, the preconditioner is set to PCBDDC and G is registered via PCBDDCSetDiscreteGradient at order = order to capture the curl kernel for H(curl) problems. G is the high-order discrete gradient G: Nédélec_order -> P_order H1 from assembleCsemKandM.
Solves the linear system A·X = B using PETSc KSP.
Drives a single KSP over every column of
Bvia KSPMatSolve, which is how the forward kernel solves for all CSEM sources simultaneously. The preconditioner is set up through setupBDDCFromPetgemGradient: whenAis of type MATIS andGis supplied, PCBDDC is configured with the exact order-p discrete gradient to capture the curl kernel of the H(curl) operator; otherwise PETSc’s default PC is used. The KSP type, tolerances and PC settings stay overridable through the PETSc options database (KSPSetFromOptions).Steps:
Create the KSP on
dm'scommunicator and setAas both the operator and the preconditioner matrix.Configure PCBDDC from
G(a no-op unlessAis MATIS andGgiven).Read solver options with KSPSetFromOptions.
Allocate the dense solution matrix
X, matched toB'slayout andA'svector type.Solve all right-hand sides with KSPMatSolve, reporting progress.
Destroy the KSP.
Note
Bmust have a size and ordering consistent withA, andG(when used) must match the DOF ordering ofA.- Parameters:
dm – [in] DMPlex mesh; its communicator drives the parallel solve.
A – [in] System matrix (H(curl) FEM operator).
B – [in] Right-hand side matrix, one column per source.
G – [in] Discrete-gradient hint for PCBDDC; may be NULL when A is not of type MATIS.
order – [in] Nédélec basis order (registered with the gradient in PCBDDC).
X – [out] Solution matrix, created internally (caller destroys).
dm – [in] DMPlex mesh; its communicator drives the parallel solve.
A – [in] System matrix (H(curl) FEM operator).
B – [in] Right-hand side matrix, one column per source.
G – [in] High-order discrete-gradient hint for PCBDDC; may be NULL when
Ais not of type MATIS.order – [in] Nedelec basis order (registered with the gradient in PCBDDC).
X – [out] Solution matrix, created internally (the caller destroys it).
- Returns:
PetscErrorCode PETSC_SUCCESS on success, or a PETSc error code otherwise.
- Returns:
PetscErrorCode PETSC_SUCCESS on success, or a PETSc error code otherwise.
-
PetscErrorCode setupBDDCFromPetgemGradient(KSP ksp, Mat A, Mat Gbddc, PetscInt order)
Configures
ksp’s PC as PCBDDC with the discrete-gradient hint, if the operator is MATIS and a gradient was supplied.Shared helper that captures the single BDDC policy used by both the forward solver (solveCsemSystem) and the inverse solver (createInvKSP): when A is of type MATIS and Gbddc is non-NULL, set PC to PCBDDC and register Gbddc (the high-order discrete gradient) via PCBDDCSetDiscreteGradient(…, order, 0, PETSC_TRUE, PETSC_TRUE). When the conditions are not met the function is a no-op so the caller’s existing default PC stays in place.
Configures
ksp’s PC as PCBDDC with the discrete-gradient hint, if the operator is MATIS and a gradient was supplied.Shared helper that captures the single PCBDDC + Nédélec discrete-gradient policy used by BOTH kernels: the forward solver (solveCsemSystem) and the inverse solver (createInvKSP). When
Ais of type MATIS andGis non-NULL, the preconditioner is set to PCBDDC andGis registered via PCBDDCSetDiscreteGradient(pc, G, 1, 0, PETSC_TRUE, PETSC_TRUE). When those conditions are not met the call is a no-op, so the caller’s default PC stays.Gis the high-order discrete gradient G : Nédélec_order –> P_order H1 produced by assembleCsemKandM (buildDiscreteGradientMatrix: each H(curl) DOF’s gradient is resolved against the full P_order H1 closure, so grad(phi_k) = sum_i G_ik N_i exactly and K·G = 0). PCBDDC reads its sparsity (GᵀG) to build the curl-kernel coarse space.The discrete gradient is the high-order operator G : Nedelec_order -> P_order H1, so it is registered at order = order (matching the column space of G); the coarse-space collapse is driven by G’s sparsity/values together with that order argument.
- Parameters:
ksp – [inout] KSP whose preconditioner is configured.
A – [in] System matrix (probed for MATIS).
G – [in] Discrete-gradient hint (may be NULL).
order – [in] Nédélec basis order registered with the gradient.
ksp – [inout] KSP whose preconditioner is configured.
A – [in] System matrix (probed for the MATIS type).
G – [in] Discrete-gradient hint; may be NULL.
order – [in] Nedelec basis order registered with the gradient.
- Returns:
PetscErrorCode PETSC_SUCCESS on success, or a PETSc error code otherwise.
- Returns:
PetscErrorCode PETSC_SUCCESS on success, or a PETSc error code otherwise.