My Project
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
80 void setReferenceDensities(unsigned regionIdx,
81 Scalar /*rhoRefOil*/,
82 Scalar rhoRefGas,
83 Scalar rhoRefWater);
84
90 void setSaturatedGasWaterVaporizationFactor(unsigned regionIdx, const SamplingPoints& samplePoints)
91 { saturatedWaterVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
92
105 void setInverseGasFormationVolumeFactor(unsigned regionIdx, const TabulatedTwoDFunction& invBg)
106 { inverseGasB_[regionIdx] = invBg; }
107
113 void setGasViscosity(unsigned regionIdx, const TabulatedTwoDFunction& mug)
114 { gasMu_[regionIdx] = mug; }
115
123 void setSaturatedGasViscosity(unsigned regionIdx,
124 const SamplingPoints& samplePoints);
125
129 void initEnd();
130
134 unsigned numRegions() const
135 { return gasReferenceDensity_.size(); }
136
140 template <class Evaluation>
141 Evaluation internalEnergy(unsigned,
142 const Evaluation&,
143 const Evaluation&,
144 const Evaluation&,
145 const Evaluation&) const
146 {
147 throw std::runtime_error("Requested the enthalpy of gas but the thermal option is not enabled");
148 }
149
153 template <class Evaluation>
154 Evaluation viscosity(unsigned regionIdx,
155 const Evaluation& /*temperature*/,
156 const Evaluation& pressure,
157 const Evaluation& /*Rv*/,
158 const Evaluation& Rvw) const
159 {
160 const Evaluation& invBg = inverseGasB_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
161 const Evaluation& invMugBg = inverseGasBMu_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
162
163 return invBg/invMugBg;
164 }
165
169 template <class Evaluation>
170 Evaluation saturatedViscosity(unsigned regionIdx,
171 const Evaluation& /*temperature*/,
172 const Evaluation& pressure) const
173 {
174 const Evaluation& invBg = inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true);
175 const Evaluation& invMugBg = inverseSaturatedGasBMu_[regionIdx].eval(pressure, /*extrapolate=*/true);
176
177 return invBg/invMugBg;
178 }
179
183 template <class Evaluation>
184 Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
185 const Evaluation& /*temperature*/,
186 const Evaluation& pressure,
187 const Evaluation& /*Rv*/,
188 const Evaluation& Rvw) const
189 { return inverseGasB_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true); }
190
194 template <class Evaluation>
195 Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
196 const Evaluation& /*temperature*/,
197 const Evaluation& pressure) const
198 { return inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true); }
199
203 template <class Evaluation>
204 Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
205 const Evaluation& /*temperature*/,
206 const Evaluation& pressure) const
207 {
208 return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
209 }
210
214 template <class Evaluation>
215 Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
216 const Evaluation& /*temperature*/,
217 const Evaluation& pressure,
218 const Evaluation& saltConcentration) const
219 {
220 if (enableRwgSalt_)
221 return saturatedWaterVaporizationSaltFactorTable_[regionIdx].eval(pressure, saltConcentration, /*extrapolate=*/true);
222 else {
223 return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
224 }
225 }
226
230 template <class Evaluation>
231 Evaluation saturatedOilVaporizationFactor(unsigned /*regionIdx*/,
232 const Evaluation& /*temperature*/,
233 const Evaluation& /*pressure*/,
234 const Evaluation& /*oilSaturation*/,
235 const Evaluation& /*maxOilSaturation*/) const
236 { return 0.0; /* this is dry humid gas! */ }
237
241 template <class Evaluation>
242 Evaluation saturatedOilVaporizationFactor(unsigned /*regionIdx*/,
243 const Evaluation& /*temperature*/,
244 const Evaluation& /*pressure*/) const
245 { return 0.0; /* this is dry humid gas! */ }
246
254 template <class Evaluation>
255 Evaluation saturationPressure(unsigned regionIdx,
256 const Evaluation&,
257 const Evaluation& Rw) const
258 {
259 typedef MathToolbox<Evaluation> Toolbox;
260
261 const auto& RwTable = saturatedWaterVaporizationFactorTable_[regionIdx];
262 const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon()*1e6;
263
264 // use the tabulated saturation pressure function to get a pretty good initial value
265 Evaluation pSat = saturationPressure_[regionIdx].eval(Rw, /*extrapolate=*/true);
266
267 // Newton method to do the remaining work. If the initial
268 // value is good, this should only take two to three
269 // iterations...
270 bool onProbation = false;
271 for (unsigned i = 0; i < 20; ++i) {
272 const Evaluation& f = RwTable.eval(pSat, /*extrapolate=*/true) - Rw;
273 const Evaluation& fPrime = RwTable.evalDerivative(pSat, /*extrapolate=*/true);
274
275 // If the derivative is "zero" Newton will not converge,
276 // so simply return our initial guess.
277 if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
278 return pSat;
279 }
280
281 const Evaluation& delta = f/fPrime;
282
283 pSat -= delta;
284
285 if (pSat < 0.0) {
286 // if the pressure is lower than 0 Pascals, we set it back to 0. if this
287 // happens twice, we give up and just return 0 Pa...
288 if (onProbation)
289 return 0.0;
290
291 onProbation = true;
292 pSat = 0.0;
293 }
294
295 if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat))*eps)
296 return pSat;
297 }
298
299 const std::string msg =
300 "Finding saturation pressure did not converge: "
301 " pSat = " + std::to_string(getValue(pSat)) +
302 ", Rw = " + std::to_string(getValue(Rw));
303 OpmLog::debug("Wet gas saturation pressure", msg);
304 throw NumericalProblem(msg);
305 }
306
307 template <class Evaluation>
308 Evaluation diffusionCoefficient(const Evaluation& /*temperature*/,
309 const Evaluation& /*pressure*/,
310 unsigned /*compIdx*/) const
311 {
312 throw std::runtime_error("Not implemented: The PVT model does not provide a diffusionCoefficient()");
313 }
314
315 Scalar gasReferenceDensity(unsigned regionIdx) const
316 { return gasReferenceDensity_[regionIdx]; }
317
318 Scalar waterReferenceDensity(unsigned regionIdx) const
319 { return waterReferenceDensity_[regionIdx]; }
320
321 const std::vector<TabulatedTwoDFunction>& inverseGasB() const {
322 return inverseGasB_;
323 }
324
325 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasB() const {
326 return inverseSaturatedGasB_;
327 }
328
329 const std::vector<TabulatedTwoDFunction>& gasMu() const {
330 return gasMu_;
331 }
332
333 const std::vector<TabulatedTwoDFunction>& inverseGasBMu() const {
334 return inverseGasBMu_;
335 }
336
337 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasBMu() const {
338 return inverseSaturatedGasBMu_;
339 }
340
341 const std::vector<TabulatedOneDFunction>& saturatedWaterVaporizationFactorTable() const {
342 return saturatedWaterVaporizationFactorTable_;
343 }
344
345 const std::vector<TabulatedTwoDFunction>& saturatedWaterVaporizationSaltFactorTable() const {
346 return saturatedWaterVaporizationSaltFactorTable_;
347 }
348
349 const std::vector<TabulatedOneDFunction>& saturationPressure() const {
350 return saturationPressure_;
351 }
352
353 Scalar vapPar1() const {
354 return vapPar1_;
355 }
356
357private:
358 void updateSaturationPressure_(unsigned regionIdx);
359
360 std::vector<Scalar> gasReferenceDensity_;
361 std::vector<Scalar> waterReferenceDensity_;
362 std::vector<TabulatedTwoDFunction> inverseGasB_;
363 std::vector<TabulatedOneDFunction> inverseSaturatedGasB_;
364 std::vector<TabulatedTwoDFunction> gasMu_;
365 std::vector<TabulatedTwoDFunction> inverseGasBMu_;
366 std::vector<TabulatedOneDFunction> inverseSaturatedGasBMu_;
367 std::vector<TabulatedOneDFunction> saturatedWaterVaporizationFactorTable_;
368 std::vector<TabulatedTwoDFunction> saturatedWaterVaporizationSaltFactorTable_;
369 std::vector<TabulatedOneDFunction> saturationPressure_;
370
371 bool enableRwgSalt_ = false;
372 Scalar vapPar1_ = 0.0;
373};
374
375} // namespace Opm
376
377#endif
Provides the OPM specific exception classes.
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...
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:184
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:231
void setGasViscosity(unsigned regionIdx, const TabulatedTwoDFunction &mug)
Initialize the viscosity of the gas phase.
Definition: DryHumidGasPvt.hpp:113
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:255
void setInverseGasFormationVolumeFactor(unsigned regionIdx, const TabulatedTwoDFunction &invBg)
Initialize the function for the gas formation volume factor.
Definition: DryHumidGasPvt.hpp:105
void initEnd()
Finish initializing the gas phase PVT properties.
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition: DryHumidGasPvt.hpp:134
void setReferenceDensities(unsigned regionIdx, Scalar, Scalar rhoRefGas, Scalar rhoRefWater)
Initialize the reference densities of all fluids for a given PVT region.
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:141
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:204
void setSaturatedGasWaterVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil vaporization factor .
Definition: DryHumidGasPvt.hpp:90
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:154
void setSaturatedGasViscosity(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the phase viscosity for oil saturated gas.
Evaluation saturatedOilVaporizationFactor(unsigned, const Evaluation &, const Evaluation &) const
Returns the oil vaporization factor [m^3/m^3] of the oil phase.
Definition: DryHumidGasPvt.hpp:242
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:215
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:170
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:195
Definition: EclipseState.hpp:55
Definition: Exceptions.hpp:40
Definition: Schedule.hpp:130
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