22#ifndef OPM_RATECONVERTER_HPP_HEADER_INCLUDED
23#define OPM_RATECONVERTER_HPP_HEADER_INCLUDED
25#include <opm/grid/utility/RegionMapping.hpp>
33#include <dune/grid/common/gridenums.hh>
34#include <dune/grid/common/rangegenerators.hh>
38#include <unordered_map>
53 namespace RateConverter {
70 template <
class Flu
idSystem,
class Region>
73 using Scalar =
typename FluidSystem::Scalar;
85 , attr_ (rmap_, Attributes())
96 template <
typename ElementContext,
class Simulator>
101 for (
const auto& reg : rmap_.activeRegions()) {
102 auto& ra = attr_.attributes(reg);
104 ra.temperature = 0.0;
108 ra.saltConcentration = 0.0;
114 std::unordered_map<RegionId, Attributes> attributes_pv;
117 std::unordered_map<RegionId, Attributes> attributes_hpv;
119 for (
const auto& reg : rmap_.activeRegions()) {
120 attributes_pv.insert({reg, Attributes()});
121 attributes_hpv.insert({reg, Attributes()});
124 ElementContext elemCtx( simulator );
125 const auto& gridView = simulator.
gridView();
126 const auto& comm = gridView.comm();
129 for (
const auto& elem : elements(gridView, Dune::Partitions::interior)) {
130 elemCtx.updatePrimaryStencil(elem);
131 elemCtx.updatePrimaryIntensiveQuantities(0);
132 const unsigned cellIdx = elemCtx.globalSpaceIndex(0, 0);
133 const auto& intQuants = elemCtx.intensiveQuantities(0, 0);
134 const auto& fs = intQuants.fluidState();
137 simulator.
model().dofTotalVolume(cellIdx)
138 * intQuants.porosity().value();
142 const auto& pu = phaseUsage_;
144 hydrocarbon -= fs.saturation(FluidSystem::waterPhaseIdx).value();
147 const int reg = rmap_.region(cellIdx);
151 const Scalar hydrocarbonPV = pv_cell*hydrocarbon;
152 if (hydrocarbonPV > 0.) {
153 auto& attr = attributes_hpv[reg];
154 attr.pv += hydrocarbonPV;
156 attr.rs += fs.Rs().value() * hydrocarbonPV;
157 attr.rv += fs.Rv().value() * hydrocarbonPV;
160 attr.pressure += fs.pressure(FluidSystem::oilPhaseIdx).value() * hydrocarbonPV;
161 attr.temperature += fs.temperature(FluidSystem::oilPhaseIdx).value() * hydrocarbonPV;
164 attr.pressure += fs.pressure(FluidSystem::gasPhaseIdx).value() * hydrocarbonPV;
165 attr.temperature += fs.temperature(FluidSystem::gasPhaseIdx).value() * hydrocarbonPV;
167 attr.saltConcentration += fs.saltConcentration().value() * hydrocarbonPV;
168 if (FluidSystem::enableDissolvedGasInWater()) {
169 attr.rsw += fs.Rsw().value() * hydrocarbonPV;
171 if (FluidSystem::enableVaporizedWater()) {
172 attr.rvw += fs.Rvw().value() * hydrocarbonPV;
177 auto& attr = attributes_pv[reg];
180 attr.rs += fs.Rs().value() * pv_cell;
181 attr.rv += fs.Rv().value() * pv_cell;
184 attr.pressure += fs.pressure(FluidSystem::oilPhaseIdx).value() * pv_cell;
185 attr.temperature += fs.temperature(FluidSystem::oilPhaseIdx).value() * pv_cell;
187 attr.pressure += fs.pressure(FluidSystem::gasPhaseIdx).value() * pv_cell;
188 attr.temperature += fs.temperature(FluidSystem::gasPhaseIdx).value() * pv_cell;
191 attr.pressure += fs.pressure(FluidSystem::waterPhaseIdx).value() * pv_cell;
192 attr.temperature += fs.temperature(FluidSystem::waterPhaseIdx).value() * pv_cell;
194 attr.saltConcentration += fs.saltConcentration().value() * pv_cell;
195 if (FluidSystem::enableDissolvedGasInWater()) {
196 attr.rsw += fs.Rsw().value() * pv_cell;
198 if (FluidSystem::enableVaporizedWater()) {
199 attr.rvw += fs.Rvw().value() * pv_cell;
206 this->sumRates(attributes_hpv,
245 template <
class Coeff>
249 template <
class Coeff ,
class Rates>
251 calcCoeff(
const RegionId r,
const int pvtRegionIdx,
const Rates& surface_rates, Coeff& coeff)
const;
253 template <
class Coeff>
262 const Scalar saltConcentration,
265 template <
class Coeff>
291 template <
class Rates>
293 const int pvtRegionIdx,
294 const Rates& surface_rates,
295 Rates& voidage_rates)
const;
331 template <
typename SurfaceRates,
typename Vo
idageRates>
339 const Scalar saltConcentration,
340 const SurfaceRates& surface_rates,
341 VoidageRates& voidage_rates)
const;
343 template <
class Rates>
344 std::pair<Scalar, Scalar>
347 const Rates& surface_rates)
const;
361 template <
class SolventModule>
365 const auto& ra = attr_.attributes(r);
366 const Scalar p = ra.pressure;
367 const Scalar T = ra.temperature;
368 const auto& solventPvt = SolventModule::solventPvt();
369 const Scalar bs = solventPvt.inverseFormationVolumeFactor(pvtRegionIdx, T, p);
382 const RegionMapping<Region> rmap_;
391 , temperature(data[1])
397 , 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,8> data;
420 Scalar& saltConcentration;
423 void sumRates(std::unordered_map<RegionId,Attributes>& attributes_hpv,
424 std::unordered_map<RegionId,Attributes>& attributes_pv,
427 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:192
#define OPM_BEGIN_PARALLEL_TRY_CATCH()
Macro to setup the try of a parallel try-catch.
Definition: DeferredLoggingErrorHelpers.hpp:158
Definition: RateConverter.hpp:71
std::pair< Scalar, Scalar > inferDissolvedVaporisedRatio(const Scalar rsMax, const Scalar rvMax, const Rates &surface_rates) const
SurfaceToReservoirVoidage(const PhaseUsage &phaseUsage, const Region ®ion)
Definition: RateConverter.hpp:81
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:97
typename RegionMapping< Region >::RegionId RegionId
Definition: RateConverter.hpp:216
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:363
typename FluidSystem::Scalar Scalar
Definition: RateConverter.hpp:73
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:92
Vanguard & vanguard()
Return a reference to the grid manager of simulation.
Definition: simulator.hh:260
const GridView & gridView() const
Return the grid view for which the simulation is done.
Definition: simulator.hh:272
Model & model()
Return the physical model used in the simulation.
Definition: simulator.hh:278
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
bool water(const PhaseUsage &pu)
Definition: RegionAttributeHelpers.hpp:309
bool oil(const PhaseUsage &pu)
Definition: RegionAttributeHelpers.hpp:322
bool gas(const PhaseUsage &pu)
Definition: RegionAttributeHelpers.hpp:335
Definition: blackoilboundaryratevector.hh:37
PhaseUsage phaseUsage(const Phases &phases)
Determine the active phases.
int RegionId
Definition: WellConstraints.hpp:37
Definition: BlackoilPhases.hpp:46