opm-common
Loading...
Searching...
No Matches
DryHumidGasPvt.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_DRY_HUMID_GAS_PVT_HPP
28#define OPM_DRY_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&);
68
69private:
70 void extendPvtgwTable_(unsigned regionIdx,
71 unsigned xIdx,
72 const SimpleTable& curTable,
73 const SimpleTable& masterTable);
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
99 const SamplingPoints& samplePoints)
100 { saturatedWaterVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
101
114 void setInverseGasFormationVolumeFactor(unsigned regionIdx,
115 const TabulatedTwoDFunction& invBg)
116 { inverseGasB_[regionIdx] = invBg; }
117
123 void setGasViscosity(unsigned regionIdx, const TabulatedTwoDFunction& mug)
124 { gasMu_[regionIdx] = mug; }
125
133 void setSaturatedGasViscosity(unsigned regionIdx,
134 const SamplingPoints& samplePoints);
135
139 void initEnd();
140
144 unsigned numRegions() const
145 { return gasReferenceDensity_.size(); }
146
150 template <class Evaluation>
151 Evaluation internalEnergy(unsigned,
152 const Evaluation&,
153 const Evaluation&,
154 const Evaluation&,
155 const Evaluation&) const
156 {
157 throw std::runtime_error("Requested the enthalpy of gas but the thermal "
158 "option is not enabled");
159 }
160
161 Scalar hVap(unsigned) const
162 {
163 throw std::runtime_error("Requested the hvap of oil but the thermal "
164 "option is not enabled");
165 }
166
170 template <class Evaluation>
171 Evaluation viscosity(unsigned regionIdx,
172 const Evaluation& /*temperature*/,
173 const Evaluation& pressure,
174 const Evaluation& /*Rv*/,
175 const Evaluation& Rvw) const
176 {
177 const Evaluation& invBg = inverseGasB_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
178 const Evaluation& invMugBg = inverseGasBMu_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
179
180 return invBg / invMugBg;
181 }
182
186 template <class Evaluation>
187 Evaluation saturatedViscosity(unsigned regionIdx,
188 const Evaluation& /*temperature*/,
189 const Evaluation& pressure) const
190 {
191 const Evaluation& invBg = inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true);
192 const Evaluation& invMugBg = inverseSaturatedGasBMu_[regionIdx].eval(pressure, /*extrapolate=*/true);
193
194 return invBg / invMugBg;
195 }
196
200 template <class Evaluation>
201 Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
202 const Evaluation& /*temperature*/,
203 const Evaluation& pressure,
204 const Evaluation& /*Rv*/,
205 const Evaluation& Rvw) const
206 { return inverseGasB_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true); }
207
211 template <class FluidState, class LhsEval = typename FluidState::Scalar>
212 std::pair<LhsEval, LhsEval>
213 inverseFormationVolumeFactorAndViscosity(const FluidState& fluidState, unsigned regionIdx)
214 {
215 const LhsEval& p = decay<LhsEval>(fluidState.pressure(FluidState::gasPhaseIdx));
216 const LhsEval& Rvw = decay<LhsEval>(fluidState.Rvw());
217
218 const auto satSegIdx = this->saturatedWaterVaporizationFactorTable_[regionIdx].findSegmentIndex(p, /*extrapolate=*/ true);
219 const auto RvwSat = this->saturatedWaterVaporizationFactorTable_[regionIdx].eval(p, SegmentIndex{satSegIdx});
220 const bool useSaturatedTables = (fluidState.saturation(FluidState::waterPhaseIdx) > 0.0) && (Rvw >= (1.0 - 1e-10) * RvwSat);
221
222 if (useSaturatedTables) {
223 const LhsEval b = this->inverseSaturatedGasB_[regionIdx].eval(p, SegmentIndex{satSegIdx});
224 const LhsEval invBMu = this->inverseSaturatedGasBMu_[regionIdx].eval(p, SegmentIndex{satSegIdx});
225 const LhsEval mu = b / invBMu;
226 return { b, mu };
227 } else {
228 unsigned ii, jj1, jj2;
229 LhsEval alpha, beta1, beta2;
230 this->inverseGasB_[regionIdx].findPoints(ii, jj1, jj2, alpha, beta1, beta2, p, Rvw, /*extrapolate =*/ true);
231 const LhsEval b = this->inverseGasB_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
232 const LhsEval invBMu = this->inverseGasBMu_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
233 const LhsEval mu = b / invBMu;
234 return { b, mu };
235 }
236 }
237
241 template <class Evaluation>
242 Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
243 const Evaluation& /*temperature*/,
244 const Evaluation& pressure) const
245 { return inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true); }
246
250 template <class Evaluation>
251 Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
252 const Evaluation& /*temperature*/,
253 const Evaluation& pressure) const
254 {
255 return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure,
256 /*extrapolate=*/true);
257 }
258
262 template <class Evaluation>
263 Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
264 const Evaluation& /*temperature*/,
265 const Evaluation& pressure,
266 const Evaluation& saltConcentration) const
267 {
268 if (enableRwgSalt_) {
269 return saturatedWaterVaporizationSaltFactorTable_[regionIdx].eval(pressure,
270 saltConcentration,
271 /*extrapolate=*/true);
272 }
273 else {
274 return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure,
275 /*extrapolate=*/true);
276 }
277 }
278
282 template <class Evaluation>
283 Evaluation saturatedOilVaporizationFactor(unsigned /*regionIdx*/,
284 const Evaluation& /*temperature*/,
285 const Evaluation& /*pressure*/,
286 const Evaluation& /*oilSaturation*/,
287 const Evaluation& /*maxOilSaturation*/) const
288 { return 0.0; /* this is dry humid gas! */ }
289
293 template <class Evaluation>
294 Evaluation saturatedOilVaporizationFactor(unsigned /*regionIdx*/,
295 const Evaluation& /*temperature*/,
296 const Evaluation& /*pressure*/) const
297 { return 0.0; /* this is dry humid gas! */ }
298
307 template <class Evaluation>
308 Evaluation saturationPressure(unsigned regionIdx,
309 const Evaluation&,
310 const Evaluation& Rw) const
311 {
312 typedef MathToolbox<Evaluation> Toolbox;
313
314 const auto& RwTable = saturatedWaterVaporizationFactorTable_[regionIdx];
315 const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon() * 1e6;
316
317 // use the tabulated saturation pressure function to get a pretty good initial value
318 Evaluation pSat = saturationPressure_[regionIdx].eval(Rw, /*extrapolate=*/true);
319
320 // Newton method to do the remaining work. If the initial
321 // value is good, this should only take two to three
322 // iterations...
323 bool onProbation = false;
324 for (unsigned i = 0; i < 20; ++i) {
325 const Evaluation& f = RwTable.eval(pSat, /*extrapolate=*/true) - Rw;
326 const Evaluation& fPrime = RwTable.evalDerivative(pSat, /*extrapolate=*/true);
327
328 // If the derivative is "zero" Newton will not converge,
329 // so simply return our initial guess.
330 if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
331 return pSat;
332 }
333
334 const Evaluation& delta = f / fPrime;
335
336 pSat -= delta;
337
338 if (pSat < 0.0) {
339 // if the pressure is lower than 0 Pascals, we set it back to 0. if this
340 // happens twice, we give up and just return 0 Pa...
341 if (onProbation) {
342 return 0.0;
343 }
344
345 onProbation = true;
346 pSat = 0.0;
347 }
348
349 if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat)) * eps) {
350 return pSat;
351 }
352 }
353
354 const std::string msg =
355 "Finding saturation pressure did not converge: "
356 " pSat = " + std::to_string(getValue(pSat)) +
357 ", Rw = " + std::to_string(getValue(Rw));
358 OpmLog::debug("Wet gas saturation pressure", msg);
359 throw NumericalProblem(msg);
360 }
361
362 template <class Evaluation>
363 Evaluation diffusionCoefficient(const Evaluation& /*temperature*/,
364 const Evaluation& /*pressure*/,
365 unsigned /*compIdx*/) const
366 {
367 throw std::runtime_error("Not implemented: The PVT model does not provide "
368 "a diffusionCoefficient()");
369 }
370
371 Scalar gasReferenceDensity(unsigned regionIdx) const
372 { return gasReferenceDensity_[regionIdx]; }
373
374 Scalar waterReferenceDensity(unsigned regionIdx) const
375 { return waterReferenceDensity_[regionIdx]; }
376
377 const std::vector<TabulatedTwoDFunction>& inverseGasB() const
378 { return inverseGasB_; }
379
380 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasB() const
381 { return inverseSaturatedGasB_; }
382
383 const std::vector<TabulatedTwoDFunction>& gasMu() const
384 { return gasMu_; }
385
386 const std::vector<TabulatedTwoDFunction>& inverseGasBMu() const
387 { return inverseGasBMu_; }
388
389 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasBMu() const
390 { return inverseSaturatedGasBMu_; }
391
392 const std::vector<TabulatedOneDFunction>& saturatedWaterVaporizationFactorTable() const
393 { return saturatedWaterVaporizationFactorTable_; }
394
395 const std::vector<TabulatedTwoDFunction>& saturatedWaterVaporizationSaltFactorTable() const
396 { return saturatedWaterVaporizationSaltFactorTable_; }
397
398 const std::vector<TabulatedOneDFunction>& saturationPressure() const
399 { return saturationPressure_; }
400
401 Scalar vapPar1() const
402 { return vapPar1_; }
403
404private:
405 void updateSaturationPressure_(unsigned regionIdx);
406
407 std::vector<Scalar> gasReferenceDensity_{};
408 std::vector<Scalar> waterReferenceDensity_{};
409 std::vector<TabulatedTwoDFunction> inverseGasB_{};
410 std::vector<TabulatedOneDFunction> inverseSaturatedGasB_{};
411 std::vector<TabulatedTwoDFunction> gasMu_{};
412 std::vector<TabulatedTwoDFunction> inverseGasBMu_{};
413 std::vector<TabulatedOneDFunction> inverseSaturatedGasBMu_{};
414 std::vector<TabulatedOneDFunction> saturatedWaterVaporizationFactorTable_{};
415 std::vector<TabulatedTwoDFunction> saturatedWaterVaporizationSaltFactorTable_{};
416 std::vector<TabulatedOneDFunction> saturationPressure_{};
417
418 bool enableRwgSalt_ = false;
419 Scalar vapPar1_ = 0.0;
420};
421
422} // namespace Opm
423
424#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...
This class represents the Pressure-Volume-Temperature relations of the gas phase with vaporized water...
Definition DryHumidGasPvt.hpp:54
Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &, const Evaluation &Rvw) const
Returns the formation volume factor [-] of the fluid phase.
Definition DryHumidGasPvt.hpp:201
Evaluation saturatedOilVaporizationFactor(unsigned, const Evaluation &, const Evaluation &, const Evaluation &, const Evaluation &) const
Returns the oil vaporization factor [m^3/m^3] of the oil phase.
Definition DryHumidGasPvt.hpp:283
void setGasViscosity(unsigned regionIdx, const TabulatedTwoDFunction &mug)
Initialize the viscosity of the gas phase.
Definition DryHumidGasPvt.hpp:123
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 DryHumidGasPvt.hpp:308
void setInverseGasFormationVolumeFactor(unsigned regionIdx, const TabulatedTwoDFunction &invBg)
Initialize the function for the gas formation volume factor.
Definition DryHumidGasPvt.hpp:114
void initEnd()
Finish initializing the gas phase PVT properties.
Definition DryHumidGasPvt.cpp:302
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition DryHumidGasPvt.hpp:144
void setReferenceDensities(unsigned regionIdx, Scalar, Scalar rhoRefGas, Scalar rhoRefWater)
Initialize the reference densities of all fluids for a given PVT region.
Definition DryHumidGasPvt.cpp:257
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 DryHumidGasPvt.hpp:151
Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the water vaporization factor [m^3/m^3] of the water phase.
Definition DryHumidGasPvt.hpp:251
void setSaturatedGasWaterVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil vaporization factor .
Definition DryHumidGasPvt.hpp:98
Evaluation viscosity(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &, const Evaluation &Rvw) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition DryHumidGasPvt.hpp:171
void setSaturatedGasViscosity(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the phase viscosity for oil saturated gas.
Definition DryHumidGasPvt.cpp:268
std::pair< LhsEval, LhsEval > inverseFormationVolumeFactorAndViscosity(const FluidState &fluidState, unsigned regionIdx)
Returns the formation volume factor [-] and viscosity [Pa s] of the fluid phase.
Definition DryHumidGasPvt.hpp:213
Evaluation saturatedOilVaporizationFactor(unsigned, const Evaluation &, const Evaluation &) const
Returns the oil vaporization factor [m^3/m^3] of the oil phase.
Definition DryHumidGasPvt.hpp:294
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 DryHumidGasPvt.hpp:263
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 DryHumidGasPvt.hpp:187
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the formation volume factor [-] of water saturated gas at a given pressure.
Definition DryHumidGasPvt.hpp:242
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 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