From f8d9f74d919198be37f29da6a2b2c350228989c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Tue, 6 Jun 2023 19:46:21 +0200 Subject: [PATCH] Reformat PAvg Class Mostly for readability. While here, also switch to using compiled item names instead of raw strings to access the DeckItems which constitute the WPAVE and WWPAVE keywords. --- opm/input/eclipse/Schedule/Well/PAvg.hpp | 69 +++++--- src/opm/input/eclipse/Schedule/Well/PAvg.cpp | 176 +++++++++---------- 2 files changed, 133 insertions(+), 112 deletions(-) diff --git a/opm/input/eclipse/Schedule/Well/PAvg.hpp b/opm/input/eclipse/Schedule/Well/PAvg.hpp index 1890e7343..086b04c42 100644 --- a/opm/input/eclipse/Schedule/Well/PAvg.hpp +++ b/opm/input/eclipse/Schedule/Well/PAvg.hpp @@ -17,43 +17,65 @@ along with OPM. If not, see . */ - #ifndef PAVE_HPP #define PAVE_HPP +namespace Opm { + class DeckRecord; +} // Namespace Opm namespace Opm { -class DeckRecord; -class PAvg { +class PAvg +{ public: - enum class DepthCorrection { + enum class DepthCorrection + { WELL = 1, RES = 2, - NONE = 3 + NONE = 3, }; PAvg(); explicit PAvg(const DeckRecord& record); - PAvg(double inner_weight, double conn_weight, DepthCorrection depth_correction, bool use_open_connections); - - double inner_weight() const; - double conn_weight() const; - bool use_porv() const; - bool open_connections() const; - DepthCorrection depth_correction() const; - - - template - void serializeOp(Serializer& serializer) { - serializer(m_inner_weight); - serializer(m_conn_weight); - serializer(m_depth_correction); - serializer(m_open_connections); - } + PAvg(double inner_weight, + double conn_weight, + DepthCorrection depth_correction, + bool use_open_connections); static PAvg serializationTestObject(); + double inner_weight() const + { + return this->m_inner_weight; + } + + double conn_weight() const + { + return this->m_conn_weight; + } + + bool open_connections() const + { + return this->m_open_connections; + } + + DepthCorrection depth_correction() const + { + return this->m_depth_correction; + } + + bool use_porv() const; + + template + void serializeOp(Serializer& serializer) + { + serializer(this->m_inner_weight); + serializer(this->m_conn_weight); + serializer(this->m_depth_correction); + serializer(this->m_open_connections); + } + bool operator==(const PAvg& other) const; bool operator!=(const PAvg& other) const; @@ -64,5 +86,6 @@ private: bool m_open_connections; }; -} -#endif +} // namespace Opm + +#endif // PAVE_HPP diff --git a/src/opm/input/eclipse/Schedule/Well/PAvg.cpp b/src/opm/input/eclipse/Schedule/Well/PAvg.cpp index efdcf5af2..cdc29db42 100644 --- a/src/opm/input/eclipse/Schedule/Well/PAvg.cpp +++ b/src/opm/input/eclipse/Schedule/Well/PAvg.cpp @@ -16,124 +16,122 @@ You should have received a copy of the GNU General Public License along with OPM. If not, see . */ -#include #include + #include #include -namespace Opm { +#include +#include + +#include namespace { -PAvg::DepthCorrection depthCorrectionFromString(const std::string& s) { - if (s == "WELL") - return PAvg::DepthCorrection::WELL; - - if (s == "RES") - return PAvg::DepthCorrection::RES; - - if (s == "NONE") - return PAvg::DepthCorrection::NONE; - - throw std::invalid_argument(fmt::format("{} not recognized as depth correction mode", s)); -} - -bool openConnectionsFromString(const std::string& s) { - if (s == "OPEN") - return true; - - if (s == "ALL") - return false; - - throw std::invalid_argument(fmt::format("{} not recognized as connection indicator", s)); -} - - -} - - - -PAvg::PAvg() : - m_inner_weight(ParserKeywords::WPAVE::F1::defaultValue), - m_conn_weight(ParserKeywords::WPAVE::F2::defaultValue) +Opm::PAvg::DepthCorrection +depthCorrectionFromString(const std::string& s) { - m_depth_correction = depthCorrectionFromString( ParserKeywords::WPAVE::DEPTH_CORRECTION::defaultValue ); - m_open_connections = openConnectionsFromString( ParserKeywords::WPAVE::CONNECTION::defaultValue ); + if (s == "WELL") { + return Opm::PAvg::DepthCorrection::WELL; + } + + if (s == "RES") { + return Opm::PAvg::DepthCorrection::RES; + } + + if (s == "NONE") { + return Opm::PAvg::DepthCorrection::NONE; + } + + throw std::invalid_argument { + fmt::format("{} not recognized as depth correction mode", s) + }; } -PAvg::PAvg(double inner_weight, double conn_weight, DepthCorrection depth_correction, bool use_open_connections) : - m_inner_weight(inner_weight), - m_conn_weight(conn_weight), - m_depth_correction(depth_correction), - m_open_connections(use_open_connections) +bool openConnectionsFromString(const std::string& s) +{ + if (s == "OPEN") { + return true; + } + + if (s == "ALL") { + return false; + } + + throw std::invalid_argument { + fmt::format("{} not recognized as connection indicator", s) + }; +} + +} // Anonymous namespace + +namespace Opm { + +PAvg::PAvg() + : m_inner_weight(ParserKeywords::WPAVE::F1::defaultValue) + , m_conn_weight(ParserKeywords::WPAVE::F2::defaultValue) + , m_depth_correction(depthCorrectionFromString(ParserKeywords::WPAVE::DEPTH_CORRECTION::defaultValue)) + , m_open_connections(openConnectionsFromString(ParserKeywords::WPAVE::CONNECTION::defaultValue)) {} -PAvg PAvg::serializationTestObject() { - return PAvg(0.10, 0.30, PAvg::DepthCorrection::NONE, false); -} +PAvg::PAvg(const double inner_weight, + const double conn_weight, + const DepthCorrection depth_correction, + const bool use_open_connections) + : m_inner_weight(inner_weight) + , m_conn_weight(conn_weight) + , m_depth_correction(depth_correction) + , m_open_connections(use_open_connections) +{} PAvg::PAvg(const DeckRecord& record) : PAvg() { - /* - This code uses the WPAVE keyword to access the content of the the record, - but the record can equally well come from a WWPAVE keyword - i.e. it is a - HARD assumption that the same item names is used both for WPAVE and - WWPAVE. - */ + // This code uses the WPAVE keyword to access the content of the record, + // but the record can equally well come from a WWPAVE keyword--i.e., it + // is a HARD assumption that the same item names is used both for WPAVE + // and WWPAVE. using WPAVE = ParserKeywords::WPAVE; - const auto& item_inner_weight = record.getItem(); - const auto& item_conn_weight = record.getItem(); - const auto& item_depth_correction = record.getItem(); - const auto& item_connections = record.getItem(); - this->m_inner_weight = item_inner_weight.get(0); - this->m_conn_weight = item_conn_weight.get(0); + this->m_inner_weight = record.getItem().get(0); + this->m_conn_weight = record.getItem().get(0); - if (!item_depth_correction.defaultApplied(0)) - this->m_depth_correction = depthCorrectionFromString( item_depth_correction.get(0) ); + if (const auto& item_depth_correction = record.getItem(); + !item_depth_correction.defaultApplied(0)) + { + this->m_depth_correction = depthCorrectionFromString(item_depth_correction.get(0)); + } - if (!item_connections.defaultApplied(0)) - this->m_open_connections = openConnectionsFromString( item_connections.get(0) ); + if (const auto& item_connections = record.getItem(); + !item_connections.defaultApplied(0)) + { + this->m_open_connections = openConnectionsFromString(item_connections.get(0)); + } } - -double PAvg::inner_weight() const { - return this->m_inner_weight; +PAvg PAvg::serializationTestObject() +{ + return PAvg(0.10, 0.30, PAvg::DepthCorrection::NONE, false); } -double PAvg::conn_weight() const { - return this->m_conn_weight; +bool PAvg::use_porv() const +{ + return (this->m_conn_weight != 1) + || (this->m_inner_weight < 0); } -PAvg::DepthCorrection PAvg::depth_correction() const { - return this->m_depth_correction; +bool PAvg::operator==(const PAvg& other) const +{ + return (this->m_inner_weight == other.m_inner_weight) + && (this->m_conn_weight == other.m_conn_weight) + && (this->m_depth_correction == other.m_depth_correction) + && (this->m_open_connections == other.m_open_connections) + ; } -bool PAvg::open_connections() const { - return this->m_open_connections; -} - -bool PAvg::use_porv() const { - if (this->m_conn_weight != 1) - return true; - - if (this->m_inner_weight < 0) - return true; - - return false; -} - - -bool PAvg::operator==(const PAvg& other) const { - return this->m_inner_weight == other.m_inner_weight && - this->m_conn_weight == other.m_conn_weight && - this->m_depth_correction == other.m_depth_correction && - this->m_open_connections == other.m_open_connections; -} - -bool PAvg::operator!=(const PAvg& other) const { +bool PAvg::operator!=(const PAvg& other) const +{ return !(*this == other); }