My Project
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
38namespace Opm {
39
40#if HAVE_ECL_INPUT
41class EclipseState;
42class Schedule;
43class SimpleTable;
44#endif
45
50template <class Scalar>
52{
53 using SamplingPoints = std::vector<std::pair<Scalar, Scalar>>;
54
55public:
58
59#if HAVE_ECL_INPUT
65 void initFromState(const EclipseState& eclState, const Schedule&);
66
67private:
68 void extendPvtgwTable_(unsigned regionIdx,
69 unsigned xIdx,
70 const SimpleTable& curTable,
71 const SimpleTable& masterTable);
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 setSaturatedGasWaterVaporizationFactor(unsigned regionIdx, const SamplingPoints& samplePoints)
96 { saturatedWaterVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
97
110 void setInverseGasFormationVolumeFactor(unsigned regionIdx, const TabulatedTwoDFunction& invBg)
111 { inverseGasB_[regionIdx] = invBg; }
112
118 void setGasViscosity(unsigned regionIdx, const TabulatedTwoDFunction& mug)
119 { gasMu_[regionIdx] = mug; }
120
128 void setSaturatedGasViscosity(unsigned regionIdx,
129 const SamplingPoints& samplePoints);
130
134 void initEnd();
135
139 unsigned numRegions() const
140 { return gasReferenceDensity_.size(); }
141
145 template <class Evaluation>
146 Evaluation internalEnergy(unsigned,
147 const Evaluation&,
148 const Evaluation&,
149 const Evaluation&,
150 const Evaluation&) const
151 {
152 throw std::runtime_error("Requested the enthalpy of gas but the thermal option is not enabled");
153 }
154
158 template <class Evaluation>
159 Evaluation viscosity(unsigned regionIdx,
160 const Evaluation& /*temperature*/,
161 const Evaluation& pressure,
162 const Evaluation& /*Rv*/,
163 const Evaluation& Rvw) const
164 {
165 const Evaluation& invBg = inverseGasB_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
166 const Evaluation& invMugBg = inverseGasBMu_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
167
168 return invBg/invMugBg;
169 }
170
174 template <class Evaluation>
175 Evaluation saturatedViscosity(unsigned regionIdx,
176 const Evaluation& /*temperature*/,
177 const Evaluation& pressure) const
178 {
179 const Evaluation& invBg = inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true);
180 const Evaluation& invMugBg = inverseSaturatedGasBMu_[regionIdx].eval(pressure, /*extrapolate=*/true);
181
182 return invBg/invMugBg;
183 }
184
188 template <class Evaluation>
189 Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
190 const Evaluation& /*temperature*/,
191 const Evaluation& pressure,
192 const Evaluation& /*Rv*/,
193 const Evaluation& Rvw) const
194 { return inverseGasB_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true); }
195
199 template <class Evaluation>
200 Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
201 const Evaluation& /*temperature*/,
202 const Evaluation& pressure) const
203 { return inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true); }
204
208 template <class Evaluation>
209 Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
210 const Evaluation& /*temperature*/,
211 const Evaluation& pressure) const
212 {
213 return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
214 }
215
219 template <class Evaluation>
220 Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
221 const Evaluation& /*temperature*/,
222 const Evaluation& pressure,
223 const Evaluation& saltConcentration) const
224 {
225 if (enableRwgSalt_)
226 return saturatedWaterVaporizationSaltFactorTable_[regionIdx].eval(pressure, saltConcentration, /*extrapolate=*/true);
227 else {
228 return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
229 }
230 }
231
235 template <class Evaluation>
236 Evaluation saturatedOilVaporizationFactor(unsigned /*regionIdx*/,
237 const Evaluation& /*temperature*/,
238 const Evaluation& /*pressure*/,
239 const Evaluation& /*oilSaturation*/,
240 const Evaluation& /*maxOilSaturation*/) const
241 { return 0.0; /* this is dry humid gas! */ }
242
246 template <class Evaluation>
247 Evaluation saturatedOilVaporizationFactor(unsigned /*regionIdx*/,
248 const Evaluation& /*temperature*/,
249 const Evaluation& /*pressure*/) const
250 { return 0.0; /* this is dry humid gas! */ }
251
259 template <class Evaluation>
260 Evaluation saturationPressure(unsigned regionIdx,
261 const Evaluation&,
262 const Evaluation& Rw) const
263 {
264 typedef MathToolbox<Evaluation> Toolbox;
265
266 const auto& RwTable = saturatedWaterVaporizationFactorTable_[regionIdx];
267 const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon()*1e6;
268
269 // use the tabulated saturation pressure function to get a pretty good initial value
270 Evaluation pSat = saturationPressure_[regionIdx].eval(Rw, /*extrapolate=*/true);
271
272 // Newton method to do the remaining work. If the initial
273 // value is good, this should only take two to three
274 // iterations...
275 bool onProbation = false;
276 for (unsigned i = 0; i < 20; ++i) {
277 const Evaluation& f = RwTable.eval(pSat, /*extrapolate=*/true) - Rw;
278 const Evaluation& fPrime = RwTable.evalDerivative(pSat, /*extrapolate=*/true);
279
280 // If the derivative is "zero" Newton will not converge,
281 // so simply return our initial guess.
282 if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
283 return pSat;
284 }
285
286 const Evaluation& delta = f/fPrime;
287
288 pSat -= delta;
289
290 if (pSat < 0.0) {
291 // if the pressure is lower than 0 Pascals, we set it back to 0. if this
292 // happens twice, we give up and just return 0 Pa...
293 if (onProbation)
294 return 0.0;
295
296 onProbation = true;
297 pSat = 0.0;
298 }
299
300 if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat))*eps)
301 return pSat;
302 }
303
304 const std::string msg =
305 "Finding saturation pressure did not converge: "
306 " pSat = " + std::to_string(getValue(pSat)) +
307 ", Rw = " + std::to_string(getValue(Rw));
308 OpmLog::debug("Wet gas saturation pressure", msg);
309 throw NumericalProblem(msg);
310 }
311
312 template <class Evaluation>
313 Evaluation diffusionCoefficient(const Evaluation& /*temperature*/,
314 const Evaluation& /*pressure*/,
315 unsigned /*compIdx*/) const
316 {
317 throw std::runtime_error("Not implemented: The PVT model does not provide a diffusionCoefficient()");
318 }
319
320 Scalar gasReferenceDensity(unsigned regionIdx) const
321 { return gasReferenceDensity_[regionIdx]; }
322
323 Scalar waterReferenceDensity(unsigned regionIdx) const
324 { return waterReferenceDensity_[regionIdx]; }
325
326 const std::vector<TabulatedTwoDFunction>& inverseGasB() const {
327 return inverseGasB_;
328 }
329
330 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasB() const {
331 return inverseSaturatedGasB_;
332 }
333
334 const std::vector<TabulatedTwoDFunction>& gasMu() const {
335 return gasMu_;
336 }
337
338 const std::vector<TabulatedTwoDFunction>& inverseGasBMu() const {
339 return inverseGasBMu_;
340 }
341
342 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasBMu() const {
343 return inverseSaturatedGasBMu_;
344 }
345
346 const std::vector<TabulatedOneDFunction>& saturatedWaterVaporizationFactorTable() const {
347 return saturatedWaterVaporizationFactorTable_;
348 }
349
350 const std::vector<TabulatedTwoDFunction>& saturatedWaterVaporizationSaltFactorTable() const {
351 return saturatedWaterVaporizationSaltFactorTable_;
352 }
353
354 const std::vector<TabulatedOneDFunction>& saturationPressure() const {
355 return saturationPressure_;
356 }
357
358 Scalar vapPar1() const {
359 return vapPar1_;
360 }
361
362private:
363 void updateSaturationPressure_(unsigned regionIdx);
364
365 std::vector<Scalar> gasReferenceDensity_;
366 std::vector<Scalar> waterReferenceDensity_;
367 std::vector<TabulatedTwoDFunction> inverseGasB_;
368 std::vector<TabulatedOneDFunction> inverseSaturatedGasB_;
369 std::vector<TabulatedTwoDFunction> gasMu_;
370 std::vector<TabulatedTwoDFunction> inverseGasBMu_;
371 std::vector<TabulatedOneDFunction> inverseSaturatedGasBMu_;
372 std::vector<TabulatedOneDFunction> saturatedWaterVaporizationFactorTable_;
373 std::vector<TabulatedTwoDFunction> saturatedWaterVaporizationSaltFactorTable_;
374 std::vector<TabulatedOneDFunction> saturationPressure_;
375
376 bool enableRwgSalt_ = false;
377 Scalar vapPar1_ = 0.0;
378};
379
380} // namespace Opm
381
382#endif
A central place for various physical constants occuring in some equations.
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:52
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:189
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:236
void setGasViscosity(unsigned regionIdx, const TabulatedTwoDFunction &mug)
Initialize the viscosity of the gas phase.
Definition DryHumidGasPvt.hpp:118
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:260
void setInverseGasFormationVolumeFactor(unsigned regionIdx, const TabulatedTwoDFunction &invBg)
Initialize the function for the gas formation volume factor.
Definition DryHumidGasPvt.hpp:110
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:139
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:146
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:209
void setSaturatedGasWaterVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil vaporization factor .
Definition DryHumidGasPvt.hpp:95
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:159
void setSaturatedGasViscosity(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the phase viscosity for oil saturated gas.
Definition DryHumidGasPvt.cpp:268
Evaluation saturatedOilVaporizationFactor(unsigned, const Evaluation &, const Evaluation &) const
Returns the oil vaporization factor [m^3/m^3] of the oil phase.
Definition DryHumidGasPvt.hpp:247
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:220
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:175
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:200
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 implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Definition MathToolbox.hpp:50