From f2c895c70183e240db2598df2a64cf274c8f19f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Kvalsvik?= Date: Mon, 31 Oct 2016 11:49:56 +0100 Subject: [PATCH] Return zero for non-existing well/completion To be consistent with the general summary behaviour and more input tolerant, 0.0 is returned when some phase, completion or well is requested that isn't provided by the simulator. Solves the issue discussed in https://github.com/OPM/opm-output/pull/122 and extends the test input deck to trigger this behaviour. --- opm/output/data/Wells.hpp | 21 +++++++++++++-------- tests/summary_deck.DATA | 13 +++++++++++++ tests/test_Wells.cpp | 4 ++-- tests/test_regionCache.cpp | 2 +- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/opm/output/data/Wells.hpp b/opm/output/data/Wells.hpp index 31ac1641c..a2b2ad19f 100644 --- a/opm/output/data/Wells.hpp +++ b/opm/output/data/Wells.hpp @@ -104,28 +104,33 @@ namespace Opm { public: double get(const std::string& well_name , Rates::opt m) const { - const auto& well = this->at(well_name); - return well.rates.get( m ); + const auto& well = this->find( well_name ); + if( well == this->end() ) return 0.0; + + return well->second.rates.get( m, 0.0 ); } 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& witr = this->find( well_name ); + if( witr == this->end() ) return 0.0; + + const auto& well = witr->second; 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 ); + if( completion == well.completions.end() ) + return 0.0; + + return completion->rates.get( m, 0.0 ); } - }; + using Wells = WellRates; - //using Wells = std::map; /* IMPLEMENTATIONS */ inline bool Rates::has( opt m ) const { diff --git a/tests/summary_deck.DATA b/tests/summary_deck.DATA index d38a53223..d7678c6d8 100644 --- a/tests/summary_deck.DATA +++ b/tests/summary_deck.DATA @@ -530,3 +530,16 @@ TSTEP -- up historical rates and volumes. These volumes however don't change, i.e. -- every time step has the same set of values 10 10 / + +-- Register a fourth well with completions later. This ensure we handle when +-- wells are registered or activated later in a simulation +WELSPECS + 'W_4' 'G_3' 1 1 3.33 'OIL' 7* / +/ + +COMPDAT + W_4 1 1 3 3 / +/ + +TSTEP +10 10 / diff --git a/tests/test_Wells.cpp b/tests/test_Wells.cpp index ca7255fc7..17d95f1fa 100644 --- a/tests/test_Wells.cpp +++ b/tests/test_Wells.cpp @@ -121,9 +121,9 @@ BOOST_AUTO_TEST_CASE(get_completions) { 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( 0.0, wellRates.get("NO_SUCH_WELL" , data::Rates::opt::wat) ); 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( 0.0, wellRates.get("OP_2" , 10000 , data::Rates::opt::wat) ); BOOST_CHECK_EQUAL( 26.41 , wellRates.get( "OP_2" , 188 , data::Rates::opt::wat)); } diff --git a/tests/test_regionCache.cpp b/tests/test_regionCache.cpp index 36317d69a..1ab428705 100644 --- a/tests/test_regionCache.cpp +++ b/tests/test_regionCache.cpp @@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE(create) { BOOST_CHECK_EQUAL( c.size() , 0 ); { - const auto& empty = rc.completions( 3 ); + const auto& empty = rc.completions( 4 ); BOOST_CHECK_EQUAL( empty.size() , 0 ); }