-
Notifications
You must be signed in to change notification settings - Fork 17
[Ramses][Poisson] CG/ PCG(Jacobi preconditioner)/BICGSTAB(with restart) #1183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
To perform the dot product we first compute the Hadamard product of the vectors and then by a global sum reduction of the output vector we obtained the final result.
two vectors refers to Y = aX + Y three vectors refers to Z = aX + bY + Z
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @Akos299, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request significantly enhances the Ramses simulation model by integrating advanced self-gravity capabilities through the implementation of Conjugate Gradient (CG) and Preconditioned Conjugate Gradient (PCG) solvers for Poisson's equation. The focus is on providing robust, single-node functionality for convergence testing, laying essential groundwork for future extensions to Adaptive Mesh Refinement (AMR) and Message Passing Interface (MPI). The changes involve adding core linear algebra components, configuring solver parameters, and integrating the new solvers into the existing simulation framework.
Highlights
- New Self-Gravity Solvers: The pull request introduces the Conjugate Gradient (CG) and Preconditioned Conjugate Gradient (PCG) iterative solvers for Poisson's equation, enabling self-gravity calculations within the Ramses simulation model.
- Modular Linear Algebra Components: A comprehensive set of modular linear algebra operations, such as sparse matrix-vector products, Hadamard products, various AXPY/AYPX vector operations, sum reductions, and a Jacobi preconditioner, have been implemented as reusable nodes in the solver graph.
- Configurable Solver Parameters: New configuration options and Python bindings have been added, allowing users to precisely control the self-gravity solver's behavior, including setting the gravitational constant (G), maximum iterations, and convergence tolerance.
- Initial Convergence Test and Example: A new Python example script (
exemples/self_gravity_cg.py) has been added to demonstrate the PCG solver's functionality and perform a convergence test, aligning with established benchmarks like Athena++. - Refactored Laplacian Calculation: The 7-point discretized Laplacian stencil, a core component of the Poisson solver, has been refactored into a dedicated and reusable function (
laplacian_7pt). - Seamless Solver Integration: The chosen self-gravity solver (CG or PCG) is now dynamically integrated into the main simulation loop, and the computed gravitational potential is seamlessly saved back to the simulation's primary data structures for subsequent time steps.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces Conjugate Gradient (CG) and Preconditioned Conjugate Gradient (PCG) solvers for the Poisson equation, which is a significant step towards implementing self-gravity. The changes are extensive, adding many new C++ files for the solver nodes and logic, along with a Python example script for testing. The overall structure is well-designed, breaking down the solver into modular components (nodes). However, I've identified a critical bug in one of the new node headers and a few medium-severity issues related to consistency and code clarity that should be addressed.
src/shammodels/ramses/include/shammodels/ramses/modules/NodeAXPYThreeVectors.hpp
Outdated
Show resolved
Hide resolved
src/shammodels/ramses/include/shammodels/ramses/modules/NodePCGLoop.hpp
Outdated
Show resolved
Hide resolved
tdavidcl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a tiny pre-review.
Essentially on the global scope my current concern is that some of the big solvergraph module require Storage & Config & Context. Ideally that should never be the case as the module is not standalone anymore which defeat the purposes of solvergraphs.
I would be better to feed the module with FieldRefs and parameters instead.
src/shammodels/ramses/include/shammodels/ramses/modules/NodeBICGSTABLoop.hpp
Outdated
Show resolved
Hide resolved
src/shammodels/ramses/include/shammodels/ramses/modules/NodeCGLoop.hpp
Outdated
Show resolved
Hide resolved
src/shammodels/ramses/include/shammodels/ramses/modules/NodePCGLoop.hpp
Outdated
Show resolved
Hide resolved
Workflow reportworkflow report corresponding to commit f34628f Pre-commit check reportSome failures were detected in base source checks checks. Suggested changesDetailed changes :diff --git a/src/shammodels/ramses/src/Solver.cpp b/src/shammodels/ramses/src/Solver.cpp
index e3f959e8..037cf951 100644
--- a/src/shammodels/ramses/src/Solver.cpp
+++ b/src/shammodels/ramses/src/Solver.cpp
@@ -664,8 +664,8 @@ void shammodels::basegodunov::Solver<Tvec, TgridVec>::init_solver_graph() {
std::make_shared<decltype(attach_rhov_dust)>(std::move(attach_rhov_dust)));
}
- if (solver_config.is_gravity_on()){
- shamrock::solvergraph::GetFieldRefFromLayer<Tscal> attach_phi
+ if (solver_config.is_gravity_on()) {
+ shamrock::solvergraph::GetFieldRefFromLayer<Tscal> attach_phi
= shamrock::solvergraph::GetFieldRefFromLayer<Tscal>(storage.ghost_layout, "phi");
attach_phi.set_edges(storage.merged_patchdata_ghost, storage.refs_phi);
solver_sequence.push_back(
|
Poisson solvers (CG , PCG, and BICGSTAB) without AMR and MPI.
We perform the same convergence test as in Athena++.
Based on this PR, we will add in the upcoming days in the following order: