opm-simulators
AluGridLevelCartesianIndexMapper.hpp
1 //===========================================================================
2 //
3 // File: AluGridLevelCartesianIndexMapper.hpp
4 //
5 // Created: Tue October 01 09:44:00 2024
6 //
7 // Author(s): Antonella Ritorto <antonella.ritorto@opm-op.com>
8 //
9 //
10 // $Date$
11 //
12 // $Revision$
13 //
14 //===========================================================================
15 
16 /*
17  Copyright 2024 Equinor ASA.
18 
19  This file is part of The Open Porous Media project (OPM).
20 
21  OPM is free software: you can redistribute it and/or modify
22  it under the terms of the GNU General Public License as published by
23  the Free Software Foundation, either version 3 of the License, or
24  (at your option) any later version.
25 
26  OPM is distributed in the hope that it will be useful,
27  but WITHOUT ANY WARRANTY; without even the implied warranty of
28  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29  GNU General Public License for more details.
30 
31  You should have received a copy of the GNU General Public License
32  along with OPM. If not, see <http://www.gnu.org/licenses/>.
33 */
34 #ifndef OPM_ALUGRIDLEVELCARTESIANINDEXMAPPER_HPP
35 #define OPM_ALUGRIDLEVELCARTESIANINDEXMAPPER_HPP
36 
37 #include <dune/alugrid/grid.hh>
38 #include <opm/grid/common/LevelCartesianIndexMapper.hpp>
39 #include <opm/simulators/flow/AluGridCartesianIndexMapper.hpp>
40 
41 #include <array>
42 #include <memory>
43 
44 namespace Opm {
45 
46 // Interface class to access the local Cartesian grid of each level grid (when refinement).
47 // Further documentation in opm/grid/common/LevelCartesianIndexMapper.hpp
48 //
49 // Adapter Design Pattern: In this case, LevelCartesianIndexMapper uses the Object Adapter variant, where it holds an instance
50 // (here, a std::unique_ptr) of CartesianIndexMapper, the wrapped type. The goal is to provide a standardized interface, allowing
51 // incompatible functionality (such as Cartesian indexing in the context of refinement that may not be supported - yet -for all
52 // grid types, like CpGrid) to integrate smoothly within the existing conventions.
53 //
54 // Specialization for AluGrid
55 template<>
56 class LevelCartesianIndexMapper<Dune::ALUGrid<3, 3, Dune::cube, Dune::nonconforming>>
57 {
58 
59 #if HAVE_MPI
60  using Grid = Dune::ALUGrid<3, 3, Dune::cube, Dune::nonconforming, Dune::ALUGridMPIComm>;
61 #else
62  using Grid = Dune::ALUGrid<3, 3, Dune::cube, Dune::nonconforming, Dune::ALUGridNoComm>;
63 #endif //HAVE_MPI
64 
65  public:
66  static constexpr int dimension = 3 ;
67 
68  explicit LevelCartesianIndexMapper(const Dune::CartesianIndexMapper<Grid>& cartesianIndexMapper)
69  : cartesianIndexMapper_{std::make_unique<Dune::CartesianIndexMapper<Grid>>(cartesianIndexMapper)}
70  {}
71 
72  const std::array<int,3>& cartesianDimensions(int level) const
73  {
74  throwIfLevelPositive(level);
75  return cartesianIndexMapper_ ->cartesianDimensions();
76  }
77 
78  int cartesianSize(int level) const
79  {
80  throwIfLevelPositive(level);
81  return cartesianIndexMapper_->cartesianSize();
82  }
83 
84  int compressedSize(int level) const
85  {
86  throwIfLevelPositive(level);
87  return cartesianIndexMapper_-> compressedSize();
88  }
89 
90  int cartesianIndex( const int compressedElementIndex, const int level) const
91  {
92  throwIfLevelPositive(level);;
93  return cartesianIndexMapper_->cartesianIndex(compressedElementIndex);
94  }
95 
96  void cartesianCoordinate(const int compressedElementIndex, std::array<int,dimension>& coords, int level) const
97  {
98  throwIfLevelPositive(level);
99  cartesianIndexMapper_->cartesianCoordinate(compressedElementIndex, coords);
100  }
101 
102  private:
103  std::unique_ptr<Dune::CartesianIndexMapper<Grid>> cartesianIndexMapper_;
104 
105  void throwIfLevelPositive(int level) const
106  {
107  if (level) {
108  throw std::invalid_argument("Invalid level.\n");
109  }
110  }
111 };
112 
113 }
114 
115 #endif
Definition: EclGenericWriter.hpp:50
Definition: fvbaseprimaryvariables.hh:161
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
Definition: CollectDataOnIORank.hpp:49