From 12f87578d641c029a86b4954b888d0ab30ca81c7 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 11:21:56 +0100 Subject: [PATCH 01/13] make WList constructible from variables also make it default constructible, add accessors and equality operator --- .../eclipse/EclipseState/Schedule/Well/WList.hpp | 6 ++++++ .../eclipse/EclipseState/Schedule/Well/WList.cpp | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/opm/parser/eclipse/EclipseState/Schedule/Well/WList.hpp b/opm/parser/eclipse/EclipseState/Schedule/Well/WList.hpp index 814a4ed0b..dd6bb545f 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Well/WList.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Well/WList.hpp @@ -26,14 +26,20 @@ namespace Opm { class WList { public: using storage = std::unordered_set; + + WList() = default; + WList(const storage& wlist); std::size_t size() const; void add(const std::string& well); void del(const std::string& well); bool has(const std::string& well) const; std::vector wells() const; + const storage& wellList() const; storage::const_iterator begin() const; storage::const_iterator end() const; + + bool operator==(const WList& data) const; private: storage well_list; }; diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Well/WList.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Well/WList.cpp index 85884368e..8d3b52308 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Well/WList.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Well/WList.cpp @@ -21,6 +21,11 @@ namespace Opm { +WList::WList(const storage& wlist) : + well_list(wlist) +{ +} + std::size_t WList::size() const { return this->well_list.size(); @@ -51,4 +56,12 @@ WList::storage::const_iterator WList::end() const { return this->well_list.end(); } +const WList::storage& WList::wellList() const { + return this->well_list; +} + +bool WList::operator==(const WList& data) const { + return this->wellList() == data.wellList(); +} + } From 4c626c22653ac17200a3ce1647fccd46caea6cd1 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 11:21:56 +0100 Subject: [PATCH 02/13] make WListManager constructible from variables also make it default constructible, add accessors and equality operator --- .../EclipseState/Schedule/Well/WListManager.hpp | 6 ++++++ .../EclipseState/Schedule/Well/WListManager.cpp | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/opm/parser/eclipse/EclipseState/Schedule/Well/WListManager.hpp b/opm/parser/eclipse/EclipseState/Schedule/Well/WListManager.hpp index 8d1915368..7151a73f4 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Well/WListManager.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Well/WListManager.hpp @@ -27,11 +27,17 @@ class WList; class WListManager { public: + WListManager() = default; + WListManager(const std::map& list); bool hasList(const std::string&) const; WList& getList(const std::string& name); const WList& getList(const std::string& name) const; WList& newList(const std::string& name); void delWell(const std::string& well); + + const std::map& lists() const; + bool operator==(const WListManager& data) const; + private: std::map wlists; }; diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Well/WListManager.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Well/WListManager.cpp index d4fb76153..36c7dc7ee 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Well/WListManager.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Well/WListManager.cpp @@ -22,6 +22,11 @@ namespace Opm { + WListManager::WListManager(const std::map& list) + : wlists(list) + { + } + bool WListManager::hasList(const std::string& name) const { return (this->wlists.find(name) != this->wlists.end()); } @@ -49,4 +54,12 @@ namespace Opm { } } + const std::map& WListManager::lists() const { + return this->wlists; + } + + bool WListManager::operator==(const WListManager& data) const { + return this->lists() == data.lists(); + } + } From c0183ae78a9d91e702c85e2948b6c2efffea182e Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 11:12:46 +0100 Subject: [PATCH 03/13] make UDQFunction constructible from variables also make it default constructible and add equality operator --- .../eclipse/EclipseState/Schedule/UDQ/UDQFunction.hpp | 4 ++++ .../eclipse/EclipseState/Schedule/UDQ/UDQFunction.cpp | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunction.hpp b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunction.hpp index fe6bce96c..94b2af7c8 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunction.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunction.hpp @@ -33,10 +33,14 @@ namespace Opm { class UDQFunction { public: + UDQFunction() : func_type(UDQTokenType::error) {} UDQFunction(const std::string& name); + UDQFunction(const std::string& name, UDQTokenType funcType); virtual ~UDQFunction() = default; const std::string& name() const; UDQTokenType type() const; + bool operator==(const UDQFunction& data) const; + private: std::string m_name; UDQTokenType func_type; diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunction.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunction.cpp index 1f37dbbce..a33e51a39 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunction.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunction.cpp @@ -33,6 +33,12 @@ UDQFunction::UDQFunction(const std::string& name) : { } +UDQFunction::UDQFunction(const std::string& name, UDQTokenType funcType) : + m_name(name), + func_type(funcType) +{ +} + UDQTokenType UDQFunction::type() const { return this->func_type; } @@ -41,6 +47,11 @@ const std::string& UDQFunction::name() const { return this->m_name; } +bool UDQFunction::operator==(const UDQFunction& data) const { + return this->name() == data.name() && + this->type() == data.type(); +} + UDQScalarFunction::UDQScalarFunction(const std::string&name, std::function f) : UDQFunction(name), func(std::move(f)) From dab5f226e168b3a521149c6b0af9add8f832222a Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 11:18:21 +0100 Subject: [PATCH 04/13] 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; +} + + } From 9c991241c0bb6fad8860def8e2615e0fe481d042 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 11:09:17 +0100 Subject: [PATCH 05/13] changed: make UDQASTNode part of public API needed for serialization --- CMakeLists_files.cmake | 1 + .../parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.hpp | 0 .../parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.cpp | 3 +-- src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.cpp | 2 +- src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQParser.hpp | 3 +-- 5 files changed, 4 insertions(+), 5 deletions(-) rename {src/opm => opm}/parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.hpp (100%) diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 3a49cd8c0..0d3fb906f 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -651,6 +651,7 @@ if(ENABLE_ECL_INPUT) opm/parser/eclipse/EclipseState/checkDeck.hpp opm/parser/eclipse/EclipseState/Runspec.hpp opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.hpp + opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.hpp opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.hpp opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQContext.hpp opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQConfig.hpp diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.hpp b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.hpp similarity index 100% rename from src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.hpp rename to opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.hpp diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.cpp index 0304c3652..a9ca10054 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.cpp @@ -18,12 +18,11 @@ */ #include +#include #include #include #include -#include "UDQASTNode.hpp" - namespace Opm { diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.cpp index af03f017b..e2bb83b5a 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.cpp @@ -23,12 +23,12 @@ #include #include +#include #include #include #include "../../../Parser/raw/RawConsts.hpp" #include "UDQParser.hpp" -#include "UDQASTNode.hpp" namespace Opm { diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQParser.hpp b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQParser.hpp index d2a9bd80c..3720aa942 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQParser.hpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQParser.hpp @@ -23,12 +23,11 @@ #include #include +#include #include #include #include -#include "UDQASTNode.hpp" - namespace Opm { class ParseContext; From 6720e6a6cb16d49b663140ef34245988025043ae Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 11:12:46 +0100 Subject: [PATCH 06/13] make UDQASTNode constructible from variables also make it default constructible, add accessors and equality operator --- .../EclipseState/Schedule/UDQ/UDQASTNode.hpp | 18 ++++- .../EclipseState/Schedule/UDQ/UDQASTNode.cpp | 65 +++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.hpp b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.hpp index fdc138d8b..613574365 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.hpp @@ -35,13 +35,19 @@ namespace Opm { class UDQASTNode { public: + UDQASTNode(); explicit UDQASTNode(UDQTokenType type_arg); explicit UDQASTNode(double scalar_value); UDQASTNode(UDQTokenType type_arg, const std::string& func_name, const UDQASTNode& arg); UDQASTNode(UDQTokenType type_arg, const std::string& func_name, const UDQASTNode& left, const UDQASTNode& right); UDQASTNode(UDQTokenType type_arg, const std::string& func_name); UDQASTNode(UDQTokenType type_arg, const std::string& string_value, const std::vector& selector); - + UDQASTNode(UDQVarType varType, UDQTokenType typ, + const std::string& stringVal, + double scalarVal, + const std::vector& selectors, + const std::shared_ptr& left_arg, + const std::shared_ptr& right_arg); UDQSet eval(UDQVarType eval_target, const UDQContext& context) const; @@ -53,6 +59,16 @@ public: void set_right(const UDQASTNode& arg); UDQASTNode* get_left() const; UDQASTNode* get_right() const; + + bool operator==(const UDQASTNode& data) const; + + const std::string& stringValue() const; + UDQTokenType getType() const; + double scalarValue() const; + const std::vector& getSelectors() const; + const std::shared_ptr& getLeft() const; + const std::shared_ptr& getRight() const; + private: UDQTokenType type; void func_tokens(std::set& tokens) const; diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.cpp index a9ca10054..528e7f3ca 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQASTNode.cpp @@ -25,6 +25,9 @@ namespace Opm { +UDQASTNode::UDQASTNode() : + UDQASTNode(UDQTokenType::error) +{} UDQASTNode::UDQASTNode(UDQTokenType type_arg) : @@ -101,6 +104,22 @@ UDQASTNode::UDQASTNode(UDQTokenType type_arg, } +UDQASTNode::UDQASTNode(UDQVarType varType, UDQTokenType typ, + const std::string& stringVal, + double scalarVal, + const std::vector& selectors, + const std::shared_ptr& left_arg, + const std::shared_ptr& right_arg) : + var_type(varType), + type(typ), + string_value(stringVal), + selector(selectors), + scalar_value(scalarVal), + left(left_arg), + right(right_arg) +{} + + UDQASTNode::UDQASTNode(UDQTokenType type_arg, const std::string& string_value_arg, const std::vector& selector_arg) : @@ -274,4 +293,50 @@ void UDQASTNode::set_right(const UDQASTNode& arg) { this->update_type(arg); } +bool UDQASTNode::operator==(const UDQASTNode& data) const { + if ((this->getLeft() && !data.getLeft()) || + (!this->getLeft() && data.getLeft())) + return false; + + if (this->getLeft() && !(*this->getLeft() == *data.getLeft())) + return false; + + if ((this->getRight() && !data.getRight()) || + (!this->getRight() && data.getRight())) + return false; + + if (this->getRight() && !(*this->getRight() == *data.getRight())) + return false; + + return type == data.type && + var_type == data.var_type && + string_value == data.string_value && + scalar_value == data.scalar_value && + selector == data.selector; +} + +const std::string& UDQASTNode::stringValue() const { + return string_value; +} + +double UDQASTNode::scalarValue() const { + return scalar_value; +} + +const std::vector& UDQASTNode::getSelectors() const { + return selector; +} + +const std::shared_ptr& UDQASTNode::getLeft() const { + return left; +} + +const std::shared_ptr& UDQASTNode::getRight() const { + return right; +} + +UDQTokenType UDQASTNode::getType() const { + return type; +} + } From 45aad7e7fd079d84b9328a3767a0653c1eea32c0 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 11:18:21 +0100 Subject: [PATCH 07/13] remove unused member variable from UDQDefine --- opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.hpp | 1 - .../parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.cpp | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.hpp b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.hpp index 07c87f8ad..592b99e34 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.hpp @@ -62,7 +62,6 @@ public: UDQVarType var_type() const; std::set func_tokens() const; private: - const UDQParams& udq_params; // Beacuse of the shared RNG stream this must be a reference. std::string m_keyword; std::shared_ptr ast; UDQVarType m_var_type; diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.cpp index e2bb83b5a..d2bfc2378 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.cpp @@ -78,12 +78,11 @@ UDQDefine::UDQDefine(const UDQParams& udq_params_arg, {} -UDQDefine::UDQDefine(const UDQParams& udq_params_arg, +UDQDefine::UDQDefine(const UDQParams& udq_params, const std::string& keyword, const std::vector& deck_data, const ParseContext& parseContext, ErrorGuard& errors) : - udq_params(udq_params_arg), m_keyword(keyword), m_var_type(UDQ::varType(keyword)) { @@ -121,7 +120,7 @@ UDQDefine::UDQDefine(const UDQParams& udq_params_arg, } } - this->ast = std::make_shared( UDQParser::parse(this->udq_params, this->m_var_type, this->m_keyword, tokens, parseContext, errors) ); + this->ast = std::make_shared( UDQParser::parse(udq_params, this->m_var_type, this->m_keyword, tokens, parseContext, errors) ); this->string_data = ""; for (std::size_t index = 0; index < deck_data.size(); index++) { From 5d6046fdae566c84806c653a4cf47c272c59e666 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 11:12:46 +0100 Subject: [PATCH 08/13] make UDQDefine constructible from variables also make it default constructible, add accessors and equality operator --- .../EclipseState/Schedule/UDQ/UDQDefine.hpp | 10 ++++++ .../EclipseState/Schedule/UDQ/UDQDefine.cpp | 31 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.hpp b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.hpp index 592b99e34..ba288aada 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.hpp @@ -38,6 +38,8 @@ class ErrorGuard; class UDQDefine{ public: + UDQDefine(); + UDQDefine(const UDQParams& udq_params, const std::string& keyword, const std::vector& deck_data); @@ -55,12 +57,20 @@ public: const ParseContext& parseContext, T&& errors); + UDQDefine(const std::string& keyword, + std::shared_ptr astPtr, + UDQVarType type, + const std::string& string_data); UDQSet eval(const UDQContext& context) const; const std::string& keyword() const; const std::string& input_string() const; UDQVarType var_type() const; std::set func_tokens() const; + std::shared_ptr getAst() const; + + bool operator==(const UDQDefine& data) const; + private: std::string m_keyword; std::shared_ptr ast; diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.cpp index d2bfc2378..541b775b3 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQDefine.cpp @@ -61,6 +61,10 @@ std::vector quote_split(const std::string& item) { } +UDQDefine::UDQDefine() + : m_var_type(UDQVarType::NONE) +{} + template UDQDefine::UDQDefine(const UDQParams& udq_params_arg, const std::string& keyword, @@ -130,6 +134,18 @@ UDQDefine::UDQDefine(const UDQParams& udq_params, } } + +UDQDefine::UDQDefine(const std::string& keyword, + std::shared_ptr astPtr, + UDQVarType type, + const std::string& stringData) + : m_keyword(keyword) + , ast(astPtr) + , m_var_type(type) + , string_data(stringData) +{} + + namespace { /* @@ -217,4 +233,19 @@ std::set UDQDefine::func_tokens() const { return this->ast->func_tokens(); } +std::shared_ptr UDQDefine::getAst() const { + return this->ast; +} + +bool UDQDefine::operator==(const UDQDefine& data) const { + if ((ast && !data.ast) || (!ast && data.ast)) + return false; + if (ast && !(*ast == *data.ast)) + return false; + + return this->keyword() == data.keyword() && + this->var_type() == data.var_type() && + this->input_string() == data.input_string(); +} + } From 426ee94a754a063df5b1e5271fd8f71e3b5cbee4 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 11:15:48 +0100 Subject: [PATCH 09/13] add equality operator to UDQAssign::AssignRecord --- opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.hpp b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.hpp index 628814fbc..f778a1c19 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.hpp @@ -42,6 +42,11 @@ public: struct AssignRecord { std::vector selector; double value; + + bool operator==(const AssignRecord& data) const { + return selector == data.selector && + value == data.value; + } }; UDQAssign(const std::string& keyword, const std::vector& selector, double value); From ec907c22c12323b90088f8eb7eff69dd5ac1b8bd Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 11:12:46 +0100 Subject: [PATCH 10/13] make UDQAssign constructible from variables also make it default constructible, add accessors and equality operator --- .../EclipseState/Schedule/UDQ/UDQAssign.hpp | 10 ++++++++ .../EclipseState/Schedule/UDQ/UDQAssign.cpp | 25 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.hpp b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.hpp index f778a1c19..bdf975343 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.hpp @@ -49,11 +49,21 @@ public: } }; + UDQAssign(); UDQAssign(const std::string& keyword, const std::vector& selector, double value); + UDQAssign(const std::string& keyword, + UDQVarType varType, + const std::vector& records); + const std::string& keyword() const; UDQVarType var_type() const; void add_record(const std::vector& selector, double value); UDQSet eval(const std::vector& wells) const; + + const std::vector& getRecords() const; + + bool operator==(const UDQAssign& data) const; + private: std::string m_keyword; UDQVarType m_var_type; diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.cpp index ede52301f..8a44d853d 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.cpp @@ -22,6 +22,11 @@ namespace Opm { +UDQAssign::UDQAssign() : + m_var_type(UDQVarType::NONE) +{ +} + UDQAssign::UDQAssign(const std::string& keyword, const std::vector& selector, double value) : m_keyword(keyword), m_var_type(UDQ::varType(keyword)) @@ -29,6 +34,15 @@ UDQAssign::UDQAssign(const std::string& keyword, const std::vector& this->add_record(selector, value); } +UDQAssign::UDQAssign(const std::string& keyword, + UDQVarType varType, + const std::vector& record) : + m_keyword(keyword), + m_var_type(varType), + records(record) +{ +} + void UDQAssign::add_record(const std::vector& selector, double value) { this->records.push_back({selector, value}); } @@ -58,4 +72,15 @@ UDQSet UDQAssign::eval(const std::vector& wells) const { } throw std::invalid_argument("Not yet implemented"); } + +const std::vector& UDQAssign::getRecords() const { + return records; +} + +bool UDQAssign::operator==(const UDQAssign& data) const { + return this->keyword() == data.keyword() && + this->var_type() == data.var_type() && + this->getRecords() == data.getRecords(); +} + } From 763bc692114d35d359ccd1684c94e42e93170ca9 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 11:21:56 +0100 Subject: [PATCH 11/13] add equality operator to UDQIndex --- opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQInput.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQInput.hpp b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQInput.hpp index 3fa824dbe..cc0366bab 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQInput.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQInput.hpp @@ -42,6 +42,13 @@ public: { } + bool operator==(const UDQIndex& data) const { + return insert_index == data.insert_index && + typed_insert_index == data.typed_insert_index && + action == data.action && + var_type == data.var_type; + } + std::size_t insert_index; std::size_t typed_insert_index; From 5c203e29b50164f27a0cf1c48b377719ee9e0886 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 11:12:46 +0100 Subject: [PATCH 12/13] make UDQConfig constructible from variables also make it default constructible, add accessors and equality operator --- .../EclipseState/Schedule/UDQ/UDQConfig.hpp | 18 +++++++ .../EclipseState/Schedule/UDQ/UDQConfig.cpp | 52 +++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQConfig.hpp b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQConfig.hpp index c7a8b54ba..362d2cfa7 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQConfig.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQConfig.hpp @@ -40,8 +40,18 @@ namespace Opm { class Deck; class UDQConfig { public: + UDQConfig() = default; explicit UDQConfig(const Deck& deck); explicit UDQConfig(const UDQParams& params); + UDQConfig(const UDQParams& params, + const UDQFunctionTable& funcTable, + const std::unordered_map& definition, + const std::unordered_map& assignment, + const std::unordered_map& unit, + const OrderedMap& inputIdx, + const std::map& tCount); + + const std::string& unit(const std::string& key) const; bool has_unit(const std::string& keyword) const; bool has_keyword(const std::string& keyword) const; @@ -52,6 +62,11 @@ namespace Opm { void add_define(const std::string& quantity, const std::vector& expression); std::vector definitions() const; + const std::unordered_map& definitionMap() const; + const std::unordered_map& assignmentMap() const; + const std::unordered_map& unitsMap() const; + const OrderedMap& inputIndex() const; + const std::map& typeCount() const; std::vector definitions(UDQVarType var_type) const; std::vector input() const; @@ -66,6 +81,9 @@ namespace Opm { std::vector assignments(UDQVarType var_type) const; const UDQParams& params() const; const UDQFunctionTable& function_table() const; + + bool operator==(const UDQConfig& config) const; + private: void add_node(const std::string& quantity, UDQAction action); diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQConfig.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQConfig.cpp index cba27c9bf..54b9e2b91 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQConfig.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQConfig.cpp @@ -46,6 +46,22 @@ namespace Opm { {} + UDQConfig::UDQConfig(const UDQParams& params, + const UDQFunctionTable& funcTable, + const std::unordered_map& definition, + const std::unordered_map& assignment, + const std::unordered_map& unit, + const OrderedMap& inputIdx, + const std::map& tCount) : + udq_params(params), + udqft(funcTable), + m_definitions(definition), + m_assignments(assignment), + units(unit), + input_index(inputIdx), + type_count(tCount) + {} + const UDQParams& UDQConfig::params() const { return this->udq_params; @@ -256,6 +272,42 @@ namespace Opm { return this->udqft; } + + const std::unordered_map& UDQConfig::definitionMap() const { + return this->m_definitions; + } + + + const std::unordered_map& UDQConfig::assignmentMap() const { + return this->m_assignments; + } + + + const std::unordered_map& UDQConfig::unitsMap() const { + return this->units; + } + + + const OrderedMap& UDQConfig::inputIndex() const { + return this->input_index; + } + + + const std::map& UDQConfig::typeCount() const { + return this->type_count; + } + + + bool UDQConfig::operator==(const UDQConfig& data) const { + return this->params() == data.params() && + this->function_table() == data.function_table() && + this->definitionMap() == data.definitionMap() && + this->assignmentMap() == data.assignmentMap() && + this->unitsMap() == data.unitsMap() && + this->inputIndex() == data.inputIndex() && + this->typeCount() == data.typeCount(); + } + } From 2a8f944b6f784a7f87f99204668dbc25aead6775 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 11:12:46 +0100 Subject: [PATCH 13/13] make UDQActive constructible from variables also make it default constructible, add accessors and equality operator --- .../EclipseState/Schedule/UDQ/UDQActive.hpp | 32 +++++++++++++++++ .../EclipseState/Schedule/UDQ/UDQActive.cpp | 34 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQActive.hpp b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQActive.hpp index 296a5a012..9cafadaca 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQActive.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQActive.hpp @@ -37,6 +37,13 @@ public: class Record{ public: + Record() : + input_index(0), + control(UDAControl::WCONPROD_ORAT), + uad_code(0), + use_count(1) + {} + Record(const std::string& udq_arg, std::size_t input_index_arg, std::size_t use_index_arg, const std::string& wgname_arg, UDAControl control_arg) : udq(udq_arg), input_index(input_index_arg), @@ -74,6 +81,11 @@ public: class InputRecord { public: + InputRecord() : + input_index(0), + control(UDAControl::WCONPROD_ORAT) + {} + InputRecord(std::size_t input_index_arg, const std::string& udq_arg, const std::string& wgname_arg, UDAControl control_arg) : input_index(input_index_arg), udq(udq_arg), @@ -81,12 +93,24 @@ public: control(control_arg) {} + bool operator==(const InputRecord& other) const { + return this->input_index == other.input_index && + this->udq == other.udq && + this->wgname == other.wgname && + this->control == other.control; + } + std::size_t input_index; std::string udq; std::string wgname; UDAControl control; }; + UDQActive() = default; + UDQActive(const std::vector& inputRecs, + const std::vector& outputRecs, + const std::unordered_map& udqkeys, + const std::unordered_map& wgkeys); int update(const UDQConfig& udq_config, const UDAValue& uda, const std::string& wgname, UDAControl control); std::size_t IUAD_size() const; std::size_t IUAP_size() const; @@ -94,6 +118,14 @@ public: Record operator[](std::size_t index) const; const std::vector& get_iuad() const; std::vector get_iuap() const; + + const std::vector& getInputRecords() const; + const std::vector& getOutputRecords() const; + const std::unordered_map& getUdqKeys() const; + const std::unordered_map& getWgKeys() const; + + bool operator==(const UDQActive& data) const; + private: std::string udq_hash(const std::string& udq, UDAControl control); std::string wg_hash(const std::string& wgname, UDAControl control); diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQActive.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQActive.cpp index eac8e34be..b838278a2 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQActive.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQActive.cpp @@ -25,6 +25,16 @@ namespace Opm { +UDQActive::UDQActive(const std::vector& inputRecs, + const std::vector& outputRecs, + const std::unordered_map& udqkeys, + const std::unordered_map& wgkeys) + : input_data(inputRecs) + , output_data(outputRecs) + , udq_keys(udqkeys) + , wg_keys(wgkeys) +{} + std::size_t UDQActive::IUAD_size() const { const auto& output = this->get_iuad(); return output.size(); @@ -173,6 +183,30 @@ UDQActive::Record UDQActive::operator[](std::size_t index) const { return output_record; } +const std::vector& UDQActive::getInputRecords() const { + return input_data; +} + +const std::vector& UDQActive::getOutputRecords() const { + return output_data; +} + +const std::unordered_map& UDQActive::getUdqKeys() const { + return udq_keys; +} + +const std::unordered_map& UDQActive::getWgKeys() const { + return wg_keys; +} + + +bool UDQActive::operator==(const UDQActive& data) const { + return this->getInputRecords() == data.getInputRecords() && + this->getOutputRecords() == data.getOutputRecords() && + this->getUdqKeys() == data.getUdqKeys() && + this->getWgKeys() == data.getWgKeys(); +} + }