From 17fcdfc87ab085eb58b2b1720c212fda447e1891 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Thu, 14 Jan 2021 19:22:34 +0100 Subject: [PATCH] Use ScheduleState to handle VFP propertes + simplifications --- examples/printvfp.cpp | 6 +-- opm/simulators/wells/BlackoilWellModel.hpp | 2 +- .../wells/BlackoilWellModel_impl.hpp | 16 +++---- opm/simulators/wells/VFPInjProperties.cpp | 20 ++------ opm/simulators/wells/VFPInjProperties.hpp | 18 +------- opm/simulators/wells/VFPProdProperties.cpp | 20 ++------ opm/simulators/wells/VFPProdProperties.hpp | 18 +------- opm/simulators/wells/VFPProperties.hpp | 46 ++++++++----------- opm/simulators/wells/WellInterface.hpp | 4 +- opm/simulators/wells/WellInterface_impl.hpp | 2 +- tests/test_vfpproperties.cpp | 10 ++-- 11 files changed, 53 insertions(+), 109 deletions(-) diff --git a/examples/printvfp.cpp b/examples/printvfp.cpp index e2b357235..b29e81de1 100644 --- a/examples/printvfp.cpp +++ b/examples/printvfp.cpp @@ -36,12 +36,11 @@ using namespace Opm; struct Setup { - using VFP = VFPProperties; std::unique_ptr ecl_state; std::shared_ptr python; std::unique_ptr schedule; std::unique_ptr summary_state; - std::unique_ptr vfp_properties; + std::unique_ptr vfp_properties; Setup(const std::string& file) { @@ -56,7 +55,8 @@ struct Setup summary_state.reset( new SummaryState(std::chrono::system_clock::from_time_t(schedule->getStartTime()))); } const int step = 0; - vfp_properties = std::make_unique(schedule->getVFPInjTables(step), schedule->getVFPProdTables(step)); + const auto& sched_state = schedule->operator[](step); + vfp_properties = std::make_unique(sched_state.vfpinj(), sched_state.vfpprod()); }; }; diff --git a/opm/simulators/wells/BlackoilWellModel.hpp b/opm/simulators/wells/BlackoilWellModel.hpp index d385e6ac4..b5a8aa0fe 100644 --- a/opm/simulators/wells/BlackoilWellModel.hpp +++ b/opm/simulators/wells/BlackoilWellModel.hpp @@ -333,7 +333,7 @@ namespace Opm { std::optional last_run_wellpi_{}; std::unique_ptr rateConverter_; - std::unique_ptr> vfp_properties_; + std::unique_ptr vfp_properties_; SimulatorReportSingle last_report_; diff --git a/opm/simulators/wells/BlackoilWellModel_impl.hpp b/opm/simulators/wells/BlackoilWellModel_impl.hpp index 5208c6328..177818689 100644 --- a/opm/simulators/wells/BlackoilWellModel_impl.hpp +++ b/opm/simulators/wells/BlackoilWellModel_impl.hpp @@ -302,14 +302,14 @@ namespace Opm { std::vector(local_num_cells_, 0))); rateConverter_->template defineState(ebosSimulator_); - // update VFP properties - vfp_properties_.reset (new VFPProperties ( - schedule().getVFPInjTables(timeStepIdx), - schedule().getVFPProdTables(timeStepIdx)) ); - - this->initializeWellProdIndCalculators(); - if (this->schedule()[timeStepIdx].events().hasEvent(ScheduleEvents::Events::WELL_PRODUCTIVITY_INDEX)) { - this->runWellPIScaling(timeStepIdx, local_deferredLogger); + { + const auto& sched_state = this->schedule()[timeStepIdx]; + // update VFP properties + vfp_properties_.reset(new VFPProperties( sched_state.vfpinj(), sched_state.vfpprod()) ); + this->initializeWellProdIndCalculators(); + if (sched_state.events().hasEvent(ScheduleEvents::Events::WELL_PRODUCTIVITY_INDEX)) { + this->runWellPIScaling(timeStepIdx, local_deferredLogger); + } } // update the previous well state. This is used to restart failed steps. diff --git a/opm/simulators/wells/VFPInjProperties.cpp b/opm/simulators/wells/VFPInjProperties.cpp index c68dd89e0..90be1980b 100644 --- a/opm/simulators/wells/VFPInjProperties.cpp +++ b/opm/simulators/wells/VFPInjProperties.cpp @@ -32,21 +32,6 @@ namespace Opm { -VFPInjProperties::VFPInjProperties() { - -} - - -VFPInjProperties::VFPInjProperties(const VFPInjTable* table){ - m_tables[table->getTableNum()] = table; -} - - -VFPInjProperties::VFPInjProperties(const VFPInjProperties::InjTable& tables) { - for (const auto& table : tables) { - m_tables[table.first] = table.second.get(); - } -} double VFPInjProperties::bhp(int table_id, @@ -98,4 +83,9 @@ bool VFPInjProperties::hasTable(const int table_id) const { return detail::hasTable(m_tables, table_id); } +void VFPInjProperties::addTable(const VFPInjTable * new_table) { + this->m_tables.emplace( new_table->getTableNum(), new_table ); +} + + } //Namespace Opm diff --git a/opm/simulators/wells/VFPInjProperties.hpp b/opm/simulators/wells/VFPInjProperties.hpp index e2fcee784..9f985ac6f 100644 --- a/opm/simulators/wells/VFPInjProperties.hpp +++ b/opm/simulators/wells/VFPInjProperties.hpp @@ -34,25 +34,11 @@ namespace Opm { class VFPInjProperties { public: + VFPInjProperties() = default; /** - * Empty constructor - */ - VFPInjProperties(); - - /** - * Constructor * Takes *no* ownership of data. - * @param inj_table A *single* VFPINJ table */ - explicit VFPInjProperties(const VFPInjTable* inj_table); - - /** - * Constructor - * Takes *no* ownership of data. - * @param inj_tables A map of different VFPINJ tables. - */ - using InjTable = std::map >; - explicit VFPInjProperties(const InjTable& inj_tables); + void addTable(const VFPInjTable * new_table); /** * Linear interpolation of bhp as a function of the input parameters given as diff --git a/opm/simulators/wells/VFPProdProperties.cpp b/opm/simulators/wells/VFPProdProperties.cpp index f53482e0c..168c3c35f 100644 --- a/opm/simulators/wells/VFPProdProperties.cpp +++ b/opm/simulators/wells/VFPProdProperties.cpp @@ -33,23 +33,6 @@ namespace Opm { -VFPProdProperties::VFPProdProperties() { - -} - - -VFPProdProperties::VFPProdProperties(const VFPProdTable* table){ - m_tables[table->getTableNum()] = table; -} - - -VFPProdProperties::VFPProdProperties(const VFPProdProperties::ProdTable& tables) { - for (const auto& table : tables) { - m_tables[table.first] = table.second.get(); - } -} - - double VFPProdProperties::thp(int table_id, const double& aqua, const double& liquid, @@ -261,5 +244,8 @@ calculateBhpWithTHPTarget(const std::vector& ipr_a, } } +void VFPProdProperties::addTable(const VFPProdTable * new_table) { + this->m_tables.emplace( new_table->getTableNum(), new_table ); +} } diff --git a/opm/simulators/wells/VFPProdProperties.hpp b/opm/simulators/wells/VFPProdProperties.hpp index 3183fd0d0..6a60486f3 100644 --- a/opm/simulators/wells/VFPProdProperties.hpp +++ b/opm/simulators/wells/VFPProdProperties.hpp @@ -38,25 +38,11 @@ namespace Opm { */ class VFPProdProperties { public: + VFPProdProperties() = default; /** - * Empty constructor - */ - VFPProdProperties(); - - /** - * Constructor * Takes *no* ownership of data. - * @param prod_table A *single* VFPPROD table */ - explicit VFPProdProperties(const VFPProdTable* prod_table); - - /** - * Constructor - * Takes *no* ownership of data. - * @param prod_tables A map of different VFPPROD tables. - */ - using ProdTable = std::map >; - explicit VFPProdProperties(const ProdTable& prod_tables); + void addTable(const VFPProdTable * new_table); /** * Linear interpolation of bhp as a function of the input parameters given as diff --git a/opm/simulators/wells/VFPProperties.hpp b/opm/simulators/wells/VFPProperties.hpp index e0d285b4c..96c5661c1 100644 --- a/opm/simulators/wells/VFPProperties.hpp +++ b/opm/simulators/wells/VFPProperties.hpp @@ -23,6 +23,9 @@ #include #include +#include +#include + #include namespace Opm { @@ -31,26 +34,10 @@ namespace Opm { * A thin wrapper class that holds one VFPProdProperties and one * VFPInjProperties object. */ -template class VFPProperties { public: - VFPProperties() {} + VFPProperties() = default; - /** - * Constructor - * Takes *no* ownership of data. - * @param inj_table A *single* VFPINJ table or NULL (no table) - * @param prod_table A *single* VFPPROD table or NULL (no table) - */ - explicit VFPProperties(const VFPInjTable* inj_table, const VFPProdTable* prod_table) - { - if (inj_table != nullptr) { - m_inj.reset(new VFPInjProp(inj_table)); - } - if (prod_table != nullptr) { - m_prod.reset(new VFPProdProp(prod_table)); - } - } /** * Constructor @@ -58,27 +45,34 @@ public: * @param inj_tables A map of different VFPINJ tables. * @param prod_tables A map of different VFPPROD tables. */ - VFPProperties(const std::map >& inj_tables, - const std::map >& prod_tables) - : m_inj(new VFPInjProp(inj_tables)), m_prod(new VFPProdProp(prod_tables)) {} + + VFPProperties(const std::vector& inj_tables, + const std::vector& prod_tables) + { + for (const auto& vfpinj_ptr : inj_tables) + this->m_inj.addTable( vfpinj_ptr ); + + for (const auto& vfpprod_ptr : prod_tables) + this->m_prod.addTable( vfpprod_ptr ); + }; /** * Returns the VFP properties for injection wells */ - const VFPInjProp* getInj() const { - return m_inj.get(); + const VFPInjProperties* getInj() const { + return &m_inj; } /** * Returns the VFP properties for production wells */ - const VFPProdProp* getProd() const { - return m_prod.get(); + const VFPProdProperties* getProd() const { + return &m_prod; } private: - std::shared_ptr m_inj; - std::shared_ptr m_prod; + VFPInjProperties m_inj; + VFPProdProperties m_prod; }; diff --git a/opm/simulators/wells/WellInterface.hpp b/opm/simulators/wells/WellInterface.hpp index 7f87907b1..e43b5e81b 100644 --- a/opm/simulators/wells/WellInterface.hpp +++ b/opm/simulators/wells/WellInterface.hpp @@ -151,7 +151,7 @@ namespace Opm /// Well cells. const std::vector& cells() const {return well_cells_; } - void setVFPProperties(const VFPProperties* vfp_properties_arg); + void setVFPProperties(const VFPProperties* vfp_properties_arg); void setGuideRate(const GuideRate* guide_rate_arg); @@ -384,7 +384,7 @@ namespace Opm bool getAllowCrossFlow() const; - const VFPProperties* vfp_properties_; + const VFPProperties* vfp_properties_; const GuideRate* guide_rate_; diff --git a/opm/simulators/wells/WellInterface_impl.hpp b/opm/simulators/wells/WellInterface_impl.hpp index ab69be61a..92c4abeeb 100644 --- a/opm/simulators/wells/WellInterface_impl.hpp +++ b/opm/simulators/wells/WellInterface_impl.hpp @@ -174,7 +174,7 @@ namespace Opm template void WellInterface:: - setVFPProperties(const VFPProperties* vfp_properties_arg) + setVFPProperties(const VFPProperties* vfp_properties_arg) { vfp_properties_ = vfp_properties_arg; } diff --git a/tests/test_vfpproperties.cpp b/tests/test_vfpproperties.cpp index 0162e717c..11a133659 100644 --- a/tests/test_vfpproperties.cpp +++ b/tests/test_vfpproperties.cpp @@ -205,7 +205,8 @@ struct TrivialFixture { alq_axis, data)); - properties.reset(new Opm::VFPProdProperties(table.get())); + properties = std::make_shared(); + properties->addTable( table.get() ); } double& operator()(size_t thp_idx, size_t wfr_idx, size_t gfr_idx, size_t alq_idx, size_t flo_idx) { @@ -590,7 +591,8 @@ VFPPROD \n\ Opm::Parser parser; auto deck = parser.parseString(table_str); Opm::VFPProdTable table(deck.getKeyword("VFPPROD", 0), units); - Opm::VFPProdProperties properties(&table); + Opm::VFPProdProperties properties; + properties.addTable( &table ); const int n = 5; //Number of points to check per axis double bhp_sad = 0.0; //Sum of absolute difference @@ -649,8 +651,8 @@ BOOST_AUTO_TEST_CASE(ParseInterpolateRealisticVFPPROD) BOOST_CHECK_EQUAL(deck.count("VFPPROD"), 1); Opm::VFPProdTable table(deck.getKeyword("VFPPROD", 0), units); - - Opm::VFPProdProperties properties(&table); + Opm::VFPProdProperties properties; + properties.addTable(&table); //Do some rudimentary testing //Get the BHP as a function of rate, thp, wfr, gfr, alq