opm-grid
LookUpCellCentroid.hh
1 //===========================================================================
2 //
3 // File: LookUpCellCentroid.hh
4 //
5 // Created: Wed July 26 10:48:00 2023
6 //
7 // Author(s): Antonella Ritorto <antonella.ritorto@opm-op.com>
8 //
9 //
10 // $Date$
11 //
12 // $Revision$
13 //
14 //===========================================================================
15 
16 /*
17  Copyright 2023 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 
35 #include <dune/grid/common/mcmgmapper.hh>
36 #include <opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp>
37 #include <opm/grid/common/CartesianIndexMapper.hpp>
38 
39 #include <type_traits>
40 
41 namespace Dune
42 {
43 class CpGrid;
44 }
45 
46 namespace Opm
47 {
48 
49 class EclipseGrid;
50 
57 template <typename Grid, typename GridView>
59 {
64  explicit LookUpCellCentroid(const GridView& gridView,
65  const Dune::CartesianIndexMapper<Grid>& cartMapper,
66  const Opm::EclipseGrid* eclgrid) :
67  gridView_(gridView),
68  cartMapper_(&cartMapper),
69  eclGrid_(eclgrid)
70  {
71  }
72 
83  template<typename GridType = Grid>
84  typename std::enable_if_t<!std::is_same_v<GridType,Dune::CpGrid>, std::array<double,3>>
85  operator()(std::size_t elemIdx) const;
86 
95  // \param [in] elemIdx Element Index.
97  template<typename GridType = Grid>
98  typename std::enable_if_t<std::is_same_v<GridType,Dune::CpGrid>, std::array<double,3>>
99  operator()(std::size_t elemIdx) const;
100 
101 
102  const GridView& gridView_;
103  const Dune::CartesianIndexMapper<Grid>* cartMapper_;
104  const Opm::EclipseGrid* eclGrid_;
105 
106 }; // end LookUpCellCentroid struct
107 }
108 // end namespace Opm
109 
110 
111 template<typename Grid, typename GridView>
112 template<typename GridType>
113 typename std::enable_if_t<!std::is_same_v<GridType,Dune::CpGrid>, std::array<double,3>>
115 {
116  static_assert(std::is_same_v<Grid,GridType>);
117  return this -> eclGrid_ -> getCellCenter(this -> cartMapper_->cartesianIndex(elemIdx));
118 }
119 
120 template<typename Grid, typename GridView>
121 template<typename GridType>
122 typename std::enable_if_t<std::is_same_v<GridType,Dune::CpGrid>,std::array<double,3>>
124 {
125  static_assert(std::is_same_v<Grid,GridType>);
126  return this -> gridView_.grid().getEclCentroid(elemIdx); // Warning! might need to be changed, due to issue in simulators
127 }
LookUpCellCentroid struct - To search cell centroids via element index.
Definition: LookUpCellCentroid.hh:58
The namespace Dune is the main namespace for all Dune code.
Definition: CartesianIndexMapper.hpp:9
Holds the implementation of the CpGrid as a pimple.
Definition: CellQuadrature.cpp:71
Interface class to access the logical Cartesian grid as used in industry standard simulator decks...
Definition: CartesianIndexMapper.hpp:15
LookUpCellCentroid(const GridView &gridView, const Dune::CartesianIndexMapper< Grid > &cartMapper, const Opm::EclipseGrid *eclgrid)
: Constructor taking a GridView, CartesianMapper
Definition: LookUpCellCentroid.hh:64
std::enable_if_t<!std::is_same_v< GridType, Dune::CpGrid >, std::array< double, 3 > > operator()(std::size_t elemIdx) const
: Call operator
Definition: LookUpCellCentroid.hh:114