From f8c250be34fc47ecf3c416586f736242d59a483e Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Thu, 5 Mar 2020 10:05:02 +0100 Subject: [PATCH] UDAValue: change from ::reset() to ::operator=() --- opm/parser/eclipse/Deck/UDAValue.hpp | 5 +-- src/opm/parser/eclipse/Deck/UDAValue.cpp | 7 +++- .../EclipseState/Schedule/Well/Well.cpp | 2 +- .../Schedule/Well/WellInjectionProperties.cpp | 14 +++---- .../Well/WellProductionProperties.cpp | 21 +++++----- tests/parser/UDQTests.cpp | 4 +- tests/parser/WellTests.cpp | 40 +++++++++---------- 7 files changed, 47 insertions(+), 46 deletions(-) diff --git a/opm/parser/eclipse/Deck/UDAValue.hpp b/opm/parser/eclipse/Deck/UDAValue.hpp index 8f797c47c..355f30e7e 100644 --- a/opm/parser/eclipse/Deck/UDAValue.hpp +++ b/opm/parser/eclipse/Deck/UDAValue.hpp @@ -55,15 +55,14 @@ public: template bool is() const; - void reset(double value); - void reset(const std::string& value); - void assert_numeric() const; void assert_numeric(const std::string& error_msg) const; const Dimension& get_dim() const; bool operator==(const UDAValue& other) const; bool operator!=(const UDAValue& other) const; + UDAValue& operator=(double value); + UDAValue& operator=(const std::string& value); bool is_numeric() { return numeric_value; } diff --git a/src/opm/parser/eclipse/Deck/UDAValue.cpp b/src/opm/parser/eclipse/Deck/UDAValue.cpp index 223e677d8..b5361e47c 100644 --- a/src/opm/parser/eclipse/Deck/UDAValue.cpp +++ b/src/opm/parser/eclipse/Deck/UDAValue.cpp @@ -96,14 +96,17 @@ double UDAValue::getSI() const { return this->dim.convertRawToSi(this->double_value); } -void UDAValue::reset(double value) { + +UDAValue& UDAValue::operator=(double value) { this->double_value = value; this->numeric_value = true; + return *this; } -void UDAValue::reset(const std::string& value) { +UDAValue& UDAValue::operator=(const std::string& value) { this->string_value = value; this->numeric_value = false; + return *this; } template<> diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Well/Well.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Well/Well.cpp index b018ab3ef..746bcc5f0 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Well/Well.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Well/Well.cpp @@ -273,7 +273,7 @@ bool Well::updateEconLimits(std::shared_ptr econ_limit void Well::switchToProducer() { auto p = std::make_shared(this->getInjectionProperties()); - p->BHPTarget.reset(0); + p->BHPTarget = 0; p->dropInjectionControl( Opm::Well::InjectorCMode::BHP ); this->updateInjection( p ); this->updateProducer(true); diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellInjectionProperties.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellInjectionProperties.cpp index b23bb1d92..21c6e73e3 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellInjectionProperties.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellInjectionProperties.cpp @@ -150,14 +150,14 @@ namespace Opm { if (cmode == Well::WELTARGCMode::BHP){ if (this->predictionMode) { this->BHPTarget.assert_numeric("Can not combine UDA and WELTARG"); - this->BHPTarget.reset( newValue ); + this->BHPTarget = newValue; } else this->bhp_hist_limit = newValue * SiFactorP; } else if (cmode == WELTARGCMode::ORAT){ if(this->injectorType == InjectorType::OIL){ this->surfaceInjectionRate.assert_numeric("Can not combine UDA and WELTARG"); - this->surfaceInjectionRate.reset( newValue ); + this->surfaceInjectionRate = newValue; }else{ std::invalid_argument("Well type must be OIL to set the oil rate"); } @@ -165,7 +165,7 @@ namespace Opm { else if (cmode == WELTARGCMode::WRAT){ if (this->injectorType == InjectorType::WATER) { this->surfaceInjectionRate.assert_numeric("Can not combine UDA and WELTARG"); - this->surfaceInjectionRate.reset( newValue ); + this->surfaceInjectionRate = newValue; } else std::invalid_argument("Well type must be WATER to set the water rate"); @@ -173,21 +173,21 @@ namespace Opm { else if (cmode == WELTARGCMode::GRAT){ if(this->injectorType == InjectorType::GAS){ this->surfaceInjectionRate.assert_numeric("Can not combine UDA and WELTARG"); - this->surfaceInjectionRate.reset( newValue ); + this->surfaceInjectionRate = newValue; }else{ std::invalid_argument("Well type must be GAS to set the gas rate"); } } else if (cmode == WELTARGCMode::THP){ this->THPTarget.assert_numeric("Can not combine UDA and WELTARG"); - this->THPTarget.reset( newValue ); + this->THPTarget = newValue; } else if (cmode == WELTARGCMode::VFP){ this->VFPTableNumber = static_cast (newValue); } else if (cmode == WELTARGCMode::RESV){ this->surfaceInjectionRate.assert_numeric("Can not combine UDA and WELTARG"); - this->reservoirInjectionRate.reset( newValue ); + this->reservoirInjectionRate = newValue; } else if (cmode != WELTARGCMode::GUID){ throw std::invalid_argument("Invalid keyword (MODE) supplied"); @@ -206,7 +206,7 @@ namespace Opm { if (!record.getItem("RATE").defaultApplied(0)) { double injectionRate = record.getItem("RATE").get(0); - this->surfaceInjectionRate.reset( injectionRate ); + this->surfaceInjectionRate = injectionRate; } if ( record.getItem( "BHP" ).hasValue(0) ) this->BHPH = record.getItem("BHP").getSIDouble(0); diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellProductionProperties.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellProductionProperties.cpp index 59bf8fd68..c7665c6b4 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellProductionProperties.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellProductionProperties.cpp @@ -101,8 +101,7 @@ namespace Opm { this->predictionMode = false; // update LiquidRate. The funnny constrction with explicitly making a new // UDAValue is to ensure that the UDAValue has the correct dimension. - this->LiquidRate = UDAValue(this->LiquidRate, this->OilRate.get_dim()); - this->LiquidRate.reset(this->WaterRate.get() + this->OilRate.get()); + this->LiquidRate = UDAValue(this->WaterRate.get() + this->OilRate.get(), this->OilRate.get_dim()); if ( record.getItem( "BHP" ).hasValue(0) ) this->BHPH = record.getItem("BHP").get(0).getSI(); @@ -208,8 +207,8 @@ namespace Opm { void Well::WellProductionProperties::handleWCONHIST(const DeckRecord& record) { this->init_rates(record); - this->LiquidRate.reset(0); - this->ResVRate.reset(0); + this->LiquidRate = 0; + this->ResVRate = 0; // when the well is switching to history matching producer from prediction mode // or switching from injector to producer @@ -229,40 +228,40 @@ namespace Opm { void Well::WellProductionProperties::handleWELTARG(Well::WELTARGCMode cmode, double newValue, double SiFactorP) { if (cmode == WELTARGCMode::ORAT){ this->OilRate.assert_numeric("Can not combine UDA and WELTARG"); - this->OilRate.reset( newValue ); + this->OilRate = newValue; this->addProductionControl( ProducerCMode::ORAT ); } else if (cmode == WELTARGCMode::WRAT){ this->WaterRate.assert_numeric("Can not combine UDA and WELTARG"); - this->WaterRate.reset( newValue ); + this->WaterRate = newValue; this->addProductionControl( ProducerCMode::WRAT ); } else if (cmode == WELTARGCMode::GRAT){ this->GasRate.assert_numeric("Can not combine UDA and WELTARG"); - this->GasRate.reset( newValue ); + this->GasRate = newValue; this->addProductionControl( ProducerCMode::GRAT ); } else if (cmode == WELTARGCMode::LRAT){ this->LiquidRate.assert_numeric("Can not combine UDA and WELTARG"); - this->LiquidRate.reset( newValue ); + this->LiquidRate = newValue; this->addProductionControl( ProducerCMode::LRAT ); } else if (cmode == WELTARGCMode::RESV){ this->ResVRate.assert_numeric("Can not combine UDA and WELTARG"); - this->ResVRate.reset( newValue ); + this->ResVRate = newValue; this->addProductionControl( ProducerCMode::RESV ); } else if (cmode == WELTARGCMode::BHP){ if (this->predictionMode) { this->BHPTarget.assert_numeric("Can not combine UDA and WELTARG"); - this->BHPTarget.reset( newValue ); + this->BHPTarget = newValue; } else this->bhp_hist_limit = newValue * SiFactorP; this->addProductionControl( ProducerCMode::BHP ); } else if (cmode == WELTARGCMode::THP){ this->THPTarget.assert_numeric("Can not combine UDA and WELTARG"); - this->THPTarget.reset(newValue ); + this->THPTarget = newValue; this->addProductionControl( ProducerCMode::THP ); } else if (cmode == WELTARGCMode::VFP) diff --git a/tests/parser/UDQTests.cpp b/tests/parser/UDQTests.cpp index 0714a1b56..6bc47284b 100644 --- a/tests/parser/UDQTests.cpp +++ b/tests/parser/UDQTests.cpp @@ -1217,10 +1217,10 @@ BOOST_AUTO_TEST_CASE(UDA_VALUE) { BOOST_CHECK(!value0.is()); BOOST_CHECK_EQUAL( value0.get(), 0); BOOST_CHECK_THROW( value0.get(), std::invalid_argument); - value0.reset( 10 ); + value0 = 10; BOOST_CHECK_EQUAL( value0.get(), 10); BOOST_CHECK_THROW( value0.get(), std::invalid_argument); - value0.reset( "STRING" ); + value0 = "STRING"; BOOST_CHECK_EQUAL( value0.get(), std::string("STRING")); BOOST_CHECK_THROW( value0.get(), std::invalid_argument); diff --git a/tests/parser/WellTests.cpp b/tests/parser/WellTests.cpp index ae339d708..3ea97363d 100644 --- a/tests/parser/WellTests.cpp +++ b/tests/parser/WellTests.cpp @@ -211,7 +211,7 @@ BOOST_AUTO_TEST_CASE(isProducerCorrectlySet) { /* Set a surface injection rate => Well becomes an Injector */ auto injectionProps1 = std::make_shared(well.getInjectionProperties()); - injectionProps1->surfaceInjectionRate.reset(100); + injectionProps1->surfaceInjectionRate = 100; well.updateInjection(injectionProps1); BOOST_CHECK_EQUAL( true , well.isInjector()); BOOST_CHECK_EQUAL( false , well.isProducer()); @@ -224,7 +224,7 @@ BOOST_AUTO_TEST_CASE(isProducerCorrectlySet) { /* Set a reservoir injection rate => Well becomes an Injector */ auto injectionProps2 = std::make_shared(well.getInjectionProperties()); - injectionProps2->reservoirInjectionRate.reset(200); + injectionProps2->reservoirInjectionRate = 200; well.updateInjection(injectionProps2); BOOST_CHECK_EQUAL( false , well.isProducer()); BOOST_CHECK_EQUAL( 200 , well.getInjectionProperties().reservoirInjectionRate.get()); @@ -238,9 +238,9 @@ BOOST_AUTO_TEST_CASE(isProducerCorrectlySet) { well.updateInjection(injectionProps3); auto properties = std::make_shared( well.getProductionProperties() ); - properties->OilRate.reset(100); - properties->GasRate.reset(200); - properties->WaterRate.reset(300); + properties->OilRate = 100; + properties->GasRate = 200; + properties->WaterRate = 300; well.updateProduction(properties); BOOST_CHECK_EQUAL( false , well.isInjector()); @@ -277,14 +277,14 @@ BOOST_AUTO_TEST_CASE(XHPLimitDefault) { auto productionProps = std::make_shared(well.getProductionProperties()); - productionProps->BHPTarget.reset(100); + productionProps->BHPTarget = 100; productionProps->addProductionControl(Opm::Well::ProducerCMode::BHP); well.updateProduction(productionProps); BOOST_CHECK_EQUAL( 100 , well.getProductionProperties().BHPTarget.get()); BOOST_CHECK_EQUAL( true, well.getProductionProperties().hasProductionControl( Opm::Well::ProducerCMode::BHP )); auto injProps = std::make_shared(well.getInjectionProperties()); - injProps->THPTarget.reset(200); + injProps->THPTarget = 200; well.updateInjection(injProps); BOOST_CHECK_EQUAL( 200 , well.getInjectionProperties().THPTarget.get()); BOOST_CHECK( !well.getInjectionProperties().hasInjectionControl( Opm::Well::InjectorCMode::THP )); @@ -318,26 +318,26 @@ BOOST_AUTO_TEST_CASE(WellHaveProductionControlLimit) { BOOST_CHECK( !well.getProductionProperties().hasProductionControl( Opm::Well::ProducerCMode::RESV )); auto properties1 = std::make_shared(well.getProductionProperties()); - properties1->OilRate.reset(100); + properties1->OilRate = 100; properties1->addProductionControl(Opm::Well::ProducerCMode::ORAT); well.updateProduction(properties1); BOOST_CHECK( well.getProductionProperties().hasProductionControl( Opm::Well::ProducerCMode::ORAT )); BOOST_CHECK( !well.getProductionProperties().hasProductionControl( Opm::Well::ProducerCMode::RESV )); auto properties2 = std::make_shared(well.getProductionProperties()); - properties2->ResVRate.reset( 100 ); + properties2->ResVRate = 100; properties2->addProductionControl(Opm::Well::ProducerCMode::RESV); well.updateProduction(properties2); BOOST_CHECK( well.getProductionProperties().hasProductionControl( Opm::Well::ProducerCMode::RESV )); auto properties3 = std::make_shared(well.getProductionProperties()); - properties3->OilRate.reset(100); - properties3->WaterRate.reset(100); - properties3->GasRate.reset(100); - properties3->LiquidRate.reset(100); - properties3->ResVRate.reset(100); - properties3->BHPTarget.reset(100); - properties3->THPTarget.reset(100); + properties3->OilRate = 100; + properties3->WaterRate = 100; + properties3->GasRate = 100; + properties3->LiquidRate = 100; + properties3->ResVRate = 100; + properties3->BHPTarget = 100; + properties3->THPTarget = 100; properties3->addProductionControl(Opm::Well::ProducerCMode::ORAT); properties3->addProductionControl(Opm::Well::ProducerCMode::LRAT); properties3->addProductionControl(Opm::Well::ProducerCMode::BHP); @@ -364,22 +364,22 @@ BOOST_AUTO_TEST_CASE(WellHaveInjectionControlLimit) { BOOST_CHECK( !well.getInjectionProperties().hasInjectionControl( Opm::Well::InjectorCMode::RESV )); auto injProps1 = std::make_shared(well.getInjectionProperties()); - injProps1->surfaceInjectionRate.reset(100); + injProps1->surfaceInjectionRate = 100; injProps1->addInjectionControl(Opm::Well::InjectorCMode::RATE); well.updateInjection(injProps1); BOOST_CHECK( well.getInjectionProperties().hasInjectionControl( Opm::Well::InjectorCMode::RATE )); BOOST_CHECK( !well.getInjectionProperties().hasInjectionControl( Opm::Well::InjectorCMode::RESV )); auto injProps2 = std::make_shared(well.getInjectionProperties()); - injProps2->reservoirInjectionRate.reset(100); + injProps2->reservoirInjectionRate = 100; injProps2->addInjectionControl(Opm::Well::InjectorCMode::RESV); well.updateInjection(injProps2); BOOST_CHECK( well.getInjectionProperties().hasInjectionControl( Opm::Well::InjectorCMode::RESV )); auto injProps3 = std::make_shared(well.getInjectionProperties()); - injProps3->BHPTarget.reset(100); + injProps3->BHPTarget = 100; injProps3->addInjectionControl(Opm::Well::InjectorCMode::BHP); - injProps3->THPTarget.reset(100); + injProps3->THPTarget = 100; injProps3->addInjectionControl(Opm::Well::InjectorCMode::THP); well.updateInjection(injProps3);