My Project
Loading...
Searching...
No Matches
LookUpData.hh
1//===========================================================================
2//
3// File: LookUpData.hh
4//
5// Created: Tue May 23 14:44: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#ifndef OPM_LOOKUPDATA_HH
35#define OPM_LOOKUPDATA_HH
36
37#include <dune/grid/common/mcmgmapper.hh>
38
39#include <opm/grid/cpgrid/Entity.hpp>
40
41#include <type_traits>
42#include <vector>
43
44namespace Dune
45{
46class CpGrid;
47
48namespace cpgrid
49{
50template<int codim> class Entity;
51}
52
53}
54
55namespace Opm
56{
57
64template <typename Grid, typename GridView>
66{
67public:
70 explicit LookUpData(const GridView& gridView) :
71 gridView_(gridView),
72 elemMapper_(gridView, Dune::mcmgElementLayout())
73 {
74 }
75
88 template<typename EntityType, typename FeatureType>
89 FeatureType operator()(const EntityType& elem, const std::vector<FeatureType>& feature_vec) const;
90
102 template<typename FeatureType>
103 FeatureType operator()(const int& elemIdx, const std::vector<FeatureType>& feature_vec) const;
104
112 template<typename EntityType, typename GridType = Grid>
113 typename std::enable_if_t<!std::is_same_v<GridType,Dune::CpGrid>,int> getOriginIndexFromEntity(const EntityType& elem) const;
114
122 template<typename EntityType, typename GridType = Grid>
123 typename std::enable_if_t<std::is_same_v<GridType,Dune::CpGrid>,int> getOriginIndexFromEntity(const EntityType& elem) const;
124
131 template<typename GridType>
132 typename std::enable_if_t<!std::is_same_v<GridType,Dune::CpGrid>,int> getOriginIndex(const int& elemIdx) const;
133
140 template<typename GridType = Grid>
141 typename std::enable_if_t<std::is_same_v<GridType,Dune::CpGrid>,int> getOriginIndex(const int& elemIdx) const;
142
143
144protected:
145 const GridView& gridView_;
146 Dune::MultipleCodimMultipleGeomTypeMapper<GridView> elemMapper_;
147}; // end LookUpData class
148
155template<typename Grid, typename GridView>
157{
158public:
163 explicit LookUpCartesianData(const GridView& gridView,
164 const Dune::CartesianIndexMapper<Grid>& mapper) :
165 gridView_(gridView),
166 elemMapper_(gridView, Dune::mcmgElementLayout()),
167 cartMapper_(&mapper)
168 {
169 }
170
183 template<typename EntityType, typename FeatureType>
184 FeatureType operator()(const EntityType& elem,const std::vector<FeatureType>& feature_vec) const;
185
197 template<typename FeatureType>
198 FeatureType operator()(const int& elemIdx, const std::vector<FeatureType>& feature_vec) const;
199
207 template<typename EntityType, typename GridType = Grid>
208 typename std::enable_if_t<!std::is_same_v<GridType,Dune::CpGrid>,int> getOriginIndexFromEntity(const EntityType& elem) const;
209
217 template<typename EntityType, typename GridType = Grid>
218 typename std::enable_if_t<std::is_same_v<GridType,Dune::CpGrid>,int> getOriginIndexFromEntity(const EntityType& elem) const;
219
226 template<typename GridType = Grid>
227 typename std::enable_if_t<!std::is_same_v<GridType,Dune::CpGrid>,int> getOriginIndex(const int& elemIdx) const;
228
235 template<typename GridType = Grid>
236 typename std::enable_if_t<std::is_same_v<GridType,Dune::CpGrid>,int> getOriginIndex(const int& elemIdx) const;
237
238
239protected:
240 const GridView& gridView_;
241 Dune::MultipleCodimMultipleGeomTypeMapper<GridView> elemMapper_;
242 const Dune::CartesianIndexMapper<Grid>* cartMapper_;
243}; // end LookUpCartesianData class
244}
245// end namespace Opm
246
247
248
250
251template<typename Grid, typename GridView>
252template<typename EntityType, typename FeatureType>
253FeatureType Opm::LookUpData<Grid,GridView>::operator()(const EntityType& elem, const std::vector<FeatureType>& feature_vec) const
254{
255 assert( (0 <= this->getOriginIndexFromEntity<EntityType,Grid>(elem)) &&
256 (static_cast<int>(feature_vec.size()) > this->getOriginIndexFromEntity<EntityType,Grid>(elem)) );
257 return feature_vec[this->getOriginIndexFromEntity<EntityType,Grid>(elem)];
258}
259
260template<typename Grid, typename GridView>
261template<typename FeatureType>
262FeatureType Opm::LookUpData<Grid,GridView>::operator()(const int& elemIdx, const std::vector<FeatureType>& feature_vec) const
263{
264 assert(0 <= this-> getOriginIndex<Grid>(elemIdx) && static_cast<int>(feature_vec.size()) > this-> getOriginIndex<Grid>(elemIdx));
265 return feature_vec[getOriginIndex<Grid>(elemIdx)];
266}
267
268template<typename Grid, typename GridView>
269template<typename EntityType, typename GridType>
270typename std::enable_if_t<!std::is_same_v<GridType,Dune::CpGrid>,int>
272{
273 static_assert(std::is_same_v<Grid,GridType>);
274 return this-> elemMapper_.index(elem);
275}
276
277template<typename Grid, typename GridView>
278template<typename EntityType, typename GridType>
279typename std::enable_if_t<std::is_same_v<GridType,Dune::CpGrid>,int>
281{
282 static_assert(std::is_same_v<Grid,GridType>);
283 return elem.getOrigin().index();
284}
285
286template<typename Grid, typename GridView>
287template<typename GridType>
288typename std::enable_if_t<!std::is_same_v<GridType,Dune::CpGrid>,int>
290{
291 static_assert(std::is_same_v<Grid,GridType>);
292 return elemIdx;
293}
294
295template<typename Grid, typename GridView>
296template<typename GridType>
297typename std::enable_if_t<std::is_same_v<GridType,Dune::CpGrid>,int>
299{
300 static_assert(std::is_same_v<Grid,GridType>);
301 const auto& elem = Dune::cpgrid::Entity<0>(*(gridView_.grid().current_view_data_), elemIdx, true);
302 return elem.getOrigin().index(); // getOrign() returns parent Entity or the equivalent Entity in level 0.
303}
304
305
306
308
309template<typename Grid, typename GridView>
310template<typename EntityType, typename FeatureType>
312 (const EntityType& elem, const std::vector<FeatureType>& feature_vec) const
313{
314 assert(cartMapper_);
315 assert( (0 <= this->getOriginIndexFromEntity<EntityType,Grid>(elem)) &&
316 (static_cast<int>(feature_vec.size()) > this-> getOriginIndexFromEntity<EntityType,Grid>(elem)) );
317 return feature_vec[cartMapper_-> cartesianIndex(this->elemMapper_.index(elem))];
318}
319
320template<typename Grid, typename GridView>
321template<typename FeatureType>
322FeatureType Opm::LookUpCartesianData<Grid,GridView>::operator()(const int& elemIdx, const std::vector<FeatureType>& feature_vec) const
323{
324 assert(cartMapper_);
325 assert(0 <= this->getOriginIndex<Grid>(elemIdx) &&
326 static_cast<int>(feature_vec.size()) > this-> getOriginIndex<Grid>(elemIdx));
327 return feature_vec[cartMapper_-> cartesianIndex(elemIdx)];
328}
329
330template<typename Grid, typename GridView>
331template<typename EntityType, typename GridType>
332typename std::enable_if_t<!std::is_same_v<GridType,Dune::CpGrid>,int>
334{
335 static_assert(std::is_same_v<Grid,GridType>);
336 return elemMapper_.index(elem);
337}
338
339template<typename Grid, typename GridView>
340template<typename EntityType, typename GridType>
341typename std::enable_if_t<std::is_same_v<GridType,Dune::CpGrid>,int>
343{
344 static_assert(std::is_same_v<Grid,GridType>);
345 return elem.getOrigin().index();
346}
347
348template<typename Grid, typename GridView>
349template<typename GridType>
350typename std::enable_if_t<!std::is_same_v<GridType,Dune::CpGrid>,int>
352{
353 static_assert(std::is_same_v<Grid,GridType>);
354 return elemIdx;
355}
356
357template<typename Grid, typename GridView>
358template<typename GridType>
359typename std::enable_if_t<std::is_same_v<GridType,Dune::CpGrid>,int>
361{
362 static_assert(std::is_same_v<Grid,GridType>);
363 const auto& elem = Dune::cpgrid::Entity<0>(*(gridView_.grid().current_view_data_), elemIdx, true);
364 return elem.getOrigin().index(); // getOrign() returns parent Entity or the equivalent Entity in level 0.
365}
366
367#endif
Interface class to access the logical Cartesian grid as used in industry standard simulator decks.
Definition CartesianIndexMapper.hpp:16
Definition Entity.hpp:65
LookUpCartesianData - To search data via CartesianIndex (cartesianMapper)
Definition LookUpData.hh:157
FeatureType operator()(const EntityType &elem, const std::vector< FeatureType > &feature_vec) const
: Call operator taking an EntityObject and a FeatureVector.
Definition LookUpData.hh:312
std::enable_if_t<!std::is_same_v< GridType, Dune::CpGrid >, int > getOriginIndex(const int &elemIdx) const
: For general grids, it retunrs the same element index.
Definition LookUpData.hh:351
LookUpCartesianData(const GridView &gridView, const Dune::CartesianIndexMapper< Grid > &mapper)
: Constructor taking a GridView and a CartesianIndexMapper
Definition LookUpData.hh:163
std::enable_if_t<!std::is_same_v< GridType, Dune::CpGrid >, int > getOriginIndexFromEntity(const EntityType &elem) const
: For general grids, it retunrs the same Entity index.
Definition LookUpData.hh:333
LookUpData class - To search data via element index.
Definition LookUpData.hh:66
FeatureType operator()(const EntityType &elem, const std::vector< FeatureType > &feature_vec) const
: Call operator taking an EntityObject and a FeatureVector.
Definition LookUpData.hh:253
std::enable_if_t<!std::is_same_v< GridType, Dune::CpGrid >, int > getOriginIndexFromEntity(const EntityType &elem) const
: For general grids, it retunrs the same Entity index.
Definition LookUpData.hh:271
LookUpData(const GridView &gridView)
: Constructor taking a GridView
Definition LookUpData.hh:70
std::enable_if_t<!std::is_same_v< GridType, Dune::CpGrid >, int > getOriginIndex(const int &elemIdx) const
: For general grids, it retunrs the same element index.
Definition LookUpData.hh:289
Copyright 2019 Equinor AS.
Definition CartesianIndexMapper.hpp:10
Holds the implementation of the CpGrid as a pimple.
Definition CellQuadrature.cpp:68