Add caching of well and group names in SummaryState

This commit is contained in:
Joakim Hove
2020-06-11 22:06:52 +02:00
parent 082820380d
commit 10b2b2ac48
2 changed files with 28 additions and 11 deletions

View File

@@ -20,12 +20,13 @@
#ifndef SUMMARY_STATE_H
#define SUMMARY_STATE_H
#include <string>
#include <chrono>
#include <vector>
#include <iosfwd>
#include <optional>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <iosfwd>
#include <vector>
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<std::string> wells() const;
const std::vector<std::string>& wells() const;
std::vector<std::string> wells(const std::string& var) const;
std::vector<std::string> groups() const;
const std::vector<std::string>& groups() const;
std::vector<std::string> groups(const std::string& var) const;
std::vector<char> serialize() const;
void deserialize(const std::vector<char>& buffer);
@@ -112,10 +113,12 @@ private:
// The first key is the variable and the second key is the well.
std::unordered_map<std::string, std::unordered_map<std::string, double>> well_values;
std::unordered_set<std::string> m_wells;
mutable std::optional<std::vector<std::string>> well_names;
// The first key is the variable and the second key is the group.
std::unordered_map<std::string, std::unordered_map<std::string, double>> group_values;
std::unordered_set<std::string> m_groups;
mutable std::optional<std::vector<std::string>> group_names;
};

View File

@@ -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<std::string> SummaryState::wells() const {
return std::vector<std::string>(this->m_wells.begin(), this->m_wells.end());
const std::vector<std::string>& SummaryState::wells() const {
if (!this->well_names)
this->well_names = std::vector<std::string>(this->m_wells.begin(), this->m_wells.end());
return *this->well_names;
}
@@ -255,8 +266,11 @@ namespace {
}
std::vector<std::string> SummaryState::groups() const {
return std::vector<std::string>(this->m_groups.begin(), this->m_groups.end());
const std::vector<std::string>& SummaryState::groups() const {
if (!this->group_names)
this->group_names = std::vector<std::string>(this->m_groups.begin(), this->m_groups.end());
return *this->group_names;
}
std::size_t SummaryState::num_wells() const {