23 #ifndef OPM_REGIONATTRIBUTEHELPERS_HPP_HEADER_INCLUDED 24 #define OPM_REGIONATTRIBUTEHELPERS_HPP_HEADER_INCLUDED 26 #include <opm/grid/utility/RegionMapping.hpp> 28 #include <dune/grid/common/gridenums.hh> 33 #include <type_traits> 34 #include <unordered_map> 39 namespace RegionAttributeHelpers {
45 template <
class RegionID,
bool>
49 typename std::remove_reference<RegionID>::type &;
52 template <
class RegionID>
55 using type = RegionID;
65 template<
class Scalar,
bool is_parallel>
79 std::tuple<Scalar, Scalar, Scalar, Scalar, int>
81 const std::vector<Scalar>& temperature,
82 const std::vector<Scalar>& rs,
83 const std::vector<Scalar>& rv,
84 const std::vector<Scalar>& ownership,
86 if ( ownership[cell] )
88 return std::make_tuple(pressure[cell],
96 return std::make_tuple(0, 0, 0, 0, 0);
100 template<
class Scalar>
103 std::tuple<Scalar, Scalar, Scalar, Scalar, int>
104 operator()(
const std::vector<Scalar>& pressure,
105 const std::vector<Scalar>& temperature,
106 const std::vector<Scalar>& rs,
107 const std::vector<Scalar>& rv,
108 const std::vector<Scalar>&,
110 return std::make_tuple(pressure[cell],
129 template <
typename RegionId,
class Attributes>
139 <RegionId, std::is_integral<RegionId>::value>::type;
142 typename std::remove_reference<RegionId>::type;
149 explicit Value(
const Attributes& attr)
159 std::unordered_map<ID, std::unique_ptr<Value>>;
175 template <
class RMap>
177 const Attributes& attr)
179 using VT =
typename AttributeMap::value_type;
181 for (
const auto& r : rmap.activeRegions()) {
182 auto v = std::make_unique<Value>(attr);
184 const auto stat = attr_.insert(VT(r, std::move(v)));
188 const auto& cells = rmap.cells(r);
190 assert (! cells.empty());
193 stat.first->second->cell_ = cells[0];
207 return this->find(reg).cell_;
212 return this->attr_.find(reg) != this->attr_.end();
215 void insert(
const RegionID r,
const Attributes& attr)
217 auto [pos, inserted] = this->attr_.try_emplace(r, std::make_unique<Value>(attr));
219 pos->second->cell_ = -1;
245 return this->find(reg).attr_;
258 return this->find(reg).attr_;
268 const Value& find(
const RegionID reg)
const 270 const auto& i = attr_.find(reg);
272 if (i == attr_.end()) {
273 throw std::invalid_argument(
"Unknown region ID");
284 const auto& i = attr_.find(reg);
286 if (i == attr_.end()) {
287 throw std::invalid_argument(
"Unknown region ID");
const AttributeMap & attributes() const
Request read-only access to region's attributes.
Definition: RegionAttributeHelpers.hpp:229
Computes the temperature, pressure, and counter increment.
Definition: RegionAttributeHelpers.hpp:66
Aggregate per-region attributes along with region's representative cell.
Definition: RegionAttributeHelpers.hpp:148
Attributes & attributes(const RegionID reg)
Request modifiable access to region's attributes.
Definition: RegionAttributeHelpers.hpp:256
std::tuple< Scalar, Scalar, Scalar, Scalar, int > operator()(const std::vector< Scalar > &pressure, const std::vector< Scalar > &temperature, const std::vector< Scalar > &rs, const std::vector< Scalar > &rv, const std::vector< Scalar > &ownership, std::size_t cell)
Computes the temperature, pressure, and counter increment.
Definition: RegionAttributeHelpers.hpp:80
int cell(const RegionID reg) const
Retrieve representative cell in region.
Definition: RegionAttributeHelpers.hpp:205
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
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:139
Definition: RegionAttributeHelpers.hpp:46
RegionAttributes(const RMap &rmap, const Attributes &attr)
Constructor.
Definition: RegionAttributeHelpers.hpp:176
Provide mapping from Region IDs to user-specified collection of per-region attributes.
Definition: RegionAttributeHelpers.hpp:130
const Attributes & attributes(const RegionID reg) const
Request read-only access to region's attributes.
Definition: RegionAttributeHelpers.hpp:243