GridPropertyInitializers.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2014 Andreas Lauser
3 
4  This file is part of the Open Porous Media project (OPM).
5 
6  OPM is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  OPM is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OPM. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #ifndef ECLIPSE_GRIDPROPERTY_INITIALIZERS_HPP
20 #define ECLIPSE_GRIDPROPERTY_INITIALIZERS_HPP
21 
22 #include <vector>
23 #include <string>
24 #include <exception>
25 #include <memory>
26 #include <limits>
27 #include <algorithm>
28 #include <cmath>
29 
30 #include <cassert>
31 
35 
36 
37 
38 /*
39  This classes initialize GridProperty objects. Most commonly, they just get a constant
40  value but some properties (e.g, some of these related to endpoint scaling) need more
41  complex schemes like table lookups.
42 */
43 namespace Opm {
44 
45 // forward definitions
46 class Deck;
47 class EclipseState;
48 class EnptvdTable;
49 class ImptvdTable;
50 
51 template <class ValueType>
53 {
54 protected:
56  { }
57 
58 public:
59  virtual void apply(std::vector<ValueType>& values) const = 0;
60 };
61 
62 template <class ValueType>
64  : public GridPropertyBaseInitializer<ValueType>
65 {
66 public:
67  GridPropertyConstantInitializer(const ValueType& value)
68  : m_value(value)
69  { }
70 
71  void apply(std::vector<ValueType>& values) const
72  {
73  std::fill(values.begin(), values.end(), m_value);
74  }
75 
76 private:
77  ValueType m_value;
78 };
79 
80 
81 
82 
83 
84 // initialize the TEMPI grid property using the temperature vs depth
85 // table (stemming from the TEMPVD or the RTEMPVD keyword)
86 template <class EclipseState=Opm::EclipseState,
87  class Deck=Opm::Deck>
89  : public GridPropertyBaseInitializer<double>
90 {
91 public:
92  GridPropertyTemperatureLookupInitializer(const Deck& deck, const EclipseState& eclipseState)
93  : m_deck(deck)
94  , m_eclipseState(eclipseState)
95  { }
96 
97  void apply(std::vector<double>& values) const
98  {
99  if (!m_deck.hasKeyword("EQLNUM")) {
100  // if values are defaulted in the TEMPI keyword, but no
101  // EQLNUM is specified, you will get NaNs...
102  double nan = std::numeric_limits<double>::quiet_NaN();
103  std::fill(values.begin(), values.end(), nan);
104  return;
105  }
106 
107  auto tables = m_eclipseState.getTableManager();
108  auto eclipseGrid = m_eclipseState.getEclipseGrid();
109  const TableContainer& rtempvdTables = tables->getRtempvdTables();
110  const std::vector<int>& eqlNum = m_eclipseState.getIntGridProperty("EQLNUM")->getData();
111 
112  for (size_t cellIdx = 0; cellIdx < eqlNum.size(); ++ cellIdx) {
113  int cellEquilNum = eqlNum[cellIdx];
114  const RtempvdTable& rtempvdTable = rtempvdTables.getTable<RtempvdTable>(cellEquilNum);
115  double cellDepth = std::get<2>(eclipseGrid->getCellCenter(cellIdx));
116  values[cellIdx] = rtempvdTable.evaluate("Temperature", cellDepth);
117  }
118  }
119 
120 private:
121  const Deck& m_deck;
122  const EclipseState& m_eclipseState;
123 };
124 
125 }
126 
127 #endif
Definition: RtempvdTable.hpp:28
Definition: TableContainer.hpp:31
void apply(std::vector< ValueType > &values) const
Definition: GridPropertyInitializers.hpp:71
bool hasKeyword(DeckKeywordConstPtr keyword) const
Definition: Deck.hpp:29
EclipseGridConstPtr getEclipseGrid() const
GridPropertyTemperatureLookupInitializer(const Deck &deck, const EclipseState &eclipseState)
Definition: GridPropertyInitializers.hpp:92
Definition: Deck.hpp:31
GridPropertyBaseInitializer()
Definition: GridPropertyInitializers.hpp:55
Definition: EclipseState.hpp:50
std::shared_ptr< const TableManager > getTableManager() const
Definition: GridPropertyInitializers.hpp:52
double evaluate(const std::string &columnName, double xPos) const
Evaluate a column of the table at a given position.
const SimpleTable & getTable(size_t tableNumber) const
GridPropertyConstantInitializer(const ValueType &value)
Definition: GridPropertyInitializers.hpp:67
void apply(std::vector< double > &values) const
Definition: GridPropertyInitializers.hpp:97
Definition: GridPropertyInitializers.hpp:88
std::shared_ptr< GridProperty< int > > getIntGridProperty(const std::string &keyword) const
Definition: GridPropertyInitializers.hpp:63
virtual void apply(std::vector< ValueType > &values) const =0