Add WList manager

This commit is contained in:
Joakim Hove
2019-01-14 11:26:47 +01:00
parent eb5454aeaf
commit eae4a080cd
4 changed files with 124 additions and 1 deletions

View File

@@ -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

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#include <cstddef>
#include <map>
#include <vector>
#include <string>
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<std::string, WList> wlists;
};
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#include <opm/parser/eclipse/EclipseState/Schedule/WList.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/WListManager.hpp>
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);
}
}
}

View File

@@ -25,6 +25,7 @@
#include <boost/test/unit_test.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/WList.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/WListManager.hpp>
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());
}