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) :
89 template<
class ElementOrIndex,
class FieldProperties>
90 auto operator()(
const ElementOrIndex& elementOrIdx,
const FieldProperties& fieldProp)
const;
94 const std::string& propString)
const;
97 template<
typename IntType>
99 const std::string& propString,
100 const bool& needsTranslation,
101 std::function<
void(IntType,
int)> valueCheck = [](IntType,
int){})
const;
104 template<
typename ElemOrIndex>
106 const std::string& propString,
107 const ElemOrIndex& elemOrIndex)
const;
110 template<
typename ElemOrIndex>
111 int fieldPropInt(
const FieldPropsManager& fieldPropsManager,
112 const std::string& propString,
113 const ElemOrIndex& elemOrIndex)
const;
116 template<
typename ElementType>
152 template<
typename Gr
idType,
typename ElementType>
167template<
typename Gr
id,
typename Gr
idView>
181 bool isFieldPropInLgr =
false) :
197 template<
class ElementOrIndex,
class FieldProperties>
198 auto operator()(
const ElementOrIndex& elemIdx,
const FieldProperties& fieldProp)
const;
203 const std::string& propString)
const;
206 template<
typename IntType>
208 const std::string& propString,
209 const bool& needsTranslation,
210 std::function<
void(IntType,
int)> valueCheck = [](IntType,
int){})
const;
213 template<
typename ElemOrIndex>
215 const std::string& propString,
216 const ElemOrIndex& elemOrIndex)
const;
219 template<
typename ElemOrIndex>
220 int fieldPropInt(
const FieldPropsManager& fieldPropsManager,
221 const std::string& propString,
222 const ElemOrIndex& elemOrIndex)
const;
225 template<
class ElementType>
265 template<
class Gr
idType,
class ElementType>
280template<
typename Gr
id,
typename Gr
idView>
281template<
class ElementOrIndex,
class FieldProperties>
283 const FieldProperties& fieldProp)
const
285 const auto& fieldPropIdx = this->getFieldPropIdx(elemIdx);
286 assert(0 <= fieldPropIdx &&
static_cast<int>(fieldProp.size()) > fieldPropIdx);
287 return fieldProp[fieldPropIdx];
290template<
typename Gr
id,
typename Gr
idView>
292 const std::string& propString)
const
294 std::vector<double> fieldPropOnLeaf;
295 unsigned int numElements = gridView_.size(0);
296 fieldPropOnLeaf.resize(numElements);
297 const auto& fieldProp = fieldPropsManager.get_double(propString);
298 if ( (propString ==
"PORV") && (gridView_.grid().maxLevel() > 0)) {
303 for (
const auto& element : elements(gridView_)) {
304 const auto& elemIdx = this-> elemMapper_.index(element);
305 const auto& fieldPropIdx = this->getFieldPropIdx<Grid>(elemIdx);
306 if (element.hasFather()) {
307 const auto fatherVolume = element.father().geometry().volume();
308 const auto& elemVolume = element.geometry().volume();
309 fieldPropOnLeaf[elemIdx] = fieldProp[fieldPropIdx] * elemVolume / fatherVolume;
312 fieldPropOnLeaf[elemIdx] = fieldProp[fieldPropIdx];
317 for (
const auto& element : elements(gridView_)) {
318 const auto& elemIdx = this-> elemMapper_.index(element);
319 const auto& fieldPropIdx = this->getFieldPropIdx<Grid>(elemIdx);
320 fieldPropOnLeaf[elemIdx] = fieldProp[fieldPropIdx];
323 return fieldPropOnLeaf;
326template<
typename Gr
id,
typename Gr
idView>
327template<
typename IntType>
329 const std::string& propString,
330 const bool& needsTranslation,
331 std::function<
void(IntType,
int)> valueCheck)
const
333 std::vector<IntType> fieldPropOnLeaf;
334 unsigned int numElements = gridView_.size(0);
335 fieldPropOnLeaf.resize(numElements);
336 const auto& fieldProp = fieldPropsManager.get_int(propString);
337 for (
const auto& element : elements(gridView_)) {
338 const auto& elemIdx = this-> elemMapper_.index(element);
339 const auto& fieldPropIdx = this->getFieldPropIdx(elemIdx);
340 fieldPropOnLeaf[elemIdx] = fieldProp[fieldPropIdx] - needsTranslation;
341 valueCheck(fieldProp[fieldPropIdx], fieldPropIdx);
343 return fieldPropOnLeaf;
346template<
typename Gr
id,
typename Gr
idView>
347template<
typename ElemOrIndex>
349 const std::string& propString,
350 const ElemOrIndex& elemOrIndex)
const
352 const auto& fieldPropVec = fieldPropsManager.get_double(propString);
353 return this ->operator()(elemOrIndex,fieldPropVec);
356template<
typename Gr
id,
typename Gr
idView>
357template<
typename ElemOrIndex>
359 const std::string& propString,
360 const ElemOrIndex& elemOrIndex)
const
362 const auto& fieldPropVec = fieldPropsManager.get_int(propString);
363 return this ->operator()(elemOrIndex,fieldPropVec);
366template<
typename Gr
id,
typename Gr
idView>
367template<
typename ElementType>
369 return this->
template getFieldPropIdx<Grid, ElementType>(elementOrIndex);
372template<
typename Gr
id,
typename Gr
idView>
373template<
typename Gr
idType,
typename IndexType>
376 constexpr static bool isIntegral = std::is_integral_v<IndexType>;
377 if constexpr (std::is_same_v<GridType, Dune::CpGrid>) {
378 static_assert(std::is_same_v<Grid,GridType>);
379 if constexpr (isIntegral) {
381 if (isFieldPropInLgr_ && elem.level()) {
383 return elem.getLevelElem().index();
386 return elem.getOrigin().index();
389 static_assert(std::is_same_v<IndexType, Dune::cpgrid::Entity<0>>);
390 if (isFieldPropInLgr_ && elementOrIndex.level()) {
392 return elementOrIndex.getLevelElem().index();
395 return elementOrIndex.getOrigin().index();
399 static_assert(std::is_same_v<Grid,GridType>);
400 if constexpr (isIntegral) {
402 assert(gridView_.grid().maxLevel() == 0);
403 return elementOrIndex;
405 assert(elementOrIndex.level() == 0);
406 return this-> elemMapper_.index(elementOrIndex);
414template<
typename Gr
id,
typename Gr
idView>
415template<
typename IndexType,
typename FieldPropType>
417 const FieldPropType& fieldProp)
const
420 const auto fieldPropCartIdx = this->getFieldPropCartesianIdx<Grid>(elementOrIndex);
421 assert(0 <= fieldPropCartIdx && (
static_cast<int>(fieldProp.size()) > fieldPropCartIdx));
422 return fieldProp[fieldPropCartIdx];
425template<
typename Gr
id,
typename Gr
idView>
427 const std::string& propString)
const
429 std::vector<double> fieldPropOnLeaf;
430 unsigned int numElements = gridView_.size(0);
431 fieldPropOnLeaf.resize(numElements);
432 const auto& fieldProp = fieldPropsManager.get_double(propString);
433 for (
unsigned int elemIdx = 0; elemIdx < numElements; ++elemIdx) {
434 const auto fieldPropCartIdx = this->getFieldPropCartesianIdx<Grid>(elemIdx);
435 fieldPropOnLeaf[elemIdx] = fieldProp[fieldPropCartIdx];
437 return fieldPropOnLeaf;
440template<
typename Gr
id,
typename Gr
idView>
441template<
typename IntType>
443 const std::string& propString,
444 const bool& needsTranslation,
445 std::function<
void(IntType,
int)> valueCheck)
const
447 std::vector<IntType> fieldPropOnLeaf;
448 unsigned int numElements = gridView_.size(0);
449 fieldPropOnLeaf.resize(numElements);
450 const auto& fieldProp = fieldPropsManager.get_int(propString);
451 for (
unsigned elemIdx = 0; elemIdx < numElements; ++elemIdx) {
452 const auto fieldPropCartIdx = this->getFieldPropCartesianIdx<Grid>(elemIdx);
453 fieldPropOnLeaf[elemIdx] = fieldProp[fieldPropCartIdx] - needsTranslation;
454 valueCheck(fieldProp[fieldPropCartIdx], fieldPropCartIdx);
456 return fieldPropOnLeaf;
459template<
typename Gr
id,
typename Gr
idView>
460template<
typename ElemOrIndex>
462 const std::string& propString,
463 const ElemOrIndex& elemOrIndex)
const
465 const auto& fieldPropVec = fieldPropsManager.get_double(propString);
466 return this ->operator()(elemOrIndex,fieldPropVec);
469template<
typename Gr
id,
typename Gr
idView>
470template<
typename ElemOrIndex>
472 const std::string& propString,
473 const ElemOrIndex& elemOrIndex)
const
475 const auto& fieldPropVec = fieldPropsManager.get_int(propString);
476 return this ->operator()(elemOrIndex,fieldPropVec);
479template<
typename Gr
id,
typename Gr
idView>
480template<
class ElementType>
482 return this->getFieldPropCartesianIdx<Grid, ElementType>(elemIdx);
485template<
typename Gr
id,
typename Gr
idView>
486template<
typename Gr
idType,
typename ElementType>
489 constexpr static bool isIntegral = std::is_integral_v<ElementType>;
490 if constexpr (std::is_same_v<GridType, Dune::CpGrid>) {
491 static_assert(std::is_same_v<Grid,GridType>);
492 if constexpr (isIntegral) {
494 return this -> getFieldPropCartesianIdx<Dune::CpGrid>(elem);
496 if (isFieldPropInLgr_ && elementOrIndex.level()) {
497 return elementOrIndex.getLevelCartesianIdx();
500 return cartMapper_-> cartesianIndex(this->elemMapper_.index(elementOrIndex));
504 if constexpr (isIntegral) {
505 static_assert(std::is_same_v<Grid,GridType>);
506 return cartMapper_-> cartesianIndex(elementOrIndex);
508 static_assert(std::is_same_v<Grid,GridType>);
510 assert(gridView_.grid().maxLevel() == 0);
511 return cartMapper_-> cartesianIndex(this->elemMapper_.index(elementOrIndex));
Interface class to access the logical Cartesian grid as used in industry standard simulator decks.
Definition: common/CartesianIndexMapper.hpp:16
Definition: LookUpData.hh:169
const GridView & gridView_
Definition: LookUpData.hh:269
auto operator()(const ElementOrIndex &elemIdx, const FieldProperties &fieldProp) const
: Get field property for an element in the leaf grid view, from a vector, via Cartesian Index.
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:426
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:471
LookUpCartesianData(const GridView &gridView, const Dune::CartesianIndexMapper< Grid > &mapper, bool isFieldPropInLgr=false)
: Constructor taking a GridView, a CartesianIndexMapper, and a bool
Definition: LookUpData.hh:179
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:461
auto getFieldPropCartesianIdx(const ElementType &elemIdx) const
Calls getFieldPropCartesianIdx<Grid, ElementType>(elemIdx)
Definition: LookUpData.hh:481
const Dune::CartesianIndexMapper< Grid > * cartMapper_
Definition: LookUpData.hh:271
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:442
bool isFieldPropInLgr_
Definition: LookUpData.hh:272
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > elemMapper_
Definition: LookUpData.hh:270
Definition: LookUpData.hh:63
auto operator()(const ElementOrIndex &elementOrIdx, const FieldProperties &fieldProp) const
: Get field propertry for an element or index in the leaf grid view, from a vector and element index.
Definition: LookUpData.hh:282
bool isFieldPropInLgr_
Definition: LookUpData.hh:158
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:291
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > elemMapper_
Definition: LookUpData.hh:157
const GridView & gridView_
Definition: LookUpData.hh:156
auto getFieldPropIdx(const ElementType &elem) const
Return the index used for retrieving field properties, depending on whether the grid is a CpGrid or a...
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:328
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:358
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:348
auto getFieldPropIdx(const ElementType &elem) const
calls getFieldPropIdx<Grid, ElementType>(elem)
Definition: LookUpData.hh:368
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