From 10b2b2ac48d4a4ff35b6c358b2edb1d76ace1802 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Thu, 11 Jun 2020 22:06:52 +0200 Subject: [PATCH] Add caching of well and group names in SummaryState --- .../EclipseState/Schedule/SummaryState.hpp | 13 ++++++---- .../EclipseState/Schedule/SummaryState.cpp | 26 ++++++++++++++----- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp b/opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp index 8adcf4492..cf5814d5b 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp @@ -20,12 +20,13 @@ #ifndef SUMMARY_STATE_H #define SUMMARY_STATE_H -#include #include -#include +#include +#include +#include #include #include -#include +#include namespace Opm{ @@ -94,9 +95,9 @@ public: double get_well_var(const std::string& well, const std::string& var) const; double get_group_var(const std::string& group, const std::string& var) const; - std::vector wells() const; + const std::vector& wells() const; std::vector wells(const std::string& var) const; - std::vector groups() const; + const std::vector& groups() const; std::vector groups(const std::string& var) const; std::vector serialize() const; void deserialize(const std::vector& buffer); @@ -112,10 +113,12 @@ private: // The first key is the variable and the second key is the well. std::unordered_map> well_values; std::unordered_set m_wells; + mutable std::optional> well_names; // The first key is the variable and the second key is the group. std::unordered_map> group_values; std::unordered_set m_groups; + mutable std::optional> group_names; }; diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/SummaryState.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/SummaryState.cpp index f3bde6ae6..014f8c2d2 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/SummaryState.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/SummaryState.cpp @@ -132,7 +132,10 @@ namespace { this->values[key] = value; this->group_values[var][group] = value; } - this->m_groups.insert(group); + if (this->m_groups.count(group) == 0) { + this->m_groups.insert(group); + this->group_names.reset(); + } } void SummaryState::update_well_var(const std::string& well, const std::string& var, double value) { @@ -144,7 +147,10 @@ namespace { this->values[key] = value; this->well_values[var][well] = value; } - this->m_wells.insert(well); + if (this->m_wells.count(well) == 0) { + this->m_wells.insert(well); + this->well_names.reset(); + } } void SummaryState::update_udq(const UDQSet& udq_set) { @@ -189,6 +195,7 @@ namespace { return false; erase_var(this->well_values, var, well); + this->well_names.reset(); return true; } @@ -198,6 +205,7 @@ namespace { return false; erase_var(this->group_values, var, group); + this->group_names.reset(); return true; } @@ -245,8 +253,11 @@ namespace { } - std::vector SummaryState::wells() const { - return std::vector(this->m_wells.begin(), this->m_wells.end()); + const std::vector& SummaryState::wells() const { + if (!this->well_names) + this->well_names = std::vector(this->m_wells.begin(), this->m_wells.end()); + + return *this->well_names; } @@ -255,8 +266,11 @@ namespace { } - std::vector SummaryState::groups() const { - return std::vector(this->m_groups.begin(), this->m_groups.end()); + const std::vector& SummaryState::groups() const { + if (!this->group_names) + this->group_names = std::vector(this->m_groups.begin(), this->m_groups.end()); + + return *this->group_names; } std::size_t SummaryState::num_wells() const {