Merge pull request #3060 from joakim-hove/wellpi-extract

Extract method wellPI() from existing lambda implementation
This commit is contained in:
Joakim Hove 2021-02-13 08:55:35 +01:00 committed by GitHub
commit 591826ea4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 32 deletions

View File

@ -267,6 +267,7 @@ namespace Opm {
/// Returns true if the well was actually found and shut.
bool forceShutWellByNameIfPredictionMode(const std::string& wellname, const double simulation_time);
double wellPI(int well_index) const;
protected:
Simulator& ebosSimulator_;

View File

@ -2576,6 +2576,40 @@ namespace Opm {
template<typename TypeTag>
double
BlackoilWellModel<TypeTag>::
wellPI(int well_index) const
{
const auto& pu = this->phase_usage_;
const auto np = this->numPhases();
const auto* pi = &this->well_state_.productivityIndex()[np*well_index + 0];
const auto preferred = this->wells_ecl_[well_index].getPreferredPhase();
switch (preferred) { // Should really have LIQUID = OIL + WATER here too...
case Phase::WATER:
return pu.phase_used[BlackoilPhases::PhaseIndex::Aqua]
? pi[pu.phase_pos[BlackoilPhases::PhaseIndex::Aqua]]
: 0.0;
case Phase::OIL:
return pu.phase_used[BlackoilPhases::PhaseIndex::Liquid]
? pi[pu.phase_pos[BlackoilPhases::PhaseIndex::Liquid]]
: 0.0;
case Phase::GAS:
return pu.phase_used[BlackoilPhases::PhaseIndex::Vapour]
? pi[pu.phase_pos[BlackoilPhases::PhaseIndex::Vapour]]
: 0.0;
default:
throw std::invalid_argument {
"Unsupported preferred phase " +
std::to_string(static_cast<int>(preferred))
};
}
}
template<typename TypeTag>
void
@ -2595,37 +2629,6 @@ namespace Opm {
ScheduleEvents::Events::WELL_PRODUCTIVITY_INDEX);
};
auto getWellPI = [this](const int well_index) -> double
{
const auto& pu = this->phase_usage_;
const auto np = this->numPhases();
const auto* pi = &this->well_state_.productivityIndex()[np*well_index + 0];
const auto preferred = this->wells_ecl_[well_index].getPreferredPhase();
switch (preferred) { // Should really have LIQUID = OIL + WATER here too...
case Phase::WATER:
return pu.phase_used[BlackoilPhases::PhaseIndex::Aqua]
? pi[pu.phase_pos[BlackoilPhases::PhaseIndex::Aqua]]
: 0.0;
case Phase::OIL:
return pu.phase_used[BlackoilPhases::PhaseIndex::Liquid]
? pi[pu.phase_pos[BlackoilPhases::PhaseIndex::Liquid]]
: 0.0;
case Phase::GAS:
return pu.phase_used[BlackoilPhases::PhaseIndex::Vapour]
? pi[pu.phase_pos[BlackoilPhases::PhaseIndex::Vapour]]
: 0.0;
default:
throw std::invalid_argument {
"Unsupported preferred phase " +
std::to_string(static_cast<int>(preferred))
};
}
};
auto rescaleWellPI =
[this, timeStepIdx](const int well_index,
const double newWellPI) -> void
@ -2663,7 +2666,7 @@ namespace Opm {
const auto nw = this->numLocalWells();
for (auto wellID = 0*nw; wellID < nw; ++wellID) {
if (hasWellPIEvent(wellID)) {
const auto newWellPI = getWellPI(wellID);
const auto newWellPI = this->wellPI(wellID);
rescaleWellPI(wellID, newWellPI);
}
}