From 82f88ce973fcdfff52f877b3bf3f16f9ae3d9088 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 3 Jun 2019 17:05:46 +0200 Subject: [PATCH] Update total check in SummaryState --- .../EclipseState/Schedule/SummaryState.cpp | 20 +++++++++---------- tests/test_Summary.cpp | 4 ++++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/SummaryState.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/SummaryState.cpp index b549256dc..ee0e98f89 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/SummaryState.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/SummaryState.cpp @@ -26,25 +26,23 @@ 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"}; + static const std::vector 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(':'); + // Starting with ':' - that is probably broken?! if (sep_pos == 0) return false; if (sep_pos == std::string::npos) { - 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; - - std::string sub_key = key.substr(1, key.size() - (1 + end_shift)); - return (totals.count( sub_key ) == 1); + for (const auto& total : totals) { + if (key.compare(1, total.size(), total) == 0) + return true; } + return false; } else return is_total(key.substr(0,sep_pos)); diff --git a/tests/test_Summary.cpp b/tests/test_Summary.cpp index f51423814..a0a36adb6 100644 --- a/tests/test_Summary.cpp +++ b/tests/test_Summary.cpp @@ -3218,6 +3218,10 @@ BOOST_AUTO_TEST_CASE(SummaryState_TOTAL) { st.update("FOPTH", 100); BOOST_CHECK_EQUAL(st.get("FOPTH"), 200); + st.update("WGPTS", 100); + BOOST_CHECK_EQUAL(st.get("WGPTS"), 100); + st.update("WGPTS", 100); + BOOST_CHECK_EQUAL(st.get("WGPTS"), 200); st.update_elapsed(100); BOOST_CHECK_EQUAL(st.get_elapsed(), 100);