My Project
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
85 void setReferenceDensities(unsigned regionIdx,
86 Scalar rhoRefOil,
87 Scalar rhoRefGas,
88 Scalar rhoRefWater);
89
95 void setSaturatedGasWaterVaporizationFactor(unsigned regionIdx, const SamplingPoints& samplePoints)
96 { saturatedWaterVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
97
103 void setSaturatedGasOilVaporizationFactor(unsigned regionIdx, const SamplingPoints& samplePoints)
104 { saturatedOilVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
105
106
110 void initEnd();
111
115 unsigned numRegions() const
116 { return gasReferenceDensity_.size(); }
117
121 template <class Evaluation>
122 Evaluation internalEnergy(unsigned,
123 const Evaluation&,
124 const Evaluation&,
125 const Evaluation&,
126 const Evaluation&) const
127 {
128 throw std::runtime_error("Requested the enthalpy of gas but the thermal option is not enabled");
129 }
130
134 template <class Evaluation>
135 Evaluation viscosity(unsigned regionIdx,
136 const Evaluation& /*temperature*/,
137 const Evaluation& pressure,
138 const Evaluation& Rv,
139 const Evaluation& Rvw) const
140 {
141 const Evaluation& temperature = 1E30;
142
143 if (Rv >= (1.0 - 1e-10)*saturatedOilVaporizationFactor(regionIdx, temperature, pressure)) {
144 const Evaluation& invBg = inverseGasBRvSat_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
145 const Evaluation& invMugBg = inverseGasBMuRvSat_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
146 return invBg/invMugBg;
147 }
148 else {
149 // for Rv undersaturated viscosity is evaluated at saturated Rvw values
150 const Evaluation& invBg = inverseGasBRvwSat_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true);
151 const Evaluation& invMugBg = inverseGasBMuRvwSat_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true);
152 return invBg/invMugBg;
153 }
154 }
155
159 template <class Evaluation>
160 Evaluation saturatedViscosity(unsigned regionIdx,
161 const Evaluation& /*temperature*/,
162 const Evaluation& pressure) const
163 {
164 const Evaluation& invBg = inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true);
165 const Evaluation& invMugBg = inverseSaturatedGasBMu_[regionIdx].eval(pressure, /*extrapolate=*/true);
166
167 return invBg/invMugBg;
168 }
169
173 // template <class Evaluation>
174 // Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
175 // const Evaluation& /*temperature*/,
176 // const Evaluation& pressure,
177 // const Evaluation& Rw) const
178 // { return inverseGasB_[regionIdx].eval(pressure, Rw, /*extrapolate=*/true); }
179
180 template <class Evaluation>
181 Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
182 const Evaluation& /*temperature*/,
183 const Evaluation& pressure,
184 const Evaluation& Rv,
185 const Evaluation& Rvw) const
186 {
187 const Evaluation& temperature = 1E30;
188
189 if (Rv >= (1.0 - 1e-10)*saturatedOilVaporizationFactor(regionIdx, temperature, pressure)) {
190 return inverseGasBRvSat_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
191 }
192 else {
193 // for Rv undersaturated Bg^-1 is evaluated at saturated Rvw values
194 return inverseGasBRvwSat_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true);
195 }
196
197 }
198
199
203 template <class Evaluation>
204 Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
205 const Evaluation& /*temperature*/,
206 const Evaluation& pressure) const
207 { return inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true); }
208
212 template <class Evaluation>
213 Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
214 const Evaluation& /*temperature*/,
215 const Evaluation& pressure) const
216 {
217 return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
218 }
219
223 template <class Evaluation>
224 Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
225 const Evaluation& /*temperature*/,
226 const Evaluation& pressure,
227 const Evaluation& saltConcentration) const
228 {
229 if (enableRwgSalt_)
230 return saturatedWaterVaporizationSaltFactorTable_[regionIdx].eval(pressure, saltConcentration, /*extrapolate=*/true);
231 else {
232 return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
233 }
234
235 }
236
237 template <class Evaluation>
238 Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
239 const Evaluation& /*temperature*/,
240 const Evaluation& pressure) const
241 {
242 return saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
243 }
244
252 template <class Evaluation>
253 Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
254 const Evaluation& /*temperature*/,
255 const Evaluation& pressure,
256 const Evaluation& oilSaturation,
257 Evaluation maxOilSaturation) const
258 {
259 Evaluation tmp =
260 saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
261
262 // apply the vaporization parameters for the gas phase (cf. the Eclipse VAPPARS
263 // keyword)
264 maxOilSaturation = min(maxOilSaturation, Scalar(1.0));
265 if (vapPar1_ > 0.0 && maxOilSaturation > 0.01 && oilSaturation < maxOilSaturation) {
266 constexpr const Scalar eps = 0.001;
267 const Evaluation& So = max(oilSaturation, eps);
268 tmp *= max(1e-3, pow(So/maxOilSaturation, vapPar1_));
269 }
270
271 return tmp;
272 }
273
281 //PJPE assume dependence on Rv
282 template <class Evaluation>
283 Evaluation saturationPressure(unsigned regionIdx,
284 const Evaluation&,
285 const Evaluation& Rw) const
286 {
287 using Toolbox = MathToolbox<Evaluation>;
288
289 const auto& RwTable = saturatedWaterVaporizationFactorTable_[regionIdx];
290 constexpr const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon()*1e6;
291
292 // use the tabulated saturation pressure function to get a pretty good initial value
293 Evaluation pSat = saturationPressure_[regionIdx].eval(Rw, /*extrapolate=*/true);
294
295 // Newton method to do the remaining work. If the initial
296 // value is good, this should only take two to three
297 // iterations...
298 bool onProbation = false;
299 for (unsigned i = 0; i < 20; ++i) {
300 const Evaluation& f = RwTable.eval(pSat, /*extrapolate=*/true) - Rw;
301 const Evaluation& fPrime = RwTable.evalDerivative(pSat, /*extrapolate=*/true);
302
303 // If the derivative is "zero" Newton will not converge,
304 // so simply return our initial guess.
305 if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
306 return pSat;
307 }
308
309 const Evaluation& delta = f/fPrime;
310
311 pSat -= delta;
312
313 if (pSat < 0.0) {
314 // if the pressure is lower than 0 Pascals, we set it back to 0. if this
315 // happens twice, we give up and just return 0 Pa...
316 if (onProbation)
317 return 0.0;
318
319 onProbation = true;
320 pSat = 0.0;
321 }
322
323 if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat))*eps)
324 return pSat;
325 }
326
327 const std::string msg =
328 "Finding saturation pressure did not converge: "
329 "pSat = " + std::to_string(getValue(pSat)) +
330 ", Rw = " + std::to_string(getValue(Rw));
331 OpmLog::debug("Wet gas saturation pressure", msg);
332 throw NumericalProblem(msg);
333 }
334
335 template <class Evaluation>
336 Evaluation diffusionCoefficient(const Evaluation& /*temperature*/,
337 const Evaluation& /*pressure*/,
338 unsigned /*compIdx*/) const
339 {
340 throw std::runtime_error("Not implemented: The PVT model does not provide a diffusionCoefficient()");
341 }
342
343 Scalar gasReferenceDensity(unsigned regionIdx) const
344 { return gasReferenceDensity_[regionIdx]; }
345
346 Scalar oilReferenceDensity(unsigned regionIdx) const
347 { return oilReferenceDensity_[regionIdx]; }
348
349 Scalar waterReferenceDensity(unsigned regionIdx) const
350 { return waterReferenceDensity_[regionIdx]; }
351
352 const std::vector<TabulatedTwoDFunction>& inverseGasB() const {
353 return inverseGasBRvSat_;
354 }
355
356 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasB() const {
357 return inverseSaturatedGasB_;
358 }
359
360 const std::vector<TabulatedTwoDFunction>& gasMu() const {
361 return gasMuRvSat_;
362 }
363
364 const std::vector<TabulatedTwoDFunction>& inverseGasBMu() const {
365 return inverseGasBMuRvSat_;
366 }
367
368 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasBMu() const {
369 return inverseSaturatedGasBMu_;
370 }
371
372 const std::vector<TabulatedOneDFunction>& saturatedWaterVaporizationFactorTable() const {
373 return saturatedWaterVaporizationFactorTable_;
374 }
375
376 const std::vector<TabulatedTwoDFunction>& saturatedWaterVaporizationSaltFactorTable() const {
377 return saturatedWaterVaporizationSaltFactorTable_;
378 }
379
380 const std::vector<TabulatedOneDFunction>& saturatedOilVaporizationFactorTable() const {
381 return saturatedOilVaporizationFactorTable_;
382 }
383
384 const std::vector<TabulatedOneDFunction>& saturationPressure() const {
385 return saturationPressure_;
386 }
387
388 Scalar vapPar1() const {
389 return vapPar1_;
390 }
391
392private:
393 void updateSaturationPressure_(unsigned regionIdx);
394
395 std::vector<Scalar> gasReferenceDensity_;
396 std::vector<Scalar> oilReferenceDensity_;
397 std::vector<Scalar> waterReferenceDensity_;
398 std::vector<TabulatedTwoDFunction> inverseGasBRvwSat_;
399 std::vector<TabulatedTwoDFunction> inverseGasBRvSat_;
400 std::vector<TabulatedOneDFunction> inverseSaturatedGasB_;
401 std::vector<TabulatedTwoDFunction> gasMuRvwSat_;
402 std::vector<TabulatedTwoDFunction> gasMuRvSat_;
403 std::vector<TabulatedTwoDFunction> inverseGasBMuRvwSat_;
404 std::vector<TabulatedTwoDFunction> inverseGasBMuRvSat_;
405 std::vector<TabulatedOneDFunction> inverseSaturatedGasBMu_;
406 std::vector<TabulatedOneDFunction> saturatedWaterVaporizationFactorTable_;
407 std::vector<TabulatedTwoDFunction> saturatedWaterVaporizationSaltFactorTable_;
408 std::vector<TabulatedOneDFunction> saturatedOilVaporizationFactorTable_;
409 std::vector<TabulatedOneDFunction> saturationPressure_;
410
411 bool enableRwgSalt_ = false;
412 Scalar vapPar1_ = 0.0;
413};
414
415} // namespace Opm
416
417#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 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:283
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition: WetHumidGasPvt.hpp:115
void setSaturatedGasOilVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil vaporization factor .
Definition: WetHumidGasPvt.hpp:103
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:135
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:224
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:204
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:213
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:160
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:253
void setReferenceDensities(unsigned regionIdx, Scalar rhoRefOil, Scalar rhoRefGas, Scalar rhoRefWater)
Initialize the reference densities of all fluids for a given PVT region.
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:181
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:122
void initEnd()
Finish initializing the gas phase PVT properties.
void setSaturatedGasWaterVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the water vaporization factor .
Definition: WetHumidGasPvt.hpp:95
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: MathToolbox.hpp:50