Simplified implementation and (slightly) changed behaviour of Schedule::getWells(wellNamePattern)

Improved performance by checking for wildcard before entering the loop. Logic slightly changed since method now only supports wildcards at the end of the string.
This commit is contained in:
Atle Haugan
2014-05-14 15:10:17 +02:00
parent 344d02ad1c
commit 47ef4ed0e6
2 changed files with 12 additions and 19 deletions

View File

@@ -21,6 +21,7 @@
#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
#include <opm/parser/eclipse/Deck/Section.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/regex.hpp>
#include <regex>
#include <iostream>
@@ -553,22 +554,18 @@ namespace Opm {
std::vector<WellPtr> Schedule::getWells(const std::string& wellNamePattern) const {
std::vector<WellPtr> wells;
for (auto iter = m_wells.begin(); iter != m_wells.end(); ++iter) {
WellPtr well = (*iter).second;
size_t wildcard_pos=wellNamePattern.find("*");
if (wildcard_pos!=std::string::npos) {
size_t first=well->name().find(wellNamePattern.substr(0, wildcard_pos));
size_t second=well->name().find(wellNamePattern.substr(wildcard_pos+1));
if(first!=std::string::npos && second!=std::string::npos) {
wells.push_back(well);
}
}
else {
if (well->name().compare(wellNamePattern) == 0) {
wells.push_back(well);
size_t wildcard_pos = wellNamePattern.find("*");
if (wildcard_pos == wellNamePattern.length()-1) {
for (auto iter = m_wells.begin(); iter != m_wells.end(); ++iter) {
WellPtr well = (*iter).second;
if (wellNamePattern.compare (0, wildcard_pos, well->name(), 0, wildcard_pos) == 0) {
wells.push_back (well);
}
}
}
else {
wells.push_back(getWell(wellNamePattern));
}
return wells;
}

View File

@@ -62,7 +62,7 @@ DeckPtr createDeckWithWells() {
" 10 AUG 2007 / \n"
"/\n"
"WELSPECS\n"
" \'W_2\' \'OP\' 30 37 3.33 \'OIL\' 7* / \n"
" \'WX2\' \'OP\' 30 37 3.33 \'OIL\' 7* / \n"
" \'W_3\' \'OP\' 20 51 3.92 \'OIL\' 7* / \n"
"/\n";
@@ -188,11 +188,7 @@ BOOST_AUTO_TEST_CASE(WellsIteratorWithRegex_HasWells_WellsReturned) {
wellNamePattern = "W_*";
wells = schedule.getWells(wellNamePattern);
BOOST_CHECK_EQUAL(3U, wells.size());
wellNamePattern = "*2";
wells = schedule.getWells(wellNamePattern);
BOOST_CHECK_EQUAL(1U, wells.size());
BOOST_CHECK_EQUAL(2U, wells.size());
wellNamePattern = "W_3";
wells = schedule.getWells(wellNamePattern);