diff --git a/opm/output/eclipse/RegionCache.hpp b/opm/output/eclipse/RegionCache.hpp index a132e2b6a..a328e3994 100644 --- a/opm/output/eclipse/RegionCache.hpp +++ b/opm/output/eclipse/RegionCache.hpp @@ -20,23 +20,25 @@ #ifndef OPM_REGION_CACHE_HPP #define OPM_REGION_CACHE_HPP +#include +#include #include namespace Opm { class Schedule; class EclipseGrid; + class FieldPropsManager; namespace out { class RegionCache { public: RegionCache() = default; - RegionCache(const std::vector& fipnum, const EclipseGrid& grid, const Schedule& schedule); - const std::vector>& connections( int region_id ) const; + 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; private: std::vector> connections_empty; - - std::map>> connection_map; + std::map , std::vector>> connection_map; }; } } diff --git a/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp b/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp index a01c24633..2831581dc 100644 --- a/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp +++ b/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp @@ -178,6 +178,7 @@ namespace Opm { is required to calculate the summary variables. */ bool require3DField( const std::string& keyword) const; + std::set fip_regions() const; bool operator==(const SummaryConfig& data) const; diff --git a/src/opm/output/eclipse/RegionCache.cpp b/src/opm/output/eclipse/RegionCache.cpp index 6eef34560..d252053c4 100644 --- a/src/opm/output/eclipse/RegionCache.cpp +++ b/src/opm/output/eclipse/RegionCache.cpp @@ -18,6 +18,7 @@ */ #include +#include #include #include #include @@ -28,25 +29,30 @@ namespace Opm { namespace out { -RegionCache::RegionCache(const std::vector& fipnum, const EclipseGrid& grid, const Schedule& schedule) { +RegionCache::RegionCache(const std::set& fip_regions, const FieldPropsManager& fp, const EclipseGrid& grid, const Schedule& schedule) { + for (const auto& fip_name : fip_regions) { + const auto& fip_region = fp.get_int(fip_name); - const auto& wells = schedule.getWellsatEnd(); - for (const auto& well : wells) { - const auto& connections = well.getConnections( ); - 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()); - int region_id = fipnum[active_index]; - auto& well_index_list = this->connection_map[ region_id ]; - well_index_list.push_back( { well.name() , active_index } ); + const auto& wells = schedule.getWellsatEnd(); + for (const auto& well : wells) { + const auto& connections = well.getConnections( ); + 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()); + int region_id = fip_region[active_index]; + auto key = std::make_pair(fip_name, region_id); + auto& well_index_list = this->connection_map[ key ]; + well_index_list.push_back( { well.name() , active_index } ); + } } } } } - const std::vector>& RegionCache::connections( int region_id ) const { - const auto iter = this->connection_map.find( region_id ); + const std::vector>& RegionCache::connections( const std::string& region_name, int region_id ) const { + auto key = std::make_pair(region_name, region_id); + const auto iter = this->connection_map.find( key ); if (iter == this->connection_map.end()) return this->connections_empty; else diff --git a/src/opm/output/eclipse/Summary.cpp b/src/opm/output/eclipse/Summary.cpp index cb3e1a8df..2577ffb6e 100644 --- a/src/opm/output/eclipse/Summary.cpp +++ b/src/opm/output/eclipse/Summary.cpp @@ -717,7 +717,7 @@ inline quantity duration( const fn_args& args ) { template quantity region_rate( const fn_args& args ) { double sum = 0; - const auto& well_connections = args.regionCache.connections( args.num ); + const auto& well_connections = args.regionCache.connections( args.fip_region, args.num ); for (const auto& pair : well_connections) { @@ -1438,7 +1438,7 @@ inline std::vector find_wells( const Opm::Schedule& schedule, const auto region = node.number; - for ( const auto& connection : regionCache.connections( region ) ){ + for ( const auto& connection : regionCache.connections( node.fip_region, region ) ){ const auto& w_name = connection.first; if (schedule.hasWell(w_name, sim_step)) { const auto& well = schedule.getWell( w_name, sim_step ); @@ -2393,7 +2393,7 @@ SummaryImplementation(const EclipseState& es, const Schedule& sched, const std::string& basename) : grid_ (std::cref(grid)) - , regCache_ (es.globalFieldProps().get_int("FIPNUM"), grid, sched) + , regCache_ (sumcfg.fip_regions(), es.globalFieldProps(), grid, sched) , deferredSMSpec_(makeDeferredSMSpecCreation(es, grid, sched)) , rset_ (makeResultSet(es.cfg().io(), basename)) , fmt_ { es.cfg().io().getFMTOUT() } diff --git a/src/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.cpp b/src/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.cpp index 6e1582fa2..7077d485d 100644 --- a/src/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.cpp +++ b/src/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.cpp @@ -1161,6 +1161,18 @@ bool SummaryConfig::require3DField( const std::string& keyword ) const { } + +std::set SummaryConfig::fip_regions() const { + std::set reg_set; + for (const auto& node : this->keywords) { + const auto& fip_region = node.fip_region(); + if (fip_region.size() > 0) + reg_set.insert( fip_region ); + } + return reg_set; +} + + bool SummaryConfig::operator==(const Opm::SummaryConfig& data) const { return this->keywords == data.keywords && this->short_keywords == data.short_keywords && diff --git a/tests/test_SummaryNode.cpp b/tests/test_SummaryNode.cpp index 1efbd0d01..999f5bb51 100644 --- a/tests/test_SummaryNode.cpp +++ b/tests/test_SummaryNode.cpp @@ -35,14 +35,14 @@ BOOST_AUTO_TEST_CASE(UniqueKey) { using Category = Opm::EclIO::SummaryNode::Category; using Type = Opm::EclIO::SummaryNode::Type; - expect_key( { "KEYW", Category::Well, Type::Rate, "NORA", 1 }, "KEYW:NORA" ); - expect_key( { "KEYW", Category::Group, Type::Rate, "NORA", 2 }, "KEYW:NORA" ); - expect_key( { "KEYW", Category::Field, Type::Rate, "NORA", 3 }, "KEYW" ); - expect_key( { "KEYW", Category::Region, Type::Rate, "NORA", 4 }, "KEYW:4" ); - expect_key( { "KEYW", Category::Block, Type::Rate, "NORA", 5 }, "KEYW:5" ); - expect_key( { "KEYW", Category::Connection, Type::Rate, "NORA", 6 }, "KEYW:NORA:6" ); - expect_key( { "KEYW", Category::Segment, Type::Rate, "NORA", 7 }, "KEYW:NORA:7" ); - expect_key( { "KEYW", Category::Miscellaneous, Type::Rate, "NORA", 8 }, "KEYW" ); + expect_key( { "KEYW", Category::Well, Type::Rate, "NORA", 1 ,""}, "KEYW:NORA" ); + expect_key( { "KEYW", Category::Group, Type::Rate, "NORA", 2 ,""}, "KEYW:NORA" ); + expect_key( { "KEYW", Category::Field, Type::Rate, "NORA", 3 ,""}, "KEYW" ); + expect_key( { "KEYW", Category::Region, Type::Rate, "NORA", 4 ,""}, "KEYW:4" ); + expect_key( { "KEYW", Category::Block, Type::Rate, "NORA", 5 ,""}, "KEYW:5" ); + expect_key( { "KEYW", Category::Connection, Type::Rate, "NORA", 6 ,""}, "KEYW:NORA:6" ); + expect_key( { "KEYW", Category::Segment, Type::Rate, "NORA", 7 ,""}, "KEYW:NORA:7" ); + expect_key( { "KEYW", Category::Miscellaneous, Type::Rate, "NORA", 8 ,""}, "KEYW" ); } BOOST_AUTO_TEST_CASE(InjectedNumberRenderer) { @@ -54,7 +54,8 @@ BOOST_AUTO_TEST_CASE(InjectedNumberRenderer) { Category::Region, Type::Undefined, "-", - 2 + 2, + "" }; Opm::EclIO::SummaryNode negativeNode { @@ -62,7 +63,8 @@ BOOST_AUTO_TEST_CASE(InjectedNumberRenderer) { Category::Region, Type::Undefined, "-", - -2 + -2, + "" }; auto chooseSign = [](const Opm::EclIO::SummaryNode& node) -> std::string { @@ -74,7 +76,7 @@ BOOST_AUTO_TEST_CASE(InjectedNumberRenderer) { } BOOST_AUTO_TEST_CASE(user_defined) { - auto summary_node = Opm::EclIO::SummaryNode{"FU_VAR1", Opm::EclIO::SummaryNode::Category::Field, Opm::EclIO::SummaryNode::Type::Undefined, "", -1 }; + auto summary_node = Opm::EclIO::SummaryNode{"FU_VAR1", Opm::EclIO::SummaryNode::Category::Field, Opm::EclIO::SummaryNode::Type::Undefined, "", -1 , ""}; BOOST_CHECK( summary_node.is_user_defined() ); } diff --git a/tests/test_regionCache.cpp b/tests/test_regionCache.cpp index 5bc88da82..f25d02f81 100644 --- a/tests/test_regionCache.cpp +++ b/tests/test_regionCache.cpp @@ -46,14 +46,14 @@ BOOST_AUTO_TEST_CASE(create) { EclipseState es(deck); const EclipseGrid& grid = es.getInputGrid(); Schedule schedule( deck, es, python); - out::RegionCache rc(es.fieldProps().get_int("FIPNUM"), grid, schedule); + out::RegionCache rc({"FIPNUM"}, es.fieldProps(), grid, schedule); { - const auto& empty = rc.connections( 4 ); + const auto& empty = rc.connections( "FIPNUM", 4 ); BOOST_CHECK_EQUAL( empty.size() , 0 ); } { - const auto& top_layer = rc.connections( 1 ); + const auto& top_layer = rc.connections( "FIPNUM", 1 ); BOOST_CHECK_EQUAL( top_layer.size() , 3 ); { auto pair = top_layer[0];