Skip to content

Conversation

@Akos299
Copy link
Collaborator

@Akos299 Akos299 commented Aug 15, 2025

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:

  • MPI
  • coupling with hydro
  • AMR

Akos299 and others added 6 commits August 15, 2025 10:32
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
Copy link

@gemini-code-assist gemini-code-assist bot left a 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

  1. 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.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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.

@tdavidcl tdavidcl added the draft label Aug 16, 2025
Copy link
Member

@tdavidcl tdavidcl left a 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.

@Akos299 Akos299 changed the title [Ramses][Poisson] CG/ PCG (Jacobi preconditioner) [Ramses][Poisson] CG/ PCG(Jacobi preconditioner)/BICGSTAB(with restart) Aug 18, 2025
@github-actions
Copy link

Workflow report

workflow report corresponding to commit f34628f
Commiter email is [email protected]

Pre-commit check report

Some failures were detected in base source checks checks.
Check the On PR / Linting / Base source checks (pull_request) job in the tests for more detailled output

Suggested changes

Detailed 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(

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants