FullTable.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_FULL_TABLE_HPP
20 #define OPM_PARSER_FULL_TABLE_HPP
21 
25 
26 #include <map>
27 #include <memory>
28 #include <string>
29 #include <vector>
30 #include <cassert>
31 
32 namespace Opm {
33  template <class OuterTable, class InnerTable>
34  class FullTable
35  {
37  typedef std::shared_ptr<const OuterTable> OuterTableConstPtr;
38  typedef std::shared_ptr<InnerTable> InnerTablePtr;
39  typedef std::shared_ptr<const InnerTable> InnerTableConstPtr;
40 
41  protected:
42  FullTable(const FullTable&) = default;
43 
56  void init(Opm::DeckKeywordConstPtr keyword, size_t tableIdx)
57  {
58  OuterTable* outerTable = new OuterTable;
59  outerTable->init(keyword, tableIdx);
60  m_outerTable.reset(outerTable);
61 
62  for (size_t rowIdx = 0; rowIdx < m_outerTable->numRecords(); ++rowIdx) {
63  InnerTable *curRow = new InnerTable;
64  auto record = keyword->getRecord( m_outerTable->firstRecordIndex() + rowIdx );
65  auto item = record->getItem( 1 );
66  curRow->init(item);
67  m_innerTables.push_back(std::shared_ptr<const InnerTable>(curRow));
68  }
69  }
70 
71  public:
72  FullTable() = default;
73 
74  typedef std::shared_ptr<Self> Pointer;
75  typedef std::shared_ptr<const Self> ConstPointer;
76 
77  static size_t numTables(Opm::DeckKeywordConstPtr keyword)
78  { return OuterTable::numTables(keyword); }
79 
80  std::shared_ptr<const OuterTable> getOuterTable() const
81  { return m_outerTable; }
82 
83  std::shared_ptr<const InnerTable> getInnerTable(size_t rowIdx) const
84  {
85  assert(rowIdx < m_innerTables.size());
86  return m_innerTables[rowIdx];
87  }
88 
89  protected:
90  std::shared_ptr<const OuterTable> m_outerTable;
91  std::vector<std::shared_ptr<const InnerTable> > m_innerTables;
92 
93  };
94 
97 }
98 
99 #endif
100 
std::vector< std::shared_ptr< const InnerTable > > m_innerTables
Definition: FullTable.hpp:91
Definition: Deck.hpp:29
std::shared_ptr< const DeckKeyword > DeckKeywordConstPtr
Definition: DeckKeyword.hpp:71
void init(Opm::DeckKeywordConstPtr keyword, size_t tableIdx)
Read full tables from keywords like PVTO.
Definition: FullTable.hpp:56
static size_t numTables(Opm::DeckKeywordConstPtr keyword)
Definition: FullTable.hpp:77
FullTable< Opm::MultiRecordTable, Opm::SimpleTable >::Pointer FullTablePtr
Definition: FullTable.hpp:95
std::shared_ptr< const OuterTable > m_outerTable
Definition: FullTable.hpp:90
std::shared_ptr< Self > Pointer
Definition: FullTable.hpp:74
std::shared_ptr< const InnerTable > getInnerTable(size_t rowIdx) const
Definition: FullTable.hpp:83
FullTable()=default
std::shared_ptr< const OuterTable > getOuterTable() const
Definition: FullTable.hpp:80
Definition: FullTable.hpp:34
std::shared_ptr< const Self > ConstPointer
Definition: FullTable.hpp:75
FullTable< Opm::MultiRecordTable, Opm::SimpleTable >::ConstPointer FullTableConstPtr
Definition: FullTable.hpp:96