GasvisctTable.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2015 by 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 OPM_PARSER_GASVISCT_TABLE_HPP
20 #define OPM_PARSER_GASVISCT_TABLE_HPP
21 
22 #include "SimpleTable.hpp"
23 
24 namespace Opm {
25  // forward declaration
26  class TableManager;
27 
28  class GasvisctTable : public SimpleTable {
29  public:
30  friend class TableManager;
31  GasvisctTable() = default;
32 
37  void init(const Deck& deck, Opm::DeckItemConstPtr deckItem)
38  {
39  int numComponents = deck.getKeyword("COMPS")->getRecord(0)->getItem(0)->getInt(0);
40 
41  auto temperatureDimension = deck.getActiveUnitSystem()->getDimension("Temperature");
42  auto viscosityDimension = deck.getActiveUnitSystem()->getDimension("Viscosity");
43 
44  // create the columns: temperature plus one viscosity column per component
45  std::vector<std::string> columnNames;
46  columnNames.push_back("Temperature");
47 
48  for (int compIdx = 0; compIdx < numComponents; ++ compIdx)
49  columnNames.push_back("Viscosity" + std::to_string(static_cast<long long>(compIdx)));
50 
51  SimpleTable::createColumns(columnNames);
52 
53  // extract the actual data from the deck
54  size_t numFlatItems = deckItem->size( );
55  if ( numFlatItems % numColumns() != 0)
56  throw std::runtime_error("Number of columns in the data file is inconsistent "
57  "with the expected number for keyword GASVISCT");
58 
59  for (size_t rowIdx = 0; rowIdx*numColumns() < numFlatItems; ++rowIdx) {
60  // add the current temperature
61  int deckItemIdx = rowIdx*numColumns();
62 
63  bool isDefaulted = deckItem->defaultApplied( deckItemIdx );
64  this->m_valueDefaulted[0].push_back(isDefaulted);
65 
66  if (!isDefaulted) {
67  double T = deckItem->getRawDouble( deckItemIdx );
68  this->m_columns[0].push_back(temperatureDimension->convertRawToSi(T));
69  }
70 
71  // deal with the component viscosities
72  for (int compIdx = 0; compIdx < numComponents; ++compIdx) {
73  deckItemIdx = rowIdx*numColumns() + compIdx + 1;
74  size_t columnIdx = compIdx + 1;
75 
76  isDefaulted = deckItem->defaultApplied( deckItemIdx );
77  this->m_valueDefaulted[columnIdx].push_back(isDefaulted);
78 
79  if (!isDefaulted) {
80  double mu = deckItem->getRawDouble( deckItemIdx );
81  this->m_columns[columnIdx].push_back(viscosityDimension->convertRawToSi(mu));
82  }
83  }
84  }
85 
86  // make sure that the columns agree with the keyword specification of the
87  // reference manual. (actually, the documentation does not say anyting about
88  // whether items of these columns are defaultable or not, so we assume here
89  // that they are not.)
90  SimpleTable::checkNonDefaultable("Temperature");
91  SimpleTable::checkMonotonic("Temperature", /*isAscending=*/true);
92 
93  for (int compIdx = 0; compIdx < numComponents; ++compIdx) {
94  std::string columnName = "Viscosity" + std::to_string(static_cast<long long>(compIdx));
96  SimpleTable::checkMonotonic(columnName,
97  /*isAscending=*/true,
98  /*strictlyMonotonic=*/false);
99  }
100  }
101 
103  using SimpleTable::numRows;
105  using SimpleTable::evaluate;
106 
107  const std::vector<double> &getTemperatureColumn() const
108  { return SimpleTable::getColumn(0); }
109 
110  const std::vector<double> &getGasViscosityColumn(size_t compIdx) const
111  { return SimpleTable::getColumn(1 + compIdx); }
112  };
113 }
114 
115 #endif
size_t numColumns() const
Definition: Deck.hpp:29
std::vector< std::vector< double > > m_columns
Definition: SimpleTable.hpp:87
void createColumns(const std::vector< std::string > &columnNames)
const std::vector< double > & getColumn(const std::string &name) const
void checkNonDefaultable(const std::string &columnName)
Definition: Deck.hpp:31
std::shared_ptr< const DeckItem > DeckItemConstPtr
Definition: DeckItem.hpp:127
std::vector< std::vector< bool > > m_valueDefaulted
Definition: SimpleTable.hpp:88
GasvisctTable()=default
Definition: TableManager.hpp:66
std::shared_ptr< UnitSystem > getActiveUnitSystem() const
Definition: GasvisctTable.hpp:28
const std::vector< double > & getTemperatureColumn() const
Definition: GasvisctTable.hpp:107
size_t numRows() const
static size_t numTables(Opm::DeckKeywordConstPtr keyword)
Returns the number of tables in a keyword.
double evaluate(const std::string &columnName, double xPos) const
Evaluate a column of the table at a given position.
void checkMonotonic(const std::string &columnName, bool isAscending, bool isStrictlyMonotonic=true)
const std::vector< double > & getGasViscosityColumn(size_t compIdx) const
Definition: GasvisctTable.hpp:110
Definition: SimpleTable.hpp:32
void init(const Deck &deck, Opm::DeckItemConstPtr deckItem)
Read the GASVISCT keyword and provide some convenience methods for it.
Definition: GasvisctTable.hpp:37
DeckKeywordConstPtr getKeyword(const std::string &keyword, size_t index) const