mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Merge pull request #1664 from GitPaean/removing_some_repeated_code_phase_usage
removing some repeated code in phaseUsageFromDeck
This commit is contained in:
commit
e3c0a21d6d
@ -31,19 +31,15 @@
|
|||||||
|
|
||||||
namespace Opm
|
namespace Opm
|
||||||
{
|
{
|
||||||
|
/// Determine the active phases
|
||||||
/// Looks at presence of WATER, OIL and GAS keywords in state object
|
inline PhaseUsage phaseUsage(const Phases& phases) {
|
||||||
/// to determine active phases.
|
|
||||||
inline PhaseUsage phaseUsageFromDeck(const Opm::EclipseState& eclipseState)
|
|
||||||
{
|
|
||||||
PhaseUsage pu;
|
PhaseUsage pu;
|
||||||
std::fill(pu.phase_used, pu.phase_used + BlackoilPhases::MaxNumPhases + BlackoilPhases::NumCryptoPhases, 0);
|
std::fill(pu.phase_used, pu.phase_used + BlackoilPhases::MaxNumPhases + BlackoilPhases::NumCryptoPhases, 0);
|
||||||
|
|
||||||
const auto& phase = eclipseState.runspec().phases();
|
|
||||||
// Discover phase usage.
|
// Discover phase usage.
|
||||||
pu.phase_used[BlackoilPhases::Aqua] = phase.active(Phase::WATER);
|
pu.phase_used[BlackoilPhases::Aqua] = phases.active(Phase::WATER);
|
||||||
pu.phase_used[BlackoilPhases::Liquid] = phase.active(Phase::OIL);
|
pu.phase_used[BlackoilPhases::Liquid] = phases.active(Phase::OIL);
|
||||||
pu.phase_used[BlackoilPhases::Vapour] = phase.active(Phase::GAS);
|
pu.phase_used[BlackoilPhases::Vapour] = phases.active(Phase::GAS);
|
||||||
|
|
||||||
pu.num_phases = 0;
|
pu.num_phases = 0;
|
||||||
int numActivePhases = 0;
|
int numActivePhases = 0;
|
||||||
@ -70,7 +66,7 @@ namespace Opm
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add solvent info
|
// Add solvent info
|
||||||
pu.has_solvent = phase.active(Phase::SOLVENT);
|
pu.has_solvent = phases.active(Phase::SOLVENT);
|
||||||
if (pu.has_solvent) {
|
if (pu.has_solvent) {
|
||||||
// this is quite a hack: even though solvent is not considered as in
|
// 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
|
// MaxNumPhases and pu.num_phases because this would break a lot of
|
||||||
@ -84,7 +80,7 @@ namespace Opm
|
|||||||
pu.phase_pos[BlackoilPhases::Solvent] = -1;
|
pu.phase_pos[BlackoilPhases::Solvent] = -1;
|
||||||
|
|
||||||
// Add polymer info
|
// Add polymer info
|
||||||
pu.has_polymer = phase.active(Phase::POLYMER);
|
pu.has_polymer = phases.active(Phase::POLYMER);
|
||||||
if (pu.has_polymer) {
|
if (pu.has_polymer) {
|
||||||
// this is quite a hack: even though polymer is not considered as in
|
// 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
|
// MaxNumPhases and pu.num_phases because this would break a lot of
|
||||||
@ -98,7 +94,7 @@ namespace Opm
|
|||||||
pu.phase_pos[BlackoilPhases::Polymer] = -1;
|
pu.phase_pos[BlackoilPhases::Polymer] = -1;
|
||||||
|
|
||||||
// Add energy info
|
// Add energy info
|
||||||
pu.has_energy = phase.active(Phase::ENERGY);
|
pu.has_energy = phases.active(Phase::ENERGY);
|
||||||
if (pu.has_energy) {
|
if (pu.has_energy) {
|
||||||
// this is quite a hack: even though energy is not considered as in
|
// 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
|
// MaxNumPhases and pu.num_phases because this would break a lot of
|
||||||
@ -114,88 +110,23 @@ namespace Opm
|
|||||||
return pu;
|
return pu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Looks at presence of WATER, OIL and GAS keywords in state object
|
||||||
|
/// to determine active phases.
|
||||||
|
inline PhaseUsage phaseUsageFromDeck(const Opm::EclipseState& eclipseState)
|
||||||
|
{
|
||||||
|
const auto& phases = eclipseState.runspec().phases();
|
||||||
|
|
||||||
|
return phaseUsage(phases);
|
||||||
|
}
|
||||||
|
|
||||||
/// Looks at presence of WATER, OIL and GAS keywords in deck
|
/// Looks at presence of WATER, OIL and GAS keywords in deck
|
||||||
/// to determine active phases.
|
/// to determine active phases.
|
||||||
inline PhaseUsage phaseUsageFromDeck(const Opm::Deck& deck)
|
inline PhaseUsage phaseUsageFromDeck(const Opm::Deck& deck)
|
||||||
{
|
{
|
||||||
PhaseUsage pu;
|
|
||||||
std::fill(pu.phase_used, pu.phase_used + BlackoilPhases::MaxNumPhases + BlackoilPhases::NumCryptoPhases, 0);
|
|
||||||
|
|
||||||
Runspec runspec( deck );
|
Runspec runspec( deck );
|
||||||
const auto& phase = runspec.phases();
|
const auto& phases = runspec.phases();
|
||||||
|
|
||||||
// Discover phase usage.
|
return phaseUsage(phases);
|
||||||
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[phaseIdx]) {
|
|
||||||
pu.phase_pos[phaseIdx] = -1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
pu.phase_pos[phaseIdx] = numActivePhases;
|
|
||||||
++ numActivePhases;
|
|
||||||
pu.num_phases = numActivePhases;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only 2 or 3 phase systems handled.
|
|
||||||
if (pu.num_phases < 2 || pu.num_phases > 3) {
|
|
||||||
OPM_THROW(std::runtime_error, "Cannot handle cases with " << pu.num_phases << " phases.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// We need oil systems, since we do not support the keywords needed for
|
|
||||||
// water-gas systems.
|
|
||||||
if (!pu.phase_used[BlackoilPhases::Liquid]) {
|
|
||||||
OPM_THROW(std::runtime_error, "Cannot handle cases with no OIL, i.e. water-gas systems.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add solvent info
|
|
||||||
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 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user