From dab5f226e168b3a521149c6b0af9add8f832222a Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 11:18:21 +0100 Subject: [PATCH] make UDQFunctionTable constructible from variables also make it default constructible, add accessors and equality operator --- .../Schedule/UDQ/UDQFunctionTable.hpp | 14 ++++++- .../Schedule/UDQ/UDQFunctionTable.cpp | 40 ++++++++++++++++++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunctionTable.hpp b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunctionTable.hpp index b4482a8a9..eb80352c2 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunctionTable.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunctionTable.hpp @@ -30,14 +30,24 @@ namespace Opm { class UDQFunctionTable { public: + using FunctionMap = std::unordered_map>; explicit UDQFunctionTable(const UDQParams& params); UDQFunctionTable(); + UDQFunctionTable(const UDQParams& param, + const FunctionMap& map); bool has_function(const std::string& name) const; const UDQFunction& get(const std::string& name) const; + + const UDQParams& getParams() const; + const FunctionMap& functionMap() const; + + bool operator==(const UDQFunctionTable& data) const; + private: - void insert_function(std::shared_ptr func); + void insert_function(std::shared_ptr func); UDQParams params; - std::unordered_map> function_table; + FunctionMap function_table; }; } #endif diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunctionTable.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunctionTable.cpp index db3e16cc3..8085fdd8e 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunctionTable.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunctionTable.cpp @@ -91,8 +91,13 @@ UDQFunctionTable::UDQFunctionTable(const UDQParams& params_arg) : this->insert_function( std::make_shared("UMAX", UDQBinaryFunction::UMAX )); } +UDQFunctionTable::UDQFunctionTable(const UDQParams& param, + const FunctionMap& map) : + params(param), + function_table(map) +{} -void UDQFunctionTable::insert_function(std::shared_ptr func) { +void UDQFunctionTable::insert_function(std::shared_ptr func) { auto name = func->name(); this->function_table.emplace( std::move(name), std::move(func) ); } @@ -111,4 +116,37 @@ const UDQFunction& UDQFunctionTable::get(const std::string& name) const { const auto& pair_ptr = this->function_table.find(name); return *pair_ptr->second; } + +const UDQParams& UDQFunctionTable::getParams() const { + return this->params; +} + +const UDQFunctionTable::FunctionMap& UDQFunctionTable::functionMap() const { + return this->function_table; +} + +bool UDQFunctionTable::operator==(const UDQFunctionTable& data) const { + if (!(this->getParams() == data.getParams())) + return false; + + if (this->functionMap().size() != data.functionMap().size()) + return false; + + auto tIt = this->functionMap().begin(); + auto dIt = data.functionMap().begin(); + for (; tIt != this->functionMap().end(); ++tIt, ++dIt) { + if (tIt->first != dIt->first) + return false; + + if ((tIt->second && !dIt->second) || (!tIt->second && dIt->second)) + return false; + + if (tIt->second && !(*tIt->second == *dIt->second)) + return false; + } + + return true; +} + + }