My Project
WetGasPvt.hpp
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18
19 Consult the COPYING file in the top-level source directory of this
20 module for the precise wording of the license and the list of
21 copyright holders.
22*/
27#ifndef OPM_WET_GAS_PVT_HPP
28#define OPM_WET_GAS_PVT_HPP
29
31#include <opm/common/OpmLog/OpmLog.hpp>
32
36
37namespace Opm {
38
39#if HAVE_ECL_INPUT
40class EclipseState;
41class Schedule;
42class SimpleTable;
43#endif
44
49template <class Scalar>
51{
52 using SamplingPoints = std::vector<std::pair<Scalar, Scalar>>;
53
54public:
57
58#if HAVE_ECL_INPUT
64 void initFromState(const EclipseState& eclState, const Schedule& schedule);
65
66private:
67 void extendPvtgTable_(unsigned regionIdx,
68 unsigned xIdx,
69 const SimpleTable& curTable,
70 const SimpleTable& masterTable);
71
72public:
73#endif // HAVE_ECL_INPUT
74
75 void setNumRegions(size_t numRegions);
76
80 void setReferenceDensities(unsigned regionIdx,
81 Scalar rhoRefOil,
82 Scalar rhoRefGas,
83 Scalar /*rhoRefWater*/);
84
90 void setSaturatedGasOilVaporizationFactor(unsigned regionIdx, const SamplingPoints& samplePoints)
91 { saturatedOilVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
92
103 const SamplingPoints& samplePoints);
104
117 void setInverseGasFormationVolumeFactor(unsigned regionIdx, const TabulatedTwoDFunction& invBg)
118 { inverseGasB_[regionIdx] = invBg; }
119
125 void setGasViscosity(unsigned regionIdx, const TabulatedTwoDFunction& mug)
126 { gasMu_[regionIdx] = mug; }
127
135 void setSaturatedGasViscosity(unsigned regionIdx,
136 const SamplingPoints& samplePoints);
137
141 void initEnd();
142
146 unsigned numRegions() const
147 { return gasReferenceDensity_.size(); }
148
152 template <class Evaluation>
153 Evaluation internalEnergy(unsigned,
154 const Evaluation&,
155 const Evaluation&,
156 const Evaluation&,
157 const Evaluation&) const
158 {
159 throw std::runtime_error("Requested the enthalpy of gas but the thermal option is not enabled");
160 }
161
165 template <class Evaluation>
166 Evaluation viscosity(unsigned regionIdx,
167 const Evaluation& /*temperature*/,
168 const Evaluation& pressure,
169 const Evaluation& Rv,
170 const Evaluation& /*Rvw*/) const
171 {
172 const Evaluation& invBg = inverseGasB_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true);
173 const Evaluation& invMugBg = inverseGasBMu_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true);
174
175 return invBg/invMugBg;
176 }
177
181 template <class Evaluation>
182 Evaluation saturatedViscosity(unsigned regionIdx,
183 const Evaluation& /*temperature*/,
184 const Evaluation& pressure) const
185 {
186 const Evaluation& invBg = inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true);
187 const Evaluation& invMugBg = inverseSaturatedGasBMu_[regionIdx].eval(pressure, /*extrapolate=*/true);
188
189 return invBg/invMugBg;
190 }
191
195 template <class Evaluation>
196 Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
197 const Evaluation& /*temperature*/,
198 const Evaluation& pressure,
199 const Evaluation& Rv,
200 const Evaluation& /*Rvw*/) const
201 { return inverseGasB_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true); }
202
206 template <class Evaluation>
207 Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
208 const Evaluation& /*temperature*/,
209 const Evaluation& pressure) const
210 { return inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true); }
211
215 template <class Evaluation>
216 Evaluation saturatedWaterVaporizationFactor(unsigned /*regionIdx*/,
217 const Evaluation& /*temperature*/,
218 const Evaluation& /*pressure*/) const
219 { return 0.0; /* this is non-humid gas! */ }
220
224 template <class Evaluation = Scalar>
225 Evaluation saturatedWaterVaporizationFactor(unsigned /*regionIdx*/,
226 const Evaluation& /*temperature*/,
227 const Evaluation& /*pressure*/,
228 const Evaluation& /*saltConcentration*/) const
229 { return 0.0; }
230
234 template <class Evaluation>
235 Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
236 const Evaluation& /*temperature*/,
237 const Evaluation& pressure) const
238 {
239 return saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
240 }
241
249 template <class Evaluation>
250 Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
251 const Evaluation& /*temperature*/,
252 const Evaluation& pressure,
253 const Evaluation& oilSaturation,
254 Evaluation maxOilSaturation) const
255 {
256 Evaluation tmp =
257 saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
258
259 // apply the vaporization parameters for the gas phase (cf. the Eclipse VAPPARS
260 // keyword)
261 maxOilSaturation = min(maxOilSaturation, Scalar(1.0));
262 if (vapPar1_ > 0.0 && maxOilSaturation > 0.01 && oilSaturation < maxOilSaturation) {
263 constexpr const Scalar eps = 0.001;
264 const Evaluation& So = max(oilSaturation, eps);
265 tmp *= max(1e-3, pow(So/maxOilSaturation, vapPar1_));
266 }
267
268 return tmp;
269 }
270
281 template <class Evaluation>
282 Evaluation saturationPressure(unsigned regionIdx,
283 const Evaluation&,
284 const Evaluation& Rv) const
285 {
286 typedef MathToolbox<Evaluation> Toolbox;
287
288 const auto& RvTable = saturatedOilVaporizationFactorTable_[regionIdx];
289 constexpr const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon()*1e6;
290
291 // use the tabulated saturation pressure function to get a pretty good initial value
292 Evaluation pSat = saturationPressure_[regionIdx].eval(Rv, /*extrapolate=*/true);
293
294 // Newton method to do the remaining work. If the initial
295 // value is good, this should only take two to three
296 // iterations...
297 bool onProbation = false;
298 for (unsigned i = 0; i < 20; ++i) {
299 const Evaluation& f = RvTable.eval(pSat, /*extrapolate=*/true) - Rv;
300 const Evaluation& fPrime = RvTable.evalDerivative(pSat, /*extrapolate=*/true);
301
302 // If the derivative is "zero" Newton will not converge,
303 // so simply return our initial guess.
304 if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
305 return pSat;
306 }
307
308 const Evaluation& delta = f/fPrime;
309
310 pSat -= delta;
311
312 if (pSat < 0.0) {
313 // if the pressure is lower than 0 Pascals, we set it back to 0. if this
314 // happens twice, we give up and just return 0 Pa...
315 if (onProbation)
316 return 0.0;
317
318 onProbation = true;
319 pSat = 0.0;
320 }
321
322 if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat))*eps)
323 return pSat;
324 }
325
326 const std::string msg =
327 "Finding saturation pressure did not converge: "
328 "pSat = " + std::to_string(getValue(pSat)) +
329 ", Rv = " + std::to_string(getValue(Rv));
330 OpmLog::debug("Wet gas saturation pressure", msg);
331 throw NumericalProblem(msg);
332 }
333
334 template <class Evaluation>
335 Evaluation diffusionCoefficient(const Evaluation& /*temperature*/,
336 const Evaluation& /*pressure*/,
337 unsigned /*compIdx*/) const
338 {
339 throw std::runtime_error("Not implemented: The PVT model does not provide a diffusionCoefficient()");
340 }
341
342 Scalar gasReferenceDensity(unsigned regionIdx) const
343 { return gasReferenceDensity_[regionIdx]; }
344
345 Scalar oilReferenceDensity(unsigned regionIdx) const
346 { return oilReferenceDensity_[regionIdx]; }
347
348 const std::vector<TabulatedTwoDFunction>& inverseGasB() const {
349 return inverseGasB_;
350 }
351
352 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasB() const {
353 return inverseSaturatedGasB_;
354 }
355
356 const std::vector<TabulatedTwoDFunction>& gasMu() const {
357 return gasMu_;
358 }
359
360 const std::vector<TabulatedTwoDFunction>& inverseGasBMu() const {
361 return inverseGasBMu_;
362 }
363
364 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasBMu() const {
365 return inverseSaturatedGasBMu_;
366 }
367
368 const std::vector<TabulatedOneDFunction>& saturatedOilVaporizationFactorTable() const {
369 return saturatedOilVaporizationFactorTable_;
370 }
371
372 const std::vector<TabulatedOneDFunction>& saturationPressure() const {
373 return saturationPressure_;
374 }
375
376 Scalar vapPar1() const {
377 return vapPar1_;
378 }
379
380private:
381 void updateSaturationPressure_(unsigned regionIdx);
382
383 std::vector<Scalar> gasReferenceDensity_;
384 std::vector<Scalar> oilReferenceDensity_;
385 std::vector<TabulatedTwoDFunction> inverseGasB_;
386 std::vector<TabulatedOneDFunction> inverseSaturatedGasB_;
387 std::vector<TabulatedTwoDFunction> gasMu_;
388 std::vector<TabulatedTwoDFunction> inverseGasBMu_;
389 std::vector<TabulatedOneDFunction> inverseSaturatedGasBMu_;
390 std::vector<TabulatedOneDFunction> saturatedOilVaporizationFactorTable_;
391 std::vector<TabulatedOneDFunction> saturationPressure_;
392
393 Scalar vapPar1_ = 0.0;
394};
395
396} // namespace Opm
397
398#endif
Provides the OPM specific exception classes.
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...
Implements a scalar function that depends on two variables and which is sampled uniformly in the X di...
Definition: EclipseState.hpp:55
Definition: Exceptions.hpp:40
Definition: Schedule.hpp:130
Definition: SimpleTable.hpp:35
Implements a linearly interpolated scalar function that depends on one variable.
Definition: Tabulated1DFunction.hpp:51
Implements a scalar function that depends on two variables and which is sampled uniformly in the X di...
Definition: UniformXTabulated2DFunction.hpp:54
This class represents the Pressure-Volume-Temperature relations of the gas phas with vaporized oil.
Definition: WetGasPvt.hpp:51
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the formation volume factor [-] of oil saturated gas at a given pressure.
Definition: WetGasPvt.hpp:207
Evaluation saturatedOilVaporizationFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the oil vaporization factor [m^3/m^3] of the gas phase.
Definition: WetGasPvt.hpp:235
void initEnd()
Finish initializing the gas phase PVT properties.
Evaluation saturationPressure(unsigned regionIdx, const Evaluation &, const Evaluation &Rv) const
Returns the saturation pressure of the gas phase [Pa] depending on its mass fraction of the oil compo...
Definition: WetGasPvt.hpp:282
Evaluation internalEnergy(unsigned, const Evaluation &, const Evaluation &, const Evaluation &, const Evaluation &) const
Returns the specific enthalpy [J/kg] of gas given a set of parameters.
Definition: WetGasPvt.hpp:153
Evaluation saturatedOilVaporizationFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &oilSaturation, Evaluation maxOilSaturation) const
Returns the oil vaporization factor [m^3/m^3] of the gas phase.
Definition: WetGasPvt.hpp:250
void setGasViscosity(unsigned regionIdx, const TabulatedTwoDFunction &mug)
Initialize the viscosity of the gas phase.
Definition: WetGasPvt.hpp:125
Evaluation saturatedWaterVaporizationFactor(unsigned, const Evaluation &, const Evaluation &) const
Returns the water vaporization factor [m^3/m^3] of the gasphase.
Definition: WetGasPvt.hpp:216
Evaluation saturatedWaterVaporizationFactor(unsigned, const Evaluation &, const Evaluation &, const Evaluation &) const
Returns the water vaporization factor [m^3/m^3] of water saturated gas.
Definition: WetGasPvt.hpp:225
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition: WetGasPvt.hpp:146
void setSaturatedGasViscosity(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the phase viscosity for oil saturated gas.
void setSaturatedGasFormationVolumeFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the gas formation volume factor.
Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &Rv, const Evaluation &) const
Returns the formation volume factor [-] of the fluid phase.
Definition: WetGasPvt.hpp:196
void setSaturatedGasOilVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil vaporization factor .
Definition: WetGasPvt.hpp:90
void setInverseGasFormationVolumeFactor(unsigned regionIdx, const TabulatedTwoDFunction &invBg)
Initialize the function for the gas formation volume factor.
Definition: WetGasPvt.hpp:117
Evaluation saturatedViscosity(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the dynamic viscosity [Pa s] of oil saturated gas at a given pressure.
Definition: WetGasPvt.hpp:182
Evaluation viscosity(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &Rv, const Evaluation &) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition: WetGasPvt.hpp:166
void setReferenceDensities(unsigned regionIdx, Scalar rhoRefOil, Scalar rhoRefGas, Scalar)
Initialize the reference densities of all fluids for a given PVT region.
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: MathToolbox.hpp:50