From 423b6596fbd2cc65a827213969f0ddd456785327 Mon Sep 17 00:00:00 2001 From: Antonella Ritorto Date: Wed, 6 Nov 2024 09:36:40 +0100 Subject: [PATCH] Minor refactorization in LevelCartesianIndexMapper for AluGrid and PolyhedralGrid --- .../flow/AluGridLevelCartesianIndexMapper.hpp | 18 ++++++++++++------ opm/simulators/flow/AluGridVanguard.hpp | 3 ++- opm/simulators/flow/PolyhedralGridVanguard.hpp | 3 ++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/opm/simulators/flow/AluGridLevelCartesianIndexMapper.hpp b/opm/simulators/flow/AluGridLevelCartesianIndexMapper.hpp index a39bee022..bebc0028c 100644 --- a/opm/simulators/flow/AluGridLevelCartesianIndexMapper.hpp +++ b/opm/simulators/flow/AluGridLevelCartesianIndexMapper.hpp @@ -43,6 +43,15 @@ namespace Opm { +// Interface class to access the local Cartesian grid of each level grid (when refinement). +// Further documentation in opm/grid/common/LevelCartesianIndexMapper.hpp +// +// Adapter Design Pattern: In this case, LevelCartesianIndexMapper uses the Object Adapter variant, where it holds an instance +// (here, a std::unique_ptr) of CartesianIndexMapper, the wrapped type. The goal is to provide a standardized interface, allowing +// incompatible functionality (such as Cartesian indexing in the context of refinement that may not be supported - yet -for all +// grid types, like CpGrid) to integrate smoothly within the existing conventions. +// +// Specialization for AluGrid template<> class LevelCartesianIndexMapper> { @@ -56,12 +65,10 @@ class LevelCartesianIndexMapper& cartesianIndexMapper) - : grid_{&grid} - , cartesianIndexMapper_{std::make_unique>(cartesianIndexMapper)} + explicit LevelCartesianIndexMapper(const Dune::CartesianIndexMapper& cartesianIndexMapper) + : cartesianIndexMapper_{std::make_unique>(cartesianIndexMapper)} {} - + const std::array& cartesianDimensions(int level) const { throwIfLevelPositive(level); @@ -93,7 +100,6 @@ class LevelCartesianIndexMapper> cartesianIndexMapper_; void throwIfLevelPositive(int level) const diff --git a/opm/simulators/flow/AluGridVanguard.hpp b/opm/simulators/flow/AluGridVanguard.hpp index 2f65caf5f..52b01ab0a 100644 --- a/opm/simulators/flow/AluGridVanguard.hpp +++ b/opm/simulators/flow/AluGridVanguard.hpp @@ -238,9 +238,10 @@ public: /*! * \brief Returns the object which maps a global element index of the simulation grid * to the corresponding element index of the level logically Cartesian index. + * No refinement is supported for AluGrid so it coincides with CartesianIndexMapper. */ const LevelCartesianIndexMapper levelCartesianIndexMapper() const - { return LevelCartesianIndexMapper(*grid_, *cartesianIndexMapper_); } + { return LevelCartesianIndexMapper(*cartesianIndexMapper_); } /*! * \brief Returns mapper from compressed to cartesian indices for the EQUIL grid diff --git a/opm/simulators/flow/PolyhedralGridVanguard.hpp b/opm/simulators/flow/PolyhedralGridVanguard.hpp index aea3cb0b7..c12e5441b 100644 --- a/opm/simulators/flow/PolyhedralGridVanguard.hpp +++ b/opm/simulators/flow/PolyhedralGridVanguard.hpp @@ -174,9 +174,10 @@ public: /*! * \brief Returns the object which maps a global element index of the simulation grid * to the corresponding element index of the level logically Cartesian index. + * No refinement is supported for AluGrid so it coincides with CartesianIndexMapper. */ const LevelCartesianIndexMapper levelCartesianIndexMapper() const - { return LevelCartesianIndexMapper(*grid_); } + { return LevelCartesianIndexMapper(*cartesianIndexMapper_); } /*! * \brief Returns mapper from compressed to cartesian indices for the EQUIL grid