RegionCache object can manage multiple fip regions

This commit is contained in:
Joakim Hove 2020-08-27 07:59:50 +02:00
parent d5a21427b4
commit dad067835c
7 changed files with 56 additions and 33 deletions

View File

@ -20,23 +20,25 @@
#ifndef OPM_REGION_CACHE_HPP
#define OPM_REGION_CACHE_HPP
#include <map>
#include <set>
#include <vector>
namespace Opm {
class Schedule;
class EclipseGrid;
class FieldPropsManager;
namespace out {
class RegionCache {
public:
RegionCache() = default;
RegionCache(const std::vector<int>& fipnum, const EclipseGrid& grid, const Schedule& schedule);
const std::vector<std::pair<std::string,size_t>>& connections( int region_id ) const;
RegionCache(const std::set<std::string>& fip_regions, const FieldPropsManager& fp, const EclipseGrid& grid, const Schedule& schedule);
const std::vector<std::pair<std::string,size_t>>& connections( const std::string& region_name, int region_id ) const;
private:
std::vector<std::pair<std::string,size_t>> connections_empty;
std::map<int , std::vector<std::pair<std::string,size_t>>> connection_map;
std::map<std::pair<std::string, int> , std::vector<std::pair<std::string,size_t>>> connection_map;
};
}
}

View File

@ -178,6 +178,7 @@ namespace Opm {
is required to calculate the summary variables.
*/
bool require3DField( const std::string& keyword) const;
std::set<std::string> fip_regions() const;
bool operator==(const SummaryConfig& data) const;

View File

@ -18,6 +18,7 @@
*/
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Well/Connection.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Well/WellConnections.hpp>
@ -28,25 +29,30 @@
namespace Opm {
namespace out {
RegionCache::RegionCache(const std::vector<int>& fipnum, const EclipseGrid& grid, const Schedule& schedule) {
RegionCache::RegionCache(const std::set<std::string>& 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<std::pair<std::string,size_t>>& RegionCache::connections( int region_id ) const {
const auto iter = this->connection_map.find( region_id );
const std::vector<std::pair<std::string,size_t>>& 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

View File

@ -717,7 +717,7 @@ inline quantity duration( const fn_args& args ) {
template<rt phase , bool injection>
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<Opm::Well> 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() }

View File

@ -1161,6 +1161,18 @@ bool SummaryConfig::require3DField( const std::string& keyword ) const {
}
std::set<std::string> SummaryConfig::fip_regions() const {
std::set<std::string> 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 &&

View File

@ -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() );
}

View File

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