add support for region = 0 i.e. field

This commit is contained in:
Tor Harald Sandve 2021-09-06 14:54:26 +02:00
parent f9832d8830
commit f497fa0fd7
2 changed files with 45 additions and 19 deletions

View File

@ -140,6 +140,27 @@ namespace Opm {
typename Select::RegionIDParameter typename Select::RegionIDParameter
<RegionId, std::is_integral<RegionId>::value>::type; <RegionId, std::is_integral<RegionId>::value>::type;
using ID =
typename std::remove_reference<RegionId>::type;
/**
* Aggregate per-region attributes along with region's
* representative cell.
*/
struct Value {
Value(const Attributes& attr)
: attr_(attr)
, cell_(-1)
{}
Attributes attr_;
int cell_;
};
using AttributeMap =
std::unordered_map<ID, std::unique_ptr<Value>>;
/** /**
* Constructor. * Constructor.
* *
@ -213,6 +234,17 @@ namespace Opm {
} }
} }
/**
* Request read-only access to region's attributes.
*
*
* \return Read-only access to all regions attributes.
*/
const AttributeMap& attributes() const
{
return attr_;
}
/** /**
* Request read-only access to region's attributes. * Request read-only access to region's attributes.
@ -241,25 +273,6 @@ namespace Opm {
} }
private: private:
/**
* Aggregate per-region attributes along with region's
* representative cell.
*/
struct Value {
Value(const Attributes& attr)
: attr_(attr)
, cell_(-1)
{}
Attributes attr_;
int cell_;
};
using ID =
typename std::remove_reference<RegionId>::type;
using AttributeMap =
std::unordered_map<ID, std::unique_ptr<Value>>;
AttributeMap attr_; AttributeMap attr_;

View File

@ -218,6 +218,19 @@ namespace Opm {
double double
pressure(const RegionId r) const pressure(const RegionId r) const
{ {
if (r == 0 ) // region 0 is the whole field
{
double pressure = 0.0;
int num_active_regions = 0;
for (const auto& attr : attr_.attributes()) {
const auto& value = *attr.second;
const auto& ra = value.attr_;
pressure += ra.pressure;
num_active_regions ++;
}
return pressure / num_active_regions;
}
const auto& ra = attr_.attributes(r); const auto& ra = attr_.attributes(r);
return ra.pressure; return ra.pressure;
} }