Skip to content

Commit

Permalink
Merge pull request OPM#798 from joakim-hove/summary-total-fixup
Browse files Browse the repository at this point in the history
Update total check in SummaryState
  • Loading branch information
bska authored Jun 6, 2019
2 parents b1067db + 82f88ce commit dff91dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/opm/parser/eclipse/EclipseState/Schedule/SummaryState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,23 @@ namespace Opm{
namespace {

bool is_total(const std::string& key) {
static const std::unordered_set<std::string> 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<std::string> 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));
Expand Down
4 changes: 4 additions & 0 deletions tests/test_Summary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit dff91dd

Please sign in to comment.