From 89c8cb886b7fb60f0d13e4a8fd0915f52b783053 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 3 Jun 2019 11:41:44 +0200 Subject: [PATCH] Correctly detect totals in SummaryState --- .../EclipseState/Schedule/SummaryState.cpp | 17 ++++++++++++++--- tests/test_Summary.cpp | 5 +++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/SummaryState.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/SummaryState.cpp index 3e8814191..c68354a8f 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/SummaryState.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/SummaryState.cpp @@ -17,6 +17,7 @@ along with OPM. If not, see . */ +#include #include @@ -24,16 +25,26 @@ namespace Opm{ namespace { bool is_total(const std::string& key) { + static const std::unordered_set totals = {"OPT" , "GPT" , "WPT" , "GIT", "WIT", "OPTF" , "OPTS" , "OIT" , "OVPT" , "OVIT" , "MWT" , + "WVPT" , "WVIT" , "GMT" , "GPTF" , "SGT" , "GST" , "FGT" , "GCT" , "GIMT" , + "WGPT" , "WGIT" , "EGT" , "EXGT" , "GVPT" , "GVIT" , "LPT" , "VPT" , "VIT" , "NPT" , "NIT", + "CPT", "CIT"}; + auto sep_pos = key.find(':'); if (sep_pos == 0) return false; if (sep_pos == std::string::npos) { - if (key.back() == 'T') - return true; + if (key.back() == 'T' || key.compare(key.size() - 2, 2, "TH") == 0) { + std::size_t end_shift = 0; + if (key.back() == 'H') + end_shift += 1; - return (key.compare(key.size() - 2, 2, "TH") == 0); + std::string sub_key = key.substr(1, key.size() - (1 + end_shift)); + return (totals.count( sub_key ) == 1); + } + return false; } else return is_total(key.substr(0,sep_pos)); } diff --git a/tests/test_Summary.cpp b/tests/test_Summary.cpp index 84ec9a2f0..31c93072d 100644 --- a/tests/test_Summary.cpp +++ b/tests/test_Summary.cpp @@ -3193,6 +3193,11 @@ BOOST_AUTO_TEST_CASE(SummaryState_TOTAL) { st.update_well_var("OP1", "WOPR", 100); BOOST_CHECK_EQUAL(st.get_well_var("OP1", "WOPR"), 100); + st.update_well_var("OP1", "WWCT", 0.50); + BOOST_CHECK_EQUAL(st.get_well_var("OP1", "WWCT"), 0.50); + st.update_well_var("OP1", "WWCT", 0.50); + BOOST_CHECK_EQUAL(st.get_well_var("OP1", "WWCT"), 0.50); + st.update_well_var("OP1", "WOPT", 100); BOOST_CHECK_EQUAL(st.get_well_var("OP1", "WOPT"), 100); st.update_well_var("OP1", "WOPT", 100);