opm-common
Loading...
Searching...
No Matches
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
37#include <cstddef>
38
39namespace Opm {
40
41#if HAVE_ECL_INPUT
42class EclipseState;
43class Schedule;
44class SimpleTable;
45#endif
46
51template <class Scalar>
53{
54 using SamplingPoints = std::vector<std::pair<Scalar, Scalar>>;
55
56public:
57 using TabulatedTwoDFunction = UniformXTabulated2DFunction<Scalar>;
58 using TabulatedOneDFunction = Tabulated1DFunction<Scalar>;
59
60#if HAVE_ECL_INPUT
66 void initFromState(const EclipseState& eclState, const Schedule& schedule);
67
68private:
69 void extendPvtgTable_(unsigned regionIdx,
70 unsigned xIdx,
71 const SimpleTable& curTable,
72 const SimpleTable& masterTable);
73
74public:
75#endif // HAVE_ECL_INPUT
76
77 void setNumRegions(std::size_t numRegions);
78
79 void setVapPars(const Scalar par1, const Scalar)
80 {
81 vapPar1_ = par1;
82 }
83
87 void setReferenceDensities(unsigned regionIdx,
88 Scalar rhoRefOil,
89 Scalar rhoRefGas,
90 Scalar /*rhoRefWater*/);
91
98 void setSaturatedGasOilVaporizationFactor(unsigned regionIdx,
99 const SamplingPoints& samplePoints)
100 { saturatedOilVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
101
111 void setSaturatedGasFormationVolumeFactor(unsigned regionIdx,
112 const SamplingPoints& samplePoints);
113
126 void setInverseGasFormationVolumeFactor(unsigned regionIdx,
127 const TabulatedTwoDFunction& invBg)
128 { inverseGasB_[regionIdx] = invBg; }
129
135 void setGasViscosity(unsigned regionIdx, const TabulatedTwoDFunction& mug)
136 { gasMu_[regionIdx] = mug; }
137
145 void setSaturatedGasViscosity(unsigned regionIdx,
146 const SamplingPoints& samplePoints);
147
151 void initEnd();
152
156 unsigned numRegions() const
157 { return gasReferenceDensity_.size(); }
158
162 template <class Evaluation>
163 Evaluation internalEnergy(unsigned,
164 const Evaluation&,
165 const Evaluation&,
166 const Evaluation&,
167 const Evaluation&) const
168 {
169 throw std::runtime_error("Requested the enthalpy of gas but the thermal "
170 "option is not enabled");
171 }
172
173 Scalar hVap(unsigned) const
174 {
175 throw std::runtime_error("Requested the hvap of oil but the thermal "
176 "option is not enabled");
177 }
178
182 template <class Evaluation>
183 Evaluation viscosity(unsigned regionIdx,
184 const Evaluation& /*temperature*/,
185 const Evaluation& pressure,
186 const Evaluation& Rv,
187 const Evaluation& /*Rvw*/) const
188 {
189 const Evaluation& invBg = inverseGasB_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true);
190 const Evaluation& invMugBg = inverseGasBMu_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true);
191
192 return invBg / invMugBg;
193 }
194
198 template <class Evaluation>
199 Evaluation saturatedViscosity(unsigned regionIdx,
200 const Evaluation& /*temperature*/,
201 const Evaluation& pressure) const
202 {
203 const Evaluation& invBg = inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true);
204 const Evaluation& invMugBg = inverseSaturatedGasBMu_[regionIdx].eval(pressure, /*extrapolate=*/true);
205
206 return invBg / invMugBg;
207 }
208
212 template <class Evaluation>
213 Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
214 const Evaluation& /*temperature*/,
215 const Evaluation& pressure,
216 const Evaluation& Rv,
217 const Evaluation& /*Rvw*/) const
218 { return inverseGasB_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true); }
219
223 template <class FluidState, class LhsEval = typename FluidState::Scalar>
224 std::pair<LhsEval, LhsEval>
225 inverseFormationVolumeFactorAndViscosity(const FluidState& fluidState, unsigned regionIdx)
226 {
227 const LhsEval& p = decay<LhsEval>(fluidState.pressure(FluidState::gasPhaseIdx));
228 const LhsEval& Rv = decay<LhsEval>(fluidState.Rv());
229
230 const auto satSegIdx = this->saturatedOilVaporizationFactorTable_[regionIdx].findSegmentIndex(p, /*extrapolate=*/ true);
231 const auto RvSat = this->saturatedOilVaporizationFactorTable_[regionIdx].eval(p, SegmentIndex{satSegIdx});
232 const bool useSaturatedTables = (fluidState.saturation(FluidState::oilPhaseIdx) > 0.0) && (Rv >= (1.0 - 1e-10) * RvSat);
233
234 if (useSaturatedTables) {
235 const LhsEval b = this->inverseSaturatedGasB_[regionIdx].eval(p, SegmentIndex{satSegIdx});
236 const LhsEval invBMu = this->inverseSaturatedGasBMu_[regionIdx].eval(p, SegmentIndex{satSegIdx});
237 const LhsEval mu = b / invBMu;
238 return { b, mu };
239 } else {
240 unsigned ii, jj1, jj2;
241 LhsEval alpha, beta1, beta2;
242 this->inverseGasB_[regionIdx].findPoints(ii, jj1, jj2, alpha, beta1, beta2, p, Rv, /*extrapolate =*/ true);
243 const LhsEval b = this->inverseGasB_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
244 const LhsEval invBMu = this->inverseGasBMu_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
245 const LhsEval mu = b / invBMu;
246 return { b, mu };
247 }
248 }
249
253 template <class Evaluation>
254 Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
255 const Evaluation& /*temperature*/,
256 const Evaluation& pressure) const
257 { return inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true); }
258
262 template <class Evaluation>
263 Evaluation saturatedWaterVaporizationFactor(unsigned /*regionIdx*/,
264 const Evaluation& /*temperature*/,
265 const Evaluation& /*pressure*/) const
266 { return 0.0; /* this is non-humid gas! */ }
267
271 template <class Evaluation = Scalar>
272 Evaluation saturatedWaterVaporizationFactor(unsigned /*regionIdx*/,
273 const Evaluation& /*temperature*/,
274 const Evaluation& /*pressure*/,
275 const Evaluation& /*saltConcentration*/) const
276 { return 0.0; }
277
281 template <class Evaluation>
282 Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
283 const Evaluation& /*temperature*/,
284 const Evaluation& pressure) const
285 {
286 return saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
287 }
288
296 template <class Evaluation>
297 Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
298 const Evaluation& /*temperature*/,
299 const Evaluation& pressure,
300 const Evaluation& oilSaturation,
301 Evaluation maxOilSaturation) const
302 {
303 Evaluation tmp =
304 saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
305
306 // apply the vaporization parameters for the gas phase (cf. the Eclipse VAPPARS
307 // keyword)
308 maxOilSaturation = min(maxOilSaturation, Scalar(1.0));
309 if (vapPar1_ > 0.0 && maxOilSaturation > 0.01 && oilSaturation < maxOilSaturation) {
310 constexpr const Scalar eps = 0.001;
311 const Evaluation& So = max(oilSaturation, eps);
312 tmp *= max(1e-3, pow(So / maxOilSaturation, vapPar1_));
313 }
314
315 return tmp;
316 }
317
329 template <class Evaluation>
330 Evaluation saturationPressure(unsigned regionIdx,
331 const Evaluation&,
332 const Evaluation& Rv) const
333 {
334 using Toolbox = MathToolbox<Evaluation>;
335
336 const auto& RvTable = saturatedOilVaporizationFactorTable_[regionIdx];
337 constexpr const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon() * 1e6;
338
339 // use the tabulated saturation pressure function to get a pretty good initial value
340 Evaluation pSat = saturationPressure_[regionIdx].eval(Rv, /*extrapolate=*/true);
341
342 // Newton method to do the remaining work. If the initial
343 // value is good, this should only take two to three
344 // iterations...
345 bool onProbation = false;
346 for (unsigned i = 0; i < 20; ++i) {
347 const Evaluation& f = RvTable.eval(pSat, /*extrapolate=*/true) - Rv;
348 const Evaluation& fPrime = RvTable.evalDerivative(pSat, /*extrapolate=*/true);
349
350 // If the derivative is "zero" Newton will not converge,
351 // so simply return our initial guess.
352 if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
353 return pSat;
354 }
355
356 const Evaluation& delta = f / fPrime;
357
358 pSat -= delta;
359
360 if (pSat < 0.0) {
361 // if the pressure is lower than 0 Pascals, we set it back to 0. if this
362 // happens twice, we give up and just return 0 Pa...
363 if (onProbation) {
364 return 0.0;
365 }
366
367 onProbation = true;
368 pSat = 0.0;
369 }
370
371 if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat))*eps) {
372 return pSat;
373 }
374 }
375
376 const std::string msg =
377 "Finding saturation pressure did not converge: "
378 "pSat = " + std::to_string(getValue(pSat)) +
379 ", Rv = " + std::to_string(getValue(Rv));
380 OpmLog::debug("Wet gas saturation pressure", msg);
381 throw NumericalProblem(msg);
382 }
383
384 template <class Evaluation>
385 Evaluation diffusionCoefficient(const Evaluation& /*temperature*/,
386 const Evaluation& /*pressure*/,
387 unsigned /*compIdx*/) const
388 {
389 throw std::runtime_error("Not implemented: The PVT model does not provide "
390 "a diffusionCoefficient()");
391 }
392
393 Scalar gasReferenceDensity(unsigned regionIdx) const
394 { return gasReferenceDensity_[regionIdx]; }
395
396 Scalar oilReferenceDensity(unsigned regionIdx) const
397 { return oilReferenceDensity_[regionIdx]; }
398
399 const std::vector<TabulatedTwoDFunction>& inverseGasB() const
400 { return inverseGasB_; }
401
402 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasB() const
403 { return inverseSaturatedGasB_; }
404
405 const std::vector<TabulatedTwoDFunction>& gasMu() const
406 { return gasMu_; }
407
408 const std::vector<TabulatedTwoDFunction>& inverseGasBMu() const
409 { return inverseGasBMu_; }
410
411 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasBMu() const
412 { return inverseSaturatedGasBMu_; }
413
414 const std::vector<TabulatedOneDFunction>& saturatedOilVaporizationFactorTable() const
415 { return saturatedOilVaporizationFactorTable_; }
416
417 const std::vector<TabulatedOneDFunction>& saturationPressure() const
418 { return saturationPressure_; }
419
420 Scalar vapPar1() const
421 { return vapPar1_; }
422
423private:
424 void updateSaturationPressure_(unsigned regionIdx);
425
426 std::vector<Scalar> gasReferenceDensity_{};
427 std::vector<Scalar> oilReferenceDensity_{};
428 std::vector<TabulatedTwoDFunction> inverseGasB_{};
429 std::vector<TabulatedOneDFunction> inverseSaturatedGasB_{};
430 std::vector<TabulatedTwoDFunction> gasMu_{};
431 std::vector<TabulatedTwoDFunction> inverseGasBMu_{};
432 std::vector<TabulatedOneDFunction> inverseSaturatedGasBMu_{};
433 std::vector<TabulatedOneDFunction> saturatedOilVaporizationFactorTable_{};
434 std::vector<TabulatedOneDFunction> saturationPressure_{};
435
436 Scalar vapPar1_ = 0.0;
437};
438
439} // namespace Opm
440
441#endif
Provides the OPM specific exception classes.
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...
Implements a linearly interpolated scalar function that depends on one variable.
Implements a scalar function that depends on two variables and which is sampled uniformly in the X di...
Definition EclipseState.hpp:62
Definition Exceptions.hpp:40
Definition Schedule.hpp:101
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:55
This class represents the Pressure-Volume-Temperature relations of the gas phas with vaporized oil.
Definition WetGasPvt.hpp:53
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:254
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:282
void initEnd()
Finish initializing the gas phase PVT properties.
Definition WetGasPvt.cpp:331
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:330
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:163
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:297
void setGasViscosity(unsigned regionIdx, const TabulatedTwoDFunction &mug)
Initialize the viscosity of the gas phase.
Definition WetGasPvt.hpp:135
Evaluation saturatedWaterVaporizationFactor(unsigned, const Evaluation &, const Evaluation &) const
Returns the water vaporization factor [m^3/m^3] of the gasphase.
Definition WetGasPvt.hpp:263
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:272
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition WetGasPvt.hpp:156
void setSaturatedGasViscosity(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the phase viscosity for oil saturated gas.
Definition WetGasPvt.cpp:297
void setSaturatedGasFormationVolumeFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the gas formation volume factor.
Definition WetGasPvt.cpp:246
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:213
void setSaturatedGasOilVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil vaporization factor .
Definition WetGasPvt.hpp:98
std::pair< LhsEval, LhsEval > inverseFormationVolumeFactorAndViscosity(const FluidState &fluidState, unsigned regionIdx)
Returns the formation volume factor [-] and viscosity [Pa s] of the fluid phase.
Definition WetGasPvt.hpp:225
void setInverseGasFormationVolumeFactor(unsigned regionIdx, const TabulatedTwoDFunction &invBg)
Initialize the function for the gas formation volume factor.
Definition WetGasPvt.hpp:126
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:199
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:183
void setReferenceDensities(unsigned regionIdx, Scalar rhoRefOil, Scalar rhoRefGas, Scalar)
Initialize the reference densities of all fluids for a given PVT region.
Definition WetGasPvt.cpp:235
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Definition MathToolbox.hpp:51
Definition Tabulated1DFunction.hpp:41