Skip to content

[Stagging][AMR] Try to unify grid related utilities in a helper class#1732

Draft
tdavidcl wants to merge 1 commit intoShamrock-code:mainfrom
tdavidcl:patch-2026-03-31-09-55
Draft

[Stagging][AMR] Try to unify grid related utilities in a helper class#1732
tdavidcl wants to merge 1 commit intoShamrock-code:mainfrom
tdavidcl:patch-2026-03-31-09-55

Conversation

@tdavidcl
Copy link
Copy Markdown
Member

No description provided.

@github-actions
Copy link
Copy Markdown
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

Copy link
Copy Markdown
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 refactors the ComputeCellAABB module by introducing a BlockAMRCartesianGridUtils helper struct to centralize grid-to-float space conversions and cell size calculations. The review feedback identifies a potential precision loss in get_cell_size due to integer division, notes a redundant include for AMRBlock.hpp, and suggests moving the utility struct to a header file to facilitate code reuse across the project.

Comment on lines +23 to +50
namespace shammodels::basegodunov::modules {

template<class Tvec, class TgridVec>
struct BlockAMRCartesianGridUtils {

using Tscal = shambase::VecComponent<Tvec>;
using Tgridscal = shambase::VecComponent<TgridVec>;

static constexpr u32 dim = shambase::VectorProperties<TgridVec>::dimension;

//// grid space function

inline static Tgridscal get_cell_size(TgridVec block_min, TgridVec block_max, u32 Nside) {
return ((block_max - block_min)).x() / Nside;
}

//// real space functions

inline static Tvec to_float_space(TgridVec grid_pos, Tscal dxfact) {
return grid_pos.template convert<Tscal>() * dxfact;
}

inline static Tscal to_float_space(Tgridscal grid_pos, Tscal dxfact) {
return Tscal(grid_pos) * dxfact;
}
};

} // namespace shammodels::basegodunov::modules
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The current implementation of get_cell_size uses integer division if Tgridscal is an integer type (e.g., i64). This changes the behavior from the previous implementation, which used floating-point division, and can lead to precision loss if the block size in grid units is not a multiple of Nside. To maintain accuracy and support non-power-of-two aligned grids, the division should be performed in floating-point space. Additionally, to_float_space should be updated to handle the resulting floating-point grid size without truncating it back to an integer.

namespace shammodels::basegodunov::modules {

    template<class Tvec, class TgridVec>
    struct BlockAMRCartesianGridUtils {

        using Tscal     = shambase::VecComponent<Tvec>;
        using Tgridscal = shambase::VecComponent<TgridVec>;

        static constexpr u32 dim = shambase::VectorProperties<TgridVec>::dimension;

        //// grid space function

        inline static Tscal get_cell_size(TgridVec block_min, TgridVec block_max, u32 Nside) {
            return static_cast<Tscal>((block_max - block_min).x()) / static_cast<Tscal>(Nside);
        }

        //// real space functions

        inline static Tvec to_float_space(TgridVec grid_pos, Tscal dxfact) {
            return grid_pos.template convert<Tscal>() * dxfact;
        }

        inline static Tscal to_float_space(Tscal grid_pos, Tscal dxfact) {
            return grid_pos * dxfact;
        }
    };

} // namespace shammodels::basegodunov::modules


#include "shammodels/ramses/modules/ComputeCellAABB.hpp"
#include "shambackends/kernel_call_distrib.hpp"
#include "shammodels/common/amr/AMRBlock.hpp"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The include for AMRBlock.hpp appears to be redundant as it is not used in this file. Removing unused includes helps maintain code cleanliness and can improve compilation times.

Comment on lines +23 to +26
namespace shammodels::basegodunov::modules {

template<class Tvec, class TgridVec>
struct BlockAMRCartesianGridUtils {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The BlockAMRCartesianGridUtils struct is defined within a .cpp file, which restricts its use to this translation unit. To improve maintainability and follow the repository practice of refactoring shared logic into helper functions, this helper should be moved to a dedicated header file (e.g., include/shammodels/ramses/utils/GridUtils.hpp) so it can be shared across different modules.

References
  1. Refactor duplicated logic into a helper function or lambda to improve readability and maintainability.

@github-actions
Copy link
Copy Markdown
Contributor

Workflow report

workflow report corresponding to commit 738ef2b
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 : 7
Warnings count : 8368 → 8375 (0.1%)

Detailed changes :
+ src/shammodels/ramses/src/modules/ComputeCellAABB.cpp:26: warning: Compound shammodels::basegodunov::modules::BlockAMRCartesianGridUtils is not documented.
+ src/shammodels/ramses/src/modules/ComputeCellAABB.cpp:28: warning: Member Tscal (typedef) of struct shammodels::basegodunov::modules::BlockAMRCartesianGridUtils is not documented.
+ src/shammodels/ramses/src/modules/ComputeCellAABB.cpp:29: warning: Member Tgridscal (typedef) of struct shammodels::basegodunov::modules::BlockAMRCartesianGridUtils is not documented.
+ src/shammodels/ramses/src/modules/ComputeCellAABB.cpp:31: warning: Member dim (variable) of struct shammodels::basegodunov::modules::BlockAMRCartesianGridUtils is not documented.
+ src/shammodels/ramses/src/modules/ComputeCellAABB.cpp:35: warning: Member get_cell_size(TgridVec block_min, TgridVec block_max, u32 Nside) (function) of struct shammodels::basegodunov::modules::BlockAMRCartesianGridUtils is not documented.
+ src/shammodels/ramses/src/modules/ComputeCellAABB.cpp:41: warning: Member to_float_space(TgridVec grid_pos, Tscal dxfact) (function) of struct shammodels::basegodunov::modules::BlockAMRCartesianGridUtils is not documented.
+ src/shammodels/ramses/src/modules/ComputeCellAABB.cpp:45: warning: Member to_float_space(Tgridscal grid_pos, Tscal dxfact) (function) of struct shammodels::basegodunov::modules::BlockAMRCartesianGridUtils 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.

1 participant