From 738ef2b97b176a4d42995cc2630e9adbdf9a99d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20David--Cl=C3=A9ris?= Date: Tue, 31 Mar 2026 15:53:31 +0200 Subject: [PATCH] [Stagging][AMR] Try to unify grid related utilities in a helper class --- .../ramses/src/modules/ComputeCellAABB.cpp | 49 ++++++++++++++----- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/src/shammodels/ramses/src/modules/ComputeCellAABB.cpp b/src/shammodels/ramses/src/modules/ComputeCellAABB.cpp index b44d7a4bf0..fdb59fbad8 100644 --- a/src/shammodels/ramses/src/modules/ComputeCellAABB.cpp +++ b/src/shammodels/ramses/src/modules/ComputeCellAABB.cpp @@ -16,15 +16,47 @@ #include "shammodels/ramses/modules/ComputeCellAABB.hpp" #include "shambackends/kernel_call_distrib.hpp" +#include "shammodels/common/amr/AMRBlock.hpp" #include "shamrock/patch/PatchDataField.hpp" #include "shamsys/NodeInstance.hpp" +namespace shammodels::basegodunov::modules { + + template + struct BlockAMRCartesianGridUtils { + + using Tscal = shambase::VecComponent; + using Tgridscal = shambase::VecComponent; + + static constexpr u32 dim = shambase::VectorProperties::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() * dxfact; + } + + inline static Tscal to_float_space(Tgridscal grid_pos, Tscal dxfact) { + return Tscal(grid_pos) * dxfact; + } + }; + +} // namespace shammodels::basegodunov::modules + namespace { template struct KernelComputeCellAABB { using Tscal = shambase::VecComponent; + using Grid = shammodels::basegodunov::modules::BlockAMRCartesianGridUtils; + inline static void kernel( const shambase::DistributedData> &spans_block_min, @@ -40,8 +72,6 @@ namespace { const shambase::DistributedData &block_counts = sizes; - Tscal one_over_Nside = 1. / block_nside; - Tscal dxfact = grid_coord_to_pos_fact; sham::distributed_data_kernel_call( @@ -49,24 +79,19 @@ namespace { sham::DDMultiRef{spans_block_min, spans_block_max}, sham::DDMultiRef{spans_block_cell_sizes, spans_cell0block_aabb_lower}, block_counts, - [one_over_Nside, dxfact]( + [dxfact, block_nside]( u32 i, const TgridVec *__restrict acc_block_min, const TgridVec *__restrict acc_block_max, - Tscal *__restrict bsize, + Tscal *__restrict csize, Tvec *__restrict aabb_lower) { TgridVec lower = acc_block_min[i]; TgridVec upper = acc_block_max[i]; - Tvec lower_flt = lower.template convert() * dxfact; - Tvec upper_flt = upper.template convert() * dxfact; - - Tvec block_cell_size = (upper_flt - lower_flt) * one_over_Nside; - - Tscal res = block_cell_size.x(); + auto cell_size = Grid::get_cell_size(lower, upper, block_nside); - bsize[i] = res; - aabb_lower[i] = lower_flt; + csize[i] = Grid::to_float_space(cell_size, dxfact); + aabb_lower[i] = Grid::to_float_space(lower, dxfact); }); } };