SimpleTable.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 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_SIMPLE_TABLE_HPP
20 #define OPM_PARSER_SIMPLE_TABLE_HPP
21 
23 
24 #include <map>
25 #include <memory>
26 #include <string>
27 #include <vector>
28 #include <cassert>
29 
30 namespace Opm {
31  class PlyshlogTable;
32  class SimpleTable {
33  friend class PlyshlogTable;
34  protected:
35  SimpleTable(const SimpleTable&) = default;
36 
43  void init(Opm::DeckItemConstPtr deckItem,
44  const std::vector<std::string> &columnNames);
45 
46  public:
47  SimpleTable() = default;
48 
55  static size_t numTables(Opm::DeckKeywordConstPtr keyword);
56 
57 #ifdef BOOST_TEST_MODULE
58  // DO NOT TRY TO CALL THIS METHOD! it is only for the unit tests!
59  void initFORUNITTESTONLY(Opm::DeckItemConstPtr item,
60  const std::vector<std::string> &columnNames)
61  { init(item , columnNames ); }
62 #endif
63 
64  size_t numColumns() const;
65  size_t numRows() const;
66  const std::vector<double> &getColumn(const std::string &name) const;
67  const std::vector<double> &getColumn(size_t colIdx) const;
68 
75  double evaluate(const std::string& columnName, double xPos) const;
76 
77  protected:
78  void checkNonDefaultable(const std::string& columnName);
79  void checkMonotonic(const std::string& columnName,
80  bool isAscending,
81  bool isStrictlyMonotonic = true);
82  void applyDefaultsConstant(const std::string& columnName, double value);
83  void applyDefaultsLinear(const std::string& columnName);
84  void createColumns(const std::vector<std::string> &columnNames);
85 
86  std::map<std::string, size_t> m_columnNames;
87  std::vector<std::vector<double> > m_columns;
88  std::vector<std::vector<bool> > m_valueDefaulted;
89  };
90 
91  typedef std::shared_ptr<SimpleTable> SimpleTablePtr;
92  typedef std::shared_ptr<const SimpleTable> SimpleTableConstPtr;
93 }
94 
95 #endif
size_t numColumns() const
void init(Opm::DeckItemConstPtr deckItem, const std::vector< std::string > &columnNames)
Read simple tables from keywords like SWOF.
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)
std::shared_ptr< const DeckKeyword > DeckKeywordConstPtr
Definition: DeckKeyword.hpp:71
std::map< std::string, size_t > m_columnNames
Definition: SimpleTable.hpp:86
std::shared_ptr< const DeckItem > DeckItemConstPtr
Definition: DeckItem.hpp:127
std::vector< std::vector< bool > > m_valueDefaulted
Definition: SimpleTable.hpp:88
void applyDefaultsConstant(const std::string &columnName, double value)
std::shared_ptr< SimpleTable > SimpleTablePtr
Definition: SimpleTable.hpp:91
std::shared_ptr< const SimpleTable > SimpleTableConstPtr
Definition: SimpleTable.hpp:92
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.
SimpleTable()=default
void checkMonotonic(const std::string &columnName, bool isAscending, bool isStrictlyMonotonic=true)
Definition: SimpleTable.hpp:32
Definition: PlyshlogTable.hpp:30
void applyDefaultsLinear(const std::string &columnName)