From 08d89858af2dde0b89aedabf84606925a3446c62 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Tue, 25 Oct 2016 11:45:29 +0200 Subject: [PATCH] Extended data::Wells to inherit from std::map. --- opm/output/data/Wells.hpp | 29 ++++++++++++++++++++- tests/test_RFT.cpp | 7 +++--- tests/test_Restart.cpp | 10 ++++++-- tests/test_Summary.cpp | 29 +++++++++++++++------ tests/test_Wells.cpp | 53 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 114 insertions(+), 14 deletions(-) diff --git a/opm/output/data/Wells.hpp b/opm/output/data/Wells.hpp index 39a5743fd..31ac1641c 100644 --- a/opm/output/data/Wells.hpp +++ b/opm/output/data/Wells.hpp @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -98,8 +99,33 @@ namespace Opm { std::vector< Completion > completions; }; - using Wells = std::map< std::string, Well >; + class WellRates : public std::map { + public: + + double get(const std::string& well_name , Rates::opt m) const { + const auto& well = this->at(well_name); + return well.rates.get( m ); + } + + + double get(const std::string& well_name , Completion::active_index completion_grid_index, Rates::opt m) const { + const auto& well = this->at(well_name); + const auto& completion = std::find_if( well.completions.begin() , + well.completions.end() , + [=]( const Completion& c ) { + return c.index == completion_grid_index; }); + if (completion == well.completions.end()) + throw std::out_of_range("No such completion"); + + return completion->rates.get( m ); + } + + + }; + using Wells = WellRates; + + //using Wells = std::map; /* IMPLEMENTATIONS */ inline bool Rates::has( opt m ) const { @@ -133,6 +159,7 @@ namespace Opm { return *this; } + /* * To avoid error-prone and repetitve work when extending rates with new * values, the get+set methods use this helper get_ref to determine what diff --git a/tests/test_RFT.cpp b/tests/test_RFT.cpp index 5cd0450e9..c26b0b48d 100755 --- a/tests/test_RFT.cpp +++ b/tests/test_RFT.cpp @@ -134,10 +134,9 @@ BOOST_AUTO_TEST_CASE(test_RFT) { r2.set( data::Rates::opt::oil, 4.22 ); r2.set( data::Rates::opt::gas, 4.23 ); - Opm::data::Wells wells { - { { "OP_1", { r1, 1.0, 1.1, 3.1, 1, {} } }, - { "OP_2", { r2, 1.0, 1.1, 3.2, 1, {} } } }, - }; + Opm::data::Wells wells; + wells["OP_1"] = { r1, 1.0, 1.1, 3.1, 1, {} }; + wells["OP_2"] = { r2, 1.0, 1.1, 3.2, 1, {} }; eclipseWriter.writeTimeStep( 2, false, diff --git a/tests/test_Restart.cpp b/tests/test_Restart.cpp index 6cdc30089..5809aa382 100644 --- a/tests/test_Restart.cpp +++ b/tests/test_Restart.cpp @@ -330,8 +330,14 @@ data::Wells mkWells() { w2.control = 2; w2.completions.push_back( { 188, rc3, 36.22, 123.4 } ); - return { { "OP_1", w1 }, - { "OP_2", w2 } }; + { + data::Wells wellRates; + + wellRates["OP_1"] = w1; + wellRates["OP_2"] = w2; + + return wellRates; + } } data::Solution mkSolution( int numCells ) { diff --git a/tests/test_Summary.cpp b/tests/test_Summary.cpp index 1a8b51c14..f5e829e09 100644 --- a/tests/test_Summary.cpp +++ b/tests/test_Summary.cpp @@ -150,15 +150,30 @@ static data::Wells result_wells() { crates3.set( rt::gas, 300.2 / day ); crates3.set( rt::solvent, 300.3 / day ); - data::Completion comp1 { 1, crates1, 1.9, 123.4 }; - data::Completion comp2 { 1, crates2, 1.10, 123.4 }; - data::Completion comp3 { 3, crates3, 1.11, 123.4 }; + /* + The active index assigned to the completion must be manually + syncronized with the active index in the COMPDAT keyword in the + input deck. + */ + data::Completion well1_comp1 { 0 , crates1, 1.9 , 123.4}; + data::Completion well2_comp1 { 1 , crates2, 1.10 , 123.4}; + data::Completion well2_comp2 { 101, crates3, 1.11 , 123.4}; + data::Completion well3_comp1 { 2 , crates3, 1.11 , 123.4}; - data::Well well1 { rates1, 0.1 * ps, 0.2 * ps, 0.3 * ps, 1, { comp1 } }; - data::Well well2 { rates2, 1.1 * ps, 1.2 * ps, 1.3 * ps, 2, { comp2 } }; - data::Well well3 { rates3, 2.1 * ps, 2.2 * ps, 2.3 * ps, 3, { comp3 } }; + /* + The completions + */ + data::Well well1 { rates1, 0.1 * ps, 0.2 * ps, 0.3 * ps, 1, { {well1_comp1} } }; + data::Well well2 { rates2, 1.1 * ps, 1.2 * ps, 1.3 * ps, 2, { {well2_comp1 , well2_comp2} } }; + data::Well well3 { rates3, 2.1 * ps, 2.2 * ps, 2.3 * ps, 3, { {well3_comp1} } }; - return { { "W_1", well1 }, { "W_2", well2 }, { "W_3", well3 } }; + data::Wells wellrates; + + wellrates["W_1"] = well1; + wellrates["W_2"] = well2; + wellrates["W_3"] = well3; + + return wellrates; } ERT::ert_unique_ptr< ecl_sum_type, ecl_sum_free > readsum( const std::string& base ) { diff --git a/tests/test_Wells.cpp b/tests/test_Wells.cpp index f3d4c98b8..ca7255fc7 100644 --- a/tests/test_Wells.cpp +++ b/tests/test_Wells.cpp @@ -74,3 +74,56 @@ BOOST_AUTO_TEST_CASE(get_wrong) { } + +BOOST_AUTO_TEST_CASE(get_completions) { + data::Rates r1, r2, rc1, rc2, rc3; + r1.set( data::Rates::opt::wat, 5.67 ); + r1.set( data::Rates::opt::oil, 6.78 ); + r1.set( data::Rates::opt::gas, 7.89 ); + + r2.set( data::Rates::opt::wat, 8.90 ); + r2.set( data::Rates::opt::oil, 9.01 ); + r2.set( data::Rates::opt::gas, 10.12 ); + + rc1.set( data::Rates::opt::wat, 20.41 ); + rc1.set( data::Rates::opt::oil, 21.19 ); + rc1.set( data::Rates::opt::gas, 22.41 ); + + rc2.set( data::Rates::opt::wat, 23.19 ); + rc2.set( data::Rates::opt::oil, 24.41 ); + rc2.set( data::Rates::opt::gas, 25.19 ); + + rc3.set( data::Rates::opt::wat, 26.41 ); + rc3.set( data::Rates::opt::oil, 27.19 ); + rc3.set( data::Rates::opt::gas, 28.41 ); + + data::Well w1, w2; + w1.rates = r1; + w1.bhp = 1.23; + w1.temperature = 3.45; + w1.control = 1; + + /* + * the completion keys (active indices) and well names correspond to the + * input deck. All other entries in the well structures are arbitrary. + */ + w1.completions.push_back( { 88, rc1, 30.45 } ); + w1.completions.push_back( { 288, rc2, 33.19 } ); + + w2.rates = r2; + w2.bhp = 2.34; + w2.temperature = 4.56; + w2.control = 2; + w2.completions.push_back( { 188, rc3, 36.22 } ); + + data::Wells wellRates; + + wellRates["OP_1"] = w1; + wellRates["OP_2"] = w2; + + BOOST_CHECK_THROW( wellRates.get("NO_SUCH_WELL" , data::Rates::opt::wat), std::out_of_range); + BOOST_CHECK_EQUAL( 5.67 , wellRates.get( "OP_1" , data::Rates::opt::wat)); + + BOOST_CHECK_THROW( wellRates.get("OP_2" , 10000 , data::Rates::opt::wat), std::out_of_range); + BOOST_CHECK_EQUAL( 26.41 , wellRates.get( "OP_2" , 188 , data::Rates::opt::wat)); +}