From 1a3166d9132d8d4f4323b1e3d921c2df4a8dc709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Tue, 27 Sep 2022 16:12:19 +0200 Subject: [PATCH] Simplify Erasure From PLT States Suggested by: [at]blattms --- opm/input/eclipse/Schedule/RFTConfig.hpp | 15 +++++--- src/opm/input/eclipse/Schedule/RFTConfig.cpp | 36 ++++++++------------ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/opm/input/eclipse/Schedule/RFTConfig.hpp b/opm/input/eclipse/Schedule/RFTConfig.hpp index f9f69ad55..38a2f42ee 100644 --- a/opm/input/eclipse/Schedule/RFTConfig.hpp +++ b/opm/input/eclipse/Schedule/RFTConfig.hpp @@ -82,14 +82,21 @@ public: } private: + template + using StateMap = std::unordered_map; + // Please make sure that member functions serializeOp(), operator==(), // and serializeObject() are also up to date when changing this list of // data members. bool first_open_rft = false; - std::unordered_map rft_state; - std::unordered_map plt_state; - std::unordered_map seg_state; - std::unordered_map open_wells; + StateMap rft_state{}; + StateMap plt_state{}; + StateMap seg_state{}; + std::unordered_map open_wells{}; + + void update_state(const std::string& wname, + const PLT mode, + StateMap& state); }; } // namespace Opm diff --git a/src/opm/input/eclipse/Schedule/RFTConfig.cpp b/src/opm/input/eclipse/Schedule/RFTConfig.cpp index 30f554f52..1f668b747 100644 --- a/src/opm/input/eclipse/Schedule/RFTConfig.cpp +++ b/src/opm/input/eclipse/Schedule/RFTConfig.cpp @@ -140,11 +140,7 @@ void RFTConfig::first_open(const bool on) void RFTConfig::update(const std::string& wname, RFT mode) { if (mode == RFT::NO) { - auto iter = this->rft_state.find(wname); - if (iter != this->rft_state.end()) { - this->rft_state.erase(iter); - } - + this->rft_state.erase(wname); return; } @@ -160,30 +156,28 @@ void RFTConfig::update(const std::string& wname, RFT mode) this->rft_state.insert_or_assign(wname, mode); } -void RFTConfig::update(const std::string& wname, const PLT mode) +void RFTConfig::update_state(const std::string& wname, + const PLT mode, + StateMap& state) { if (mode == PLT::NO) { - auto iter = this->plt_state.find(wname); - if (iter != this->plt_state.end()) { - this->plt_state.erase(iter); - } - - return; + // Remove 'wname' from list of wells for which to output PLT-type + // data. + state.erase(wname); } + else { + state.insert_or_assign(wname, mode); + } +} - this->plt_state[wname] = mode; +void RFTConfig::update(const std::string& wname, const PLT mode) +{ + this->update_state(wname, mode, this->plt_state); } void RFTConfig::update_segment(const std::string& wname, const PLT mode) { - if (mode == PLT::NO) { - // Remove 'wname' from list of wells for which to output segment - // data. - this->seg_state.erase(wname); - } - else { - this->seg_state.insert_or_assign(wname, mode); - } + this->update_state(wname, mode, this->seg_state); } bool RFTConfig::active() const