Add SparseSolv iterative solvers (ICCG, ICMRTR, SGSMRTR)#86
Open
ksugahar wants to merge 4 commits intoNGSolve:masterfrom
Open
Add SparseSolv iterative solvers (ICCG, ICMRTR, SGSMRTR)#86ksugahar wants to merge 4 commits intoNGSolve:masterfrom
ksugahar wants to merge 4 commits intoNGSolve:masterfrom
Conversation
- Add IC (Incomplete Cholesky) preconditioner with shift parameter - Add ILU (Incomplete LU) preconditioner for general matrices - Add SGS (Symmetric Gauss-Seidel) preconditioner - Support FreeDofs (Dirichlet BC) handling for all preconditioners - Add OpenMP parallelization for setup and apply operations - Expose preconditioners to Python via pybind11 Based on JP-MARs/SparseSolv library. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Expose all SparseSolv iterative solvers through a unified SparseSolvSolver class with Python bindings: - ICCG: CG + Incomplete Cholesky preconditioner - ICMRTR: MRTR + Incomplete Cholesky preconditioner - SGSMRTR: MRTR with built-in Symmetric Gauss-Seidel (split formula) - CG/MRTR: solvers without preconditioner Features: - save_best_result: tracks best solution during iteration (default on) - save_residual_history: records convergence history - FreeDofs support for Dirichlet boundary conditions - BaseMatrix interface for use as inverse operator - SparseSolvResult for detailed convergence info Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ability IC Preconditioner: - Add auto-shift restart: when diagonal drops below threshold during IC factorization, increment shift parameter and restart (MATLAB reference) - Add diagonal scaling (1/sqrt(A[i,i])) before factorization - Clamp zero/negative diagonals to replacement value (instead of 1/epsilon) - New SolverConfig parameters: auto_shift, shift_increment, max_shift_value, min_diagonal_threshold, zero_diagonal_replacement, max_shift_trials CG Solver: - Check convergence before reporting breakdown (pAp < 1e-30) MRTR Solver: - Regularize near-zero denominator (like SGS-MRTR) instead of aborting Python bindings: - Add auto_shift and diagonal_scaling properties to SparseSolvSolver Revert fork-specific README changes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Tests cover: - SparseSolvSolver with all methods (ICCG, ICMRTR, SGSMRTR) on 2D/3D Poisson - IC/ILU/SGS preconditioners with NGSolve CGSolver - Auto-shift + diagonal scaling for 3D curl-curl (HCurl nograds=True) - Residual history tracking - Property accessors and error handling - Operator interface (solver * vec vs solver.Solve()) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR integrates SparseSolv, a header-only C++ library for iterative sparse linear solvers, into NGSolve. It provides:
BaseMatrixpreconditioners with NGSolve's existing Krylov solvers (e.g.CGSolver,GMRESSolver)SparseSolvSolverclass combining preconditioner + Krylov method in a singleBaseMatrixoperator, supporting:nograds=True): automatically increments the IC shift when negative pivots are detected during factorizationPython API
Files added/modified
New files (header-only library, no new build dependencies):
linalg/sparsesolv/— 14 header files (core types, preconditioners, solvers)linalg/sparsesolv_precond.hpp— NGSolve wrapper classes (ICPreconditioner,ILUPreconditioner,SGSPreconditioner,SparseSolvSolver)tests/pytest/test_sparsesolv.py— 14 pytest testsModified files:
linalg/CMakeLists.txt— install SparseSolv headerslinalg/la.hpp— includesparsesolv_precond.hpplinalg/python_linalg.cpp— Python bindings (~400 lines)Test results
All 14 new tests pass, existing solver tests unaffected:
test_sparsesolv_solver_2d_poisson[ICCG/ICMRTR/SGSMRTR]test_sparsesolv_solver_3d_poissontest_sparsesolv_solver_vs_directtest_preconditioners_with_ngsolve_cg[IC/ILU/SGS]CGSolvertest_auto_shift_curl_curltest_residual_historytest_no_residual_historytest_propertiestest_invalid_methodtest_operator_interfacesolver * vecmatchessolver.Solve()Test plan
python -m pytest test_sparsesolv.py -v)python -m pytest test_solvers.py -v)🤖 Generated with Claude Code