opm-common
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
37
38#include <cstddef>
39
40namespace Opm {
41
42#if HAVE_ECL_INPUT
43class EclipseState;
44class Schedule;
45class SimpleTable;
46#endif
47
52template <class Scalar>
54{
55 using SamplingPoints = std::vector<std::pair<Scalar, Scalar>>;
56
57public:
58 using TabulatedTwoDFunction = UniformXTabulated2DFunction<Scalar>;
59 using TabulatedOneDFunction = Tabulated1DFunction<Scalar>;
60
61#if HAVE_ECL_INPUT
67 void initFromState(const EclipseState& eclState, const Schedule& schedule);
68
69private:
70 void extendPvtgwTable_(unsigned regionIdx,
71 unsigned xIdx,
72 const SimpleTable& curTable,
73 const SimpleTable& masterTable);
74
75 void extendPvtgTable_(unsigned regionIdx,
76 unsigned xIdx,
77 const SimpleTable& curTable,
78 const SimpleTable& masterTable);
79
80public:
81#endif // HAVE_ECL_INPUT
82
83 void setNumRegions(std::size_t numRegions);
84
85 void setVapPars(const Scalar par1, const Scalar)
86 {
87 vapPar1_ = par1;
88 }
89
93 void setReferenceDensities(unsigned regionIdx,
94 Scalar rhoRefOil,
95 Scalar rhoRefGas,
96 Scalar rhoRefWater);
97
105 const SamplingPoints& samplePoints)
106 { saturatedWaterVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
107
115 const SamplingPoints& samplePoints)
116 { saturatedOilVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
117
121 void initEnd();
122
126 unsigned numRegions() const
127 { return gasReferenceDensity_.size(); }
128
132 template <class Evaluation>
133 Evaluation internalEnergy(unsigned,
134 const Evaluation&,
135 const Evaluation&,
136 const Evaluation&,
137 const Evaluation&) const
138 {
139 throw std::runtime_error("Requested the enthalpy of gas but the thermal "
140 "option is not enabled");
141 }
142
143 Scalar hVap(unsigned) const
144 {
145 throw std::runtime_error("Requested the hvap of oil but the thermal "
146 "option is not enabled");
147 }
148
152 template <class Evaluation>
153 Evaluation viscosity(unsigned regionIdx,
154 const Evaluation& /*temperature*/,
155 const Evaluation& pressure,
156 const Evaluation& Rv,
157 const Evaluation& Rvw) const
158 {
159 const Evaluation& temperature = 1E30;
160
161 if (Rv >= (1.0 - 1e-10) * saturatedOilVaporizationFactor(regionIdx, temperature, pressure)) {
162 const Evaluation& invBg = inverseGasBRvSat_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
163 const Evaluation& invMugBg = inverseGasBMuRvSat_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
164 return invBg / invMugBg;
165 }
166 else {
167 // for Rv undersaturated viscosity is evaluated at saturated Rvw values
168 const Evaluation& invBg = inverseGasBRvwSat_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true);
169 const Evaluation& invMugBg = inverseGasBMuRvwSat_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true);
170 return invBg / invMugBg;
171 }
172 }
173
177 template <class Evaluation>
178 Evaluation saturatedViscosity(unsigned regionIdx,
179 const Evaluation& /*temperature*/,
180 const Evaluation& pressure) const
181 {
182 const Evaluation& invBg = inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true);
183 const Evaluation& invMugBg = inverseSaturatedGasBMu_[regionIdx].eval(pressure, /*extrapolate=*/true);
184
185 return invBg / invMugBg;
186 }
187
191 // template <class Evaluation>
192 // Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
193 // const Evaluation& /*temperature*/,
194 // const Evaluation& pressure,
195 // const Evaluation& Rw) const
196 // { return inverseGasB_[regionIdx].eval(pressure, Rw, /*extrapolate=*/true); }
197
198 template <class Evaluation>
199 Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
200 const Evaluation& /*temperature*/,
201 const Evaluation& pressure,
202 const Evaluation& Rv,
203 const Evaluation& Rvw) const
204 {
205 const Evaluation& temperature = 1E30;
206
207 if (Rv >= (1.0 - 1e-10) * saturatedOilVaporizationFactor(regionIdx, temperature, pressure)) {
208 return inverseGasBRvSat_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
209 }
210 else {
211 // for Rv undersaturated Bg^-1 is evaluated at saturated Rvw values
212 return inverseGasBRvwSat_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true);
213 }
214 }
215
219 template <class FluidState, class LhsEval = typename FluidState::Scalar>
220 std::pair<LhsEval, LhsEval>
221 inverseFormationVolumeFactorAndViscosity(const FluidState& fluidState, unsigned regionIdx)
222 {
223 const LhsEval& p = decay<LhsEval>(fluidState.pressure(FluidState::gasPhaseIdx));
224 const LhsEval& Rv = decay<LhsEval>(fluidState.Rv());
225 const LhsEval& Rvw = decay<LhsEval>(fluidState.Rvw());
226 const LhsEval& saltConc
227 = BlackOil::template getSaltConcentration_<FluidState, LhsEval>(fluidState, regionIdx);
228
229 // It is not guaranteed that the oil and water vaporization
230 // factor tables, and also the saturated B and Mu tables, have
231 // the same pressure sample points. Therefore we do not bother
232 // to separately call findSegmentIndex() and eval() here.
233 const auto RvSat = this->saturatedOilVaporizationFactorTable_[regionIdx].eval(p, /*extrapolate=*/ true);
234 // TODO: check that handling of salt concentration is correct, it seems to only affect the saturation curve.
235 const auto RvwSat = enableRwgSalt_
236 ? this->saturatedWaterVaporizationSaltFactorTable_[regionIdx].eval(p, saltConc, /*extrapolate=*/ true)
237 : this->saturatedWaterVaporizationFactorTable_[regionIdx].eval(p, /*extrapolate=*/true);
238
239 const bool waterSaturated = (fluidState.saturation(FluidState::waterPhaseIdx) > 0.0) && (Rvw >= (1.0 - 1e-10) * RvwSat);
240 const bool oilSaturated = (fluidState.saturation(FluidState::oilPhaseIdx) > 0.0) && (Rv >= (1.0 - 1e-10) * RvSat);
241
242 if (waterSaturated && oilSaturated) {
243 const auto satSegIdx = this->inverseSaturatedGasB_[regionIdx].findSegmentIndex(p, /*extrapolate=*/ true);
244 const LhsEval b = this->inverseSaturatedGasB_[regionIdx].eval(p, SegmentIndex{satSegIdx});
245 const LhsEval invBMu = this->inverseSaturatedGasBMu_[regionIdx].eval(p, SegmentIndex{satSegIdx});
246 const LhsEval mu = b / invBMu;
247 return { b, mu };
248 } else if (oilSaturated) {
249 unsigned ii, jj1, jj2;
250 LhsEval alpha, beta1, beta2;
251 this->inverseGasBRvSat_[regionIdx].findPoints(ii, jj1, jj2, alpha, beta1, beta2, p, Rvw, /*extrapolate =*/ true);
252 const LhsEval b = this->inverseGasBRvSat_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
253 const LhsEval invBMu = this->inverseGasBMuRvSat_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
254 const LhsEval mu = b / invBMu;
255 return { b, mu };
256 } else {
257 // At this point, we assume waterSaturated is true, but this is not checked.
258 unsigned ii, jj1, jj2;
259 LhsEval alpha, beta1, beta2;
260 this->inverseGasBRvwSat_[regionIdx].findPoints(ii, jj1, jj2, alpha, beta1, beta2, p, Rv, /*extrapolate =*/ true);
261 const LhsEval b = this->inverseGasBRvwSat_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
262 const LhsEval invBMu = this->inverseGasBMuRvwSat_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
263 const LhsEval mu = b / invBMu;
264 return { b, mu };
265 }
266 }
267
271 template <class Evaluation>
272 Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
273 const Evaluation& /*temperature*/,
274 const Evaluation& pressure) const
275 { return inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true); }
276
280 template <class Evaluation>
281 Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
282 const Evaluation& /*temperature*/,
283 const Evaluation& pressure) const
284 {
285 return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
286 }
287
291 template <class Evaluation>
292 Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
293 const Evaluation& /*temperature*/,
294 const Evaluation& pressure,
295 const Evaluation& saltConcentration) const
296 {
297 if (enableRwgSalt_) {
298 return saturatedWaterVaporizationSaltFactorTable_[regionIdx].eval(pressure, saltConcentration, /*extrapolate=*/true);
299 }
300 else {
301 return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
302 }
303 }
304
305 template <class Evaluation>
306 Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
307 const Evaluation& /*temperature*/,
308 const Evaluation& pressure) const
309 {
310 return saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
311 }
312
320 template <class Evaluation>
321 Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
322 const Evaluation& /*temperature*/,
323 const Evaluation& pressure,
324 const Evaluation& oilSaturation,
325 Evaluation maxOilSaturation) const
326 {
327 Evaluation tmp =
328 saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
329
330 // apply the vaporization parameters for the gas phase (cf. the Eclipse VAPPARS
331 // keyword)
332 maxOilSaturation = min(maxOilSaturation, Scalar(1.0));
333 if (vapPar1_ > 0.0 && maxOilSaturation > 0.01 && oilSaturation < maxOilSaturation) {
334 constexpr const Scalar eps = 0.001;
335 const Evaluation& So = max(oilSaturation, eps);
336 tmp *= max(1e-3, pow(So / maxOilSaturation, vapPar1_));
337 }
338
339 return tmp;
340 }
341
350 //PJPE assume dependence on Rv
351 template <class Evaluation>
352 Evaluation saturationPressure(unsigned regionIdx,
353 const Evaluation&,
354 const Evaluation& Rw) const
355 {
356 using Toolbox = MathToolbox<Evaluation>;
357
358 const auto& RwTable = saturatedWaterVaporizationFactorTable_[regionIdx];
359 constexpr const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon() * 1e6;
360
361 // use the tabulated saturation pressure function to get a pretty good initial value
362 Evaluation pSat = saturationPressure_[regionIdx].eval(Rw, /*extrapolate=*/true);
363
364 // Newton method to do the remaining work. If the initial
365 // value is good, this should only take two to three
366 // iterations...
367 bool onProbation = false;
368 for (unsigned i = 0; i < 20; ++i) {
369 const Evaluation& f = RwTable.eval(pSat, /*extrapolate=*/true) - Rw;
370 const Evaluation& fPrime = RwTable.evalDerivative(pSat, /*extrapolate=*/true);
371
372 // If the derivative is "zero" Newton will not converge,
373 // so simply return our initial guess.
374 if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
375 return pSat;
376 }
377
378 const Evaluation& delta = f / fPrime;
379
380 pSat -= delta;
381
382 if (pSat < 0.0) {
383 // if the pressure is lower than 0 Pascals, we set it back to 0. if this
384 // happens twice, we give up and just return 0 Pa...
385 if (onProbation) {
386 return 0.0;
387 }
388
389 onProbation = true;
390 pSat = 0.0;
391 }
392
393 if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat))*eps) {
394 return pSat;
395 }
396 }
397
398 const std::string msg =
399 "Finding saturation pressure did not converge: "
400 "pSat = " + std::to_string(getValue(pSat)) +
401 ", Rw = " + std::to_string(getValue(Rw));
402 OpmLog::debug("Wet gas saturation pressure", msg);
403 throw NumericalProblem(msg);
404 }
405
406 template <class Evaluation>
407 Evaluation diffusionCoefficient(const Evaluation& /*temperature*/,
408 const Evaluation& /*pressure*/,
409 unsigned /*compIdx*/) const
410 {
411 throw std::runtime_error("Not implemented: The PVT model does not provide "
412 "a diffusionCoefficient()");
413 }
414
415 Scalar gasReferenceDensity(unsigned regionIdx) const
416 { return gasReferenceDensity_[regionIdx]; }
417
418 Scalar oilReferenceDensity(unsigned regionIdx) const
419 { return oilReferenceDensity_[regionIdx]; }
420
421 Scalar waterReferenceDensity(unsigned regionIdx) const
422 { return waterReferenceDensity_[regionIdx]; }
423
424 const std::vector<TabulatedTwoDFunction>& inverseGasB() const
425 { return inverseGasBRvSat_; }
426
427 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasB() const
428 { return inverseSaturatedGasB_; }
429
430 const std::vector<TabulatedTwoDFunction>& gasMu() const
431 { return gasMuRvSat_; }
432
433 const std::vector<TabulatedTwoDFunction>& inverseGasBMu() const
434 { return inverseGasBMuRvSat_; }
435
436 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasBMu() const
437 { return inverseSaturatedGasBMu_; }
438
439 const std::vector<TabulatedOneDFunction>& saturatedWaterVaporizationFactorTable() const
440 { return saturatedWaterVaporizationFactorTable_; }
441
442 const std::vector<TabulatedTwoDFunction>& saturatedWaterVaporizationSaltFactorTable() const
443 { return saturatedWaterVaporizationSaltFactorTable_; }
444
445 const std::vector<TabulatedOneDFunction>& saturatedOilVaporizationFactorTable() const
446 { return saturatedOilVaporizationFactorTable_; }
447
448 const std::vector<TabulatedOneDFunction>& saturationPressure() const
449 { return saturationPressure_; }
450
451 Scalar vapPar1() const
452 { return vapPar1_; }
453
454private:
455 void updateSaturationPressure_(unsigned regionIdx);
456
457 std::vector<Scalar> gasReferenceDensity_{};
458 std::vector<Scalar> oilReferenceDensity_{};
459 std::vector<Scalar> waterReferenceDensity_{};
460 std::vector<TabulatedTwoDFunction> inverseGasBRvwSat_{};
461 std::vector<TabulatedTwoDFunction> inverseGasBRvSat_{};
462 std::vector<TabulatedOneDFunction> inverseSaturatedGasB_{};
463 std::vector<TabulatedTwoDFunction> gasMuRvwSat_{};
464 std::vector<TabulatedTwoDFunction> gasMuRvSat_{};
465 std::vector<TabulatedTwoDFunction> inverseGasBMuRvwSat_{};
466 std::vector<TabulatedTwoDFunction> inverseGasBMuRvSat_{};
467 std::vector<TabulatedOneDFunction> inverseSaturatedGasBMu_{};
468 std::vector<TabulatedOneDFunction> saturatedWaterVaporizationFactorTable_{};
469 std::vector<TabulatedTwoDFunction> saturatedWaterVaporizationSaltFactorTable_{};
470 std::vector<TabulatedOneDFunction> saturatedOilVaporizationFactorTable_{};
471 std::vector<TabulatedOneDFunction> saturationPressure_{};
472
473 bool enableRwgSalt_ = false;
474 Scalar vapPar1_ = 0.0;
475};
476
477} // namespace Opm
478
479#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 phase with vaporized oil a...
Definition WetHumidGasPvt.hpp:54
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:352
std::pair< LhsEval, LhsEval > inverseFormationVolumeFactorAndViscosity(const FluidState &fluidState, unsigned regionIdx)
Returns the formation volume factor [-] and viscosity [Pa s] of the fluid phase.
Definition WetHumidGasPvt.hpp:221
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition WetHumidGasPvt.hpp:126
void setSaturatedGasOilVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil vaporization factor .
Definition WetHumidGasPvt.hpp:114
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:153
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:292
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:272
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:281
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:178
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:321
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:199
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:133
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:104
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