From d5453593959620cb28b590c7913116db1f5be424 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 19 Oct 2020 17:06:04 +0200 Subject: [PATCH 1/5] Use optional - and default to self - for reinj and voidage groups --- .../EclipseState/Schedule/Group/Group.hpp | 4 ++-- .../EclipseState/Schedule/Group/Group.cpp | 4 ++-- .../EclipseState/Schedule/KeywordHandlers.cpp | 19 ++++++------------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/Group/Group.hpp b/opm/parser/eclipse/EclipseState/Schedule/Group/Group.hpp index a23ecff16..6af49e39e 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Group/Group.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Group/Group.hpp @@ -121,8 +121,8 @@ struct GroupInjectionProperties { UDAValue resv_max_rate; UDAValue target_reinj_fraction; UDAValue target_void_fraction; - std::string reinj_group; - std::string voidage_group; + std::optional reinj_group; + std::optional voidage_group; bool available_group_control = true; static GroupInjectionProperties serializeObject(); diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Group/Group.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Group/Group.cpp index ac79b32f5..3e4e99840 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Group/Group.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Group/Group.cpp @@ -465,8 +465,8 @@ Group::InjectionControls Group::injectionControls(Phase phase, const SummaryStat ic.resv_max_rate = UDA::eval_group_uda(inj.resv_max_rate, this->m_name, st, this->udq_undefined); ic.target_reinj_fraction = UDA::eval_group_uda(inj.target_reinj_fraction, this->m_name, st, this->udq_undefined); ic.target_void_fraction = UDA::eval_group_uda(inj.target_void_fraction, this->m_name, st, this->udq_undefined); - ic.reinj_group = inj.reinj_group; - ic.voidage_group = inj.voidage_group; + ic.reinj_group = inj.reinj_group.value_or(this->m_name); + ic.voidage_group = inj.voidage_group.value_or(this->m_name); return ic; } diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/KeywordHandlers.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/KeywordHandlers.cpp index 16009bf3f..59c33de0d 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/KeywordHandlers.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/KeywordHandlers.cpp @@ -270,19 +270,8 @@ namespace { const auto voidage_target = record.getItem("VOIDAGE_TARGET").get(0); const bool is_free = DeckItem::to_bool(record.getItem("FREE").getTrimmedString(0)); - const std::optional reinj_group_name = record.getItem("REINJECT_GROUP").defaultApplied(0) - ? std::nullopt - : std::optional(record.getItem("REINJECT_GROUP").getTrimmedString(0)); - - const std::optional voidage_group_name = record.getItem("VOIDAGE_GROUP").defaultApplied(0) - ? std::nullopt - : std::optional(record.getItem("VOIDAGE_GROUP").getTrimmedString(0)); - for (const auto& group_name : group_names) { const bool availableForGroupControl = is_free && (group_name != "FIELD"); - const std::string reinj_group = reinj_group_name.value_or(group_name); - const std::string voidage_group = voidage_group_name.value_or(group_name); - auto group_ptr = std::make_shared(this->getGroup(group_name, handlerContext.currentStep)); Group::GroupInjectionProperties injection; injection.phase = phase; @@ -292,8 +281,6 @@ namespace { injection.target_reinj_fraction = reinj_target; injection.target_void_fraction = voidage_target; injection.injection_controls = 0; - injection.reinj_group = reinj_group; - injection.voidage_group = voidage_group; injection.available_group_control = availableForGroupControl; if (!record.getItem("SURFACE_TARGET").defaultApplied(0)) @@ -308,6 +295,12 @@ namespace { if (!record.getItem("VOIDAGE_TARGET").defaultApplied(0)) injection.injection_controls += static_cast(Group::InjectionCMode::VREP); + if (record.getItem("REINJECT_GROUP").hasValue(0)) + injection.reinj_group = record.getItem("REINJECT_GROUP").getTrimmedString(0); + + if (record.getItem("VOIDAGE_GROUP").hasValue(0)) + injection.voidage_group = record.getItem("VOIDAGE_GROUP").getTrimmedString(0); + if (group_ptr->updateInjection(injection)) { this->updateGroup(std::move(group_ptr), handlerContext.currentStep); m_events.addEvent( ScheduleEvents::GROUP_INJECTION_UPDATE , handlerContext.currentStep); From b72460f0c89db7d602b9d2f4f961928a534e3077 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Tue, 20 Oct 2020 08:28:55 +0200 Subject: [PATCH 2/5] Remove unused members from rst header class --- opm/io/eclipse/rst/header.hpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/opm/io/eclipse/rst/header.hpp b/opm/io/eclipse/rst/header.hpp index 0034dc195..c177b795e 100644 --- a/opm/io/eclipse/rst/header.hpp +++ b/opm/io/eclipse/rst/header.hpp @@ -84,9 +84,6 @@ struct RstHeader { int nilbrz; int ntfip ; int nmfipr; - int nrfreg; - int ntfreg; - int nplmix; int ngroup; int nwgmax; From 2bc338e87ff48456edb66bea930959ad989374f5 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Tue, 20 Oct 2020 08:34:27 +0200 Subject: [PATCH 3/5] Add functions converting integer group control modes to enum --- .../EclipseState/Schedule/Group/Group.hpp | 3 +- .../EclipseState/Schedule/Group/Group.cpp | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/Group/Group.hpp b/opm/parser/eclipse/EclipseState/Schedule/Group/Group.hpp index 6af49e39e..1b4c3dcd0 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Group/Group.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Group/Group.hpp @@ -79,6 +79,7 @@ enum class InjectionCMode : int { }; static const std::string InjectionCMode2String( InjectionCMode enumValue ); static InjectionCMode InjectionCModeFromString( const std::string& stringValue ); +static InjectionCMode InjectionCModeFromInt(int ecl_int); enum class ProductionCMode : int { @@ -94,7 +95,7 @@ enum class ProductionCMode : int { }; static const std::string ProductionCMode2String( ProductionCMode enumValue ); static ProductionCMode ProductionCModeFromString( const std::string& stringValue ); - +static ProductionCMode ProductionCModeFromInt(int ecl_int); enum class GuideRateTarget { OIL = 0, diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Group/Group.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Group/Group.cpp index 3e4e99840..89edf019c 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Group/Group.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Group/Group.cpp @@ -17,6 +17,7 @@ along with OPM. If not, see . */ +#include #include #include @@ -642,6 +643,48 @@ Group::ProductionCMode Group::ProductionCModeFromString( const std::string& stri throw std::invalid_argument("Unknown enum state string: " + stringValue ); } +Group::ProductionCMode Group::ProductionCModeFromInt(int ecl_int) { + switch (ecl_int) { + case 0: + // The inverse function in AggregateGroupData also writes 0 + // for ProductionCMode::FLD. + return ProductionCMode::NONE; + case 1: + return ProductionCMode::ORAT; + case 2: + return ProductionCMode::WRAT; + case 3: + return ProductionCMode::GRAT; + case 4: + return ProductionCMode::LRAT; + case 5: + return ProductionCMode::RESV; + default: + throw std::logic_error(fmt::format("Not recognized value: {} for PRODUCTION CMODE", ecl_int)); + } +} + +Group::InjectionCMode Group::InjectionCModeFromInt(int ecl_int) { + switch (ecl_int) { + case 0: + // The inverse function in AggregateGroupData also writes 0 + // for InjectionCMode::FLD and InjectionCMode::SALE + return InjectionCMode::NONE; + case 1: + return InjectionCMode::RATE; + case 2: + return InjectionCMode::RESV; + case 3: + return InjectionCMode::REIN; + case 4: + return InjectionCMode::VREP; + case 5: + return InjectionCMode::RESV; + default: + throw std::logic_error(fmt::format("Not recognized value: {} for INJECTION CMODE", ecl_int)); + } +} + Group::GuideRateTarget Group::GuideRateTargetFromString( const std::string& stringValue ) { if (stringValue == "OIL") return GuideRateTarget::OIL; From 5c6fa9cc519e6e87cec9791315544e1045c3bcce Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Tue, 20 Oct 2020 08:40:41 +0200 Subject: [PATCH 4/5] Add Group update events after loading from restart file --- .../parser/eclipse/EclipseState/Schedule/Schedule.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp index f800ad638..1c66e6f8c 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp @@ -1608,6 +1608,16 @@ namespace { for (const auto& rst_group : rst_state.groups) { auto group = Group{ rst_group, this->groups.size(), static_cast(report_step), udq_undefined, unit_system }; this->addGroup(group, report_step); + + if (group.isProductionGroup()) { + this->m_events.addEvent(ScheduleEvents::GROUP_PRODUCTION_UPDATE, report_step + 1); + this->addWellGroupEvent(rst_group.name, ScheduleEvents::GROUP_PRODUCTION_UPDATE, report_step + 1); + } + + if (group.isInjectionGroup()) { + this->m_events.addEvent(ScheduleEvents::GROUP_INJECTION_UPDATE, report_step + 1); + this->addWellGroupEvent(rst_group.name, ScheduleEvents::GROUP_INJECTION_UPDATE, report_step + 1); + } } for (std::size_t group_index = 0; group_index < rst_state.groups.size(); group_index++) { From 67f24bd3a7720cf25bb7c01bca0e4aa1971c539f Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Tue, 20 Oct 2020 08:36:35 +0200 Subject: [PATCH 5/5] When loading from restart: set wells active control also for SHUT --- .../EclipseState/Schedule/Well/Well.cpp | 127 +++++++++--------- 1 file changed, 63 insertions(+), 64 deletions(-) diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Well/Well.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Well/Well.cpp index 7ef27895e..37183975c 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Well/Well.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Well/Well.cpp @@ -188,43 +188,42 @@ Well::Well(const RestartIO::RstWell& rst_well, p->addProductionControl( Well::ProducerCMode::THP ); } - if (this->status == Well::Status::OPEN) { - switch (rst_well.active_control) { - case CModeVal::Group: - p->controlMode = Well::ProducerCMode::GRUP; - p->addProductionControl(Well::ProducerCMode::GRUP); - break; - case CModeVal::OilRate: - p->controlMode = Well::ProducerCMode::ORAT; - break; - case CModeVal::WatRate: - p->controlMode = Well::ProducerCMode::WRAT; - p->addProductionControl(Well::ProducerCMode::WRAT); - break; - case CModeVal::GasRate: - p->controlMode = Well::ProducerCMode::GRAT; - p->addProductionControl(Well::ProducerCMode::GRAT); - break; - case CModeVal::LiqRate: - p->controlMode = Well::ProducerCMode::LRAT; - p->addProductionControl(Well::ProducerCMode::LRAT); - break; - case CModeVal::ResVRate: - p->controlMode = Well::ProducerCMode::RESV; - p->addProductionControl(Well::ProducerCMode::RESV); - break; - case CModeVal::THP: - p->controlMode = Well::ProducerCMode::THP; - p->addProductionControl(Well::ProducerCMode::THP); - break; - case CModeVal::BHP: - p->controlMode = Well::ProducerCMode::BHP; - p->addProductionControl(Well::ProducerCMode::BHP); - break; - default: - throw std::invalid_argument("Can not convert integer value: " + std::to_string(rst_well.active_control) - + " to control type"); - } + switch (rst_well.active_control) { + case CModeVal::Group: + p->controlMode = Well::ProducerCMode::GRUP; + p->addProductionControl(Well::ProducerCMode::GRUP); + + break; + case CModeVal::OilRate: + p->controlMode = Well::ProducerCMode::ORAT; + p->addProductionControl(Well::ProducerCMode::ORAT); + break; + case CModeVal::WatRate: + p->controlMode = Well::ProducerCMode::WRAT; + p->addProductionControl(Well::ProducerCMode::WRAT); + break; + case CModeVal::GasRate: + p->controlMode = Well::ProducerCMode::GRAT; + p->addProductionControl(Well::ProducerCMode::GRAT); + break; + case CModeVal::LiqRate: + p->controlMode = Well::ProducerCMode::LRAT; + p->addProductionControl(Well::ProducerCMode::LRAT); + break; + case CModeVal::ResVRate: + p->controlMode = Well::ProducerCMode::RESV; + p->addProductionControl(Well::ProducerCMode::RESV); + break; + case CModeVal::THP: + p->controlMode = Well::ProducerCMode::THP; + p->addProductionControl(Well::ProducerCMode::THP); + break; + case CModeVal::BHP: + p->controlMode = Well::ProducerCMode::BHP; + p->addProductionControl(Well::ProducerCMode::BHP); + break; + default: + throw std::invalid_argument(fmt::format("Can not convert integer value:{} to control type", rst_well.active_control)); } p->addProductionControl(Well::ProducerCMode::BHP); @@ -236,33 +235,33 @@ Well::Well(const RestartIO::RstWell& rst_well, i->VFPTableNumber = rst_well.vfp_table; i->predictionMode = this->prediction_mode; - if (this->status == Well::Status::OPEN) { - switch (rst_well.active_control) { - case CModeVal::Group: - i->controlMode = Well::InjectorCMode::GRUP; - break; - case CModeVal::OilRate: [[fallthrough]]; - case CModeVal::WatRate: [[fallthrough]]; - case CModeVal::GasRate: [[fallthrough]]; - case CModeVal::LiqRate: - i->controlMode = Well::InjectorCMode::RATE; - i->addInjectionControl(Well::InjectorCMode::RATE); - break; - case CModeVal::ResVRate: - i->controlMode = Well::InjectorCMode::RESV; - i->addInjectionControl(Well::InjectorCMode::RESV); - break; - case CModeVal::THP: - i->controlMode = Well::InjectorCMode::THP; - i->addInjectionControl(Well::InjectorCMode::THP); - break; - case CModeVal::BHP: - i->controlMode = Well::InjectorCMode::BHP; - break; - default: - throw std::invalid_argument( - "Could not convert integer value: " + std::to_string(rst_well.active_control) + " to control type"); - } + switch (rst_well.active_control) { + case CModeVal::Group: + i->controlMode = Well::InjectorCMode::GRUP; + break; + case CModeVal::OilRate: + [[fallthrough]]; + case CModeVal::WatRate: + [[fallthrough]]; + case CModeVal::GasRate: + [[fallthrough]]; + case CModeVal::LiqRate: + i->controlMode = Well::InjectorCMode::RATE; + i->addInjectionControl(Well::InjectorCMode::RATE); + break; + case CModeVal::ResVRate: + i->controlMode = Well::InjectorCMode::RESV; + i->addInjectionControl(Well::InjectorCMode::RESV); + break; + case CModeVal::THP: + i->controlMode = Well::InjectorCMode::THP; + i->addInjectionControl(Well::InjectorCMode::THP); + break; + case CModeVal::BHP: + i->controlMode = Well::InjectorCMode::BHP; + break; + default: + throw std::invalid_argument(fmt::format("Can not convert integer value:{} to control type", rst_well.active_control)); } i->injectorType = rst_well.wtype.injector_type();