From 4e5cc1c94d9558db8fce5d9e2a82c7b52e43b58f Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Wed, 4 Nov 2020 10:41:01 +0100 Subject: [PATCH] Refactor function groupInjectionControllable() --- src/opm/output/eclipse/AggregateGroupData.cpp | 62 ++++++++----------- 1 file changed, 25 insertions(+), 37 deletions(-) diff --git a/src/opm/output/eclipse/AggregateGroupData.cpp b/src/opm/output/eclipse/AggregateGroupData.cpp index 7dbf2686c..fc2a83f36 100644 --- a/src/opm/output/eclipse/AggregateGroupData.cpp +++ b/src/opm/output/eclipse/AggregateGroupData.cpp @@ -156,50 +156,38 @@ bool groupProductionControllable(const Opm::Schedule& sched, const Opm::SummaryS } } -bool groupInjectionControllable(const Opm::Schedule& sched, const Opm::SummaryState& sumState, const Opm::Group& group, const Opm::Phase& iPhase, const size_t simStep) +void groupInjectionControllable(const Opm::Schedule& sched, const Opm::SummaryState& sumState, const Opm::Group& group, const Opm::Phase& iPhase, const size_t simStep, bool& controllable) { using wellCtrlMode = ::Opm::RestartIO::Helpers::VectorItems::IWell::Value::WellCtrlMode; - bool controllable = false; - if (group.defined( simStep )) { - if (!group.wellgroup()) { - if(!group.groups().empty()) { - for (const auto& group_name : group.groups()) { - if (groupInjectionControllable(sched, sumState, sched.getGroup(group_name, simStep), iPhase, simStep)) { - controllable = true; - continue; - } - } + if (controllable) + return; + + for (const auto& group_name : group.groups()) + groupInjectionControllable(sched, sumState, sched.getGroup(group_name, simStep), iPhase, simStep, controllable); + + for (const auto& well_name : group.wells()) { + const auto& well = sched.getWell(well_name, simStep); + if (well.isInjector() && iPhase == well.wellType().injection_phase()) { + int cur_inj_ctrl = 0; + // Find control mode for well + const std::string sum_key = "WMCTL"; + if (sumState.has_well_var(well_name, sum_key)) { + cur_inj_ctrl = static_cast(sumState.get_well_var(well_name, sum_key)); + } + + if (cur_inj_ctrl == wellCtrlMode::Group) { + controllable = true; + return; } } - else { - for (const auto& well_name : group.wells()) { - const auto& well = sched.getWell(well_name, simStep); - if (well.isInjector()) { - if (((iPhase == Opm::Phase::WATER) && (well.injectionControls(sumState).injector_type == Opm::InjectorType::WATER)) || - ((iPhase == Opm::Phase::GAS) && (well.injectionControls(sumState).injector_type == Opm::InjectorType::GAS)) - ) { - int cur_inj_ctrl = 0; - // Find control mode for well - std::string well_key_1 = "WMCTL:" + well_name; - if (sumState.has(well_key_1)) { - cur_inj_ctrl = static_cast(sumState.get(well_key_1)); - } - if (cur_inj_ctrl == wellCtrlMode::Group) { - controllable = true; - continue; - } - } - } - } - } - return controllable; - } else { - std::stringstream str; - str << "actual group has not been defined at report time: " << simStep; - throw std::invalid_argument(str.str()); } } +bool groupInjectionControllable(const Opm::Schedule& sched, const Opm::SummaryState& sumState, const Opm::Group& group, const Opm::Phase& iPhase, const size_t simStep) { + bool controllable = false; + groupInjectionControllable(sched, sumState, group, iPhase, simStep, controllable); + return controllable; +} int higherLevelProdControlGroupSeqIndex(const Opm::Schedule& sched,