My Project
Loading...
Searching...
No Matches
WetGasPvt.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_GAS_PVT_HPP
28#define OPM_WET_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 extendPvtgTable_(unsigned regionIdx,
70 unsigned xIdx,
71 const SimpleTable& curTable,
72 const SimpleTable& masterTable);
73
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
97 void setSaturatedGasOilVaporizationFactor(unsigned regionIdx,
98 const SamplingPoints& samplePoints)
99 { saturatedOilVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
100
110 void setSaturatedGasFormationVolumeFactor(unsigned regionIdx,
111 const SamplingPoints& samplePoints);
112
125 void setInverseGasFormationVolumeFactor(unsigned regionIdx,
126 const TabulatedTwoDFunction& invBg)
127 { inverseGasB_[regionIdx] = invBg; }
128
134 void setGasViscosity(unsigned regionIdx, const TabulatedTwoDFunction& mug)
135 { gasMu_[regionIdx] = mug; }
136
144 void setSaturatedGasViscosity(unsigned regionIdx,
145 const SamplingPoints& samplePoints);
146
150 void initEnd();
151
155 unsigned numRegions() const
156 { return gasReferenceDensity_.size(); }
157
161 template <class Evaluation>
162 Evaluation internalEnergy(unsigned,
163 const Evaluation&,
164 const Evaluation&,
165 const Evaluation&,
166 const Evaluation&) const
167 {
168 throw std::runtime_error("Requested the enthalpy of gas but the thermal "
169 "option is not enabled");
170 }
171
172 Scalar hVap(unsigned) const
173 {
174 throw std::runtime_error("Requested the hvap of oil but the thermal "
175 "option is not enabled");
176 }
177
181 template <class Evaluation>
182 Evaluation viscosity(unsigned regionIdx,
183 const Evaluation& /*temperature*/,
184 const Evaluation& pressure,
185 const Evaluation& Rv,
186 const Evaluation& /*Rvw*/) const
187 {
188 const Evaluation& invBg = inverseGasB_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true);
189 const Evaluation& invMugBg = inverseGasBMu_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true);
190
191 return invBg / invMugBg;
192 }
193
197 template <class Evaluation>
198 Evaluation saturatedViscosity(unsigned regionIdx,
199 const Evaluation& /*temperature*/,
200 const Evaluation& pressure) const
201 {
202 const Evaluation& invBg = inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true);
203 const Evaluation& invMugBg = inverseSaturatedGasBMu_[regionIdx].eval(pressure, /*extrapolate=*/true);
204
205 return invBg / invMugBg;
206 }
207
211 template <class Evaluation>
212 Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
213 const Evaluation& /*temperature*/,
214 const Evaluation& pressure,
215 const Evaluation& Rv,
216 const Evaluation& /*Rvw*/) const
217 { return inverseGasB_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true); }
218
222 template <class Evaluation>
223 Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
224 const Evaluation& /*temperature*/,
225 const Evaluation& pressure) const
226 { return inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true); }
227
231 template <class Evaluation>
232 Evaluation saturatedWaterVaporizationFactor(unsigned /*regionIdx*/,
233 const Evaluation& /*temperature*/,
234 const Evaluation& /*pressure*/) const
235 { return 0.0; /* this is non-humid gas! */ }
236
240 template <class Evaluation = Scalar>
241 Evaluation saturatedWaterVaporizationFactor(unsigned /*regionIdx*/,
242 const Evaluation& /*temperature*/,
243 const Evaluation& /*pressure*/,
244 const Evaluation& /*saltConcentration*/) const
245 { return 0.0; }
246
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
297 template <class Evaluation>
298 Evaluation saturationPressure(unsigned regionIdx,
299 const Evaluation&,
300 const Evaluation& Rv) const
301 {
302 using Toolbox = MathToolbox<Evaluation>;
303
304 const auto& RvTable = saturatedOilVaporizationFactorTable_[regionIdx];
305 constexpr const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon() * 1e6;
306
307 // use the tabulated saturation pressure function to get a pretty good initial value
308 Evaluation pSat = saturationPressure_[regionIdx].eval(Rv, /*extrapolate=*/true);
309
310 // Newton method to do the remaining work. If the initial
311 // value is good, this should only take two to three
312 // iterations...
313 bool onProbation = false;
314 for (unsigned i = 0; i < 20; ++i) {
315 const Evaluation& f = RvTable.eval(pSat, /*extrapolate=*/true) - Rv;
316 const Evaluation& fPrime = RvTable.evalDerivative(pSat, /*extrapolate=*/true);
317
318 // If the derivative is "zero" Newton will not converge,
319 // so simply return our initial guess.
320 if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
321 return pSat;
322 }
323
324 const Evaluation& delta = f / fPrime;
325
326 pSat -= delta;
327
328 if (pSat < 0.0) {
329 // if the pressure is lower than 0 Pascals, we set it back to 0. if this
330 // happens twice, we give up and just return 0 Pa...
331 if (onProbation) {
332 return 0.0;
333 }
334
335 onProbation = true;
336 pSat = 0.0;
337 }
338
339 if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat))*eps) {
340 return pSat;
341 }
342 }
343
344 const std::string msg =
345 "Finding saturation pressure did not converge: "
346 "pSat = " + std::to_string(getValue(pSat)) +
347 ", Rv = " + std::to_string(getValue(Rv));
348 OpmLog::debug("Wet gas saturation pressure", msg);
349 throw NumericalProblem(msg);
350 }
351
352 template <class Evaluation>
353 Evaluation diffusionCoefficient(const Evaluation& /*temperature*/,
354 const Evaluation& /*pressure*/,
355 unsigned /*compIdx*/) const
356 {
357 throw std::runtime_error("Not implemented: The PVT model does not provide "
358 "a diffusionCoefficient()");
359 }
360
361 Scalar gasReferenceDensity(unsigned regionIdx) const
362 { return gasReferenceDensity_[regionIdx]; }
363
364 Scalar oilReferenceDensity(unsigned regionIdx) const
365 { return oilReferenceDensity_[regionIdx]; }
366
367 const std::vector<TabulatedTwoDFunction>& inverseGasB() const
368 { return inverseGasB_; }
369
370 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasB() const
371 { return inverseSaturatedGasB_; }
372
373 const std::vector<TabulatedTwoDFunction>& gasMu() const
374 { return gasMu_; }
375
376 const std::vector<TabulatedTwoDFunction>& inverseGasBMu() const
377 { return inverseGasBMu_; }
378
379 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasBMu() const
380 { return inverseSaturatedGasBMu_; }
381
382 const std::vector<TabulatedOneDFunction>& saturatedOilVaporizationFactorTable() const
383 { return saturatedOilVaporizationFactorTable_; }
384
385 const std::vector<TabulatedOneDFunction>& saturationPressure() const
386 { return saturationPressure_; }
387
388 Scalar vapPar1() const
389 { return vapPar1_; }
390
391private:
392 void updateSaturationPressure_(unsigned regionIdx);
393
394 std::vector<Scalar> gasReferenceDensity_{};
395 std::vector<Scalar> oilReferenceDensity_{};
396 std::vector<TabulatedTwoDFunction> inverseGasB_{};
397 std::vector<TabulatedOneDFunction> inverseSaturatedGasB_{};
398 std::vector<TabulatedTwoDFunction> gasMu_{};
399 std::vector<TabulatedTwoDFunction> inverseGasBMu_{};
400 std::vector<TabulatedOneDFunction> inverseSaturatedGasBMu_{};
401 std::vector<TabulatedOneDFunction> saturatedOilVaporizationFactorTable_{};
402 std::vector<TabulatedOneDFunction> saturationPressure_{};
403
404 Scalar vapPar1_ = 0.0;
405};
406
407} // namespace Opm
408
409#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 phas with vaporized oil.
Definition WetGasPvt.hpp:53
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the formation volume factor [-] of oil saturated gas at a given pressure.
Definition WetGasPvt.hpp:223
Evaluation saturatedOilVaporizationFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the oil vaporization factor [m^3/m^3] of the gas phase.
Definition WetGasPvt.hpp:251
void initEnd()
Finish initializing the gas phase PVT properties.
Definition WetGasPvt.cpp:331
Evaluation saturationPressure(unsigned regionIdx, const Evaluation &, const Evaluation &Rv) const
Returns the saturation pressure of the gas phase [Pa] depending on its mass fraction of the oil compo...
Definition WetGasPvt.hpp:298
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 WetGasPvt.hpp:162
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 WetGasPvt.hpp:266
void setGasViscosity(unsigned regionIdx, const TabulatedTwoDFunction &mug)
Initialize the viscosity of the gas phase.
Definition WetGasPvt.hpp:134
Evaluation saturatedWaterVaporizationFactor(unsigned, const Evaluation &, const Evaluation &) const
Returns the water vaporization factor [m^3/m^3] of the gasphase.
Definition WetGasPvt.hpp:232
Evaluation saturatedWaterVaporizationFactor(unsigned, const Evaluation &, const Evaluation &, const Evaluation &) const
Returns the water vaporization factor [m^3/m^3] of water saturated gas.
Definition WetGasPvt.hpp:241
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition WetGasPvt.hpp:155
void setSaturatedGasViscosity(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the phase viscosity for oil saturated gas.
Definition WetGasPvt.cpp:297
void setSaturatedGasFormationVolumeFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the gas formation volume factor.
Definition WetGasPvt.cpp:246
Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &Rv, const Evaluation &) const
Returns the formation volume factor [-] of the fluid phase.
Definition WetGasPvt.hpp:212
void setSaturatedGasOilVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil vaporization factor .
Definition WetGasPvt.hpp:97
void setInverseGasFormationVolumeFactor(unsigned regionIdx, const TabulatedTwoDFunction &invBg)
Initialize the function for the gas formation volume factor.
Definition WetGasPvt.hpp:125
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 WetGasPvt.hpp:198
Evaluation viscosity(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &Rv, const Evaluation &) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition WetGasPvt.hpp:182
void setReferenceDensities(unsigned regionIdx, Scalar rhoRefOil, Scalar rhoRefGas, Scalar)
Initialize the reference densities of all fluids for a given PVT region.
Definition WetGasPvt.cpp:235
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Definition MathToolbox.hpp:51