opm-common
PhaseUsageInfo.hpp
1 // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 // vi: set et ts=4 sw=4 sts=4:
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 2 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  Consult the COPYING file in the top-level source directory of this
20  module for the precise wording of the license and the list of
21  copyright holders.
22 */
23 
24 #ifndef OPM_PHASEUSAGEINFO_HPP
25 #define OPM_PHASEUSAGEINFO_HPP
26 
27 #include <opm/common/ErrorMacros.hpp>
28 #include <opm/input/eclipse/EclipseState/EclipseState.hpp>
29 
30 #include <array>
31 #include <cassert>
32 #include <stdexcept>
33 #include <string>
34 
35 #include <opm/common/utility/gpuDecorators.hpp>
36 
37 namespace Opm
38 {
39 class Phases;
40 
41 template <typename IndexTraits>
43 public:
44  static constexpr int numPhases = IndexTraits::numPhases;
45  static constexpr int numComponents = IndexTraits::numComponents;
46 
47  static constexpr int waterPhaseIdx = IndexTraits::waterPhaseIdx;
48  static constexpr int oilPhaseIdx = IndexTraits::oilPhaseIdx;
49  static constexpr int gasPhaseIdx = IndexTraits::gasPhaseIdx;
50 
51  static constexpr int waterCompIdx = IndexTraits::waterCompIdx;
52  static constexpr int oilCompIdx = IndexTraits::oilCompIdx;
53  static constexpr int gasCompIdx = IndexTraits::gasCompIdx;
54 
56 
57  [[nodiscard]] OPM_HOST_DEVICE unsigned numActivePhases() const {
58  return numActivePhases_;
59  }
60 
61  [[nodiscard]] OPM_HOST_DEVICE bool phaseIsActive(unsigned phaseIdx) const {
62  assert(phaseIdx < numPhases);
63  return phaseIsActive_[phaseIdx];
64  }
65 
66  [[nodiscard]] OPM_HOST_DEVICE short canonicalToActivePhaseIdx(unsigned phaseIdx) const {
67  if (!phaseIsActive(phaseIdx)) {
68  OPM_THROW(std::logic_error, "Canonical phase " + std::to_string(phaseIdx) + " is not active.");
69  }
70  return canonicalToActivePhaseIdx_[phaseIdx];
71  }
72 
73  [[nodiscard]] OPM_HOST_DEVICE short activeToCanonicalPhaseIdx(unsigned activePhaseIdx) const {
74  assert(activePhaseIdx< numActivePhases_);
75  return activeToCanonicalPhaseIdx_[activePhaseIdx];
76  }
77 
78  [[nodiscard]] OPM_HOST_DEVICE short activeToCanonicalCompIdx(unsigned activeCompIdx) const {
79  // assert to remove an analyzer warning, at the current stage, numPhases == numComponents for black oil
80  assert(numActivePhases_ <= numComponents);
81  if (activeCompIdx >= numActivePhases()) {
82  return activeCompIdx; // e.g. for solvent
83  }
84  return activeToCanonicalCompIdx_[activeCompIdx];
85  }
86 
87  [[nodiscard]] OPM_HOST_DEVICE short canonicalToActiveCompIdx(unsigned compIdx) const {
88  assert(compIdx < numComponents);
89  return canonicalToActiveCompIdx_[compIdx];
90  }
91 
92  [[nodiscard]] OPM_HOST_DEVICE short activePhaseToActiveCompIdx(unsigned activePhaseIdx) const {
93  if (activePhaseIdx >= numActivePhases()) {
94  return activePhaseIdx; // e.g. for solvent
95  }
96  const short canonicalPhaseIdx = activeToCanonicalPhaseIdx(activePhaseIdx);
97  const short canonicalCompIdx = IndexTraits::phaseToComponentIdx(canonicalPhaseIdx);
98  const short activeCompIdx = canonicalToActiveCompIdx(canonicalCompIdx);
99  return activeCompIdx;
100  }
101 
102  [[nodiscard]] OPM_HOST_DEVICE short activeCompToActivePhaseIdx(unsigned activeCompIdx) const {
103  if (activeCompIdx >= numActivePhases()) {
104  return activeCompIdx; // e.g. for solvent
105  }
106  const short canonicalCompIdx = activeToCanonicalCompIdx(activeCompIdx);
107  const short canonicalPhaseIdx = IndexTraits::componentToPhaseIdx(canonicalCompIdx);
108  const short activePhaseIdx = canonicalToActivePhaseIdx(canonicalPhaseIdx);
109  return activePhaseIdx;
110  }
111 
112  void initFromPhases(const Phases& phases);
113 
114  void initFromState(const EclipseState& eclState);
115 
116  OPM_HOST_DEVICE bool hasSolvent() const noexcept {
117  return has_solvent;
118  }
119 
120  OPM_HOST_DEVICE bool hasPolymer() const noexcept {
121  return has_polymer;
122  }
123 
124  OPM_HOST_DEVICE bool hasEnergy() const noexcept {
125  return has_energy;
126  }
127 
128  OPM_HOST_DEVICE bool hasPolymerMW() const noexcept {
129  return has_polymermw;
130  }
131 
132  OPM_HOST_DEVICE bool hasFoam() const noexcept {
133  return has_foam;
134  }
135 
136  OPM_HOST_DEVICE bool hasBrine() const noexcept {
137  return has_brine;
138  }
139 
140  OPM_HOST_DEVICE bool hasZFraction() const noexcept {
141  return has_zFraction;
142  }
143 
144  OPM_HOST_DEVICE bool hasBiofilm() const noexcept {
145  return has_biofilm;
146  }
147 
148  OPM_HOST_DEVICE bool hasMICP() const noexcept {
149  return has_micp;
150  }
151 
152  OPM_HOST_DEVICE bool hasCO2orH2Store() const noexcept {
153  return has_co2_or_h2store;
154  }
155 
156 private:
157  // only account for the three main phases: oil, water, gas
158  unsigned char numActivePhases_ = 0;
159  std::array<bool, numPhases> phaseIsActive_;
160  std::array<short, numPhases> activeToCanonicalPhaseIdx_;
161  std::array<short, numPhases> canonicalToActivePhaseIdx_;
162 
163  // numComponents only account for three main components: oil, water, gas
164  std::array<short, numComponents> activeToCanonicalCompIdx_;
165  std::array<short, numComponents> canonicalToActiveCompIdx_;
166 
167  bool has_solvent{};
168  bool has_polymer{};
169  bool has_energy{};
170  // polymer molecular weight
171  bool has_polymermw{};
172  bool has_foam{};
173  bool has_brine{};
174  bool has_zFraction{};
175  bool has_biofilm{};
176  bool has_micp{};
177  bool has_co2_or_h2store{};
178 
179  // updating the mapping between active and canonical phase indices
180  void updateIndexMapping_();
181 
182  void reset_();
183 
184 };
185 
186 }
187 
188 #endif
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: EclipseState.hpp:66
Definition: PhaseUsageInfo.hpp:42
Definition: Runspec.hpp:45