opm-common
Loading...
Searching...
No Matches
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#if HAVE_ECL_INPUT
28#include <opm/common/ErrorMacros.hpp>
29#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
30#endif
31
32#include <array>
33#include <cassert>
34#include <stdexcept>
35#include <string>
36
37namespace Opm
38{
39class Phases;
40
41template <typename IndexTraits>
42class PhaseUsageInfo {
43public:
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
55 PhaseUsageInfo();
56
57 [[nodiscard]] unsigned numActivePhases() const {
58 return numActivePhases_;
59 }
60
61 [[nodiscard]] bool phaseIsActive(unsigned phaseIdx) const {
62 assert(phaseIdx < numPhases);
63 return phaseIsActive_[phaseIdx];
64 }
65
66 [[nodiscard]] short canonicalToActivePhaseIdx(unsigned phaseIdx) const {
67 if (!phaseIsActive(phaseIdx)) {
68 throw std::logic_error("Canonical phase " +
69 std::to_string(phaseIdx) + " is not active.");
70 }
71 return canonicalToActivePhaseIdx_[phaseIdx];
72 }
73
74 [[nodiscard]] short activeToCanonicalPhaseIdx(unsigned activePhaseIdx) const {
75 assert(activePhaseIdx< numActivePhases_);
76 return activeToCanonicalPhaseIdx_[activePhaseIdx];
77 }
78
79 [[nodiscard]] short activeToCanonicalCompIdx(unsigned activeCompIdx) const {
80 if (activeCompIdx >= numActivePhases()) {
81 return activeCompIdx; // e.g. for solvent
82 }
83 return activeToCanonicalCompIdx_[activeCompIdx];
84 }
85
86 [[nodiscard]] short canonicalToActiveCompIdx(unsigned compIdx) const {
87 assert(compIdx < numComponents);
88 return canonicalToActiveCompIdx_[compIdx];
89 }
90
91 [[nodiscard]] short activePhaseToActiveCompIdx(unsigned activePhaseIdx) const {
92 if (activePhaseIdx >= numActivePhases()) {
93 return activePhaseIdx; // e.g. for solvent
94 }
95 const short canonicalPhaseIdx = activeToCanonicalPhaseIdx(activePhaseIdx);
96 const short canonicalCompIdx = IndexTraits::phaseToComponentIdx(canonicalPhaseIdx);
97 const short activeCompIdx = canonicalToActiveCompIdx(canonicalCompIdx);
98 return activeCompIdx;
99 }
100
101 [[nodiscard]] short activeCompToActivePhaseIdx(unsigned activeCompIdx) const {
102 if (activeCompIdx >= numActivePhases()) {
103 return activeCompIdx; // e.g. for solvent
104 }
105 const short canonicalCompIdx = activeToCanonicalCompIdx(activeCompIdx);
106 const short canonicalPhaseIdx = IndexTraits::componentToPhaseIdx(canonicalCompIdx);
107 const short activePhaseIdx = canonicalToActivePhaseIdx(canonicalPhaseIdx);
108 return activePhaseIdx;
109 }
110
111#if HAVE_ECL_INPUT
112 void initFromPhases(const Phases& phases);
113
114 void initFromState(const EclipseState& eclState);
115#endif
116
117 bool hasSolvent() const noexcept {
118 return has_solvent;
119 }
120
121 bool hasPolymer() const noexcept {
122 return has_polymer;
123 }
124
125 bool hasEnergy() const noexcept {
126 return has_energy;
127 }
128
129 bool hasPolymerMW() const noexcept {
130 return has_polymermw;
131 }
132
133 bool hasFoam() const noexcept {
134 return has_foam;
135 }
136
137 bool hasBrine() const noexcept {
138 return has_brine;
139 }
140
141 bool hasZFraction() const noexcept {
142 return has_zFraction;
143 }
144
145 bool hasBiofilm() const noexcept {
146 return has_biofilm;
147 }
148
149 bool hasMICP() const noexcept {
150 return has_micp;
151 }
152
153 bool hasCO2orH2Store() const noexcept {
154 return has_co2_or_h2store;
155 }
156
157private:
158 // only account for the three main phases: oil, water, gas
159 unsigned char numActivePhases_ = 0;
160 std::array<bool, numPhases> phaseIsActive_;
161 std::array<short, numPhases> activeToCanonicalPhaseIdx_;
162 std::array<short, numPhases> canonicalToActivePhaseIdx_;
163
164 // numComponents only account for three main components: oil, water, gas
165 std::array<short, numComponents> activeToCanonicalCompIdx_;
166 std::array<short, numComponents> canonicalToActiveCompIdx_;
167
168 bool has_solvent{};
169 bool has_polymer{};
170 bool has_energy{};
171 // polymer molecular weight
172 bool has_polymermw{};
173 bool has_foam{};
174 bool has_brine{};
175 bool has_zFraction{};
176 bool has_biofilm{};
177 bool has_micp{};
178 bool has_co2_or_h2store{};
179
180 // updating the mapping between active and canonical phase indices
181 void updateIndexMapping_();
182
183 void reset_();
184
185};
186
187}
188
189#endif
Definition EclipseState.hpp:62
Definition Runspec.hpp:46
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30