My Project
Loading...
Searching...
No Matches
WetHumidGasPvt.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_HUMID_GAS_PVT_HPP
28#define OPM_WET_HUMID_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:
59
60#if HAVE_ECL_INPUT
66 void initFromState(const EclipseState& eclState, const Schedule& schedule);
67
68private:
69 void extendPvtgwTable_(unsigned regionIdx,
70 unsigned xIdx,
71 const SimpleTable& curTable,
72 const SimpleTable& masterTable);
73
74 void extendPvtgTable_(unsigned regionIdx,
75 unsigned xIdx,
76 const SimpleTable& curTable,
77 const SimpleTable& masterTable);
78
79public:
80#endif // HAVE_ECL_INPUT
81
82 void setNumRegions(std::size_t numRegions);
83
84 void setVapPars(const Scalar par1, const Scalar)
85 {
86 vapPar1_ = par1;
87 }
88
92 void setReferenceDensities(unsigned regionIdx,
93 Scalar rhoRefOil,
94 Scalar rhoRefGas,
95 Scalar rhoRefWater);
96
103 const SamplingPoints& samplePoints)
104 { saturatedWaterVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
105
112 const SamplingPoints& samplePoints)
113 { saturatedOilVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
114
118 void initEnd();
119
123 unsigned numRegions() const
124 { return gasReferenceDensity_.size(); }
125
129 template <class Evaluation>
130 Evaluation internalEnergy(unsigned,
131 const Evaluation&,
132 const Evaluation&,
133 const Evaluation&,
134 const Evaluation&) const
135 {
136 throw std::runtime_error("Requested the enthalpy of gas but the thermal "
137 "option is not enabled");
138 }
139
140 Scalar hVap(unsigned) const
141 {
142 throw std::runtime_error("Requested the hvap of oil but the thermal "
143 "option is not enabled");
144 }
145
149 template <class Evaluation>
150 Evaluation viscosity(unsigned regionIdx,
151 const Evaluation& /*temperature*/,
152 const Evaluation& pressure,
153 const Evaluation& Rv,
154 const Evaluation& Rvw) const
155 {
156 const Evaluation& temperature = 1E30;
157
158 if (Rv >= (1.0 - 1e-10) * saturatedOilVaporizationFactor(regionIdx, temperature, pressure)) {
159 const Evaluation& invBg = inverseGasBRvSat_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
160 const Evaluation& invMugBg = inverseGasBMuRvSat_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
161 return invBg / invMugBg;
162 }
163 else {
164 // for Rv undersaturated viscosity is evaluated at saturated Rvw values
165 const Evaluation& invBg = inverseGasBRvwSat_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true);
166 const Evaluation& invMugBg = inverseGasBMuRvwSat_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true);
167 return invBg / invMugBg;
168 }
169 }
170
174 template <class Evaluation>
175 Evaluation saturatedViscosity(unsigned regionIdx,
176 const Evaluation& /*temperature*/,
177 const Evaluation& pressure) const
178 {
179 const Evaluation& invBg = inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true);
180 const Evaluation& invMugBg = inverseSaturatedGasBMu_[regionIdx].eval(pressure, /*extrapolate=*/true);
181
182 return invBg / invMugBg;
183 }
184
188 // template <class Evaluation>
189 // Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
190 // const Evaluation& /*temperature*/,
191 // const Evaluation& pressure,
192 // const Evaluation& Rw) const
193 // { return inverseGasB_[regionIdx].eval(pressure, Rw, /*extrapolate=*/true); }
194
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 {
202 const Evaluation& temperature = 1E30;
203
204 if (Rv >= (1.0 - 1e-10) * saturatedOilVaporizationFactor(regionIdx, temperature, pressure)) {
205 return inverseGasBRvSat_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
206 }
207 else {
208 // for Rv undersaturated Bg^-1 is evaluated at saturated Rvw values
209 return inverseGasBRvwSat_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true);
210 }
211 }
212
216 template <class Evaluation>
217 Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
218 const Evaluation& /*temperature*/,
219 const Evaluation& pressure) const
220 { return inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true); }
221
225 template <class Evaluation>
226 Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
227 const Evaluation& /*temperature*/,
228 const Evaluation& pressure) const
229 {
230 return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
231 }
232
236 template <class Evaluation>
237 Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
238 const Evaluation& /*temperature*/,
239 const Evaluation& pressure,
240 const Evaluation& saltConcentration) const
241 {
242 if (enableRwgSalt_) {
243 return saturatedWaterVaporizationSaltFactorTable_[regionIdx].eval(pressure, saltConcentration, /*extrapolate=*/true);
244 }
245 else {
246 return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
247 }
248 }
249
250 template <class Evaluation>
251 Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
252 const Evaluation& /*temperature*/,
253 const Evaluation& pressure) const
254 {
255 return saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
256 }
257
265 template <class Evaluation>
266 Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
267 const Evaluation& /*temperature*/,
268 const Evaluation& pressure,
269 const Evaluation& oilSaturation,
270 Evaluation maxOilSaturation) const
271 {
272 Evaluation tmp =
273 saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
274
275 // apply the vaporization parameters for the gas phase (cf. the Eclipse VAPPARS
276 // keyword)
277 maxOilSaturation = min(maxOilSaturation, Scalar(1.0));
278 if (vapPar1_ > 0.0 && maxOilSaturation > 0.01 && oilSaturation < maxOilSaturation) {
279 constexpr const Scalar eps = 0.001;
280 const Evaluation& So = max(oilSaturation, eps);
281 tmp *= max(1e-3, pow(So / maxOilSaturation, vapPar1_));
282 }
283
284 return tmp;
285 }
286
294 //PJPE assume dependence on Rv
295 template <class Evaluation>
296 Evaluation saturationPressure(unsigned regionIdx,
297 const Evaluation&,
298 const Evaluation& Rw) const
299 {
300 using Toolbox = MathToolbox<Evaluation>;
301
302 const auto& RwTable = saturatedWaterVaporizationFactorTable_[regionIdx];
303 constexpr const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon() * 1e6;
304
305 // use the tabulated saturation pressure function to get a pretty good initial value
306 Evaluation pSat = saturationPressure_[regionIdx].eval(Rw, /*extrapolate=*/true);
307
308 // Newton method to do the remaining work. If the initial
309 // value is good, this should only take two to three
310 // iterations...
311 bool onProbation = false;
312 for (unsigned i = 0; i < 20; ++i) {
313 const Evaluation& f = RwTable.eval(pSat, /*extrapolate=*/true) - Rw;
314 const Evaluation& fPrime = RwTable.evalDerivative(pSat, /*extrapolate=*/true);
315
316 // If the derivative is "zero" Newton will not converge,
317 // so simply return our initial guess.
318 if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
319 return pSat;
320 }
321
322 const Evaluation& delta = f / fPrime;
323
324 pSat -= delta;
325
326 if (pSat < 0.0) {
327 // if the pressure is lower than 0 Pascals, we set it back to 0. if this
328 // happens twice, we give up and just return 0 Pa...
329 if (onProbation) {
330 return 0.0;
331 }
332
333 onProbation = true;
334 pSat = 0.0;
335 }
336
337 if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat))*eps) {
338 return pSat;
339 }
340 }
341
342 const std::string msg =
343 "Finding saturation pressure did not converge: "
344 "pSat = " + std::to_string(getValue(pSat)) +
345 ", Rw = " + std::to_string(getValue(Rw));
346 OpmLog::debug("Wet gas saturation pressure", msg);
347 throw NumericalProblem(msg);
348 }
349
350 template <class Evaluation>
351 Evaluation diffusionCoefficient(const Evaluation& /*temperature*/,
352 const Evaluation& /*pressure*/,
353 unsigned /*compIdx*/) const
354 {
355 throw std::runtime_error("Not implemented: The PVT model does not provide "
356 "a diffusionCoefficient()");
357 }
358
359 Scalar gasReferenceDensity(unsigned regionIdx) const
360 { return gasReferenceDensity_[regionIdx]; }
361
362 Scalar oilReferenceDensity(unsigned regionIdx) const
363 { return oilReferenceDensity_[regionIdx]; }
364
365 Scalar waterReferenceDensity(unsigned regionIdx) const
366 { return waterReferenceDensity_[regionIdx]; }
367
368 const std::vector<TabulatedTwoDFunction>& inverseGasB() const
369 { return inverseGasBRvSat_; }
370
371 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasB() const
372 { return inverseSaturatedGasB_; }
373
374 const std::vector<TabulatedTwoDFunction>& gasMu() const
375 { return gasMuRvSat_; }
376
377 const std::vector<TabulatedTwoDFunction>& inverseGasBMu() const
378 { return inverseGasBMuRvSat_; }
379
380 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasBMu() const
381 { return inverseSaturatedGasBMu_; }
382
383 const std::vector<TabulatedOneDFunction>& saturatedWaterVaporizationFactorTable() const
384 { return saturatedWaterVaporizationFactorTable_; }
385
386 const std::vector<TabulatedTwoDFunction>& saturatedWaterVaporizationSaltFactorTable() const
387 { return saturatedWaterVaporizationSaltFactorTable_; }
388
389 const std::vector<TabulatedOneDFunction>& saturatedOilVaporizationFactorTable() const
390 { return saturatedOilVaporizationFactorTable_; }
391
392 const std::vector<TabulatedOneDFunction>& saturationPressure() const
393 { return saturationPressure_; }
394
395 Scalar vapPar1() const
396 { return vapPar1_; }
397
398private:
399 void updateSaturationPressure_(unsigned regionIdx);
400
401 std::vector<Scalar> gasReferenceDensity_{};
402 std::vector<Scalar> oilReferenceDensity_{};
403 std::vector<Scalar> waterReferenceDensity_{};
404 std::vector<TabulatedTwoDFunction> inverseGasBRvwSat_{};
405 std::vector<TabulatedTwoDFunction> inverseGasBRvSat_{};
406 std::vector<TabulatedOneDFunction> inverseSaturatedGasB_{};
407 std::vector<TabulatedTwoDFunction> gasMuRvwSat_{};
408 std::vector<TabulatedTwoDFunction> gasMuRvSat_{};
409 std::vector<TabulatedTwoDFunction> inverseGasBMuRvwSat_{};
410 std::vector<TabulatedTwoDFunction> inverseGasBMuRvSat_{};
411 std::vector<TabulatedOneDFunction> inverseSaturatedGasBMu_{};
412 std::vector<TabulatedOneDFunction> saturatedWaterVaporizationFactorTable_{};
413 std::vector<TabulatedTwoDFunction> saturatedWaterVaporizationSaltFactorTable_{};
414 std::vector<TabulatedOneDFunction> saturatedOilVaporizationFactorTable_{};
415 std::vector<TabulatedOneDFunction> saturationPressure_{};
416
417 bool enableRwgSalt_ = false;
418 Scalar vapPar1_ = 0.0;
419};
420
421} // namespace Opm
422
423#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:63
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 phase with vaporized oil a...
Definition WetHumidGasPvt.hpp:53
Evaluation saturationPressure(unsigned regionIdx, const Evaluation &, const Evaluation &Rw) const
Returns the saturation pressure of the gas phase [Pa] depending on its mass fraction of the water com...
Definition WetHumidGasPvt.hpp:296
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition WetHumidGasPvt.hpp:123
void setSaturatedGasOilVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil vaporization factor .
Definition WetHumidGasPvt.hpp:111
Evaluation viscosity(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &Rv, const Evaluation &Rvw) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition WetHumidGasPvt.hpp:150
Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &saltConcentration) const
Returns the water vaporization factor [m^3/m^3] of the water phase.
Definition WetHumidGasPvt.hpp:237
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the formation volume factor [-] of water saturated gas at a given pressure.
Definition WetHumidGasPvt.hpp:217
Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the water vaporization factor [m^3/m^3] of the water phase.
Definition WetHumidGasPvt.hpp:226
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 WetHumidGasPvt.hpp:175
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 WetHumidGasPvt.hpp:266
void setReferenceDensities(unsigned regionIdx, Scalar rhoRefOil, Scalar rhoRefGas, Scalar rhoRefWater)
Initialize the reference densities of all fluids for a given PVT region.
Definition WetHumidGasPvt.cpp:422
Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &Rv, const Evaluation &Rvw) const
Returns the formation volume factor [-] of the fluid phase.
Definition WetHumidGasPvt.hpp:196
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 WetHumidGasPvt.hpp:130
void initEnd()
Finish initializing the gas phase PVT properties.
Definition WetHumidGasPvt.cpp:433
void setSaturatedGasWaterVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the water vaporization factor .
Definition WetHumidGasPvt.hpp:102
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Definition MathToolbox.hpp:51