Skip to content

Add Preconditioned Conjugate Gradient Method#188

Open
julianlitz wants to merge 9 commits intomainfrom
litz_pcg_01
Open

Add Preconditioned Conjugate Gradient Method#188
julianlitz wants to merge 9 commits intomainfrom
litz_pcg_01

Conversation

@julianlitz
Copy link
Collaborator

@julianlitz julianlitz commented Feb 27, 2026

Add Preconditioned Conjugate Gradient (PCG)

Rather than running GMGPolar as a standalone iterative solver, we can exploit it as a preconditioner for CG.

Each PCG iteration approximates the action of A^{-1} by running a cheap FMG approximation followed by one multigrid cycle. Good enough to serve as a preconditioner, but much cheaper than iterating GMGPolar to full convergence.

The non-extrapolated operator A is used as the preconditioner M, even when solving the extrapolated system (see Litz et al.). The extrapolated operator A_ex cannot serve as preconditioner because its right-hand side requires evaluating a source term function, whereas PCG only has access to a discretized residual vector at each iteration. This was validated on the paper_v2_conjugate_gradient branch.

The implementation is tightly integrated with the existing solver, so the additional memory cost is just two vectors. The three PCG work vectors (r, z, A*p) are aliased onto storage that already exists (level.rhs(), level.solution(), level.residual()), and only the solution x and search direction p require fresh allocations.

When combined with extrapolation, the PCG solver converges in up to 4× fewer iterations than standalone GMGPolar and runs up to 2× faster end-to-end. A significant gain for a minimal implementation cost.

Merge Request - GuideLine Checklist

Guideline to check code before resolve WIP and approval, respectively.
As many checkboxes as possible should be ticked.

Checks by code author:

Always to be checked:

  • There is at least one issue associated with the pull request.
  • New code adheres with the coding guidelines
  • No large data files have been added to the repository. Maximum size for files should be of the order of KB not MB. In particular avoid adding of pdf, word, or other files that cannot be change-tracked correctly by git.

If functions were changed or functionality was added:

  • Tests for new functionality has been added
  • A local test was succesful

If new functionality was added:

  • There is appropriate documentation of your work. (use doxygen style comments)

If new third party software is used:

  • Did you pay attention to its license? Please remember to add it to the wiki after successful merging.

If new mathematical methods or epidemiological terms are used:

  • Are new methods referenced? Did you provide further documentation?

Checks by code reviewer(s):

  • Is the code clean of development artifacts e.g., unnecessary comments, prints, ...
  • The ticket goals for each associated issue are reached or problems are clearly addressed (i.e., a new issue was introduced).
  • There are appropriate unit tests and they pass.
  • The git history is clean and linearized for the merge request. All reviewers should squash commits and write a simple and meaningful commit message.
  • Coverage report for new code is acceptable.
  • No large data files have been added to the repository. Maximum size for files should be of the order of KB not MB. In particular avoid adding of pdf, word, or other files that cannot be change-tracked correctly by git.

@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 78.30882% with 59 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.91%. Comparing base (aac9b10) to head (e8d7055).

Files with missing lines Patch % Lines
src/GMGPolar/setup.cpp 8.82% 31 Missing ⚠️
src/ConfigParser/config_parser.cpp 52.94% 16 Missing ⚠️
src/GMGPolar/solver.cpp 92.98% 8 Missing ⚠️
src/GMGPolar/gmgpolar.cpp 94.44% 3 Missing ⚠️
src/Level/level.cpp 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #188      +/-   ##
==========================================
- Coverage   95.28%   94.91%   -0.38%     
==========================================
  Files          94       94              
  Lines        9316     9517     +201     
==========================================
+ Hits         8877     9033     +156     
- Misses        439      484      +45     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant