From 732c5ae4d298c2e33911a11b83255d3c4ba2786f Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 18 Feb 2019 15:08:36 +0100 Subject: [PATCH] Add class UDQAssign --- CMakeLists_files.cmake | 2 + .../eclipse/EclipseState/Schedule/UDQ/UDQ.hpp | 3 + .../EclipseState/Schedule/UDQ/UDQAssign.hpp | 47 +++++++++++++ .../eclipse/EclipseState/Schedule/UDQ/UDQ.cpp | 12 +++- .../EclipseState/Schedule/UDQ/UDQAssign.cpp | 53 +++++++++++++++ tests/parser/UDQTests.cpp | 67 ++++++++++++++++++- 6 files changed, 182 insertions(+), 2 deletions(-) create mode 100644 opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.hpp create mode 100644 src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.cpp diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 649a4ee0c..12506e23a 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -128,6 +128,7 @@ if(ENABLE_ECL_INPUT) src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQSet.cpp src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQWellSet.cpp src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQ.cpp + src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.cpp src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQContext.cpp src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQExpression.cpp src/opm/parser/eclipse/EclipseState/Schedule/VFPInjTable.cpp @@ -512,6 +513,7 @@ if(ENABLE_ECL_INPUT) opm/parser/eclipse/EclipseState/IOConfig/IOConfig.hpp 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/UDQContext.hpp opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQ.hpp opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQParams.hpp diff --git a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQ.hpp b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQ.hpp index caae98d6b..61623c563 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQ.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQ.hpp @@ -25,6 +25,7 @@ #include #include +#include namespace Opm { @@ -35,8 +36,10 @@ namespace Opm { const std::vector& expressions() const noexcept; const std::string& unit(const std::string& key) const; void assign_unit(const std::string& keyword, const std::string& unit); + const std::vector& assignments() const; private: std::vector m_expressions; + std::vector m_assignments; std::unordered_map units; }; } diff --git a/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.hpp b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.hpp new file mode 100644 index 000000000..58fe39486 --- /dev/null +++ b/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.hpp @@ -0,0 +1,47 @@ +/* + Copyright 2018 Statoil ASA. + + This file is part of the Open Porous Media project (OPM). + + OPM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OPM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with OPM. If not, see . +*/ + + +#ifndef UDQASSIGN_HPP_ +#define UDQASSIGN_HPP_ + +#include +#include + +#include + +namespace Opm { + +class UDQAssign{ +public: + UDQAssign(const std::string& keyword, const std::vector& selector, double value); + const std::string& keyword() const; + double value() const; + const std::vector& selector() const; + UDQWellSet eval_wells(const std::vector& wells) const; +private: + std::string m_keyword; + std::vector m_selector; + double m_value; +}; +} + + + +#endif diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQ.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQ.cpp index b7702660b..0db3f0fc0 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQ.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQ.cpp @@ -40,7 +40,11 @@ namespace Opm { if (action == UDQAction::UNITS) this->assign_unit( quantity, data[0] ); - else + else if (action == UDQAction::ASSIGN) { + std::vector selector(data.begin(), data.end() - 1); + double value = std::stod(data.back()); + this->m_assignments.emplace_back( quantity, selector, value ); + } else this->m_expressions.emplace_back(action, quantity, data); } @@ -49,6 +53,12 @@ namespace Opm { return this->m_expressions; } + + const std::vector& UDQ::assignments() const { + return this->m_assignments; + } + + const std::string& UDQ::unit(const std::string& key) const { const auto pair_ptr = this->units.find(key); if (pair_ptr == this->units.end()) diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.cpp new file mode 100644 index 000000000..f67fc4be3 --- /dev/null +++ b/src/opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.cpp @@ -0,0 +1,53 @@ +/* + Copyright 2018 Statoil ASA. + + This file is part of the Open Porous Media project (OPM). + + OPM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OPM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with OPM. If not, see . + */ + +#include + +namespace Opm { + +UDQAssign::UDQAssign(const std::string& keyword, const std::vector& selector, double value) : + m_keyword(keyword), + m_selector(selector), + m_value(value) +{} + + +const std::string& UDQAssign::keyword() const { + return this->m_keyword; +} + +const std::vector& UDQAssign::selector() const { + return this->m_selector; +} + +double UDQAssign::value() const { + return this->m_value; +} + +UDQWellSet UDQAssign::eval_wells(const std::vector& wells) const { + UDQWellSet ws(wells); + + if (this->m_selector.empty()) + ws.assign(this->m_value); + else + ws.assign(this->m_selector[0], this->m_value); + + return ws; +} +} diff --git a/tests/parser/UDQTests.cpp b/tests/parser/UDQTests.cpp index 9c987c120..7e27796b8 100644 --- a/tests/parser/UDQTests.cpp +++ b/tests/parser/UDQTests.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include using namespace Opm; @@ -158,7 +159,7 @@ BOOST_AUTO_TEST_CASE(UDQ_KEYWORD) { } -BOOST_AUTO_TEST_CASE(UDQ_DATA) { +BOOST_AUTO_TEST_CASE(UDQ_DEFINE_DATA) { const std::string input = R"( RUNSPEC @@ -188,6 +189,45 @@ DEFINE WUMW1 WBHP 'P*1*' UMAX WBHP 'P*4*' / BOOST_CHECK_EQUAL_COLLECTIONS(rec1.tokens().begin(), rec1.tokens().end(), exp1.begin(), exp1.end()); } +BOOST_AUTO_TEST_CASE(UDQ_ASSIGN_DATA) { + const std::string input = R"( +RUNSPEC + +UDQDIMS + 10* 'Y'/ + +UDQPARAM + 3* 0.25 / + +SCHEDULE + +UDQ +ASSIGN WU1 P12 4.0 / +ASSIGN WU2 8.0 / +/ + + +)"; + const auto schedule = make_schedule(input); + const auto& udq = schedule.getUDQConfig(0); + const auto& assignments = udq.assignments(); + const auto& ass0 = assignments[0]; + const auto& ass1 = assignments[1]; + + + BOOST_CHECK_EQUAL(ass0.keyword(), "WU1"); + BOOST_CHECK_EQUAL(ass1.keyword(), "WU2"); + + BOOST_CHECK_EQUAL(ass0.value(), 4.0 ); + BOOST_CHECK_EQUAL(ass1.value(), 8.0 ); + + std::vector sel0 = {"P12"}; + std::vector sel1 = {}; + BOOST_CHECK_EQUAL_COLLECTIONS(ass0.selector().begin(), ass0.selector().end(), sel0.begin(), sel0.end()); + BOOST_CHECK_EQUAL_COLLECTIONS(ass1.selector().begin(), ass1.selector().end(), sel1.begin(), sel1.end()); +} + + BOOST_AUTO_TEST_CASE(UDQ_CONTEXT) { @@ -299,3 +339,28 @@ BOOST_AUTO_TEST_CASE(UDQWellSetTest) { BOOST_CHECK_EQUAL(ws["P1"].value(), 4.0); BOOST_CHECK_EQUAL(ws["P2"].value(), 4.0); } + + +BOOST_AUTO_TEST_CASE(UDQASSIGN_TEST) { + UDQAssign as1("WUPR", {}, 1.0); + UDQAssign as2("WUPR", {"P*"}, 2.0); + UDQAssign as3("WUPR", {"P1"}, 4.0); + std::vector ws1 = {"P1", "P2", "I1", "I2"}; + + auto res1 = as1.eval_wells(ws1); + BOOST_CHECK_EQUAL(res1.size(), 4); + BOOST_CHECK_EQUAL(res1["P1"].value(), 1.0); + BOOST_CHECK_EQUAL(res1["I2"].value(), 1.0); + + auto res2 = as2.eval_wells(ws1); + BOOST_CHECK_EQUAL(res2["P1"].value(), 2.0); + BOOST_CHECK_EQUAL(res2["P2"].value(), 2.0); + BOOST_CHECK(!res2["I1"].defined()); + BOOST_CHECK(!res2["I2"].defined()); + + auto res3 = as3.eval_wells(ws1); + BOOST_CHECK_EQUAL(res3["P1"].value(), 4.0); + BOOST_CHECK(!res3["P2"].defined()); + BOOST_CHECK(!res3["I1"].defined()); + BOOST_CHECK(!res3["I2"].defined()); +}