22#ifndef OPM_RATECONVERTER_HPP_HEADER_INCLUDED
23#define OPM_RATECONVERTER_HPP_HEADER_INCLUDED
25#include <opm/core/props/BlackoilPhases.hpp>
26#include <opm/grid/utility/RegionMapping.hpp>
27#include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp>
28#include <opm/simulators/wells/RegionAttributeHelpers.hpp>
30#include <opm/simulators/utils/ParallelCommunication.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 EbosSimulator>
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();
125 OPM_BEGIN_PARALLEL_TRY_CATCH();
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;
201 OPM_END_PARALLEL_TRY_CATCH(
"SurfaceToReservoirVoidage::defineState() failed: ", simulator.vanguard().grid().comm());
203 this->sumRates(attributes_hpv,
213 using RegionId =
typename RegionMapping<Region>::RegionId;
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>
264 calcInjCoeff(
const RegionId r,
const int pvtRegionIdx, Coeff& coeff)
const;
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>
342 inferDissolvedVaporisedRatio(
const double rsMax,
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,
422 Parallel::Communication comm);
424 RegionAttributeHelpers::RegionAttributes<RegionId, Attributes> attr_;
Convert component rates at surface conditions to phase (voidage) rates at reservoir conditions.
Definition: RateConverter.hpp:70
SurfaceToReservoirVoidage(const PhaseUsage &phaseUsage, const Region ®ion)
Constructor.
Definition: RateConverter.hpp:78
void calcCoeffSolvent(const RegionId r, const int pvtRegionIdx, double &coeff) const
Compute coefficients for surface-to-reservoir voidage conversion for solvent.
Definition: RateConverter.hpp:360
void calcReservoirVoidageRates(const RegionId r, const int pvtRegionIdx, const Rates &surface_rates, Rates &voidage_rates) const
Convert surface volume flow rates to reservoir voidage flow rates.
Definition: RateConverter.cpp:332
void calcCoeff(const RegionId r, const int pvtRegionIdx, Coeff &coeff) const
Compute coefficients for surface-to-reservoir voidage conversion.
Definition: RateConverter.cpp:129
typename RegionMapping< Region >::RegionId RegionId
Region identifier.
Definition: RateConverter.hpp:213
void defineState(const EbosSimulator &simulator)
Compute pore volume averaged hydrocarbon state pressure, rs and rv.
Definition: RateConverter.hpp:94
bool water(const PhaseUsage &pu)
Active water predicate.
Definition: RegionAttributeHelpers.hpp:308
bool oil(const PhaseUsage &pu)
Active oil predicate.
Definition: RegionAttributeHelpers.hpp:321
bool gas(const PhaseUsage &pu)
Active gas predicate.
Definition: RegionAttributeHelpers.hpp:334
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27
PhaseUsage phaseUsage(const Phases &phases)
Determine the active phases.
Definition: phaseUsageFromDeck.cpp:37
Definition: BlackoilPhases.hpp:46