From 244871829d9531bd2298ae530577a830006c5e9b Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Wed, 6 Dec 2017 16:12:00 +0100 Subject: [PATCH] PhaseUsage: handle polymer and solvent the same way as energy --- opm/core/props/BlackoilPhases.hpp | 15 +++- opm/core/props/phaseUsageFromDeck.hpp | 120 +++++++++++++++++--------- 2 files changed, 90 insertions(+), 45 deletions(-) diff --git a/opm/core/props/BlackoilPhases.hpp b/opm/core/props/BlackoilPhases.hpp index 0cc025bc6..0e7494d0f 100644 --- a/opm/core/props/BlackoilPhases.hpp +++ b/opm/core/props/BlackoilPhases.hpp @@ -28,16 +28,23 @@ namespace Opm { public: static const int MaxNumPhases = 3; - // enum ComponentIndex { Water = 0, Oil = 1, Gas = 2 }; - enum PhaseIndex { Aqua = 0, Liquid = 1, Vapour = 2, Energy = 3 }; + // "Crypto phases" are "phases" (or rather "conservation quantities") in the + // sense that they can be active or not and canonical indices can be translated + // to and from active ones. That said, they are not considered by num_phases or + // MaxNumPhases. The crypto phases which are currently implemented are solvent, + // polymer and energy. + static const int NumCryptoPhases = 3; + + // enum ComponentIndex { Water = 0, Oil = 1, Gas = 2 }; + enum PhaseIndex { Aqua = 0, Liquid = 1, Vapour = 2, Solvent = 3, Polymer = 4, Energy = 5 }; }; struct PhaseUsage : public BlackoilPhases { int num_phases; - int phase_used[MaxNumPhases + 1]; - int phase_pos[MaxNumPhases + 1]; + int phase_used[MaxNumPhases + NumCryptoPhases]; + int phase_pos[MaxNumPhases + NumCryptoPhases]; bool has_solvent; bool has_polymer; bool has_energy; diff --git a/opm/core/props/phaseUsageFromDeck.hpp b/opm/core/props/phaseUsageFromDeck.hpp index ded3edb5f..1b2fb4f6f 100644 --- a/opm/core/props/phaseUsageFromDeck.hpp +++ b/opm/core/props/phaseUsageFromDeck.hpp @@ -1,3 +1,4 @@ + /* Copyright 2012 SINTEF ICT, Applied Mathematics. @@ -36,23 +37,18 @@ namespace Opm inline PhaseUsage phaseUsageFromDeck(const Opm::EclipseState& eclipseState) { PhaseUsage pu; - std::fill(pu.phase_used, pu.phase_used + BlackoilPhases::MaxNumPhases, 0); + std::fill(pu.phase_used, pu.phase_used + BlackoilPhases::MaxNumPhases + BlackoilPhases::NumCryptoPhases, 0); const auto& phase = eclipseState.runspec().phases(); // Discover phase usage. - if (phase.active(Phase::WATER)) { - pu.phase_used[BlackoilPhases::Aqua] = 1; - } - if (phase.active(Phase::OIL)) { - pu.phase_used[BlackoilPhases::Liquid] = 1; - } - if (phase.active(Phase::GAS)) { - pu.phase_used[BlackoilPhases::Vapour] = 1; - } + pu.phase_used[BlackoilPhases::Aqua] = phase.active(Phase::WATER); + pu.phase_used[BlackoilPhases::Liquid] = phase.active(Phase::OIL); + pu.phase_used[BlackoilPhases::Vapour] = phase.active(Phase::GAS); + pu.num_phases = 0; int numActivePhases = 0; for (int phaseIdx = 0; phaseIdx < BlackoilPhases::MaxNumPhases; ++phaseIdx) { - if (!pu.phase_used[numActivePhases]) { + if (!pu.phase_used[phaseIdx]) { pu.phase_pos[phaseIdx] = -1; } else { @@ -74,16 +70,32 @@ namespace Opm } // Add solvent info - pu.has_solvent = false; - if (phase.active(Phase::SOLVENT)) { - pu.has_solvent = true; + pu.has_solvent = phase.active(Phase::SOLVENT); + if (pu.has_solvent) { + // this is quite a hack: even though solvent is not considered as in + // MaxNumPhases and pu.num_phases because this would break a lot of + // assumptions in old code, it is nevertheless an index to be translated + // to. solvent and solvent are even larger hacks because not even this can be + // done for them. + pu.phase_pos[BlackoilPhases::Solvent] = numActivePhases; + ++ numActivePhases; } + else + pu.phase_pos[BlackoilPhases::Solvent] = -1; - // Add polyme info - pu.has_polymer = false; - if (phase.active(Phase::POLYMER)) { - pu.has_polymer = true; + // Add polymer info + pu.has_polymer = phase.active(Phase::POLYMER); + if (pu.has_polymer) { + // this is quite a hack: even though polymer is not considered as in + // MaxNumPhases and pu.num_phases because this would break a lot of + // assumptions in old code, it is nevertheless an index to be translated + // to. polymer and solvent are even larger hacks because not even this can be + // done for them. + pu.phase_pos[BlackoilPhases::Polymer] = numActivePhases; + ++ numActivePhases; } + else + pu.phase_pos[BlackoilPhases::Polymer] = -1; // Add energy info pu.has_energy = phase.active(Phase::ENERGY); @@ -96,6 +108,9 @@ namespace Opm pu.phase_pos[BlackoilPhases::Energy] = numActivePhases; ++ numActivePhases; } + else + pu.phase_pos[BlackoilPhases::Energy] = -1; + return pu; } @@ -104,30 +119,26 @@ namespace Opm inline PhaseUsage phaseUsageFromDeck(const Opm::Deck& deck) { PhaseUsage pu; - std::fill(pu.phase_used, pu.phase_used + BlackoilPhases::MaxNumPhases, 0); + std::fill(pu.phase_used, pu.phase_used + BlackoilPhases::MaxNumPhases + BlackoilPhases::NumCryptoPhases, 0); Runspec runspec( deck ); const auto& phase = runspec.phases(); // Discover phase usage. - if (phase.active( Phase::WATER )) { - pu.phase_used[BlackoilPhases::Aqua] = 1; - } - if (phase.active( Phase::OIL )) { - pu.phase_used[BlackoilPhases::Liquid] = 1; - } - if (phase.active( Phase::GAS )) { - pu.phase_used[BlackoilPhases::Vapour] = 1; - } + pu.phase_used[BlackoilPhases::Aqua] = phase.active(Phase::WATER); + pu.phase_used[BlackoilPhases::Liquid] = phase.active(Phase::OIL); + pu.phase_used[BlackoilPhases::Vapour] = phase.active(Phase::GAS); + pu.num_phases = 0; - for (int i = 0; i < BlackoilPhases::MaxNumPhases; ++i) { - if (pu.phase_used[i]) { - pu.phase_pos[i] = pu.num_phases; - pu.num_phases += 1; + int numActivePhases = 0; + for (int phaseIdx = 0; phaseIdx < BlackoilPhases::MaxNumPhases; ++phaseIdx) { + if (!pu.phase_used[phaseIdx]) { + pu.phase_pos[phaseIdx] = -1; } else { - //Set to ridiculous value on purpose: should never be used - pu.phase_pos[i] = 2000000000; + pu.phase_pos[phaseIdx] = numActivePhases; + ++ numActivePhases; + pu.num_phases = numActivePhases; } } @@ -143,19 +154,46 @@ namespace Opm } // Add solvent info - pu.has_solvent = false; - if (phase.active(Phase::SOLVENT)) { - pu.has_solvent = true; + pu.has_solvent = phase.active(Phase::SOLVENT); + if (pu.has_solvent) { + // this is quite a hack: even though solvent is not considered as in + // MaxNumPhases and pu.num_phases because this would break a lot of + // assumptions in old code, it is nevertheless an index to be translated + // to. solvent and solvent are even larger hacks because not even this can be + // done for them. + pu.phase_pos[BlackoilPhases::Solvent] = numActivePhases; + ++ numActivePhases; } + else + pu.phase_pos[BlackoilPhases::Solvent] = -1; - // Add polyme info - pu.has_polymer = false; - if (phase.active(Phase::POLYMER)) { - pu.has_polymer = true; + // Add polymer info + pu.has_polymer = phase.active(Phase::POLYMER); + if (pu.has_polymer) { + // this is quite a hack: even though polymer is not considered as in + // MaxNumPhases and pu.num_phases because this would break a lot of + // assumptions in old code, it is nevertheless an index to be translated + // to. polymer and solvent are even larger hacks because not even this can be + // done for them. + pu.phase_pos[BlackoilPhases::Polymer] = numActivePhases; + ++ numActivePhases; } + else + pu.phase_pos[BlackoilPhases::Polymer] = -1; // Add energy info pu.has_energy = phase.active(Phase::ENERGY); + if (pu.has_energy) { + // this is quite a hack: even though energy is not considered as in + // MaxNumPhases and pu.num_phases because this would break a lot of + // assumptions in old code, it is nevertheless an index to be translated + // to. polymer and solvent are even larger hacks because not even this can be + // done for them. + pu.phase_pos[BlackoilPhases::Energy] = numActivePhases; + ++ numActivePhases; + } + else + pu.phase_pos[BlackoilPhases::Energy] = -1; return pu; }