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
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 extendPvtgwTable_(unsigned regionIdx,
68 unsigned xIdx,
69 const SimpleTable& curTable,
70 const SimpleTable& masterTable);
71
72 void extendPvtgTable_(unsigned regionIdx,
73 unsigned xIdx,
74 const SimpleTable& curTable,
75 const SimpleTable& masterTable);
76
77public:
78#endif // HAVE_ECL_INPUT
79
80 void setNumRegions(size_t numRegions);
81
82 void setVapPars(const Scalar par1, const Scalar)
83 {
84 vapPar1_ = par1;
85 }
86
90 void setReferenceDensities(unsigned regionIdx,
91 Scalar rhoRefOil,
92 Scalar rhoRefGas,
93 Scalar rhoRefWater);
94
100 void setSaturatedGasWaterVaporizationFactor(unsigned regionIdx, const SamplingPoints& samplePoints)
101 { saturatedWaterVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
102
108 void setSaturatedGasOilVaporizationFactor(unsigned regionIdx, const SamplingPoints& samplePoints)
109 { saturatedOilVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
110
111
115 void initEnd();
116
120 unsigned numRegions() const
121 { return gasReferenceDensity_.size(); }
122
126 template <class Evaluation>
127 Evaluation internalEnergy(unsigned,
128 const Evaluation&,
129 const Evaluation&,
130 const Evaluation&,
131 const Evaluation&) const
132 {
133 throw std::runtime_error("Requested the enthalpy of gas but the thermal option is not enabled");
134 }
135
139 template <class Evaluation>
140 Evaluation viscosity(unsigned regionIdx,
141 const Evaluation& /*temperature*/,
142 const Evaluation& pressure,
143 const Evaluation& Rv,
144 const Evaluation& Rvw) const
145 {
146 const Evaluation& temperature = 1E30;
147
148 if (Rv >= (1.0 - 1e-10)*saturatedOilVaporizationFactor(regionIdx, temperature, pressure)) {
149 const Evaluation& invBg = inverseGasBRvSat_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
150 const Evaluation& invMugBg = inverseGasBMuRvSat_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
151 return invBg/invMugBg;
152 }
153 else {
154 // for Rv undersaturated viscosity is evaluated at saturated Rvw values
155 const Evaluation& invBg = inverseGasBRvwSat_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true);
156 const Evaluation& invMugBg = inverseGasBMuRvwSat_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true);
157 return invBg/invMugBg;
158 }
159 }
160
164 template <class Evaluation>
165 Evaluation saturatedViscosity(unsigned regionIdx,
166 const Evaluation& /*temperature*/,
167 const Evaluation& pressure) const
168 {
169 const Evaluation& invBg = inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true);
170 const Evaluation& invMugBg = inverseSaturatedGasBMu_[regionIdx].eval(pressure, /*extrapolate=*/true);
171
172 return invBg/invMugBg;
173 }
174
178 // template <class Evaluation>
179 // Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
180 // const Evaluation& /*temperature*/,
181 // const Evaluation& pressure,
182 // const Evaluation& Rw) const
183 // { return inverseGasB_[regionIdx].eval(pressure, Rw, /*extrapolate=*/true); }
184
185 template <class Evaluation>
186 Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
187 const Evaluation& /*temperature*/,
188 const Evaluation& pressure,
189 const Evaluation& Rv,
190 const Evaluation& Rvw) const
191 {
192 const Evaluation& temperature = 1E30;
193
194 if (Rv >= (1.0 - 1e-10)*saturatedOilVaporizationFactor(regionIdx, temperature, pressure)) {
195 return inverseGasBRvSat_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
196 }
197 else {
198 // for Rv undersaturated Bg^-1 is evaluated at saturated Rvw values
199 return inverseGasBRvwSat_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true);
200 }
201
202 }
203
204
208 template <class Evaluation>
209 Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
210 const Evaluation& /*temperature*/,
211 const Evaluation& pressure) const
212 { return inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true); }
213
217 template <class Evaluation>
218 Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
219 const Evaluation& /*temperature*/,
220 const Evaluation& pressure) const
221 {
222 return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
223 }
224
228 template <class Evaluation>
229 Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
230 const Evaluation& /*temperature*/,
231 const Evaluation& pressure,
232 const Evaluation& saltConcentration) const
233 {
234 if (enableRwgSalt_)
235 return saturatedWaterVaporizationSaltFactorTable_[regionIdx].eval(pressure, saltConcentration, /*extrapolate=*/true);
236 else {
237 return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
238 }
239
240 }
241
242 template <class Evaluation>
243 Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
244 const Evaluation& /*temperature*/,
245 const Evaluation& pressure) const
246 {
247 return saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
248 }
249
257 template <class Evaluation>
258 Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
259 const Evaluation& /*temperature*/,
260 const Evaluation& pressure,
261 const Evaluation& oilSaturation,
262 Evaluation maxOilSaturation) const
263 {
264 Evaluation tmp =
265 saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
266
267 // apply the vaporization parameters for the gas phase (cf. the Eclipse VAPPARS
268 // keyword)
269 maxOilSaturation = min(maxOilSaturation, Scalar(1.0));
270 if (vapPar1_ > 0.0 && maxOilSaturation > 0.01 && oilSaturation < maxOilSaturation) {
271 constexpr const Scalar eps = 0.001;
272 const Evaluation& So = max(oilSaturation, eps);
273 tmp *= max(1e-3, pow(So/maxOilSaturation, vapPar1_));
274 }
275
276 return tmp;
277 }
278
286 //PJPE assume dependence on Rv
287 template <class Evaluation>
288 Evaluation saturationPressure(unsigned regionIdx,
289 const Evaluation&,
290 const Evaluation& Rw) const
291 {
292 using Toolbox = MathToolbox<Evaluation>;
293
294 const auto& RwTable = saturatedWaterVaporizationFactorTable_[regionIdx];
295 constexpr const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon()*1e6;
296
297 // use the tabulated saturation pressure function to get a pretty good initial value
298 Evaluation pSat = saturationPressure_[regionIdx].eval(Rw, /*extrapolate=*/true);
299
300 // Newton method to do the remaining work. If the initial
301 // value is good, this should only take two to three
302 // iterations...
303 bool onProbation = false;
304 for (unsigned i = 0; i < 20; ++i) {
305 const Evaluation& f = RwTable.eval(pSat, /*extrapolate=*/true) - Rw;
306 const Evaluation& fPrime = RwTable.evalDerivative(pSat, /*extrapolate=*/true);
307
308 // If the derivative is "zero" Newton will not converge,
309 // so simply return our initial guess.
310 if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
311 return pSat;
312 }
313
314 const Evaluation& delta = f/fPrime;
315
316 pSat -= delta;
317
318 if (pSat < 0.0) {
319 // if the pressure is lower than 0 Pascals, we set it back to 0. if this
320 // happens twice, we give up and just return 0 Pa...
321 if (onProbation)
322 return 0.0;
323
324 onProbation = true;
325 pSat = 0.0;
326 }
327
328 if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat))*eps)
329 return pSat;
330 }
331
332 const std::string msg =
333 "Finding saturation pressure did not converge: "
334 "pSat = " + std::to_string(getValue(pSat)) +
335 ", Rw = " + std::to_string(getValue(Rw));
336 OpmLog::debug("Wet gas saturation pressure", msg);
337 throw NumericalProblem(msg);
338 }
339
340 template <class Evaluation>
341 Evaluation diffusionCoefficient(const Evaluation& /*temperature*/,
342 const Evaluation& /*pressure*/,
343 unsigned /*compIdx*/) const
344 {
345 throw std::runtime_error("Not implemented: The PVT model does not provide a diffusionCoefficient()");
346 }
347
348 Scalar gasReferenceDensity(unsigned regionIdx) const
349 { return gasReferenceDensity_[regionIdx]; }
350
351 Scalar oilReferenceDensity(unsigned regionIdx) const
352 { return oilReferenceDensity_[regionIdx]; }
353
354 Scalar waterReferenceDensity(unsigned regionIdx) const
355 { return waterReferenceDensity_[regionIdx]; }
356
357 const std::vector<TabulatedTwoDFunction>& inverseGasB() const {
358 return inverseGasBRvSat_;
359 }
360
361 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasB() const {
362 return inverseSaturatedGasB_;
363 }
364
365 const std::vector<TabulatedTwoDFunction>& gasMu() const {
366 return gasMuRvSat_;
367 }
368
369 const std::vector<TabulatedTwoDFunction>& inverseGasBMu() const {
370 return inverseGasBMuRvSat_;
371 }
372
373 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasBMu() const {
374 return inverseSaturatedGasBMu_;
375 }
376
377 const std::vector<TabulatedOneDFunction>& saturatedWaterVaporizationFactorTable() const {
378 return saturatedWaterVaporizationFactorTable_;
379 }
380
381 const std::vector<TabulatedTwoDFunction>& saturatedWaterVaporizationSaltFactorTable() const {
382 return saturatedWaterVaporizationSaltFactorTable_;
383 }
384
385 const std::vector<TabulatedOneDFunction>& saturatedOilVaporizationFactorTable() const {
386 return saturatedOilVaporizationFactorTable_;
387 }
388
389 const std::vector<TabulatedOneDFunction>& saturationPressure() const {
390 return saturationPressure_;
391 }
392
393 Scalar vapPar1() const {
394 return vapPar1_;
395 }
396
397private:
398 void updateSaturationPressure_(unsigned regionIdx);
399
400 std::vector<Scalar> gasReferenceDensity_;
401 std::vector<Scalar> oilReferenceDensity_;
402 std::vector<Scalar> waterReferenceDensity_;
403 std::vector<TabulatedTwoDFunction> inverseGasBRvwSat_;
404 std::vector<TabulatedTwoDFunction> inverseGasBRvSat_;
405 std::vector<TabulatedOneDFunction> inverseSaturatedGasB_;
406 std::vector<TabulatedTwoDFunction> gasMuRvwSat_;
407 std::vector<TabulatedTwoDFunction> gasMuRvSat_;
408 std::vector<TabulatedTwoDFunction> inverseGasBMuRvwSat_;
409 std::vector<TabulatedTwoDFunction> inverseGasBMuRvSat_;
410 std::vector<TabulatedOneDFunction> inverseSaturatedGasBMu_;
411 std::vector<TabulatedOneDFunction> saturatedWaterVaporizationFactorTable_;
412 std::vector<TabulatedTwoDFunction> saturatedWaterVaporizationSaltFactorTable_;
413 std::vector<TabulatedOneDFunction> saturatedOilVaporizationFactorTable_;
414 std::vector<TabulatedOneDFunction> saturationPressure_;
415
416 bool enableRwgSalt_ = false;
417 Scalar vapPar1_ = 0.0;
418};
419
420} // namespace Opm
421
422#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:88
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 phase with vaporized oil a...
Definition WetHumidGasPvt.hpp:51
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:288
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition WetHumidGasPvt.hpp:120
void setSaturatedGasOilVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil vaporization factor .
Definition WetHumidGasPvt.hpp:108
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:140
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:229
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:209
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:218
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:165
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:258
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:186
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:127
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:100
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Definition MathToolbox.hpp:50