22#ifndef OPM_RATECONVERTER_HPP_HEADER_INCLUDED
23#define OPM_RATECONVERTER_HPP_HEADER_INCLUDED
25#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>
72 using Scalar =
typename FluidSystem::Scalar;
81 , attr_ (rmap_, Attributes())
92 template <
typename ElementContext,
class Simulator>
97 for (
const auto& reg : rmap_.activeRegions()) {
98 auto& ra = attr_.attributes(reg);
100 ra.temperature = 0.0;
104 ra.saltConcentration = 0.0;
110 std::unordered_map<RegionId, Attributes> attributes_pv;
113 std::unordered_map<RegionId, Attributes> attributes_hpv;
115 for (
const auto& reg : rmap_.activeRegions()) {
116 attributes_pv.insert({reg, Attributes()});
117 attributes_hpv.insert({reg, Attributes()});
120 ElementContext elemCtx( simulator );
121 const auto& gridView = simulator.
gridView();
122 const auto& comm = gridView.comm();
125 for (
const auto& elem : elements(gridView, Dune::Partitions::interior)) {
126 elemCtx.updatePrimaryStencil(elem);
127 elemCtx.updatePrimaryIntensiveQuantities(0);
128 const unsigned cellIdx = elemCtx.globalSpaceIndex(0, 0);
129 const auto& intQuants = elemCtx.intensiveQuantities(0, 0);
130 const auto& fs = intQuants.fluidState();
133 simulator.
model().dofTotalVolume(simulator.
vanguard().gridEquilIdxToGridIdx(cellIdx))
134 * intQuants.porosity().value();
138 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
139 hydrocarbon -= fs.saturation(FluidSystem::waterPhaseIdx).value();
142 const int reg = rmap_.region(cellIdx);
146 const Scalar hydrocarbonPV = pv_cell*hydrocarbon;
147 if (hydrocarbonPV > 0.) {
148 auto& attr = attributes_hpv[reg];
149 attr.pv += hydrocarbonPV;
150 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
151 attr.rs += fs.Rs().value() * hydrocarbonPV;
152 attr.rv += fs.Rv().value() * hydrocarbonPV;
153 const Scalar oilPV = pv_cell * fs.saturation(FluidSystem::oilPhaseIdx).value();
154 const Scalar gasPV = pv_cell * fs.saturation(FluidSystem::gasPhaseIdx).value();
155 attr.rs_oil += fs.Rs().value() * oilPV;
156 attr.oil_pv += oilPV;
157 attr.rv_gas += fs.Rv().value() * gasPV;
158 attr.gas_pv += gasPV;
160 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
161 attr.pressure += fs.pressure(FluidSystem::oilPhaseIdx).value() * hydrocarbonPV;
162 attr.temperature += fs.temperature(FluidSystem::oilPhaseIdx).value() * hydrocarbonPV;
164 assert(FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx));
165 attr.pressure += fs.pressure(FluidSystem::gasPhaseIdx).value() * hydrocarbonPV;
166 attr.temperature += fs.temperature(FluidSystem::gasPhaseIdx).value() * hydrocarbonPV;
168 attr.saltConcentration += fs.saltConcentration().value() * hydrocarbonPV;
169 if (FluidSystem::enableDissolvedGasInWater()) {
170 attr.rsw += fs.Rsw().value() * hydrocarbonPV;
172 if (FluidSystem::enableVaporizedWater()) {
173 attr.rvw += fs.Rvw().value() * hydrocarbonPV;
178 auto& attr = attributes_pv[reg];
180 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
181 attr.rs += fs.Rs().value() * pv_cell;
182 attr.rv += fs.Rv().value() * pv_cell;
184 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
185 attr.pressure += fs.pressure(FluidSystem::oilPhaseIdx).value() * pv_cell;
186 attr.temperature += fs.temperature(FluidSystem::oilPhaseIdx).value() * pv_cell;
187 }
else if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
188 attr.pressure += fs.pressure(FluidSystem::gasPhaseIdx).value() * pv_cell;
189 attr.temperature += fs.temperature(FluidSystem::gasPhaseIdx).value() * pv_cell;
191 assert(FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx));
192 attr.pressure += fs.pressure(FluidSystem::waterPhaseIdx).value() * pv_cell;
193 attr.temperature += fs.temperature(FluidSystem::waterPhaseIdx).value() * pv_cell;
195 attr.saltConcentration += fs.saltConcentration().value() * pv_cell;
196 if (FluidSystem::enableDissolvedGasInWater()) {
197 attr.rsw += fs.Rsw().value() * pv_cell;
199 if (FluidSystem::enableVaporizedWater()) {
200 attr.rvw += fs.Rvw().value() * pv_cell;
207 this->sumRates(attributes_hpv,
246 template <
class Coeff>
250 template <
class Coeff ,
class Rates>
252 calcCoeff(
const RegionId r,
const int pvtRegionIdx,
const Rates& surface_rates, Coeff& coeff)
const;
254 template <
class Coeff>
263 const Scalar saltConcentration,
266 template <
class Coeff>
292 template <
class Rates>
294 const int pvtRegionIdx,
295 const Rates& surface_rates,
296 Rates& voidage_rates)
const;
332 template <
typename SurfaceRates,
typename Vo
idageRates>
340 const Scalar saltConcentration,
341 const SurfaceRates& surface_rates,
342 VoidageRates& voidage_rates)
const;
344 template <
class Rates>
345 std::pair<Scalar, Scalar>
348 const Rates& surface_rates)
const;
362 template <
class SolventModule>
366 const auto& ra = attr_.attributes(r);
367 const Scalar p = ra.pressure;
368 const Scalar T = ra.temperature;
369 const auto& solventPvt = SolventModule::solventPvt();
370 const Scalar bs = solventPvt.inverseFormationVolumeFactor(pvtRegionIdx, T, p);
378 const RegionMapping<Region> rmap_;
387 , temperature(data[1])
393 , saltConcentration(data[7])
400 Attributes(
const Attributes& rhs)
403 this->data = rhs.data;
406 Attributes& operator=(
const Attributes& rhs)
408 this->data = rhs.data;
412 std::array<Scalar,12> data;
420 Scalar& saltConcentration;
428 void sumRates(std::unordered_map<RegionId,Attributes>& attributes_hpv,
429 std::unordered_map<RegionId,Attributes>& attributes_pv,
432 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:197
#define OPM_BEGIN_PARALLEL_TRY_CATCH()
Macro to setup the try of a parallel try-catch.
Definition: DeferredLoggingErrorHelpers.hpp:160
Definition: RateConverter.hpp:70
std::pair< Scalar, Scalar > inferDissolvedVaporisedRatio(const Scalar rsMax, const Scalar rvMax, const Rates &surface_rates) const
SurfaceToReservoirVoidage(const Region ®ion)
Definition: RateConverter.hpp:79
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 calcCoeff(const int pvtRegionIdx, const Scalar p, const Scalar rs, const Scalar rv, const Scalar rsw, const Scalar rvw, const Scalar T, const Scalar saltConcentration, Coeff &coeff) const
void defineState(const Simulator &simulator)
Definition: RateConverter.hpp:93
typename RegionMapping< Region >::RegionId RegionId
Definition: RateConverter.hpp:217
void calcReservoirVoidageRates(const int pvtRegionIdx, const Scalar p, const Scalar rs, const Scalar rv, const Scalar rsw, const Scalar rvw, const Scalar T, const Scalar saltConcentration, const SurfaceRates &surface_rates, VoidageRates &voidage_rates) const
void calcCoeffSolvent(const RegionId r, const int pvtRegionIdx, Scalar &coeff) const
Definition: RateConverter.hpp:364
typename FluidSystem::Scalar Scalar
Definition: RateConverter.hpp:72
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:87
Vanguard & vanguard()
Return a reference to the grid manager of simulation.
Definition: simulator.hh:242
const GridView & gridView() const
Return the grid view for which the simulation is done.
Definition: simulator.hh:254
Model & model()
Return the physical model used in the simulation.
Definition: simulator.hh:260
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: blackoilbioeffectsmodules.hh:45
int RegionId
Definition: WellConstraints.hpp:38