diff --git a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp index f3a89122b..17b256d31 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp @@ -121,6 +121,11 @@ namespace Opm std::vector wellNames(size_t timeStep) const; std::vector wellNames() const; + std::vector groupNames(const std::string& pattern, size_t timeStep) const; + std::vector groupNames(size_t timeStep) const; + std::vector groupNames(const std::string& pattern) const; + std::vector groupNames() const; + void updateWell(std::shared_ptr well, size_t reportStep); const Well2& getWell2(const std::string& wellName, size_t timeStep) const; const Well2& getWell2atEnd(const std::string& well_name) const; diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp index 00576ee79..8ce59daae 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp @@ -68,6 +68,15 @@ namespace Opm { +namespace { + + bool name_match(const std::string& pattern, const std::string& name) { + int flags = 0; + return (fnmatch(pattern.c_str(), name.c_str(), flags) == 0); + } + +} + Schedule::Schedule( const Deck& deck, const EclipseGrid& grid, const Eclipse3DProperties& eclipseProperties, @@ -2028,10 +2037,9 @@ namespace Opm { // Normal pattern matching auto star_pos = pattern.find('*'); if (star_pos != std::string::npos) { - int flags = 0; std::vector names; for (const auto& well_pair : this->wells_static) { - if (fnmatch(pattern.c_str(), well_pair.first.c_str(), flags) == 0) { + if (name_match(pattern, well_pair.first)) { const auto& dynamic_state = well_pair.second; if (dynamic_state.get(timeStep)) names.push_back(well_pair.first); @@ -2077,6 +2085,74 @@ namespace Opm { return names; } + std::vector Schedule::groupNames(const std::string& pattern, size_t timeStep) const { + if (pattern.size() == 0) + return {}; + + // Normal pattern matching + auto star_pos = pattern.find('*'); + if (star_pos != std::string::npos) { + std::vector names; + for (const auto& group_pair : this->m_groups) { + if (name_match(pattern, group_pair.first)) { + const auto& group = group_pair.second; + if (group.hasBeenDefined(timeStep)) + names.push_back(group_pair.first); + } + } + return names; + } + + // Normal group name without any special characters + if (this->hasGroup(pattern)) { + const auto& group = this->m_groups.at(pattern); + if (group.hasBeenDefined(timeStep)) + return { pattern }; + } + return {}; + } + + std::vector Schedule::groupNames(size_t timeStep) const { + std::vector names; + for (const auto& group_pair : this->m_groups) { + const auto& group = group_pair.second; + if (group.hasBeenDefined(timeStep)) + names.push_back( group.name() ); + } + return names; + } + + std::vector Schedule::groupNames(const std::string& pattern) const { + if (pattern.size() == 0) + return {}; + + // Normal pattern matching + auto star_pos = pattern.find('*'); + if (star_pos != std::string::npos) { + int flags = 0; + std::vector names; + for (const auto& group_pair : this->m_groups) { + if (fnmatch(pattern.c_str(), group_pair.first.c_str(), flags) == 0) + names.push_back(group_pair.first); + } + return names; + } + + // Normal group name without any special characters + if (this->hasGroup(pattern)) + return { pattern }; + + return {}; + } + + std::vector Schedule::groupNames() const { + std::vector names; + for (const auto& group_pair : this->m_groups) + names.push_back(group_pair.first); + + return names; + } + void Schedule::addGroup(const std::string& groupName, size_t timeStep) { const size_t gseqIndex = m_groups.size(); diff --git a/tests/parser/ScheduleTests.cpp b/tests/parser/ScheduleTests.cpp index de52f5439..874fa1392 100644 --- a/tests/parser/ScheduleTests.cpp +++ b/tests/parser/ScheduleTests.cpp @@ -382,6 +382,12 @@ BOOST_AUTO_TEST_CASE(CreateScheduleDeckWellsOrdered) { BOOST_CHECK_EQUAL( "CG", groups[1]->name()); BOOST_CHECK_EQUAL( "BG", groups[2]->name()); BOOST_CHECK_EQUAL( "AG", groups[3]->name()); + + auto group_names = schedule.groupNames(); + BOOST_CHECK_EQUAL( "FIELD", group_names[0]); + BOOST_CHECK_EQUAL( "CG", group_names[1]); + BOOST_CHECK_EQUAL( "BG", group_names[2]); + BOOST_CHECK_EQUAL( "AG", group_names[3]); } @@ -437,6 +443,10 @@ BOOST_AUTO_TEST_CASE(CreateScheduleDeckWellsOrderedGRUPTREE) { BOOST_CHECK( has_well( parent_wells2, "BW_2" )); BOOST_CHECK( has_well( parent_wells2, "AW_3" )); } + auto group_names = schedule.groupNames("P*", 0); + BOOST_CHECK( std::find(group_names.begin(), group_names.end(), "PG1") != group_names.end() ); + BOOST_CHECK( std::find(group_names.begin(), group_names.end(), "PG2") != group_names.end() ); + BOOST_CHECK( std::find(group_names.begin(), group_names.end(), "PLATFORM") != group_names.end() ); }