diff --git a/opm/output/eclipse/RegionCache.hpp b/opm/output/eclipse/RegionCache.hpp index a328e3994..c050e44cf 100644 --- a/opm/output/eclipse/RegionCache.hpp +++ b/opm/output/eclipse/RegionCache.hpp @@ -36,9 +36,12 @@ namespace out { RegionCache(const std::set& fip_regions, const FieldPropsManager& fp, const EclipseGrid& grid, const Schedule& schedule); const std::vector>& connections( const std::string& region_name, int region_id ) const; + // A well is assigned to the region_id where the first connection is + std::vector wells(const std::string& region_name, int region_id) const; private: std::vector> connections_empty; std::map , std::vector>> connection_map; + std::map, std::vector> well_map; }; } } diff --git a/src/opm/output/eclipse/RegionCache.cpp b/src/opm/output/eclipse/RegionCache.cpp index d252053c4..3cdfe2eff 100644 --- a/src/opm/output/eclipse/RegionCache.cpp +++ b/src/opm/output/eclipse/RegionCache.cpp @@ -36,6 +36,9 @@ RegionCache::RegionCache(const std::set& fip_regions, const FieldPr const auto& wells = schedule.getWellsatEnd(); for (const auto& well : wells) { const auto& connections = well.getConnections( ); + if (connections.empty()) + continue; + for (const auto& c : connections) { if (grid.cellActive(c.getI(), c.getJ(), c.getK())) { size_t active_index = grid.activeIndex(c.getI(), c.getJ(), c.getK()); @@ -45,6 +48,11 @@ RegionCache::RegionCache(const std::set& fip_regions, const FieldPr well_index_list.push_back( { well.name() , active_index } ); } } + + const auto& conn0 = connections[0]; + auto region_id = fip_region[grid.activeIndex(conn0.global_index())]; + auto key = std::make_pair(fip_name, region_id); + this->well_map[ key ].push_back(well.name()); } } } @@ -59,6 +67,16 @@ RegionCache::RegionCache(const std::set& fip_regions, const FieldPr return iter->second; } + + std::vector RegionCache::wells(const std::string& region_name, int region_id) const { + auto key = std::make_pair(region_name, region_id); + const auto iter = this->well_map.find( key ); + if (iter == this->well_map.end()) + return {}; + else + return iter->second; + } + } } diff --git a/tests/summary_deck.DATA b/tests/summary_deck.DATA index 2e3b6e04f..4d9c1af1e 100644 --- a/tests/summary_deck.DATA +++ b/tests/summary_deck.DATA @@ -63,17 +63,17 @@ PERMZ REGIONS FIPNUM - 100*1 - 100*2 - 100*3 - 100*4 - 100*5 - 100*6 - 100*7 - 100*8 - 100*9 - 100*10 / - + 50*1 50*11 + 50*2 50*12 + 50*3 50*13 + 50*4 50*14 + 50*5 50*15 + 50*6 50*16 + 50*7 50*17 + 50*8 50*18 + 50*9 50*19 + 50*10 50*20 +/ SUMMARY DATE @@ -839,7 +839,7 @@ WELSPECS 'W_2' 'G_1' 2 1 3.33 'OIL' 7* / 'W_3' 'G_2' 3 1 3.92 'WATER' 7* / 'W_6' 'G_2' 8 8 3.92 'GAS' 7* / - 'W_5' 'G_3' 4 1 3.92 'OIL' 7* / + 'W_5' 'G_3' 6 6 3.92 'OIL' 7* / / -- Completion data. @@ -850,7 +850,7 @@ COMPDAT W_2 0 0 1 1 2* 1* 5 20 0.5 / -- Active index: 1 W_2 0 0 2 2 2* 1* 5 10 0.2 / -- Active index: 101 W_3 0 0 1 1 2* 1* 2* 0.7 / -- Active index: 2 - W_6 0 0 2 2 2* 1* 2* 0.7 / -- Active index: 2 + W_6 0 0 1 1 2* 1* 2* 0.7 / -- Active index: 2 / COMPLUMP @@ -905,7 +905,7 @@ WELSPECS / COMPDAT - W_4 1 1 3 3 / + W_4 1 1 1 3 / / WPIMULT diff --git a/tests/test_regionCache.cpp b/tests/test_regionCache.cpp index e0c0edbbc..a3d328fce 100644 --- a/tests/test_regionCache.cpp +++ b/tests/test_regionCache.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -38,6 +39,13 @@ using namespace Opm; const char* path = "summary_deck.DATA"; +bool cmp_list(const std::vector& l1, const std::vector& l2) { + std::unordered_set s1(l1.begin(), l1.end()); + std::unordered_set s2(l2.begin(), l2.end()); + return s1 == s2; +} + + BOOST_AUTO_TEST_CASE(create) { auto python = std::make_shared(); @@ -54,11 +62,17 @@ BOOST_AUTO_TEST_CASE(create) { { const auto& top_layer = rc.connections( "FIPNUM", 1 ); - BOOST_CHECK_EQUAL( top_layer.size() , 3U ); + BOOST_CHECK_EQUAL( top_layer.size() , 4U ); { auto pair = top_layer[0]; BOOST_CHECK_EQUAL( pair.first , "W_1"); BOOST_CHECK_EQUAL( pair.second , grid.activeIndex( 0,0,0)); } } + + BOOST_CHECK( rc.wells("FIPXYZ", 100).empty() ); + BOOST_CHECK( rc.wells("FIPXYZ", 1).empty() ); + BOOST_CHECK( rc.wells("FIPNUM", 100).empty() ); + BOOST_CHECK( cmp_list(rc.wells("FIPNUM", 1), {"W_1", "W_2", "W_3", "W_4"})); + BOOST_CHECK( cmp_list(rc.wells("FIPNUM", 11), {"W_6"})); }