34#ifndef OPM_LOOKUPDATA_HH
35#define OPM_LOOKUPDATA_HH
37#include <dune/grid/common/mcmgmapper.hh>
39#include <opm/input/eclipse/EclipseState/Grid/FieldPropsManager.hpp>
61template <
typename Gr
id,
typename Gr
idView>
71 explicit LookUpData(
const GridView& gridView,
bool isFieldPropInLgr =
false) :
83 template<
typename FieldPropType>
84 FieldPropType
operator()(
const int& elemIdx,
const std::vector<FieldPropType>& fieldProp)
const;
91 template<
typename EntityType,
typename FieldPropType>
92 typename std::enable_if_t<!std::is_same_v<EntityType, unsigned int>, FieldPropType>
93 operator()(
const EntityType& elem,
const std::vector<FieldPropType>& fieldProp)
const;
97 const std::string& propString)
const;
100 template<
typename IntType>
102 const std::string& propString,
103 const bool& needsTranslation,
104 std::function<
void(IntType,
int)> valueCheck = [](IntType,
int){})
const;
107 template<
typename ElemOrIndex>
109 const std::string& propString,
110 const ElemOrIndex& elemOrIndex)
const;
113 template<
typename ElemOrIndex>
114 int fieldPropInt(
const FieldPropsManager& fieldPropsManager,
115 const std::string& propString,
116 const ElemOrIndex& elemOrIndex)
const;
122 template<
typename EntityType,
typename Gr
idType = Gr
id>
123 typename std::enable_if_t<!std::is_same_v<GridType,Dune::CpGrid> && !std::is_same_v<EntityType, unsigned int>,
int>
134 template<
typename EntityType,
typename Gr
idType = Gr
id>
135 typename std::enable_if_t<std::is_same_v<GridType,Dune::CpGrid> && !std::is_same_v<EntityType, unsigned int>,
int>
142 template<
typename Gr
idType>
143 typename std::enable_if_t<!std::is_same_v<GridType,Dune::CpGrid>,
int>
154 template<
typename Gr
idType = Gr
id>
155 typename std::enable_if_t<std::is_same_v<GridType,Dune::CpGrid>,
int>
171template<
typename Gr
id,
typename Gr
idView>
185 bool isFieldPropInLgr =
false) :
198 template<
typename FieldPropType>
199 FieldPropType
operator()(
const int& elemIdx,
const std::vector<FieldPropType>& fieldProp)
const;
206 template<
typename EntityType,
typename FieldPropType>
207 typename std::enable_if_t<!std::is_same_v<EntityType, unsigned int>, FieldPropType>
208 operator()(
const EntityType& elem,
const std::vector<FieldPropType>& fieldProp)
const;
212 const std::string& propString)
const;
215 template<
typename IntType>
217 const std::string& propString,
218 const bool& needsTranslation,
219 std::function<
void(IntType,
int)> valueCheck = [](IntType,
int){})
const;
222 template<
typename ElemOrIndex>
224 const std::string& propString,
225 const ElemOrIndex& elemOrIndex)
const;
228 template<
typename ElemOrIndex>
229 int fieldPropInt(
const FieldPropsManager& fieldPropsManager,
230 const std::string& propString,
231 const ElemOrIndex& elemOrIndex)
const;
237 template<
typename EntityType,
typename Gr
idType = Gr
id>
238 typename std::enable_if_t<!std::is_same_v<GridType,Dune::CpGrid> && !std::is_same_v<EntityType, unsigned int>,
int>
248 template<
typename EntityType,
typename Gr
idType = Gr
id>
249 typename std::enable_if_t<std::is_same_v<GridType,Dune::CpGrid> && !std::is_same_v<EntityType, unsigned int>,
int>
256 template<
typename Gr
idType = Gr
id>
257 typename std::enable_if_t<!std::is_same_v<GridType,Dune::CpGrid>,
int>
267 template<
typename Gr
idType = Gr
id>
268 typename std::enable_if_t<std::is_same_v<GridType,Dune::CpGrid>,
int>
284template<
typename Gr
id,
typename Gr
idView>
285template<
typename FieldPropType>
287 const std::vector<FieldPropType>& fieldProp)
const
289 const auto& fieldPropIdx = this->getFieldPropIdx<Grid>(elemIdx);
290 assert(0 <= fieldPropIdx &&
static_cast<int>(fieldProp.size()) > fieldPropIdx);
291 return fieldProp[fieldPropIdx];
294template<
typename Gr
id,
typename Gr
idView>
295template<
typename EntityType,
typename FieldPropType>
296typename std::enable_if_t<!std::is_same_v<EntityType, unsigned int>,FieldPropType>
298 const std::vector<FieldPropType>& fieldProp)
const
300 const auto& fieldPropIdx = this->getFieldPropIdx<EntityType,Grid>(elem);
301 assert( (0 <= fieldPropIdx) && (
static_cast<int>(fieldProp.size()) > fieldPropIdx));
302 return fieldProp[fieldPropIdx];
305template<
typename Gr
id,
typename Gr
idView>
307 const std::string& propString)
const
309 std::vector<double> fieldPropOnLeaf;
310 unsigned int numElements = gridView_.size(0);
311 fieldPropOnLeaf.resize(numElements);
312 const auto& fieldProp = fieldPropsManager.get_double(propString);
313 if ( (propString ==
"PORV") && (gridView_.grid().maxLevel() > 0)) {
318 for (
const auto& element : elements(gridView_)) {
319 const auto& elemIdx = this-> elemMapper_.index(element);
320 const auto& fieldPropIdx = this->getFieldPropIdx<Grid>(elemIdx);
321 if (element.hasFather()) {
322 const auto fatherVolume = element.father().geometry().volume();
323 const auto& elemVolume = element.geometry().volume();
324 fieldPropOnLeaf[elemIdx] = fieldProp[fieldPropIdx] * elemVolume / fatherVolume;
327 fieldPropOnLeaf[elemIdx] = fieldProp[fieldPropIdx];
332 for (
const auto& element : elements(gridView_)) {
333 const auto& elemIdx = this-> elemMapper_.index(element);
334 const auto& fieldPropIdx = this->getFieldPropIdx<Grid>(elemIdx);
335 fieldPropOnLeaf[elemIdx] = fieldProp[fieldPropIdx];
338 return fieldPropOnLeaf;
341template<
typename Gr
id,
typename Gr
idView>
342template<
typename IntType>
344 const std::string& propString,
345 const bool& needsTranslation,
346 std::function<
void(IntType,
int)> valueCheck)
const
348 std::vector<IntType> fieldPropOnLeaf;
349 unsigned int numElements = gridView_.size(0);
350 fieldPropOnLeaf.resize(numElements);
351 const auto& fieldProp = fieldPropsManager.get_int(propString);
352 for (
const auto& element : elements(gridView_)) {
353 const auto& elemIdx = this-> elemMapper_.index(element);
354 const auto& fieldPropIdx = this->getFieldPropIdx<Grid>(elemIdx);
355 fieldPropOnLeaf[elemIdx] = fieldProp[fieldPropIdx] - needsTranslation;
356 valueCheck(fieldProp[fieldPropIdx], fieldPropIdx);
358 return fieldPropOnLeaf;
361template<
typename Gr
id,
typename Gr
idView>
362template<
typename ElemOrIndex>
364 const std::string& propString,
365 const ElemOrIndex& elemOrIndex)
const
367 const auto& fieldPropVec = fieldPropsManager.get_double(propString);
368 return this ->operator()(elemOrIndex,fieldPropVec);
371template<
typename Gr
id,
typename Gr
idView>
372template<
typename ElemOrIndex>
374 const std::string& propString,
375 const ElemOrIndex& elemOrIndex)
const
377 const auto& fieldPropVec = fieldPropsManager.get_int(propString);
378 return this ->operator()(elemOrIndex,fieldPropVec);
381template<
typename Gr
id,
typename Gr
idView>
382template<
typename EntityType,
typename Gr
idType>
383typename std::enable_if_t<!std::is_same_v<GridType,Dune::CpGrid> && !std::is_same_v<EntityType, unsigned int>,
int>
386 static_assert(std::is_same_v<Grid,GridType>);
387 assert(elem.level() == 0);
388 return this-> elemMapper_.index(elem);
391template<
typename Gr
id,
typename Gr
idView>
392template<
typename EntityType,
typename Gr
idType>
393typename std::enable_if_t<std::is_same_v<GridType,Dune::CpGrid> && !std::is_same_v<EntityType, unsigned int>,
int>
396 static_assert(std::is_same_v<Grid,GridType>);
397 static_assert(std::is_same_v<EntityType,Dune::cpgrid::Entity<0>>);
398 if (isFieldPropInLgr_ && elem.level()) {
400 return elem.getLevelElem().index();
403 return elem.getOrigin().index();
407template<
typename Gr
id,
typename Gr
idView>
408template<
typename Gr
idType>
409typename std::enable_if_t<!std::is_same_v<GridType,Dune::CpGrid>,
int>
412 static_assert(std::is_same_v<Grid,GridType>);
414 assert(gridView_.grid().maxLevel() == 0);
418template<
typename Gr
id,
typename Gr
idView>
419template<
typename Gr
idType>
420typename std::enable_if_t<std::is_same_v<GridType,Dune::CpGrid>,
int>
423 static_assert(std::is_same_v<Grid,GridType>);
425 if (isFieldPropInLgr_ && elem.level()) {
427 return elem.getLevelElem().index();
430 return elem.getOrigin().index();
438template<
typename Gr
id,
typename Gr
idView>
439template<
typename FieldPropType>
441 const std::vector<FieldPropType>& fieldProp)
const
444 const auto fieldPropCartIdx = this->getFieldPropCartesianIdx<Grid>(elemIdx);
445 assert(0 <= fieldPropCartIdx && (
static_cast<int>(fieldProp.size()) > fieldPropCartIdx));
446 return fieldProp[fieldPropCartIdx];
449template<
typename Gr
id,
typename Gr
idView>
450template<
typename EntityType,
typename FieldPropType>
451typename std::enable_if_t<!std::is_same_v<EntityType, unsigned int>,FieldPropType>
453 const std::vector<FieldPropType>& fieldProp)
const
456 const auto fieldPropCartIdx = this->getFieldPropCartesianIdx<EntityType,Grid>(elem);
457 assert( (0 <= fieldPropCartIdx) && (
static_cast<int>(fieldProp.size()) > fieldPropCartIdx) );
458 return fieldProp[fieldPropCartIdx];
461template<
typename Gr
id,
typename Gr
idView>
463 const std::string& propString)
const
465 std::vector<double> fieldPropOnLeaf;
466 unsigned int numElements = gridView_.size(0);
467 fieldPropOnLeaf.resize(numElements);
468 const auto& fieldProp = fieldPropsManager.get_double(propString);
469 for (
unsigned int elemIdx = 0; elemIdx < numElements; ++elemIdx) {
470 const auto fieldPropCartIdx = this->getFieldPropCartesianIdx<Grid>(elemIdx);
471 fieldPropOnLeaf[elemIdx] = fieldProp[fieldPropCartIdx];
473 return fieldPropOnLeaf;
476template<
typename Gr
id,
typename Gr
idView>
477template<
typename IntType>
479 const std::string& propString,
480 const bool& needsTranslation,
481 std::function<
void(IntType,
int)> valueCheck)
const
483 std::vector<IntType> fieldPropOnLeaf;
484 unsigned int numElements = gridView_.size(0);
485 fieldPropOnLeaf.resize(numElements);
486 const auto& fieldProp = fieldPropsManager.get_int(propString);
487 for (
unsigned elemIdx = 0; elemIdx < numElements; ++elemIdx) {
488 const auto fieldPropCartIdx = this->getFieldPropCartesianIdx<Grid>(elemIdx);
489 fieldPropOnLeaf[elemIdx] = fieldProp[fieldPropCartIdx] - needsTranslation;
490 valueCheck(fieldProp[fieldPropCartIdx], fieldPropCartIdx);
492 return fieldPropOnLeaf;
495template<
typename Gr
id,
typename Gr
idView>
496template<
typename ElemOrIndex>
498 const std::string& propString,
499 const ElemOrIndex& elemOrIndex)
const
501 const auto& fieldPropVec = fieldPropsManager.get_double(propString);
502 return this ->operator()(elemOrIndex,fieldPropVec);
505template<
typename Gr
id,
typename Gr
idView>
506template<
typename ElemOrIndex>
508 const std::string& propString,
509 const ElemOrIndex& elemOrIndex)
const
511 const auto& fieldPropVec = fieldPropsManager.get_int(propString);
512 return this ->operator()(elemOrIndex,fieldPropVec);
515template<
typename Gr
id,
typename Gr
idView>
516template<
typename EntityType,
typename Gr
idType>
517typename std::enable_if_t<!std::is_same_v<GridType,Dune::CpGrid> && !std::is_same_v<EntityType, unsigned int>,
int>
520 static_assert(std::is_same_v<Grid,GridType>);
522 assert(gridView_.grid().maxLevel() == 0);
523 return cartMapper_-> cartesianIndex(this->elemMapper_.index(elem));
526template<
typename Gr
id,
typename Gr
idView>
527template<
typename EntityType,
typename Gr
idType>
528typename std::enable_if_t<std::is_same_v<GridType,Dune::CpGrid> && !std::is_same_v<EntityType, unsigned int>,
int>
531 static_assert(std::is_same_v<Grid,GridType>);
532 if (isFieldPropInLgr_ && elem.level()) {
533 return elem.getLevelCartesianIdx();
536 return cartMapper_-> cartesianIndex(this->elemMapper_.index(elem));
540template<
typename Gr
id,
typename Gr
idView>
541template<
typename Gr
idType>
542typename std::enable_if_t<!std::is_same_v<GridType,Dune::CpGrid>,
int>
545 static_assert(std::is_same_v<Grid,GridType>);
546 return cartMapper_-> cartesianIndex(elemIdx);
549template<
typename Gr
id,
typename Gr
idView>
550template<
typename Gr
idType>
551typename std::enable_if_t<std::is_same_v<GridType,Dune::CpGrid>,
int>
554 static_assert(std::is_same_v<Grid,GridType>);
556 return this -> getFieldPropCartesianIdx<Dune::cpgrid::Entity<0>,
Dune::CpGrid>(elem);
Interface class to access the logical Cartesian grid as used in industry standard simulator decks.
Definition: common/CartesianIndexMapper.hpp:16
[ provides Dune::Grid ]
Definition: CpGrid.hpp:238
Definition: LookUpData.hh:173
FieldPropType operator()(const int &elemIdx, const std::vector< FieldPropType > &fieldProp) const
: Get field property for an element in the leaf grid view, from a vector, via Cartesian Index.
Definition: LookUpData.hh:440
const GridView & gridView_
Definition: LookUpData.hh:272
std::vector< double > assignFieldPropsDoubleOnLeaf(const FieldPropsManager &fieldPropsManager, const std::string &propString) const
: Get field property of type double from field properties manager by name.
Definition: LookUpData.hh:462
int fieldPropInt(const FieldPropsManager &fieldPropsManager, const std::string &propString, const ElemOrIndex &elemOrIndex) const
: Get property of type int from field properties manager by name, via element or its index.
Definition: LookUpData.hh:507
LookUpCartesianData(const GridView &gridView, const Dune::CartesianIndexMapper< Grid > &mapper, bool isFieldPropInLgr=false)
: Constructor taking a GridView, a CartesianIndexMapper, and a bool
Definition: LookUpData.hh:183
double fieldPropDouble(const FieldPropsManager &fieldPropsManager, const std::string &propString, const ElemOrIndex &elemOrIndex) const
: Get property of type double from field properties manager by name, via element or its index.
Definition: LookUpData.hh:497
std::enable_if_t<!std::is_same_v< GridType, Dune::CpGrid > &&!std::is_same_v< EntityType, unsigned int >, int > getFieldPropCartesianIdx(const EntityType &elem) const
: Return the same element index for all grids different from CpGrid.
Definition: LookUpData.hh:518
const Dune::CartesianIndexMapper< Grid > * cartMapper_
Definition: LookUpData.hh:274
std::vector< IntType > assignFieldPropsIntOnLeaf(const FieldPropsManager &fieldPropsManager, const std::string &propString, const bool &needsTranslation, std::function< void(IntType, int)> valueCheck=[](IntType, int){}) const
: Get field property of type int from field properties manager by name.
Definition: LookUpData.hh:478
bool isFieldPropInLgr_
Definition: LookUpData.hh:275
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > elemMapper_
Definition: LookUpData.hh:273
Definition: LookUpData.hh:63
bool isFieldPropInLgr_
Definition: LookUpData.hh:162
std::vector< double > assignFieldPropsDoubleOnLeaf(const FieldPropsManager &fieldPropsManager, const std::string &propString) const
: Get field property of type double from field properties manager by name.
Definition: LookUpData.hh:306
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > elemMapper_
Definition: LookUpData.hh:161
const GridView & gridView_
Definition: LookUpData.hh:160
LookUpData(const GridView &gridView, bool isFieldPropInLgr=false)
: Constructor taking a GridView and a bool
Definition: LookUpData.hh:71
std::vector< IntType > assignFieldPropsIntOnLeaf(const FieldPropsManager &fieldPropsManager, const std::string &propString, const bool &needsTranslation, std::function< void(IntType, int)> valueCheck=[](IntType, int){}) const
: Get field property of type int from field properties manager by name.
Definition: LookUpData.hh:343
std::enable_if_t<!std::is_same_v< GridType, Dune::CpGrid > &&!std::is_same_v< EntityType, unsigned int >, int > getFieldPropIdx(const EntityType &elem) const
: Return the same element index for all grids different from CpGrid.
Definition: LookUpData.hh:384
int fieldPropInt(const FieldPropsManager &fieldPropsManager, const std::string &propString, const ElemOrIndex &elemOrIndex) const
: Get property of type int from field properties manager by name, via element.
Definition: LookUpData.hh:373
double fieldPropDouble(const FieldPropsManager &fieldPropsManager, const std::string &propString, const ElemOrIndex &elemOrIndex) const
: Get property of type double from field properties manager by name, via element or its index.
Definition: LookUpData.hh:363
FieldPropType operator()(const int &elemIdx, const std::vector< FieldPropType > &fieldProp) const
: Get field propertry for an element in the leaf grid view, from a vector and element index.
Definition: LookUpData.hh:286
The namespace Dune is the main namespace for all Dune code.
Definition: common/CartesianIndexMapper.hpp:10
Holds the implementation of the CpGrid as a pimple.
Definition: CellQuadrature.hpp:26