23 #ifndef OPM_REGIONATTRIBUTEHELPERS_HPP_HEADER_INCLUDED
24 #define OPM_REGIONATTRIBUTEHELPERS_HPP_HEADER_INCLUDED
26 #include <opm/core/props/BlackoilPhases.hpp>
27 #include <opm/grid/utility/RegionMapping.hpp>
28 #include <opm/simulators/linalg/ParallelIstlInformation.hpp>
30 #include <dune/grid/common/gridenums.hh>
35 #include <type_traits>
36 #include <unordered_map>
41 namespace RegionAttributeHelpers {
47 template <
class RegionID,
bool>
51 typename std::remove_reference<RegionID>::type &;
54 template <
class RegionID>
57 using type = RegionID;
67 template<
bool is_parallel>
81 std::tuple<double, double, double, double, int>
83 const std::vector<double>& temperature,
84 const std::vector<double>& rs,
85 const std::vector<double>& rv,
86 const std::vector<double>& ownership,
88 if ( ownership[cell] )
90 return std::make_tuple(pressure[cell],
98 return std::make_tuple(0, 0, 0, 0, 0);
105 std::tuple<double, double, double, double, int>
106 operator()(
const std::vector<double>& pressure,
107 const std::vector<double>& temperature,
108 const std::vector<double>& rs,
109 const std::vector<double>& rv,
110 const std::vector<double>&,
112 return std::make_tuple(pressure[cell],
131 template <
typename RegionId,
class Attributes>
141 <RegionId, std::is_integral<RegionId>::value>::type;
144 typename std::remove_reference<RegionId>::type;
151 Value(
const Attributes& attr)
161 std::unordered_map<ID, std::unique_ptr<Value>>;
177 template <
class RMap>
179 const Attributes& attr)
181 using VT =
typename AttributeMap::value_type;
183 for (
const auto& r : rmap.activeRegions()) {
184 auto v = std::make_unique<Value>(attr);
186 const auto stat = attr_.insert(VT(r, std::move(v)));
190 const auto& cells = rmap.cells(r);
192 assert (! cells.empty());
195 stat.first->second->cell_ = cells[0];
209 return this->find(reg).cell_;
214 return this->attr_.find(reg) != this->attr_.end();
217 void insert(
const RegionID r,
const Attributes& attr)
219 auto [pos, inserted] = this->attr_.try_emplace(r, std::make_unique<Value>(attr));
221 pos->second->cell_ = -1;
247 return this->find(reg).attr_;
260 return this->find(reg).attr_;
270 const Value& find(
const RegionID reg)
const
272 const auto& i = attr_.find(reg);
274 if (i == attr_.end()) {
275 throw std::invalid_argument(
"Unknown region ID");
286 const auto& i = attr_.find(reg);
288 if (i == attr_.end()) {
289 throw std::invalid_argument(
"Unknown region ID");
300 namespace PhaseUsed {
311 return pu.phase_used[ BlackoilPhases::Aqua ] != 0;
324 return pu.phase_used[ BlackoilPhases::Liquid ] != 0;
337 return pu.phase_used[ BlackoilPhases::Vapour ] != 0;
360 p = pu.phase_pos[ BlackoilPhases::Aqua ];
380 p = pu.phase_pos[ BlackoilPhases::Liquid ];
400 p = pu.phase_pos[ BlackoilPhases::Vapour ];
Provide mapping from Region IDs to user-specified collection of per-region attributes.
Definition: RegionAttributeHelpers.hpp:133
Attributes & attributes(const RegionID reg)
Request modifiable access to region's attributes.
Definition: RegionAttributeHelpers.hpp:258
int cell(const RegionID reg) const
Retrieve representative cell in region.
Definition: RegionAttributeHelpers.hpp:207
const AttributeMap & attributes() const
Request read-only access to region's attributes.
Definition: RegionAttributeHelpers.hpp:231
typename Select::RegionIDParameter< RegionId, std::is_integral< RegionId >::value >::type RegionID
Expose RegionId as a vocabulary type for use in query methods.
Definition: RegionAttributeHelpers.hpp:141
RegionAttributes(const RMap &rmap, const Attributes &attr)
Constructor.
Definition: RegionAttributeHelpers.hpp:178
const Attributes & attributes(const RegionID reg) const
Request read-only access to region's attributes.
Definition: RegionAttributeHelpers.hpp:245
int gas(const PhaseUsage &pu)
Numerical ID of active gas phase.
Definition: RegionAttributeHelpers.hpp:395
int oil(const PhaseUsage &pu)
Numerical ID of active oil phase.
Definition: RegionAttributeHelpers.hpp:375
int water(const PhaseUsage &pu)
Numerical ID of active water phase.
Definition: RegionAttributeHelpers.hpp:355
bool water(const PhaseUsage &pu)
Active water predicate.
Definition: RegionAttributeHelpers.hpp:309
bool oil(const PhaseUsage &pu)
Active oil predicate.
Definition: RegionAttributeHelpers.hpp:322
bool gas(const PhaseUsage &pu)
Active gas predicate.
Definition: RegionAttributeHelpers.hpp:335
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27
Definition: BlackoilPhases.hpp:46
Computes the temperature, pressure, and counter increment.
Definition: RegionAttributeHelpers.hpp:69
std::tuple< double, double, double, double, int > operator()(const std::vector< double > &pressure, const std::vector< double > &temperature, const std::vector< double > &rs, const std::vector< double > &rv, const std::vector< double > &ownership, std::size_t cell)
Computes the temperature, pressure, and counter increment.
Definition: RegionAttributeHelpers.hpp:82
Aggregate per-region attributes along with region's representative cell.
Definition: RegionAttributeHelpers.hpp:150
Definition: RegionAttributeHelpers.hpp:49