Skip to content

[Ramses] provide utilities to set fields from primitive vars#1683

Draft
tdavidcl wants to merge 1 commit intoShamrock-code:mainfrom
tdavidcl:patch-2026-02-25-10-30
Draft

[Ramses] provide utilities to set fields from primitive vars#1683
tdavidcl wants to merge 1 commit intoShamrock-code:mainfrom
tdavidcl:patch-2026-02-25-10-30

Conversation

@tdavidcl
Copy link
Member

No description provided.

@github-actions
Copy link
Contributor

Thanks @tdavidcl 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 @tdavidcl, 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 refactors the field initialization logic within the run_kh.py example for the Ramses simulation. The primary goal is to improve code modularity and clarity by separating the definition of primitive variables (like velocity and pressure) from the calculation of conserved variables (like momentum and total energy). This makes the setup more robust and easier to understand, aligning with the concept of setting fields directly from primitive variables.

Highlights

  • Velocity and Momentum Calculation Refactoring: The rhovel_map function was refactored into a new vel_map function, which now directly returns primitive velocity components (vx, vy, vz). The new rhovel_map then uses this vel_map along with rho_map to calculate momentum.
  • Pressure Mapping Introduction: A new P_map function was introduced to explicitly calculate the pressure field, improving clarity and reusability.
  • Improved Modularity in Field Initialization: The changes enhance the modularity of field initialization by separating the calculation of primitive variables (velocity, pressure) from conserved variables (momentum, total energy), making the code cleaner and more aligned with setting fields from primitive variables.
Changelog
  • examples/ramses/run_kh.py
    • Renamed rhovel_map to vel_map and modified it to return primitive velocity components.
    • Added a new P_map function for pressure calculation.
    • Updated rhovel_map to use rho_map and the new vel_map.
    • Modified rhoetot_map to utilize the new P_map.
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

The pull request refactors the initialization of simulation fields by breaking down complex functions into smaller, more modular ones. This improves readability and maintainability. However, I've identified a performance issue in rhoetot_map where rho_map is called redundantly, and I've provided a suggestion to optimize it.

Comment on lines 208 to 213
rho = rho_map(rmin, rmax)
rhovel = rhovel_map(rmin, rmax)
P = P_map(rmin, rmax)

rhovel2 = rhovel[0] * rhovel[0] + rhovel[1] * rhovel[1] + rhovel[2] * rhovel[2]
rhoekin = 0.5 * rhovel2 / rho
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The rhoetot_map function calls rho_map and then rhovel_map, which in turn calls rho_map again. This redundant call to rho_map can be a performance bottleneck, especially since these functions are called for each cell during initialization.

You can optimize this by calculating the kinetic energy directly from the velocity and density, avoiding the call to rhovel_map and its redundant computation.

Suggested change
rho = rho_map(rmin, rmax)
rhovel = rhovel_map(rmin, rmax)
P = P_map(rmin, rmax)
rhovel2 = rhovel[0] * rhovel[0] + rhovel[1] * rhovel[1] + rhovel[2] * rhovel[2]
rhoekin = 0.5 * rhovel2 / rho
rho = rho_map(rmin, rmax)
vx, vy, vz = vel_map(rmin, rmax)
P = P_map(rmin, rmax)
rhoekin = 0.5 * rho * (vx**2 + vy**2 + vz**2)

@github-actions
Copy link
Contributor

Workflow report

workflow report corresponding to commit ee34f36
Commiter email is timothee.davidcleris@proton.me

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 : 0
New warnings : 0
Warnings count : 8183 → 8183 (0.0%)

Detailed changes :

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.

1 participant