Skip to content

[GRSPH] Conservative to primitive variable swap module#1657

Open
y-lapeyre wants to merge 12 commits intoShamrock-code:mainfrom
y-lapeyre:GR/cons2prime
Open

[GRSPH] Conservative to primitive variable swap module#1657
y-lapeyre wants to merge 12 commits intoShamrock-code:mainfrom
y-lapeyre:GR/cons2prime

Conversation

@y-lapeyre
Copy link
Collaborator

The evaluation of primitive variables is necessary at the end of each time step. Following Tejeda 2012, we express these in terms of the enthalpy w and use the equation of state to find the appropriate value of w through an iterative process.
This PR depends on #1552.

@github-actions
Copy link
Contributor

Thanks @y-lapeyre for opening this PR!

You can do multiple things directly here:
1 - Comment pre-commit.ci run to run pre-commit checks.
2 - Comment pre-commit.ci autofix to apply fixes.
3 - Add label autofix.ci to fix authorship & pre-commit for every commit made.
4 - Add label light-ci to only trigger a reduced & faster version of the CI (need the full one before merge).
5 - Add label trigger-ci to create an empty commit to trigger the CI.

Once the workflow completes a message will appear displaying informations related to the run.

Also the PR gets automatically reviewed by gemini, you can:
1 - Comment /gemini review to trigger a review
2 - Comment /gemini summary for a summary
3 - Tag it using @gemini-code-assist either in the PR or in review comments on files

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @y-lapeyre, 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 introduces a fundamental module for general relativistic hydrodynamics, enabling the conversion of conservative variables to primitive variables. This conversion is essential for advancing simulations, particularly at the end of each time step, by providing the necessary primitive state for subsequent calculations. The implementation leverages an iterative approach based on enthalpy, enhancing the accuracy and robustness of the simulation framework.

Highlights

  • New Conservative to Primitive Variable Conversion Module: Introduced NodeConsToPrim module to convert conservative hydrodynamic variables (rho*, momentum, entropy) into primitive variables (density, velocity, internal energy, pressure).
  • Iterative Enthalpy-Based Calculation: Implemented an iterative process within the ConsToPrim module to determine primitive variables, specifically using enthalpy, as described in Tejeda 2012.
  • Build System Integration: Updated CMakeLists.txt to include the newly added ConsToPrim.cpp source file, ensuring the module is compiled as part of the project.
Changelog
  • src/shammodels/ramses/CMakeLists.txt
    • Added src/modules/ConsToPrim.cpp to the list of source files.
  • src/shammodels/sph/include/shammodels/sph/modules/ConsToPrim.hpp
    • Defined the NodeConsToPrim class template, including its constructor, Edges struct for input/output fields, and declarations for internal evaluation and label methods.
  • src/shammodels/sph/src/modules/ConsToPrim.cpp
    • Implemented the _impl_evaluate_internal method for NodeConsToPrim, which performs the iterative calculation to convert conservative variables to primitive variables using an enthalpy-based approach.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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
Contributor

@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 a new module for converting conservative to primitive variables for GRSPH simulations. The implementation contains several critical issues that will prevent it from compiling or working correctly. These include the use of undefined variables within a kernel, a faulty iterative solver with incorrect logic and missing physics, and out-of-bounds memory access. Additionally, the new module appears to be added to the wrong build target in CMake. I've provided detailed comments and suggestions to address these problems.

Comment on lines +78 to +81
Tscal sqrt_g = get_sqrtg(gcov);
Tscal inv_sqrt_g = 1. / sqrt_g;
Tscal sqrt_gamma = get_sqrt_gamma(gcov);
Tscal sqrt_gamma_inv = alpha * inv_sqrt_g;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The variables gcov and alpha are used here but are not defined or captured in the kernel lambda. This will cause a compilation error. The same issue exists for betadown and gammaijUP later in the kernel (lines 106 and 109). These metric-related variables need to be available within the kernel's scope, for example by capturing them in the lambda.

@y-lapeyre
Copy link
Collaborator Author

I can't put the metric as an edge, the comma in the <> is perceived, and the preprocessor freaks out claiming too many arguments are declared.

@tdavidcl
Copy link
Member

I can't put the metric as an edge, the comma in the <> is perceived, and the preprocessor freaks out claiming too many arguments are declared.

You can be declaring an alias, i've done recently https://github.com/tdavidcl/Shamrock/blob/16ed3de43aa5cafea01af0b3306599df71a7b5bb/src/shammodels/ramses/include/shammodels/ramses/modules/SumFluxHydro.hpp.

Just declare something like

template<class Tvec, class TgridVec>
    class NodeSumFluxHydro : public shamrock::solvergraph::INode {
        using Tscal    = shambase::VecComponent<Tvec>;
        using AMRBlock = shammodels::amr::AMRBlock<Tvec, TgridVec, 1>;

        u32 block_size;

        public:
        NodeSumFluxHydro(u32 block_size) : block_size(block_size) {}

+        using CellGraphEdge = solvergraph::OrientedAMRGraphEdge<Tvec, TgridVec>;

        EXPAND_NODE_EDGES(NODE_SUM_FLUX_HYDRO)

        void _impl_evaluate_internal();

        inline virtual std::string _impl_get_label() const { return "SumFluxHydro"; }

        inline virtual std::string _impl_get_tex() const { return "TODO"; };
    };

and use it for the class name

@github-actions
Copy link
Contributor

Workflow report

workflow report corresponding to commit d38d045
Commiter email is yona.lapeyre@ens-lyon.fr

Light CI is enabled. This will only run the basic tests and not the full tests.
Merging a PR require the job "on PR / all" to pass which is disabled in this case.

Pre-commit check report

Pre-commit check: ✅

trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check for merge conflicts................................................Passed
check that executables have shebangs.....................................Passed
check that scripts with shebangs are executable..........................Passed
check for added large files..............................................Passed
check for case conflicts.................................................Passed
check for broken symlinks................................................Passed
check yaml...............................................................Passed
detect private key.......................................................Passed
No-tabs checker..........................................................Passed
Tabs remover.............................................................Passed
Validate GitHub Workflows................................................Passed
clang-format.............................................................Passed
ruff check...............................................................Passed
ruff format..............................................................Passed
Check doxygen headers....................................................Passed
Check license headers....................................................Passed
Check #pragma once.......................................................Passed
Check SYCL #include......................................................Passed
No ssh in git submodules remote..........................................Passed
No UTF-8 in files (except for authors)...................................Passed

Test pipeline can run.

Doxygen diff with main

Removed warnings : 2
New warnings : 30
Warnings count : 8222 → 8250 (0.3%)

Detailed changes :
+ src/shammodels/sph/include/shammodels/sph/modules/ConsToPrim.hpp:29: warning: Compound shammodels::sph::modules::NodeConsToPrim is not documented.
+ src/shammodels/sph/include/shammodels/sph/modules/ConsToPrim.hpp:34: warning: Member NodeConsToPrim(Tscal gamma) (function) of class shammodels::sph::modules::NodeConsToPrim is not documented.
+ src/shammodels/sph/include/shammodels/sph/modules/ConsToPrim.hpp:37: warning: Member NODE_CONS_TO_PRIM(X_RO, X_RW) (macro definition) of file ConsToPrim.hpp is not documented.
+ src/shamphys/include/shamphys/GRUtils.hpp:109: warning: Member get_gammaijUP(std::mdspan< Tscal, std::extents< SizeType, 4, 4 >, Layout2, Accessor2 > gcon) (function) of struct shamphys::GR_physics is not documented.
+ src/shamphys/include/shamphys/GRUtils.hpp:124: warning: Member get_gamma(std::mdspan< Tscal, std::extents< SizeType, 4, 4 >, Layout2, Accessor2 > gcov) (function) of struct shamphys::GR_physics is not documented.
+ src/shamphys/include/shamphys/GRUtils.hpp:137: warning: Member get_lorentz_factor(Tvec momentum, Tscal enthalpy, std::mdspan< Tscal, std::extents< SizeType, 4, 4 >, Layout2, Accessor2 > gcov) (function) of struct shamphys::GR_physics is not documented.
+ src/shamphys/include/shamphys/GRUtils.hpp:145: warning: Member get_U0(Tvec momentum, Tscal enthalpy, std::mdspan< Tscal, std::extents< SizeType, 4, 4 >, Layout2, Accessor2 > gcon) (function) of struct shamphys::GR_physics is not documented.
+ src/shamphys/include/shamphys/GRUtils.hpp:156: warning: Member get_V(Tvec vxyz, std::mdspan< Tscal, std::extents< SizeType, 4, 4 >, Layout2, Accessor2 > gcon) (function) of struct shamphys::GR_physics is not documented.
+ src/shamphys/include/shamphys/GRUtils.hpp:35: warning: Compound shamphys::GR_physics is not documented.
+ src/shamphys/include/shamphys/GRUtils.hpp:37: warning: Member get_alpha(std::mdspan< Tscal, std::extents< SizeType, 4, 4 >, Layout2, Accessor2 > gcon) (function) of struct shamphys::GR_physics is not documented.
+ src/shamphys/include/shamphys/GRUtils.hpp:43: warning: Member get_betaUP(std::mdspan< Tscal, std::extents< SizeType, 4, 4 >, Layout2, Accessor2 > gcon) (function) of struct shamphys::GR_physics is not documented.
+ src/shamphys/include/shamphys/GRUtils.hpp:56: warning: Member get_betaDOWN(std::mdspan< Tscal, std::extents< SizeType, 4, 4 >, Layout2, Accessor2 > gcov) (function) of struct shamphys::GR_physics is not documented.
+ src/shamphys/include/shamphys/GRUtils.hpp:67: warning: Member GR_dot(Tvec a, Tvec b, std::mdspan< Tscal, std::extents< SizeType, 4, 4 >, Layout2, Accessor2 > gcov) (function) of struct shamphys::GR_physics is not documented.
+ src/shamphys/include/shamphys/GRUtils.hpp:81: warning: Member GR_dot_spatial(Tvec a, Tvec b, std::mdspan< Tscal, std::extents< SizeType, 3, 3 >, Layout2, Accessor2 > gamma_ij) (function) of struct shamphys::GR_physics is not documented.
+ src/shamphys/include/shamphys/GRUtils.hpp:96: warning: Member get_gammaijDOWN(std::mdspan< Tscal, std::extents< SizeType, 4, 4 >, Layout2, Accessor2 > gcov) (function) of struct shamphys::GR_physics is not documented.
+ src/shamphys/include/shamphys/metrics.hpp:113: warning: Member get_cartesian_contravariant_metric_impl(const Kerr< Tscal > &kerr, const std::mdspan< Tscal, std::extents< SizeType, 4 >, Layout1, Accessor1 > &pos, std::mdspan< Tscal, std::extents< SizeType, 4, 4 >, Layout2, Accessor2 > &g) (function) of namespace shamphys is not documented.
+ src/shamphys/include/shamphys/metrics.hpp:181: warning: Member metric_cartesian_derivatives_impl(const Kerr< Tscal > &kerr, const std::mdspan< Tscal, std::extents< SizeType, 4 >, Layout1, Accessor1 > &pos, std::mdspan< Tscal, std::extents< SizeType, 4, 4 >, Layout2, Accessor2 > &dgcovdx, std::mdspan< Tscal, std::extents< SizeType, 4, 4 >, Layout2, Accessor2 > &dgcovdy, std::mdspan< Tscal, std::extents< SizeType, 4, 4 >, Layout2, Accessor2 > &dgcovdz) (function) of namespace shamphys is not documented.
+ src/shamphys/include/shamphys/metrics.hpp:27: warning: Compound shamphys::Kerr is not documented.
+ src/shamphys/include/shamphys/metrics.hpp:29: warning: Member a (variable) of struct shamphys::Kerr is not documented.
+ src/shamphys/include/shamphys/metrics.hpp:30: warning: Member bh_mass (variable) of struct shamphys::Kerr is not documented.
+ src/shamphys/include/shamphys/metrics.hpp:31: warning: Member rs (variable) of struct shamphys::Kerr is not documented.
+ src/shamphys/include/shamphys/metrics.hpp:33: warning: Member Kerr(Tscal spin, Tscal mass) (function) of struct shamphys::Kerr is not documented.
+ src/shamphys/include/shamphys/metrics.hpp:472: warning: Member get_cartesian_covariant_metric(const std::mdspan< Tscal, std::extents< SizeType, 4 >, Layout1, Accessor1 > pos, std::mdspan< Tscal, std::extents< SizeType, 4, 4 >, Layout2, Accessor2 > &g) (function) of namespace shamphys is not documented.
+ src/shamphys/include/shamphys/metrics.hpp:47: warning: Member get_cartesian_covariant_metric_impl(const Kerr< Tscal > &kerr, const std::mdspan< Tscal, std::extents< SizeType, 4 >, Layout1, Accessor1 > &pos, std::mdspan< Tscal, std::extents< SizeType, 4, 4 >, Layout2, Accessor2 > &g) (function) of namespace shamphys is not documented.
+ src/shamphys/include/shamphys/metrics.hpp:492: warning: Member get_cartesian_contravariant_metric(const std::mdspan< Tscal, std::extents< SizeType, 4 >, Layout1, Accessor1 > pos, std::mdspan< Tscal, std::extents< SizeType, 4, 4 >, Layout2, Accessor2 > &g) (function) of namespace shamphys is not documented.
+ src/shamphys/include/shamphys/metrics.hpp:512: warning: Member metric_cartesian_derivatives(const std::mdspan< Tscal, std::extents< SizeType, 4 >, Layout1, Accessor1 > pos, std::mdspan< Tscal, std::extents< SizeType, 4, 4 >, Layout2, Accessor2 > &dgcovdx, std::mdspan< Tscal, std::extents< SizeType, 4, 4 >, Layout2, Accessor2 > &dgcovdy, std::mdspan< Tscal, std::extents< SizeType, 4, 4 >, Layout2, Accessor2 > &dgcovdz) (function) of namespace shamphys is not documented.
+ src/shamrock/include/shamrock/solvergraph/INode.hpp:104: warning: Member get_rw_edge_base(int slot) const (function) of class shamrock::solvergraph::INode is not documented.
+ src/shamrock/include/shamrock/solvergraph/INode.hpp:95: warning: Member get_ro_edge_base(int slot) const (function) of class shamrock::solvergraph::INode is not documented.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants