44 static constexpr int numPhases = IndexTraits::numPhases;
45 static constexpr int numComponents = IndexTraits::numComponents;
47 static constexpr int waterPhaseIdx = IndexTraits::waterPhaseIdx;
48 static constexpr int oilPhaseIdx = IndexTraits::oilPhaseIdx;
49 static constexpr int gasPhaseIdx = IndexTraits::gasPhaseIdx;
51 static constexpr int waterCompIdx = IndexTraits::waterCompIdx;
52 static constexpr int oilCompIdx = IndexTraits::oilCompIdx;
53 static constexpr int gasCompIdx = IndexTraits::gasCompIdx;
57 [[nodiscard]]
unsigned numActivePhases()
const {
58 return numActivePhases_;
61 [[nodiscard]]
bool phaseIsActive(
unsigned phaseIdx)
const {
62 assert(phaseIdx < numPhases);
63 return phaseIsActive_[phaseIdx];
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.");
71 return canonicalToActivePhaseIdx_[phaseIdx];
74 [[nodiscard]]
short activeToCanonicalPhaseIdx(
unsigned activePhaseIdx)
const {
75 assert(activePhaseIdx< numActivePhases_);
76 return activeToCanonicalPhaseIdx_[activePhaseIdx];
79 [[nodiscard]]
short activeToCanonicalCompIdx(
unsigned activeCompIdx)
const {
80 if (activeCompIdx >= numActivePhases()) {
83 return activeToCanonicalCompIdx_[activeCompIdx];
86 [[nodiscard]]
short canonicalToActiveCompIdx(
unsigned compIdx)
const {
87 assert(compIdx < numComponents);
88 return canonicalToActiveCompIdx_[compIdx];
91 [[nodiscard]]
short activePhaseToActiveCompIdx(
unsigned activePhaseIdx)
const {
92 if (activePhaseIdx >= numActivePhases()) {
93 return activePhaseIdx;
95 const short canonicalPhaseIdx = activeToCanonicalPhaseIdx(activePhaseIdx);
96 const short canonicalCompIdx = IndexTraits::phaseToComponentIdx(canonicalPhaseIdx);
97 const short activeCompIdx = canonicalToActiveCompIdx(canonicalCompIdx);
101 [[nodiscard]]
short activeCompToActivePhaseIdx(
unsigned activeCompIdx)
const {
102 if (activeCompIdx >= numActivePhases()) {
103 return activeCompIdx;
105 const short canonicalCompIdx = activeToCanonicalCompIdx(activeCompIdx);
106 const short canonicalPhaseIdx = IndexTraits::componentToPhaseIdx(canonicalCompIdx);
107 const short activePhaseIdx = canonicalToActivePhaseIdx(canonicalPhaseIdx);
108 return activePhaseIdx;
112 void initFromPhases(
const Phases& phases);
117 bool hasSolvent()
const noexcept {
121 bool hasPolymer()
const noexcept {
125 bool hasEnergy()
const noexcept {
129 bool hasPolymerMW()
const noexcept {
130 return has_polymermw;
133 bool hasFoam()
const noexcept {
137 bool hasBrine()
const noexcept {
141 bool hasZFraction()
const noexcept {
142 return has_zFraction;
145 bool hasBiofilm()
const noexcept {
149 bool hasMICP()
const noexcept {
153 bool hasCO2orH2Store()
const noexcept {
154 return has_co2_or_h2store;
159 unsigned char numActivePhases_ = 0;
160 std::array<bool, numPhases> phaseIsActive_;
161 std::array<short, numPhases> activeToCanonicalPhaseIdx_;
162 std::array<short, numPhases> canonicalToActivePhaseIdx_;
165 std::array<short, numComponents> activeToCanonicalCompIdx_;
166 std::array<short, numComponents> canonicalToActiveCompIdx_;
172 bool has_polymermw{};
175 bool has_zFraction{};
178 bool has_co2_or_h2store{};
181 void updateIndexMapping_();