From 1f03a0e726e8b80c31362a0ceff15120ccb01245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Fri, 29 Oct 2021 12:01:12 +0200 Subject: [PATCH] Provide External Access to Well-Order Sorting This commit extracts the 'NameOrder' sorting operation to a new public member function, WellMatcher::sort(vector). The immediate use-case for this function is to provide a stable sorting order for wells that are matched in an ACTIONX block. Well IDs often end up in various output arrays in the restart files--e.g., in the IUAP array the matching wells are used in a WCON* keyword that employs a user-defined argument as part of setting its targets or limits--and we should strive to keep those arrays as deterministic as possible. --- .../eclipse/EclipseState/Schedule/Well/WellMatcher.hpp | 1 + .../eclipse/EclipseState/Schedule/Well/WellMatcher.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/Well/WellMatcher.hpp b/opm/parser/eclipse/EclipseState/Schedule/Well/WellMatcher.hpp index 3c633b83b..28fc89be0 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Well/WellMatcher.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Well/WellMatcher.hpp @@ -36,6 +36,7 @@ public: explicit WellMatcher(std::initializer_list wells); explicit WellMatcher(const std::vector& wells); WellMatcher(const NameOrder& well_order, const WListManager& wlm); + std::vector sort(std::vector wells) const; std::vector wells(const std::string& pattern) const; const std::vector& wells() const; diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellMatcher.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellMatcher.cpp index 40262fb5c..eb7086a3e 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellMatcher.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellMatcher.cpp @@ -17,6 +17,7 @@ along with OPM. If not, see . */ #include +#include #include #include @@ -45,6 +46,10 @@ WellMatcher::WellMatcher(const NameOrder& well_order, const WListManager &wlm) : { } +std::vector WellMatcher::sort(std::vector wells) const { + return this->m_well_order.sort(std::move(wells)); +} + const std::vector& WellMatcher::wells() const { return this->m_well_order.names(); } @@ -56,7 +61,7 @@ std::vector WellMatcher::wells(const std::string& pattern) const { // WLIST if (pattern[0] == '*' && pattern.size() > 1) - return this->m_well_order.sort( this->m_wlm.wells(pattern) ); + return this->sort( this->m_wlm.wells(pattern) ); // Normal pattern matching auto star_pos = pattern.find('*');