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
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 extendPvtgTable_(unsigned regionIdx,
68 unsigned xIdx,
69 const SimpleTable& curTable,
70 const SimpleTable& masterTable);
71
72public:
73#endif // HAVE_ECL_INPUT
74
75 void setNumRegions(size_t numRegions);
76
77 void setVapPars(const Scalar par1, const Scalar)
78 {
79 vapPar1_ = par1;
80 }
81
85 void setReferenceDensities(unsigned regionIdx,
86 Scalar rhoRefOil,
87 Scalar rhoRefGas,
88 Scalar /*rhoRefWater*/);
89
95 void setSaturatedGasOilVaporizationFactor(unsigned regionIdx, const SamplingPoints& samplePoints)
96 { saturatedOilVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
97
107 void setSaturatedGasFormationVolumeFactor(unsigned regionIdx,
108 const SamplingPoints& samplePoints);
109
122 void setInverseGasFormationVolumeFactor(unsigned regionIdx, const TabulatedTwoDFunction& invBg)
123 { inverseGasB_[regionIdx] = invBg; }
124
130 void setGasViscosity(unsigned regionIdx, const TabulatedTwoDFunction& mug)
131 { gasMu_[regionIdx] = mug; }
132
140 void setSaturatedGasViscosity(unsigned regionIdx,
141 const SamplingPoints& samplePoints);
142
146 void initEnd();
147
151 unsigned numRegions() const
152 { return gasReferenceDensity_.size(); }
153
157 template <class Evaluation>
158 Evaluation internalEnergy(unsigned,
159 const Evaluation&,
160 const Evaluation&,
161 const Evaluation&,
162 const Evaluation&) const
163 {
164 throw std::runtime_error("Requested the enthalpy of gas but the thermal 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, Rv, /*extrapolate=*/true);
178 const Evaluation& invMugBg = inverseGasBMu_[regionIdx].eval(pressure, Rv, /*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, Rv, /*extrapolate=*/true); }
207
211 template <class Evaluation>
212 Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
213 const Evaluation& /*temperature*/,
214 const Evaluation& pressure) const
215 { return inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true); }
216
220 template <class Evaluation>
221 Evaluation saturatedWaterVaporizationFactor(unsigned /*regionIdx*/,
222 const Evaluation& /*temperature*/,
223 const Evaluation& /*pressure*/) const
224 { return 0.0; /* this is non-humid gas! */ }
225
229 template <class Evaluation = Scalar>
230 Evaluation saturatedWaterVaporizationFactor(unsigned /*regionIdx*/,
231 const Evaluation& /*temperature*/,
232 const Evaluation& /*pressure*/,
233 const Evaluation& /*saltConcentration*/) const
234 { return 0.0; }
235
239 template <class Evaluation>
240 Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
241 const Evaluation& /*temperature*/,
242 const Evaluation& pressure) const
243 {
244 return saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
245 }
246
254 template <class Evaluation>
255 Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
256 const Evaluation& /*temperature*/,
257 const Evaluation& pressure,
258 const Evaluation& oilSaturation,
259 Evaluation maxOilSaturation) const
260 {
261 Evaluation tmp =
262 saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
263
264 // apply the vaporization parameters for the gas phase (cf. the Eclipse VAPPARS
265 // keyword)
266 maxOilSaturation = min(maxOilSaturation, Scalar(1.0));
267 if (vapPar1_ > 0.0 && maxOilSaturation > 0.01 && oilSaturation < maxOilSaturation) {
268 constexpr const Scalar eps = 0.001;
269 const Evaluation& So = max(oilSaturation, eps);
270 tmp *= max(1e-3, pow(So/maxOilSaturation, vapPar1_));
271 }
272
273 return tmp;
274 }
275
286 template <class Evaluation>
287 Evaluation saturationPressure(unsigned regionIdx,
288 const Evaluation&,
289 const Evaluation& Rv) const
290 {
291 typedef MathToolbox<Evaluation> Toolbox;
292
293 const auto& RvTable = saturatedOilVaporizationFactorTable_[regionIdx];
294 constexpr const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon()*1e6;
295
296 // use the tabulated saturation pressure function to get a pretty good initial value
297 Evaluation pSat = saturationPressure_[regionIdx].eval(Rv, /*extrapolate=*/true);
298
299 // Newton method to do the remaining work. If the initial
300 // value is good, this should only take two to three
301 // iterations...
302 bool onProbation = false;
303 for (unsigned i = 0; i < 20; ++i) {
304 const Evaluation& f = RvTable.eval(pSat, /*extrapolate=*/true) - Rv;
305 const Evaluation& fPrime = RvTable.evalDerivative(pSat, /*extrapolate=*/true);
306
307 // If the derivative is "zero" Newton will not converge,
308 // so simply return our initial guess.
309 if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
310 return pSat;
311 }
312
313 const Evaluation& delta = f/fPrime;
314
315 pSat -= delta;
316
317 if (pSat < 0.0) {
318 // if the pressure is lower than 0 Pascals, we set it back to 0. if this
319 // happens twice, we give up and just return 0 Pa...
320 if (onProbation)
321 return 0.0;
322
323 onProbation = true;
324 pSat = 0.0;
325 }
326
327 if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat))*eps)
328 return pSat;
329 }
330
331 const std::string msg =
332 "Finding saturation pressure did not converge: "
333 "pSat = " + std::to_string(getValue(pSat)) +
334 ", Rv = " + std::to_string(getValue(Rv));
335 OpmLog::debug("Wet gas saturation pressure", msg);
336 throw NumericalProblem(msg);
337 }
338
339 template <class Evaluation>
340 Evaluation diffusionCoefficient(const Evaluation& /*temperature*/,
341 const Evaluation& /*pressure*/,
342 unsigned /*compIdx*/) const
343 {
344 throw std::runtime_error("Not implemented: The PVT model does not provide a diffusionCoefficient()");
345 }
346
347 Scalar gasReferenceDensity(unsigned regionIdx) const
348 { return gasReferenceDensity_[regionIdx]; }
349
350 Scalar oilReferenceDensity(unsigned regionIdx) const
351 { return oilReferenceDensity_[regionIdx]; }
352
353 const std::vector<TabulatedTwoDFunction>& inverseGasB() const {
354 return inverseGasB_;
355 }
356
357 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasB() const {
358 return inverseSaturatedGasB_;
359 }
360
361 const std::vector<TabulatedTwoDFunction>& gasMu() const {
362 return gasMu_;
363 }
364
365 const std::vector<TabulatedTwoDFunction>& inverseGasBMu() const {
366 return inverseGasBMu_;
367 }
368
369 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasBMu() const {
370 return inverseSaturatedGasBMu_;
371 }
372
373 const std::vector<TabulatedOneDFunction>& saturatedOilVaporizationFactorTable() const {
374 return saturatedOilVaporizationFactorTable_;
375 }
376
377 const std::vector<TabulatedOneDFunction>& saturationPressure() const {
378 return saturationPressure_;
379 }
380
381 Scalar vapPar1() const {
382 return vapPar1_;
383 }
384
385private:
386 void updateSaturationPressure_(unsigned regionIdx);
387
388 std::vector<Scalar> gasReferenceDensity_;
389 std::vector<Scalar> oilReferenceDensity_;
390 std::vector<TabulatedTwoDFunction> inverseGasB_;
391 std::vector<TabulatedOneDFunction> inverseSaturatedGasB_;
392 std::vector<TabulatedTwoDFunction> gasMu_;
393 std::vector<TabulatedTwoDFunction> inverseGasBMu_;
394 std::vector<TabulatedOneDFunction> inverseSaturatedGasBMu_;
395 std::vector<TabulatedOneDFunction> saturatedOilVaporizationFactorTable_;
396 std::vector<TabulatedOneDFunction> saturationPressure_;
397
398 Scalar vapPar1_ = 0.0;
399};
400
401} // namespace Opm
402
403#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 phas with vaporized oil.
Definition WetGasPvt.hpp:51
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:212
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:240
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:287
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:158
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:255
void setGasViscosity(unsigned regionIdx, const TabulatedTwoDFunction &mug)
Initialize the viscosity of the gas phase.
Definition WetGasPvt.hpp:130
Evaluation saturatedWaterVaporizationFactor(unsigned, const Evaluation &, const Evaluation &) const
Returns the water vaporization factor [m^3/m^3] of the gasphase.
Definition WetGasPvt.hpp:221
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:230
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition WetGasPvt.hpp:151
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:201
void setSaturatedGasOilVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil vaporization factor .
Definition WetGasPvt.hpp:95
void setInverseGasFormationVolumeFactor(unsigned regionIdx, const TabulatedTwoDFunction &invBg)
Initialize the function for the gas formation volume factor.
Definition WetGasPvt.hpp:122
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:187
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:171
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:50