Skip to content

Commit

Permalink
Minor refactorization in LevelCartesianIndexMapper for AluGrid and Po…
Browse files Browse the repository at this point in the history
…lyhedralGrid
  • Loading branch information
aritorto committed Nov 7, 2024
1 parent 2546d2b commit e05d921
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
18 changes: 12 additions & 6 deletions opm/simulators/flow/AluGridLevelCartesianIndexMapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Dune::ALUGrid<3, 3, Dune::cube, Dune::nonconforming>>
{
Expand All @@ -56,12 +65,10 @@ class LevelCartesianIndexMapper<Dune::ALUGrid<3, 3, Dune::cube, Dune::nonconform
public:
static constexpr int dimension = 3 ;

LevelCartesianIndexMapper(const Grid& grid,
const Dune::CartesianIndexMapper<Grid>& cartesianIndexMapper)
: grid_{&grid}
, cartesianIndexMapper_{std::make_unique<Dune::CartesianIndexMapper<Grid>>(cartesianIndexMapper)}
explicit LevelCartesianIndexMapper(const Dune::CartesianIndexMapper<Grid>& cartesianIndexMapper)
: cartesianIndexMapper_{std::make_unique<Dune::CartesianIndexMapper<Grid>>(cartesianIndexMapper)}
{}

const std::array<int,3>& cartesianDimensions(int level) const
{
throwIfLevelPositive(level);
Expand Down Expand Up @@ -93,7 +100,6 @@ class LevelCartesianIndexMapper<Dune::ALUGrid<3, 3, Dune::cube, Dune::nonconform
}

private:
[[maybe_unused]] const Grid* grid_;
std::unique_ptr<Dune::CartesianIndexMapper<Grid>> cartesianIndexMapper_;

void throwIfLevelPositive(int level) const
Expand Down
3 changes: 2 additions & 1 deletion opm/simulators/flow/AluGridVanguard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,10 @@ class AluGridVanguard : public FlowBaseVanguard<TypeTag>
/*!
* \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
Expand Down
3 changes: 2 additions & 1 deletion opm/simulators/flow/PolyhedralGridVanguard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,10 @@ class PolyhedralGridVanguard : public FlowBaseVanguard<TypeTag>
/*!
* \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
Expand Down

0 comments on commit e05d921

Please sign in to comment.