opm-common
GasPlantTable.hpp
1 /*
2  Copyright 2026 Equinor ASA.
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 
20 #ifndef OPM_GAS_PLANT_TABLE_HPP
21 #define OPM_GAS_PLANT_TABLE_HPP
22 
23 #include <opm/common/OpmLog/KeywordLocation.hpp>
24 
25 #include <cassert>
26 #include <cstddef>
27 #include <unordered_set>
28 #include <vector>
29 
30 namespace Opm {
31 
32  class DeckRecord;
33 
42  {
43  public:
44  GasPlantTable() = default;
45 
49  GasPlantTable(const DeckRecord& record,
50  std::size_t numComponents,
51  const KeywordLocation& location);
52 
53  static GasPlantTable serializationTestObject();
54 
61  static void warnOnTableNumber(std::unordered_set<int>& seenTableNumbers,
62  int tableNumber,
63  std::size_t maxTables,
64  const KeywordLocation& location);
65 
68  int name() const { return this->m_table_num; }
69 
70  // The component indices are validated as 1-based deck component numbers
71  // (each in [1, numComponents]) forming a non-inverted bracket (lower <= upper).
72  // The downstream physics interpretation of the bracket is deferred to the
73  // first consumer of the recovery data.
74  int lowerComponent() const { return this->m_lower_component; }
75  int upperComponent() const { return this->m_upper_component; }
76  std::size_t numComponents() const { return this->m_num_components; }
77 
80  std::size_t rowWidth() const { return this->m_num_components + 1; }
81 
82  std::size_t numRows() const
83  {
84  // A table built through the parser always has m_num_components >= 1. A
85  // default-constructed object filled via serializeOp on the restart/MPI
86  // path bypasses the constructor; guard a zero component count so a
87  // component-less object reports no rows rather than a meaningless count.
88  if (this->m_num_components == 0) {
89  return 0;
90  }
91  return this->m_data.size() / this->rowWidth();
92  }
93 
95  double heavyMoleFraction(std::size_t row) const
96  {
97  assert(row < this->numRows());
98  return this->m_data[row * this->rowWidth()];
99  }
100 
105  double recovery(std::size_t row, std::size_t comp) const
106  {
107  assert(row < this->numRows());
108  assert(comp < this->m_num_components);
109  return this->m_data[row * this->rowWidth() + 1 + comp];
110  }
111 
112  bool operator==(const GasPlantTable& other) const;
113 
114  // serializeOp, operator==, and the member list must stay in lock-step:
115  // every member below is also compared in operator== and set in
116  // serializationTestObject().
117  template <class Serializer>
118  void serializeOp(Serializer& serializer)
119  {
120  serializer(this->m_table_num);
121  serializer(this->m_lower_component);
122  serializer(this->m_upper_component);
123  serializer(this->m_num_components);
124  serializer(this->m_data);
125  }
126 
127  private:
128  int m_table_num{};
129  int m_lower_component{};
130  int m_upper_component{};
131  std::size_t m_num_components{};
132  std::vector<double> m_data{};
133  };
134 
135 } // namespace Opm
136 
137 #endif // OPM_GAS_PLANT_TABLE_HPP
Definition: KeywordLocation.hpp:27
static void warnOnTableNumber(std::unordered_set< int > &seenTableNumbers, int tableNumber, std::size_t maxTables, const KeywordLocation &location)
Emit the GPTABLE table-number diagnostics shared by the SCHEDULE handler and the SOLUTION-section see...
Definition: GasPlantTable.cpp:150
double recovery(std::size_t row, std::size_t comp) const
Recovery fraction of component comp for row.
Definition: GasPlantTable.hpp:105
int name() const
Gas plant table number.
Definition: GasPlantTable.hpp:68
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
std::size_t rowWidth() const
Number of values stored per table row: the heavy-component mole fraction plus one recovery fraction p...
Definition: GasPlantTable.hpp:80
double heavyMoleFraction(std::size_t row) const
Heavy-component mole fraction for row (the first column of the row).
Definition: GasPlantTable.hpp:95
A single GPTABLE gas-plant recovery table.
Definition: GasPlantTable.hpp:41
Definition: DeckRecord.hpp:33
Class for (de-)serializing.
Definition: Serializer.hpp:95