19 #ifndef ECLIPSE_GRIDPROPERTY_HPP_
20 #define ECLIPSE_GRIDPROPERTY_HPP_
26 #include <unordered_map>
27 #include <boost/lexical_cast.hpp>
29 #include <ert/ecl/EclKW.hpp>
50 template <
class ValueType>
57 virtual void apply(std::vector<ValueType>& values)
const = 0;
63 template <
class DataType>
74 std::shared_ptr<const Initializer> initializer,
75 std::shared_ptr<const PostProcessor> postProcessor,
76 const std::string& dimString)
77 : m_keywordName(name),
78 m_initializer(initializer),
79 m_postProcessor(postProcessor),
80 m_dimensionString(dimString)
85 std::shared_ptr<const Initializer> initializer,
86 const std::string& dimString)
87 : m_keywordName(name),
88 m_initializer(initializer),
89 m_dimensionString(dimString)
95 const DataType defaultValue,
96 const std::string& dimString)
97 : m_keywordName(name),
99 m_dimensionString(dimString)
103 const DataType defaultValue,
104 std::shared_ptr<const PostProcessor> postProcessor,
105 const std::string& dimString)
106 : m_keywordName(name),
108 m_postProcessor(postProcessor),
109 m_dimensionString(dimString)
118 return m_keywordName;
123 return m_dimensionString;
128 return m_initializer;
133 return m_postProcessor;
138 return static_cast<bool>(m_postProcessor);
144 std::string m_keywordName;
145 std::shared_ptr<const Initializer> m_initializer;
146 std::shared_ptr<const PostProcessor> m_postProcessor;
147 std::string m_dimensionString;
152 template <
typename T>
157 GridProperty(
size_t nx ,
size_t ny ,
size_t nz ,
const SupportedKeywordInfo& kwInfo) {
162 m_data.resize( nx * ny * nz );
165 m_hasRunPostProcessor =
false;
169 return m_data.size();
186 if (index < m_data.size()) {
187 return m_data[index];
189 throw std::invalid_argument(
"Index out of range \n");
194 T
iget(
size_t i ,
size_t j ,
size_t k)
const {
195 size_t g = i + j*m_nx + k*m_nx*m_ny;
199 void iset(
size_t index, T value) {
200 if (index < m_data.size())
201 m_data[index] = value;
203 throw std::invalid_argument(
"Index out of range \n");
206 void iset(
size_t i ,
size_t j ,
size_t k , T value) {
207 size_t g = i + j*m_nx + k*m_nx*m_ny;
216 if ((m_nx == other.m_nx) && (m_ny == other.m_ny) && (m_nz == other.m_nz)) {
217 for (
size_t g=0; g < m_data.size(); g++)
218 m_data[g] *= other.m_data[g];
220 throw std::invalid_argument(
"Size mismatch between properties in mulitplyWith.");
225 m_data[index] *= factor;
234 void maskedSet(T value,
const std::vector<bool>& mask) {
250 void maskedAdd(T value,
const std::vector<bool>& mask) {
261 m_data[g] = other.m_data[g];
270 if (m_data[g] == value)
287 const auto deckItem = getDeckItem(deckKeyword);
288 for (
size_t dataPointIdx = 0; dataPointIdx < deckItem->size(); ++dataPointIdx) {
289 if (!deckItem->defaultApplied(dataPointIdx))
290 setDataPoint(dataPointIdx, dataPointIdx, deckItem);
297 if (inputBox->isGlobal())
300 const auto deckItem = getDeckItem(deckKeyword);
301 const std::vector<size_t>& indexList = inputBox->getIndexList();
302 if (indexList.size() == deckItem->size()) {
303 for (
size_t sourceIdx = 0; sourceIdx < indexList.size(); sourceIdx++) {
304 size_t targetIdx = indexList[sourceIdx];
305 if (sourceIdx < deckItem->size()
306 && !deckItem->defaultApplied(sourceIdx))
308 setDataPoint(sourceIdx, targetIdx, deckItem);
312 std::string boxSize = std::to_string(static_cast<long long>(indexList.size()));
313 std::string keywordSize = std::to_string(static_cast<long long>(deckItem->size()));
315 throw std::invalid_argument(
"Size mismatch: Box:" + boxSize +
" DecKeyword:" + keywordSize);
323 if (inputBox->isGlobal()) {
325 m_data[i] = src.m_data[i];
327 const std::vector<size_t>& indexList = inputBox->getIndexList();
328 for (
size_t i = 0; i < indexList.size(); i++) {
329 size_t targetIndex = indexList[i];
330 m_data[targetIndex] = src.m_data[targetIndex];
335 void scale(T scaleFactor , std::shared_ptr<const Box> inputBox) {
336 if (inputBox->isGlobal()) {
337 for (
size_t i = 0; i < m_data.size(); ++i)
338 m_data[i] *= scaleFactor;
340 const std::vector<size_t>& indexList = inputBox->getIndexList();
341 for (
size_t i = 0; i < indexList.size(); i++) {
342 size_t targetIndex = indexList[i];
343 m_data[targetIndex] *= scaleFactor;
349 void add(T shiftValue , std::shared_ptr<const Box> inputBox) {
350 if (inputBox->isGlobal()) {
351 for (
size_t i = 0; i < m_data.size(); ++i)
352 m_data[i] += shiftValue;
354 const std::vector<size_t>& indexList = inputBox->getIndexList();
355 for (
size_t i = 0; i < indexList.size(); i++) {
356 size_t targetIndex = indexList[i];
357 m_data[targetIndex] += shiftValue;
365 void setScalar(T value , std::shared_ptr<const Box> inputBox) {
366 if (inputBox->isGlobal()) {
367 std::fill(m_data.begin(), m_data.end(), value);
369 const std::vector<size_t>& indexList = inputBox->getIndexList();
370 for (
size_t i = 0; i < indexList.size(); i++) {
371 size_t targetIndex = indexList[i];
372 m_data[targetIndex] = value;
400 m_hasRunPostProcessor =
true;
402 postProcessor->apply( m_data );
409 eclKW.assignVector(
getData() );
414 ERT::EclKW<T>
getEclKW(std::shared_ptr<const EclipseGrid> grid)
const {
416 size_t activeIndex = 0;
418 if (grid->cellActive( g )) {
419 eclKW[activeIndex] =
iget(g);
435 for (
size_t g=0; g < m_data.size(); g++) {
437 if ((value < min) || (value > max))
438 throw std::invalid_argument(
"Property element outside valid limits");
445 if (deckKeyword->size() != 1)
446 throw std::invalid_argument(
"Grid properties can only have a single record (keyword "
447 + deckKeyword->name() +
")");
448 if (deckKeyword->getRecord(0)->size() != 1)
451 throw std::invalid_argument(
"Grid properties may only exhibit a single item (keyword "
452 + deckKeyword->name() +
")");
454 const auto deckItem = deckKeyword->getRecord(0)->getItem(0);
456 if (deckItem->size() > m_data.size())
457 throw std::invalid_argument(
"Size mismatch when setting data for:" +
getKeywordName() +
458 " keyword size: " + boost::lexical_cast<std::string>(deckItem->size())
459 +
" input size: " + boost::lexical_cast<std::string>(m_data.size()));
466 size_t m_nx,m_ny,m_nz;
467 SupportedKeywordInfo m_kwInfo;
468 std::vector<T> m_data;
469 bool m_hasRunPostProcessor;
void runPostProcessor()
Definition: GridProperty.hpp:394
void loadFromDeckKeyword(std::shared_ptr< const Box > inputBox, DeckKeywordConstPtr deckKeyword)
Definition: GridProperty.hpp:296
void initMask(T value, std::vector< bool > &mask)
Definition: GridProperty.hpp:267
void checkLimits(T min, T max) const
Definition: GridProperty.hpp:434
void scale(T scaleFactor, std::shared_ptr< const Box > inputBox)
Definition: GridProperty.hpp:335
const std::string & getKeywordName() const
Definition: GridProperty.hpp:377
void iset(size_t index, T value)
Definition: GridProperty.hpp:199
GridPropertySupportedKeywordInfo()
Definition: GridProperty.hpp:70
Definition: GridProperty.hpp:64
GridPropertyBaseInitializer< DataType > Initializer
Definition: GridProperty.hpp:67
void maskedMultiply(T value, const std::vector< bool > &mask)
Definition: GridProperty.hpp:242
void maskedSet(T value, const std::vector< bool > &mask)
Definition: GridProperty.hpp:234
GridPropertySupportedKeywordInfo(const std::string &name, std::shared_ptr< const Initializer > initializer, const std::string &dimString)
Definition: GridProperty.hpp:84
const std::string & getKeywordName() const
Definition: GridProperty.hpp:117
GridPropertyBasePostProcessor< DataType > PostProcessor
Definition: GridProperty.hpp:68
ERT::EclKW< T > getEclKW(std::shared_ptr< const EclipseGrid > grid) const
Definition: GridProperty.hpp:414
std::shared_ptr< const DeckKeyword > DeckKeywordConstPtr
Definition: DeckKeyword.hpp:71
size_t getCartesianSize() const
Definition: GridProperty.hpp:168
void add(T shiftValue, std::shared_ptr< const Box > inputBox)
Definition: GridProperty.hpp:349
GridProperty(size_t nx, size_t ny, size_t nz, const SupportedKeywordInfo &kwInfo)
Definition: GridProperty.hpp:157
const std::string & getDimensionString() const
Definition: GridProperty.hpp:122
std::shared_ptr< const DeckItem > DeckItemConstPtr
Definition: DeckItem.hpp:127
std::shared_ptr< const Initializer > getInitializer() const
Definition: GridProperty.hpp:127
size_t getNX() const
Definition: GridProperty.hpp:172
void setScalar(T value, std::shared_ptr< const Box > inputBox)
Definition: GridProperty.hpp:365
T iget(size_t index) const
Definition: GridProperty.hpp:185
void copyFrom(const GridProperty< T > &src, std::shared_ptr< const Box > inputBox)
Definition: GridProperty.hpp:322
void maskedCopy(const GridProperty< T > &other, const std::vector< bool > &mask)
Definition: GridProperty.hpp:258
ERT::EclKW< T > getEclKW() const
Definition: GridProperty.hpp:407
bool hasPostProcessor() const
Definition: GridProperty.hpp:137
virtual void apply(std::vector< ValueType > &values) const =0
const std::vector< T > & getData() const
Definition: GridProperty.hpp:228
GridPropertySupportedKeywordInfo(const std::string &name, std::shared_ptr< const Initializer > initializer, std::shared_ptr< const PostProcessor > postProcessor, const std::string &dimString)
Definition: GridProperty.hpp:73
size_t getNY() const
Definition: GridProperty.hpp:176
void multiplyValueAtIndex(size_t index, T factor)
Definition: GridProperty.hpp:224
size_t getNZ() const
Definition: GridProperty.hpp:180
std::shared_ptr< const PostProcessor > getPostProcessor() const
Definition: GridProperty.hpp:132
T iget(size_t i, size_t j, size_t k) const
Definition: GridProperty.hpp:194
Definition: GridPropertyInitializers.hpp:52
void maskedAdd(T value, const std::vector< bool > &mask)
Definition: GridProperty.hpp:250
GridPropertySupportedKeywordInfo(const std::string &name, const DataType defaultValue, const std::string &dimString)
Definition: GridProperty.hpp:94
const SupportedKeywordInfo & getKeywordInfo() const
Definition: GridProperty.hpp:381
void multiplyWith(const GridProperty< T > &other)
Definition: GridProperty.hpp:215
bool postProcessorRunRequired()
Definition: GridProperty.hpp:386
GridPropertyBasePostProcessor()
Definition: GridProperty.hpp:54
GridPropertySupportedKeywordInfo(const std::string &name, const DataType defaultValue, std::shared_ptr< const PostProcessor > postProcessor, const std::string &dimString)
Definition: GridProperty.hpp:102
const std::string & getDimensionString() const
Definition: GridProperty.hpp:51
void loadFromDeckKeyword(DeckKeywordConstPtr deckKeyword)
Definition: GridProperty.hpp:286
GridPropertySupportedKeywordInfo< T > SupportedKeywordInfo
Definition: GridProperty.hpp:155
Definition: GridPropertyInitializers.hpp:63
void iset(size_t i, size_t j, size_t k, T value)
Definition: GridProperty.hpp:206
Definition: GridProperty.hpp:153