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
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:
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
98 const SamplingPoints& samplePoints)
99 { saturatedWaterVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
100
113 void setInverseGasFormationVolumeFactor(unsigned regionIdx,
114 const TabulatedTwoDFunction& invBg)
115 { inverseGasB_[regionIdx] = invBg; }
116
122 void setGasViscosity(unsigned regionIdx, const TabulatedTwoDFunction& mug)
123 { gasMu_[regionIdx] = mug; }
124
132 void setSaturatedGasViscosity(unsigned regionIdx,
133 const SamplingPoints& samplePoints);
134
138 void initEnd();
139
143 unsigned numRegions() const
144 { return gasReferenceDensity_.size(); }
145
149 template <class Evaluation>
150 Evaluation internalEnergy(unsigned,
151 const Evaluation&,
152 const Evaluation&,
153 const Evaluation&,
154 const Evaluation&) const
155 {
156 throw std::runtime_error("Requested the enthalpy of gas but the thermal "
157 "option is not enabled");
158 }
159
160 Scalar hVap(unsigned) const
161 {
162 throw std::runtime_error("Requested the hvap of oil but the thermal "
163 "option is not enabled");
164 }
165
169 template <class Evaluation>
170 Evaluation viscosity(unsigned regionIdx,
171 const Evaluation& /*temperature*/,
172 const Evaluation& pressure,
173 const Evaluation& /*Rv*/,
174 const Evaluation& Rvw) const
175 {
176 const Evaluation& invBg = inverseGasB_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
177 const Evaluation& invMugBg = inverseGasBMu_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
178
179 return invBg / invMugBg;
180 }
181
185 template <class Evaluation>
186 Evaluation saturatedViscosity(unsigned regionIdx,
187 const Evaluation& /*temperature*/,
188 const Evaluation& pressure) const
189 {
190 const Evaluation& invBg = inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true);
191 const Evaluation& invMugBg = inverseSaturatedGasBMu_[regionIdx].eval(pressure, /*extrapolate=*/true);
192
193 return invBg / invMugBg;
194 }
195
199 template <class Evaluation>
200 Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
201 const Evaluation& /*temperature*/,
202 const Evaluation& pressure,
203 const Evaluation& /*Rv*/,
204 const Evaluation& Rvw) const
205 { return inverseGasB_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true); }
206
210 template <class Evaluation>
211 Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
212 const Evaluation& /*temperature*/,
213 const Evaluation& pressure) const
214 { return inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true); }
215
219 template <class Evaluation>
220 Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
221 const Evaluation& /*temperature*/,
222 const Evaluation& pressure) const
223 {
224 return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure,
225 /*extrapolate=*/true);
226 }
227
231 template <class Evaluation>
232 Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
233 const Evaluation& /*temperature*/,
234 const Evaluation& pressure,
235 const Evaluation& saltConcentration) const
236 {
237 if (enableRwgSalt_) {
238 return saturatedWaterVaporizationSaltFactorTable_[regionIdx].eval(pressure,
239 saltConcentration,
240 /*extrapolate=*/true);
241 }
242 else {
243 return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure,
244 /*extrapolate=*/true);
245 }
246 }
247
251 template <class Evaluation>
252 Evaluation saturatedOilVaporizationFactor(unsigned /*regionIdx*/,
253 const Evaluation& /*temperature*/,
254 const Evaluation& /*pressure*/,
255 const Evaluation& /*oilSaturation*/,
256 const Evaluation& /*maxOilSaturation*/) const
257 { return 0.0; /* this is dry humid gas! */ }
258
262 template <class Evaluation>
263 Evaluation saturatedOilVaporizationFactor(unsigned /*regionIdx*/,
264 const Evaluation& /*temperature*/,
265 const Evaluation& /*pressure*/) const
266 { return 0.0; /* this is dry humid gas! */ }
267
275 template <class Evaluation>
276 Evaluation saturationPressure(unsigned regionIdx,
277 const Evaluation&,
278 const Evaluation& Rw) const
279 {
280 typedef MathToolbox<Evaluation> Toolbox;
281
282 const auto& RwTable = saturatedWaterVaporizationFactorTable_[regionIdx];
283 const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon() * 1e6;
284
285 // use the tabulated saturation pressure function to get a pretty good initial value
286 Evaluation pSat = saturationPressure_[regionIdx].eval(Rw, /*extrapolate=*/true);
287
288 // Newton method to do the remaining work. If the initial
289 // value is good, this should only take two to three
290 // iterations...
291 bool onProbation = false;
292 for (unsigned i = 0; i < 20; ++i) {
293 const Evaluation& f = RwTable.eval(pSat, /*extrapolate=*/true) - Rw;
294 const Evaluation& fPrime = RwTable.evalDerivative(pSat, /*extrapolate=*/true);
295
296 // If the derivative is "zero" Newton will not converge,
297 // so simply return our initial guess.
298 if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
299 return pSat;
300 }
301
302 const Evaluation& delta = f / fPrime;
303
304 pSat -= delta;
305
306 if (pSat < 0.0) {
307 // if the pressure is lower than 0 Pascals, we set it back to 0. if this
308 // happens twice, we give up and just return 0 Pa...
309 if (onProbation) {
310 return 0.0;
311 }
312
313 onProbation = true;
314 pSat = 0.0;
315 }
316
317 if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat)) * eps) {
318 return pSat;
319 }
320 }
321
322 const std::string msg =
323 "Finding saturation pressure did not converge: "
324 " pSat = " + std::to_string(getValue(pSat)) +
325 ", Rw = " + std::to_string(getValue(Rw));
326 OpmLog::debug("Wet gas saturation pressure", msg);
327 throw NumericalProblem(msg);
328 }
329
330 template <class Evaluation>
331 Evaluation diffusionCoefficient(const Evaluation& /*temperature*/,
332 const Evaluation& /*pressure*/,
333 unsigned /*compIdx*/) const
334 {
335 throw std::runtime_error("Not implemented: The PVT model does not provide "
336 "a diffusionCoefficient()");
337 }
338
339 Scalar gasReferenceDensity(unsigned regionIdx) const
340 { return gasReferenceDensity_[regionIdx]; }
341
342 Scalar waterReferenceDensity(unsigned regionIdx) const
343 { return waterReferenceDensity_[regionIdx]; }
344
345 const std::vector<TabulatedTwoDFunction>& inverseGasB() const
346 { return inverseGasB_; }
347
348 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasB() const
349 { return inverseSaturatedGasB_; }
350
351 const std::vector<TabulatedTwoDFunction>& gasMu() const
352 { return gasMu_; }
353
354 const std::vector<TabulatedTwoDFunction>& inverseGasBMu() const
355 { return inverseGasBMu_; }
356
357 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasBMu() const
358 { return inverseSaturatedGasBMu_; }
359
360 const std::vector<TabulatedOneDFunction>& saturatedWaterVaporizationFactorTable() const
361 { return saturatedWaterVaporizationFactorTable_; }
362
363 const std::vector<TabulatedTwoDFunction>& saturatedWaterVaporizationSaltFactorTable() const
364 { return saturatedWaterVaporizationSaltFactorTable_; }
365
366 const std::vector<TabulatedOneDFunction>& saturationPressure() const
367 { return saturationPressure_; }
368
369 Scalar vapPar1() const
370 { return vapPar1_; }
371
372private:
373 void updateSaturationPressure_(unsigned regionIdx);
374
375 std::vector<Scalar> gasReferenceDensity_{};
376 std::vector<Scalar> waterReferenceDensity_{};
377 std::vector<TabulatedTwoDFunction> inverseGasB_{};
378 std::vector<TabulatedOneDFunction> inverseSaturatedGasB_{};
379 std::vector<TabulatedTwoDFunction> gasMu_{};
380 std::vector<TabulatedTwoDFunction> inverseGasBMu_{};
381 std::vector<TabulatedOneDFunction> inverseSaturatedGasBMu_{};
382 std::vector<TabulatedOneDFunction> saturatedWaterVaporizationFactorTable_{};
383 std::vector<TabulatedTwoDFunction> saturatedWaterVaporizationSaltFactorTable_{};
384 std::vector<TabulatedOneDFunction> saturationPressure_{};
385
386 bool enableRwgSalt_ = false;
387 Scalar vapPar1_ = 0.0;
388};
389
390} // namespace Opm
391
392#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:200
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:252
void setGasViscosity(unsigned regionIdx, const TabulatedTwoDFunction &mug)
Initialize the viscosity of the gas phase.
Definition DryHumidGasPvt.hpp:122
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:276
void setInverseGasFormationVolumeFactor(unsigned regionIdx, const TabulatedTwoDFunction &invBg)
Initialize the function for the gas formation volume factor.
Definition DryHumidGasPvt.hpp:113
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:143
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:150
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:220
void setSaturatedGasWaterVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil vaporization factor .
Definition DryHumidGasPvt.hpp:97
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:170
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:263
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:232
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:186
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:211
Definition EclipseState.hpp:63
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