From eae4a080cd71ba7135251c7b46ec864c9202c034 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 14 Jan 2019 11:26:47 +0100 Subject: [PATCH] Add WList manager --- CMakeLists_files.cmake | 2 + .../EclipseState/Schedule/WListManager.hpp | 38 +++++++++++++++ .../EclipseState/Schedule/WListManager.cpp | 48 +++++++++++++++++++ tests/parser/WLIST.cpp | 37 +++++++++++++- 4 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 opm/parser/eclipse/EclipseState/Schedule/WListManager.hpp create mode 100644 src/opm/parser/eclipse/EclipseState/Schedule/WListManager.cpp diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 16329336a..ec65ece04 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -97,6 +97,7 @@ if(ENABLE_ECL_INPUT) src/opm/parser/eclipse/EclipseState/Schedule/Tuning.cpp src/opm/parser/eclipse/EclipseState/Schedule/Well.cpp src/opm/parser/eclipse/EclipseState/Schedule/WList.cpp + src/opm/parser/eclipse/EclipseState/Schedule/WListManager.cpp src/opm/parser/eclipse/EclipseState/Schedule/WellEconProductionLimits.cpp src/opm/parser/eclipse/EclipseState/Schedule/WellInjectionProperties.cpp src/opm/parser/eclipse/EclipseState/Schedule/WellPolymerProperties.cpp @@ -467,6 +468,7 @@ if(ENABLE_ECL_INPUT) opm/parser/eclipse/EclipseState/Schedule/Well.hpp opm/parser/eclipse/EclipseState/Schedule/WellInjectionProperties.hpp opm/parser/eclipse/EclipseState/Schedule/WList.hpp + opm/parser/eclipse/EclipseState/Schedule/WListManager.hpp opm/parser/eclipse/EclipseState/Schedule/DynamicVector.hpp opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp diff --git a/opm/parser/eclipse/EclipseState/Schedule/WListManager.hpp b/opm/parser/eclipse/EclipseState/Schedule/WListManager.hpp new file mode 100644 index 000000000..b74155f28 --- /dev/null +++ b/opm/parser/eclipse/EclipseState/Schedule/WListManager.hpp @@ -0,0 +1,38 @@ +/* + Copyright 2019 Equinor 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 +#include +#include +#include + +namespace Opm { + +class WList; + +class WListManager { +public: + bool hasList(const std::string&) const; + WList& getList(const std::string& name); + WList& newList(const std::string& name); + void delWell(const std::string& well); +private: + std::map wlists; +}; + +} diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/WListManager.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/WListManager.cpp new file mode 100644 index 000000000..88956a54f --- /dev/null +++ b/src/opm/parser/eclipse/EclipseState/Schedule/WListManager.cpp @@ -0,0 +1,48 @@ +/* + Copyright 2019 Equinor 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 +#include + +namespace Opm { + + bool WListManager::hasList(const std::string& name) const { + return (this->wlists.find(name) != this->wlists.end()); + } + + + WList& WListManager::newList(const std::string& name) { + this->wlists.erase(name); + this->wlists.insert( {name, WList() }); + return this->getList(name); + } + + + WList& WListManager::getList(const std::string& name) { + return this->wlists.at(name); + } + + void WListManager::delWell(const std::string& well) { + for (auto& pair: this->wlists) { + auto& wlist = pair.second; + wlist.del(well); + } + } + +} diff --git a/tests/parser/WLIST.cpp b/tests/parser/WLIST.cpp index aba0ff73b..c1b585937 100644 --- a/tests/parser/WLIST.cpp +++ b/tests/parser/WLIST.cpp @@ -25,6 +25,7 @@ #include #include +#include BOOST_AUTO_TEST_CASE(CreateWLIST) { Opm::WList wlist; @@ -57,5 +58,39 @@ BOOST_AUTO_TEST_CASE(CreateWLIST) { BOOST_CHECK( std::find(wells2.begin(), wells2.end(), "W1") != wells2.end()); BOOST_CHECK( std::find(wells2.begin(), wells2.end(), "W2") != wells2.end()); BOOST_CHECK( std::find(wells2.begin(), wells2.end(), "W3") != wells2.end()); - +} + + +BOOST_AUTO_TEST_CASE(WLISTManager) { + Opm::WListManager wlm; + BOOST_CHECK(!wlm.hasList("NO_SUCH_LIST")); + + + { + auto& wlist1 = wlm.newList("LIST1"); + wlist1.add("A"); + wlist1.add("B"); + wlist1.add("C"); + } + // If a new list is added with the same name as an existing list the old + // list is dropped and a new list is created. + { + auto& wlist1 = wlm.newList("LIST1"); + BOOST_CHECK_EQUAL(wlist1.size(), 0); + } + auto& wlist1 = wlm.newList("LIST1"); + auto& wlist2 = wlm.newList("LIST2"); + + wlist1.add("W1"); + wlist1.add("W2"); + wlist1.add("W3"); + + wlist2.add("W1"); + wlist2.add("W2"); + wlist2.add("W3"); + + // The delWell operation will work across all well lists. + wlm.delWell("W1"); + BOOST_CHECK( std::find(wlist1.begin(), wlist1.end(), "W1") == wlist1.end()); + BOOST_CHECK( std::find(wlist2.begin(), wlist2.end(), "W1") == wlist2.end()); }