From 1b1f7b807d470dc8e67fe7e014e8f5184dc2e583 Mon Sep 17 00:00:00 2001 From: Kai Bao Date: Thu, 3 Jan 2019 13:16:15 +0100 Subject: [PATCH] re-organizing the handleWCONINH from Schedule --- .../Schedule/WellInjectionProperties.hpp | 2 - .../EclipseState/Schedule/Schedule.cpp | 48 ++++++++++--------- .../Schedule/WellInjectionProperties.cpp | 3 -- .../Schedule/WellProductionProperties.cpp | 1 - tests/parser/ScheduleTests.cpp | 2 +- 5 files changed, 27 insertions(+), 29 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/WellInjectionProperties.hpp b/opm/parser/eclipse/EclipseState/Schedule/WellInjectionProperties.hpp index aec1f0d9a..96381497d 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/WellInjectionProperties.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/WellInjectionProperties.hpp @@ -36,8 +36,6 @@ namespace Opm { double THPH; int VFPTableNumber; bool predictionMode; - // whether the BHP limit is obtained through WELTARG - bool BHPLimitFromWeltarg; int injectionControls; WellInjector::TypeEnum injectorType; WellInjector::ControlModeEnum controlMode; diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp index ceb6bdc5d..a01cfc64d 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp @@ -971,7 +971,12 @@ namespace Opm { const std::string& wellNamePattern = record.getItem("WELL").getTrimmedString(0); // convert injection rates to SI - WellInjector::TypeEnum injectorType = WellInjector::TypeFromString( record.getItem("TYPE").getTrimmedString(0)); + const auto& typeItem = record.getItem("TYPE"); + if (typeItem.defaultApplied(0)) { + const std::string msg = "Injection type can not be defaulted for keyword WCONINJH"; + throw std::invalid_argument(msg); + } + const WellInjector::TypeEnum injectorType = WellInjector::TypeFromString( typeItem.getTrimmedString(0)); double injectionRate = record.getItem("RATE").get< double >(0); injectionRate = convertInjectionRateToSI(injectionRate, injectorType, section.unitSystem()); @@ -986,9 +991,6 @@ namespace Opm { updateWellStatus( *well, currentStep, status ); WellInjectionProperties properties(well->getInjectionPropertiesCopy(currentStep)); - std::cout << " well " << well->name() << " currentStep " << currentStep << " prev_properties " << std::endl - << properties << std::endl; - properties.injectorType = injectorType; if (!record.getItem("RATE").defaultApplied(0)) { @@ -1001,22 +1003,28 @@ namespace Opm { properties.THPH = record.getItem("THP").getSIDouble(0); const std::string& cmodeString = record.getItem("CMODE").getTrimmedString(0); - WellInjector::ControlModeEnum controlMode = WellInjector::ControlModeFromString( cmodeString ); + const WellInjector::ControlModeEnum controlMode = WellInjector::ControlModeFromString( cmodeString ); - // if the BHP limit is set by WELTARG keyword, we will not try to change the BHP limit - // Otherwise, we need to make a decision - // TODO: some tests are required to check how WELTARG interacts with WCONINJH BHP control - const bool switching_from_producer = well->isProducer(currentStep); - std::cout << " well " << well->name() << " switching_from_producer " << switching_from_producer - << " at report step " << currentStep << std::endl; - if (properties.predictionMode || properties.controlMode == WellInjector::BHP || switching_from_producer) { - // there is no document about what value the default BHP limit should be - // we use the one from WCONINJE for now - properties.BHPLimit = 6895. * unit::barsa; - } else if (!properties.BHPLimitFromWeltarg && controlMode == WellInjector::BHP) { - properties.BHPLimit = properties.BHPH; + if ( !(controlMode == WellInjector::RATE || controlMode == WellInjector::BHP) ) { + const std::string msg = "Only RATE and BHP control are allowed for WCONINJH for well " + well->name(); + throw std::invalid_argument(msg); + } + + // when well is under BHP control, we use its historical BHP value as BHP limit + if (controlMode == WellInjector::BHP) { + properties.BHPLimit = properties.BHPH; + } else { + const bool switching_from_producer = well->isProducer(currentStep); + const bool switching_from_prediction = properties.predictionMode; + const bool switching_from_BHP_control = properties.controlMode == WellInjector::BHP; + if (switching_from_prediction || + switching_from_BHP_control || + switching_from_producer) { + // we use defaulted BHP value, it is from simulation, without finding any related document + properties.BHPLimit = 6891.2 * unit::barsa; + } + // otherwise, we keep its previous BHP limit } - // otherwise, the BHPLimit stays the same properties.addInjectionControl(WellInjector::BHP); @@ -1030,9 +1038,6 @@ namespace Opm { properties.VFPTableNumber = VFPTableNumber; } - std::cout << " well " << well->name() << " currentStep " << currentStep << " new_properties " << std::endl - << properties << std::endl; - if (well->setInjectionProperties(currentStep, properties)) m_events.addEvent( ScheduleEvents::INJECTION_UPDATE , currentStep ); @@ -1179,7 +1184,6 @@ namespace Opm { WellInjectionProperties prop = well->getInjectionPropertiesCopy(currentStep); if (cMode == "BHP"){ prop.BHPLimit = newValue * siFactorP; - prop.BHPLimitFromWeltarg = true; } else if (cMode == "ORAT"){ if(prop.injectorType == WellInjector::TypeEnum::OIL){ diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/WellInjectionProperties.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/WellInjectionProperties.cpp index 02672ea63..160f2afc8 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/WellInjectionProperties.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/WellInjectionProperties.cpp @@ -40,7 +40,6 @@ namespace Opm { THPH=0.0; VFPTableNumber=0; predictionMode=true; - BHPLimitFromWeltarg = false; injectionControls=0; } @@ -55,7 +54,6 @@ namespace Opm { (THPH == other.THPH) && (VFPTableNumber == other.VFPTableNumber) && (predictionMode == other.predictionMode) && - (BHPLimitFromWeltarg == other.BHPLimitFromWeltarg) && (injectionControls == other.injectionControls) && (injectorType == other.injectorType) && (controlMode == other.controlMode)) @@ -81,7 +79,6 @@ namespace Opm { << "THPH: " << wp.THPH << ", " << "VFP table: " << wp.VFPTableNumber << ", " << "prediction mode: " << wp.predictionMode << ", " - << "BHP limit is from WELTARG: " << wp.BHPLimitFromWeltarg << ", " << "injection ctrl: " << wp.injectionControls << ", " << "injector type: " << wp.injectorType << ", " << "control mode: " << wp.controlMode << " }"; diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/WellProductionProperties.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/WellProductionProperties.cpp index 492b9c0c3..c4d0bc0b2 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/WellProductionProperties.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/WellProductionProperties.cpp @@ -59,7 +59,6 @@ namespace Opm { p.THPH = record.getItem("THP").getSIDouble(0); const auto& cmodeItem = record.getItem("CMODE"); - if ( cmodeItem.defaultApplied(0) ) { const std::string msg = "control mode can not be defaulted for keyword WCONHIST"; throw std::invalid_argument(msg); diff --git a/tests/parser/ScheduleTests.cpp b/tests/parser/ScheduleTests.cpp index 4c87c916e..7bc3f5820 100644 --- a/tests/parser/ScheduleTests.cpp +++ b/tests/parser/ScheduleTests.cpp @@ -1431,7 +1431,7 @@ BOOST_AUTO_TEST_CASE(changeBhpLimitInHistoryModeWithWeltarg) { // well_i is a producer for this report step BOOST_CHECK_EQUAL(well_i->getInjectionProperties(3).BHPLimit, 0); // 3 // well_i changes from producer to injector - BOOST_CHECK_EQUAL(well_i->getInjectionProperties(4).BHPLimit, 6895 * 1e5); // 4 + BOOST_CHECK_EQUAL(well_i->getInjectionProperties(4).BHPLimit, 6891.2 * 1e5); // 4 BOOST_CHECK_EQUAL( true , well_i->getInjectionProperties(2).hasInjectionControl(Opm::WellInjector::BHP) ); // it is a producer