22#ifndef OPM_RATECONVERTER_HPP_HEADER_INCLUDED
23#define OPM_RATECONVERTER_HPP_HEADER_INCLUDED
26#include <opm/grid/utility/RegionMapping.hpp>
32#include <dune/grid/common/gridenums.hh>
33#include <dune/grid/common/rangegenerators.hh>
37#include <unordered_map>
52 namespace RateConverter {
69 template <
class Flu
idSystem,
class Region>
82 , attr_ (rmap_, Attributes())
93 template <
typename ElementContext,
class Simulator>
98 for (
const auto& reg : rmap_.activeRegions()) {
99 auto& ra = attr_.attributes(reg);
101 ra.temperature = 0.0;
105 ra.saltConcentration = 0.0;
111 std::unordered_map<RegionId, Attributes> attributes_pv;
114 std::unordered_map<RegionId, Attributes> attributes_hpv;
116 for (
const auto& reg : rmap_.activeRegions()) {
117 attributes_pv.insert({reg, Attributes()});
118 attributes_hpv.insert({reg, Attributes()});
121 ElementContext elemCtx( simulator );
122 const auto& gridView = simulator.gridView();
123 const auto& comm = gridView.comm();
126 for (
const auto& elem : elements(gridView, Dune::Partitions::interior)) {
127 elemCtx.updatePrimaryStencil(elem);
128 elemCtx.updatePrimaryIntensiveQuantities(0);
129 const unsigned cellIdx = elemCtx.globalSpaceIndex(0, 0);
130 const auto& intQuants = elemCtx.intensiveQuantities(0, 0);
131 const auto& fs = intQuants.fluidState();
133 const double pv_cell =
134 simulator.model().dofTotalVolume(cellIdx)
135 * intQuants.porosity().value();
138 double hydrocarbon = 1.0;
139 const auto& pu = phaseUsage_;
141 hydrocarbon -= fs.saturation(FluidSystem::waterPhaseIdx).value();
144 const int reg = rmap_.region(cellIdx);
148 const double hydrocarbonPV = pv_cell*hydrocarbon;
149 if (hydrocarbonPV > 0.) {
150 auto& attr = attributes_hpv[reg];
151 attr.pv += hydrocarbonPV;
153 attr.rs += fs.Rs().value() * hydrocarbonPV;
154 attr.rv += fs.Rv().value() * hydrocarbonPV;
157 attr.pressure += fs.pressure(FluidSystem::oilPhaseIdx).value() * hydrocarbonPV;
158 attr.temperature += fs.temperature(FluidSystem::oilPhaseIdx).value() * hydrocarbonPV;
161 attr.pressure += fs.pressure(FluidSystem::gasPhaseIdx).value() * hydrocarbonPV;
162 attr.temperature += fs.temperature(FluidSystem::gasPhaseIdx).value() * hydrocarbonPV;
164 attr.saltConcentration += fs.saltConcentration().value() * hydrocarbonPV;
165 if (FluidSystem::enableDissolvedGasInWater()) {
166 attr.rsw += fs.Rsw().value() * hydrocarbonPV;
168 if (FluidSystem::enableVaporizedWater()) {
169 attr.rvw += fs.Rvw().value() * hydrocarbonPV;
174 auto& attr = attributes_pv[reg];
177 attr.rs += fs.Rs().value() * pv_cell;
178 attr.rv += fs.Rv().value() * pv_cell;
181 attr.pressure += fs.pressure(FluidSystem::oilPhaseIdx).value() * pv_cell;
182 attr.temperature += fs.temperature(FluidSystem::oilPhaseIdx).value() * pv_cell;
184 attr.pressure += fs.pressure(FluidSystem::gasPhaseIdx).value() * pv_cell;
185 attr.temperature += fs.temperature(FluidSystem::gasPhaseIdx).value() * pv_cell;
188 attr.pressure += fs.pressure(FluidSystem::waterPhaseIdx).value() * pv_cell;
189 attr.temperature += fs.temperature(FluidSystem::waterPhaseIdx).value() * pv_cell;
191 attr.saltConcentration += fs.saltConcentration().value() * pv_cell;
192 if (FluidSystem::enableDissolvedGasInWater()) {
193 attr.rsw += fs.Rsw().value() * pv_cell;
195 if (FluidSystem::enableVaporizedWater()) {
196 attr.rvw += fs.Rvw().value() * pv_cell;
203 this->sumRates(attributes_hpv,
242 template <
class Coeff>
246 template <
class Coeff ,
class Rates>
248 calcCoeff(
const RegionId r,
const int pvtRegionIdx,
const Rates& surface_rates, Coeff& coeff)
const;
250 template <
class Coeff>
259 const double saltConcentration,
262 template <
class Coeff>
288 template <
class Rates>
290 const int pvtRegionIdx,
291 const Rates& surface_rates,
292 Rates& voidage_rates)
const;
328 template <
typename SurfaceRates,
typename Vo
idageRates>
336 const double saltConcentration,
337 const SurfaceRates& surface_rates,
338 VoidageRates& voidage_rates)
const;
340 template <
class Rates>
341 std::pair<double, double>
344 const Rates& surface_rates)
const;
358 template <
class SolventModule>
362 const auto& ra = attr_.attributes(r);
363 const double p = ra.pressure;
364 const double T = ra.temperature;
365 const auto& solventPvt = SolventModule::solventPvt();
366 const double bs = solventPvt.inverseFormationVolumeFactor(pvtRegionIdx, T, p);
379 const RegionMapping<Region> rmap_;
388 , temperature(data[1])
394 , saltConcentration(data[7])
397 Attributes(
const Attributes& rhs)
400 this->data = rhs.data;
403 Attributes& operator=(
const Attributes& rhs)
405 this->data = rhs.data;
409 std::array<double,8> data;
417 double& saltConcentration;
420 void sumRates(std::unordered_map<RegionId,Attributes>& attributes_hpv,
421 std::unordered_map<RegionId,Attributes>& attributes_pv,
424 RegionAttributeHelpers::RegionAttributes<RegionId, Attributes> attr_;
#define OPM_END_PARALLEL_TRY_CATCH(prefix, comm)
Catch exception and throw in a parallel try-catch clause.
Definition: DeferredLoggingErrorHelpers.hpp:172
#define OPM_BEGIN_PARALLEL_TRY_CATCH()
Macro to setup the try of a parallel try-catch.
Definition: DeferredLoggingErrorHelpers.hpp:138
Definition: RateConverter.hpp:70
SurfaceToReservoirVoidage(const PhaseUsage &phaseUsage, const Region ®ion)
Definition: RateConverter.hpp:78
void calcCoeff(const int pvtRegionIdx, const double p, const double rs, const double rv, const double rsw, const double rvw, const double T, const double saltConcentration, Coeff &coeff) const
std::pair< double, double > inferDissolvedVaporisedRatio(const double rsMax, const double rvMax, const Rates &surface_rates) const
void calcCoeffSolvent(const RegionId r, const int pvtRegionIdx, double &coeff) const
Definition: RateConverter.hpp:360
void calcReservoirVoidageRates(const RegionId r, const int pvtRegionIdx, const Rates &surface_rates, Rates &voidage_rates) const
void calcCoeff(const RegionId r, const int pvtRegionIdx, const Rates &surface_rates, Coeff &coeff) const
void calcInjCoeff(const RegionId r, const int pvtRegionIdx, Coeff &coeff) const
void calcCoeff(const RegionId r, const int pvtRegionIdx, Coeff &coeff) const
void calcReservoirVoidageRates(const int pvtRegionIdx, const double p, const double rs, const double rv, const double rsw, const double rvw, const double T, const double saltConcentration, const SurfaceRates &surface_rates, VoidageRates &voidage_rates) const
void defineState(const Simulator &simulator)
Definition: RateConverter.hpp:94
typename RegionMapping< Region >::RegionId RegionId
Definition: RateConverter.hpp:213
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
bool water(const PhaseUsage &pu)
Definition: RegionAttributeHelpers.hpp:308
bool oil(const PhaseUsage &pu)
Definition: RegionAttributeHelpers.hpp:321
bool gas(const PhaseUsage &pu)
Definition: RegionAttributeHelpers.hpp:334
Definition: BlackoilPhases.hpp:27
PhaseUsage phaseUsage(const Phases &phases)
Determine the active phases.
int RegionId
Definition: WellConstraints.hpp:38
Definition: BlackoilPhases.hpp:46