21 #ifndef OPM_RATECONVERTER_HPP_HEADER_INCLUDED
22 #define OPM_RATECONVERTER_HPP_HEADER_INCLUDED
26 #include <opm/core/props/BlackoilPhases.hpp>
27 #include <opm/core/simulator/BlackoilState.hpp>
28 #include <opm/core/utility/RegionMapping.hpp>
36 #include <type_traits>
37 #include <unordered_map>
52 namespace RateConverter {
59 template <
class RegionID,
bool>
63 typename std::remove_reference<RegionID>::type &;
66 template <
class RegionID>
85 template <
typename RegionId,
class Attributes>
95 <RegionId, std::is_integral<RegionId>::value>::type;
110 template <
class RMap>
112 const Attributes& attr)
114 using VT =
typename AttributeMap::value_type;
116 for (
const auto& r : rmap.activeRegions()) {
117 auto v = std::unique_ptr<Value>(
new Value(attr));
119 const auto stat = attr_.insert(VT(r, std::move(v)));
123 const auto& cells = rmap.cells(r);
125 assert (! cells.empty());
128 stat.first->second->cell_ = cells[0];
142 return this->find(reg).cell_;
155 return this->find(reg).attr_;
168 return this->find(reg).attr_;
177 Value(
const Attributes& attr)
187 typename std::remove_reference<RegionId>::type;
190 std::unordered_map<ID, std::unique_ptr<Value>>;
197 const Value& find(
const RegionID reg)
const
199 const auto& i = attr_.find(reg);
201 if (i == attr_.end()) {
202 throw std::invalid_argument(
"Unknown region ID");
213 const auto& i = attr_.find(reg);
215 if (i == attr_.end()) {
216 throw std::invalid_argument(
"Unknown region ID");
227 namespace PhaseUsed {
238 return pu.phase_used[ BlackoilPhases::Aqua ] != 0;
251 return pu.phase_used[ BlackoilPhases::Liquid ] != 0;
264 return pu.phase_used[ BlackoilPhases::Vapour ] != 0;
287 p = pu.phase_pos[ BlackoilPhases::Aqua ];
307 p = pu.phase_pos[ BlackoilPhases::Liquid ];
327 p = pu.phase_pos[ BlackoilPhases::Vapour ];
352 template <
class Property,
class Region>
365 const Region& region)
368 , attr_ (rmap_, Attributes(props_.numPhases()))
394 typedef typename RegionMapping<Region>::RegionId
RegionId;
419 template <
class Input,
422 calcCoeff(
const Input& in,
const RegionId r, Coeff& coeff)
const
426 const auto& pu = props_.phaseUsage();
427 const auto& ra = attr_.attributes(r);
429 const auto p = this->constant(ra.pressure);
430 const auto T = this->constant(ra.temperature);
431 const auto c = this->getRegCell(r);
437 std::fill(& coeff[0], & coeff[0] + props_.numPhases(), 0.0);
442 const V bw = props_.bWat(p, T, c).value();
444 coeff[iw] = 1.0 / bw(0);
447 const Miscibility& m = calcMiscibility(in, r);
450 const double detR = 1.0 - (m.rs(0) * m.rv(0));
455 const auto rs = this->constant(m.rs);
456 const V bo = props_.bOil(p, T, rs, m.cond, c).value();
457 const double den = bo(0) * detR;
459 coeff[io] += 1.0 / den;
462 coeff[ig] -= m.rv(0) / den;
469 const auto rv = this->constant(m.rv);
470 const V bg = props_.bGas(p, T, rv, m.cond, c).value();
471 const double den = bg(0) * detR;
473 coeff[ig] += 1.0 / den;
476 coeff[io] -= m.rs(0) / den;
485 const Property& props_;
490 const RegionMapping<Region> rmap_;
496 Attributes(
const int np)
499 , Rmax (Eigen::ArrayXd::Zero(np, 1))
507 Details::RegionAttributes<RegionId, Attributes> attr_;
547 std::vector<PhasePresence> cond;
557 calcAverages(
const BlackoilState& state)
559 const auto& press = state.pressure();
560 const auto& temp = state.temperature();
562 for (
const auto& reg : rmap_.activeRegions()) {
563 auto& ra = attr_.attributes(reg);
564 auto& p = ra.pressure;
565 auto& T = ra.temperature;
569 for (
const auto& cell : rmap_.cells(reg)) {
591 const PhaseUsage& pu = props_.phaseUsage();
596 const Eigen::ArrayXd::Index
605 for (
const auto& reg : rmap_.activeRegions()) {
606 auto& ra = attr_.attributes(reg);
608 const auto c = this->getRegCell(reg);
609 const auto p = this->constant(ra.pressure);
610 const auto T = this->constant(ra.temperature);
612 auto& Rmax = ra.Rmax;
613 Rmax.row(io) = props_.rsSat(p, T, c).value();
614 Rmax.row(ig) = props_.rvSat(p, T, c).value();
636 template <
class Input>
638 calcMiscibility(
const Input& in,
const RegionId r)
const
640 const auto& pu = props_.phaseUsage();
641 const auto& attr = attr_.attributes(r);
647 PhasePresence& cond = m.cond[0];
657 const double rsmax = attr.Rmax(io);
659 (0.0 < std::abs(in[io]))
661 : (0.0 < std::abs(in[ig])) ? rsmax : 0.0;
667 m.rs(0) = std::min(rs, rsmax);
678 const double rvmax = attr.Rmax(ig);
680 (0.0 < std::abs(in[ig]))
682 : (0.0 < std::abs(in[io])) ? rvmax : 0.0;
684 m.rv(0) = std::min(rv, rvmax);
698 return Property::ADB::constant(x);
706 constant(
const double x)
const
711 return this->constant(y);
721 typename Property::Cells
722 getRegCell(
const RegionId r)
const
724 typename Property::Cells c(1, this->attr_.cell(r));
bool oil(const PhaseUsage &pu)
Definition: RateConverter.hpp:249
Attributes & attributes(const RegionID reg)
Definition: RateConverter.hpp:166
void calcCoeff(const Input &in, const RegionId r, Coeff &coeff) const
Definition: RateConverter.hpp:422
typename std::remove_reference< RegionID >::type & type
Definition: RateConverter.hpp:63
RegionID type
Definition: RateConverter.hpp:69
AutoDiffBlock< double > ADB
Definition: BlackoilModelBase_impl.hpp:83
Definition: AdditionalObjectDeleter.hpp:22
int water(const PhaseUsage &pu)
Definition: RateConverter.hpp:282
const Attributes & attributes(const RegionID reg) const
Definition: RateConverter.hpp:153
RegionMapping< Region >::RegionId RegionId
Definition: RateConverter.hpp:394
typename Select::RegionIDParameter< RegionId, std::is_integral< RegionId >::value >::type RegionID
Definition: RateConverter.hpp:95
int cell(const RegionID reg) const
Definition: RateConverter.hpp:140
bool water(const PhaseUsage &pu)
Definition: RateConverter.hpp:236
RegionAttributes(const RMap &rmap, const Attributes &attr)
Definition: RateConverter.hpp:111
bool gas(const PhaseUsage &pu)
Definition: RateConverter.hpp:262
ADB::V V
Definition: BlackoilModelBase_impl.hpp:84
Definition: RateConverter.hpp:86
Definition: RateConverter.hpp:60
int gas(const PhaseUsage &pu)
Definition: RateConverter.hpp:322
Definition: RateConverter.hpp:353
int oil(const PhaseUsage &pu)
Definition: RateConverter.hpp:302
void defineState(const BlackoilState &state)
Definition: RateConverter.hpp:383
SurfaceToReservoirVoidage(const Property &props, const Region ®ion)
Definition: RateConverter.hpp:364