Skip to content

[RAMSES][AMR] Histogram of AMR Levels and New Block Index Map#1632

Open
Akos299 wants to merge 34 commits intoShamrock-code:mainfrom
Akos299:blocks_level_histrogram
Open

[RAMSES][AMR] Histogram of AMR Levels and New Block Index Map#1632
Akos299 wants to merge 34 commits intoShamrock-code:mainfrom
Akos299:blocks_level_histrogram

Conversation

@Akos299
Copy link
Collaborator

@Akos299 Akos299 commented Feb 11, 2026

This function computes a histogram of AMR (Adaptive Mesh Refinement) levels.
It returns :

  • A buffer containing AMR levels ordered according to the histogram.
  • A new block index map that is consistent with the ordering of the returned buffer.

The index map can be used to remap existing block-based data to match the new AMR-level ordering.

@Akos299 Akos299 requested a review from tdavidcl February 11, 2026 15:26
@github-actions
Copy link
Contributor

Thanks @Akos299 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

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 Adaptive Mesh Refinement (AMR) system by implementing the capability to compute a histogram of AMR levels and generate a consistent block index map for reordering data. It introduces a new computational step to accurately determine the base cell size for level 0, which is critical for the AMR level calculations. These new functionalities are seamlessly integrated into the solver's graph, with their execution dynamically controlled by the AMR mode configuration, ensuring computations are only performed when necessary.

Highlights

  • AMR Level Histogram and Block Index Map: Introduced a new function, amr_block_levels_histogram, to compute a histogram of Adaptive Mesh Refinement (AMR) block levels and generate a reordered block index map. This allows for efficient reordering of block-based data according to their AMR levels.
  • New Solver Graph Node for Level 0 Cell Size: Added a new solver graph node, ComputeLevel0CellSize, responsible for determining the maximum size of level 0 cells across different patches, a foundational step for subsequent AMR level calculations.
  • Conditional AMR Level Computation: Integrated the new AMR level computation nodes (ComputeLevel0CellSize and ComputeAMRLevel, the latter implied by usage) into the solver's initialization sequence. These computations are now conditionally enabled based on a new no_none_cfg flag within the AMRMode configuration.
  • Enhanced AMR Configuration: Extended the AMRMode configuration in SolverConfig.hpp with a no_none_cfg boolean flag and corresponding need_level_zero_compute() and need_amr_level_compute() methods, allowing for fine-grained control over when AMR level-related computations are performed.
Changelog
  • src/shammodels/ramses/include/shammodels/ramses/SolverConfig.hpp
    • Added a bool no_none_cfg member to the AMRMode struct.
    • Introduced need_level_zero_compute() and need_amr_level_compute() methods to AMRMode to check the no_none_cfg flag.
  • src/shammodels/ramses/include/shammodels/ramses/modules/AMRGridRefinementHandler.hpp
    • Defined TgridUint as an unsigned type for grid components.
    • Declared a private member function amr_block_levels_histogram for computing AMR block level histograms and reordering indices.
  • src/shammodels/ramses/include/shammodels/ramses/modules/ComputeLevel0CellSize.hpp
    • Added a new header file defining the ComputeLevel0CellSize solver graph node, which computes the maximum block size for level 0 cells within each patch.
  • src/shammodels/ramses/include/shammodels/ramses/modules/SolverStorage.hpp
    • Added TgridUint type alias.
    • Declared level0_size (a ScalarsEdge<TgridVec>) and amr_block_levels (a Field<TgridUint>) as shared pointers for storing computed data.
    • Updated author information.
  • src/shammodels/ramses/src/Solver.cpp
    • Included ComputeAMRLevel.hpp and ComputeLevel0CellSize.hpp.
    • Initialized storage.level0_size as a new ScalarsEdge.
    • Conditionally added ComputeLevel0CellSize and ComputeAMRLevel nodes to the solver_sequence based on solver_config.amr_mode flags.
  • src/shammodels/ramses/src/modules/AMRGridRefinementHandler.cpp
    • Implemented the amr_block_levels_histogram function, which calculates block counts per AMR level and generates a reordered index map using SYCL kernels and atomic operations.
  • src/shammodels/ramses/src/pyRamsesModel.cpp
    • Modified set_amr_mode_none to set self.amr_mode.no_none_cfg to false.
    • Modified set_amr_mode_density_based to set self.amr_mode.no_none_cfg to true.
Activity
  • No specific activity (comments, reviews, progress) was provided in the context for this pull request.
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

@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 functionality to compute a histogram of AMR levels and a corresponding block index map. The changes include adding new compute nodes to the solver graph for AMR level computation and level 0 cell size, and a new histogramming function.

My review focuses on improving code clarity, performance, and removing unused code:

  • In SolverConfig.hpp, I've suggested renaming a boolean flag for better readability.
  • In ComputeLevel0CellSize.hpp, I found an unused variable and an unnecessary computation that can be removed.
  • In AMRGridRefinementHandler.cpp, I've identified a performance bottleneck in the new histogramming function and suggested a more efficient parallel approach using a scan operation, aligning with best practices for scan accumulator types.

Overall, the changes are a good addition, and with these improvements, the code will be more robust and performant.

Akos299 and others added 3 commits February 13, 2026 13:32
@Akos299
Copy link
Collaborator Author

Akos299 commented Feb 16, 2026

I think This one is ready to be merged.

@github-actions
Copy link
Contributor

Workflow report

workflow report corresponding to commit 2e96796
Commiter email is 41898282+github-actions[bot]@users.noreply.github.com
You are using github private e-mail. This prevent proper tracing of who contributed what, please disable it (see Keep my email addresses private).
GitHub page artifact URL GitHub page artifact link (can expire)

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.

Clang-tidy diff report


391 warnings generated.
Suppressed 392 warnings (391 in non-user code, 1 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.

418 warnings generated.
Suppressed 419 warnings (418 in non-user code, 1 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.

Doxygen diff with main

Removed warnings : 5
New warnings : 6
Warnings count : 8187 → 8188 (0.0%)

Detailed changes :
+ src/shammodels/ramses/include/shammodels/ramses/modules/AMRGridRefinementHandler.hpp:45: warning: Member TgridUint (typedef) of class shammodels::basegodunov::modules::AMRGridRefinementHandler is not documented.
- src/shammodels/ramses/include/shammodels/ramses/modules/AMRGridRefinementHandler.hpp:46: warning: Member context (variable) of class shammodels::basegodunov::modules::AMRGridRefinementHandler is not documented.
+ src/shammodels/ramses/include/shammodels/ramses/modules/AMRGridRefinementHandler.hpp:47: warning: Member context (variable) of class shammodels::basegodunov::modules::AMRGridRefinementHandler is not documented.
- src/shammodels/ramses/include/shammodels/ramses/modules/AMRGridRefinementHandler.hpp:47: warning: Member solver_config (variable) of class shammodels::basegodunov::modules::AMRGridRefinementHandler is not documented.
+ src/shammodels/ramses/include/shammodels/ramses/modules/AMRGridRefinementHandler.hpp:48: warning: Member solver_config (variable) of class shammodels::basegodunov::modules::AMRGridRefinementHandler is not documented.
- src/shammodels/ramses/include/shammodels/ramses/modules/AMRGridRefinementHandler.hpp:48: warning: Member storage (variable) of class shammodels::basegodunov::modules::AMRGridRefinementHandler is not documented.
+ src/shammodels/ramses/include/shammodels/ramses/modules/AMRGridRefinementHandler.hpp:49: warning: Member storage (variable) of class shammodels::basegodunov::modules::AMRGridRefinementHandler is not documented.
- src/shammodels/ramses/include/shammodels/ramses/modules/AMRGridRefinementHandler.hpp:50: warning: Member AMRGridRefinementHandler(ShamrockCtx &context, Config &solver_config, Storage &storage) (function) of class shammodels::basegodunov::modules::AMRGridRefinementHandler is not documented.
+ src/shammodels/ramses/include/shammodels/ramses/modules/AMRGridRefinementHandler.hpp:51: warning: Member AMRGridRefinementHandler(ShamrockCtx &context, Config &solver_config, Storage &storage) (function) of class shammodels::basegodunov::modules::AMRGridRefinementHandler is not documented.
- src/shammodels/ramses/include/shammodels/ramses/modules/AMRGridRefinementHandler.hpp:53: warning: Member update_refinement() (function) of class shammodels::basegodunov::modules::AMRGridRefinementHandler is not documented.
+ src/shammodels/ramses/include/shammodels/ramses/modules/AMRGridRefinementHandler.hpp:54: warning: Member update_refinement() (function) of class shammodels::basegodunov::modules::AMRGridRefinementHandler 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