DryGasPvt.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_GAS_PVT_HPP
28#define OPM_DRY_GAS_PVT_HPP
29
31
33
34#if HAVE_ECL_INPUT
35#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
36#include <opm/input/eclipse/Schedule/Schedule.hpp>
37#include <opm/input/eclipse/EclipseState/Tables/TableManager.hpp>
38#include <opm/input/eclipse/EclipseState/Tables/PvdgTable.hpp>
39#endif
40
41#include <vector>
42
43namespace Opm {
48template <class Scalar>
50{
51 using SamplingPoints = std::vector<std::pair<Scalar, Scalar>>;
52
53public:
55
56 explicit DryGasPvt() = default;
57 DryGasPvt(const std::vector<Scalar>& gasReferenceDensity,
58 const std::vector<TabulatedOneDFunction>& inverseGasB,
59 const std::vector<TabulatedOneDFunction>& gasMu,
60 const std::vector<TabulatedOneDFunction>& inverseGasBMu)
61 : gasReferenceDensity_(gasReferenceDensity)
62 , inverseGasB_(inverseGasB)
63 , gasMu_(gasMu)
64 , inverseGasBMu_(inverseGasBMu)
65 {
66 }
67#if HAVE_ECL_INPUT
73 void initFromState(const EclipseState& eclState, const Schedule&)
74 {
75 const auto& pvdgTables = eclState.getTableManager().getPvdgTables();
76 const auto& densityTable = eclState.getTableManager().getDensityTable();
77
78 assert(pvdgTables.size() == densityTable.size());
79
80 size_t numRegions = pvdgTables.size();
82
83 for (unsigned regionIdx = 0; regionIdx < numRegions; ++ regionIdx) {
84 Scalar rhoRefO = densityTable[regionIdx].oil;
85 Scalar rhoRefG = densityTable[regionIdx].gas;
86 Scalar rhoRefW = densityTable[regionIdx].water;
87
88 setReferenceDensities(regionIdx, rhoRefO, rhoRefG, rhoRefW);
89
90 // determine the molar masses of the components
91 constexpr Scalar p = 1.01325e5; // surface pressure, [Pa]
92 constexpr Scalar T = 273.15 + 15.56; // surface temperature, [K]
93 constexpr Scalar MO = 175e-3; // [kg/mol]
94 Scalar MG = Constants<Scalar>::R*T*rhoRefG / p; // [kg/mol], consequence of the ideal gas law
95 constexpr Scalar MW = 18.0e-3; // [kg/mol]
96 // TODO (?): the molar mass of the components can possibly specified
97 // explicitly in the deck.
98 setMolarMasses(regionIdx, MO, MG, MW);
99
100 const auto& pvdgTable = pvdgTables.getTable<PvdgTable>(regionIdx);
101
102 // say 99.97% of all time: "premature optimization is the root of all
103 // evil". Eclipse does this "optimization" for apparently no good reason!
104 std::vector<Scalar> invB(pvdgTable.numRows());
105 const auto& Bg = pvdgTable.getFormationFactorColumn();
106 for (unsigned i = 0; i < Bg.size(); ++ i) {
107 invB[i] = 1.0/Bg[i];
108 }
109
110 size_t numSamples = invB.size();
111 inverseGasB_[regionIdx].setXYArrays(numSamples, pvdgTable.getPressureColumn(), invB);
112 gasMu_[regionIdx].setXYArrays(numSamples, pvdgTable.getPressureColumn(), pvdgTable.getViscosityColumn());
113 }
114
115 initEnd();
116 }
117#endif
118
120 {
121 gasReferenceDensity_.resize(numRegions);
122 inverseGasB_.resize(numRegions);
123 inverseGasBMu_.resize(numRegions);
124 gasMu_.resize(numRegions);
125 }
126
127
131 void setReferenceDensities(unsigned regionIdx,
132 Scalar /*rhoRefOil*/,
133 Scalar rhoRefGas,
134 Scalar /*rhoRefWater*/)
135 {
136 gasReferenceDensity_[regionIdx] = rhoRefGas;
137 }
138
142 void setMolarMasses(unsigned /*regionIdx*/,
143 Scalar /*MOil*/,
144 Scalar /*MGas*/,
145 Scalar /*MWater*/)
146 { }
147
153 void setGasViscosity(unsigned regionIdx, const TabulatedOneDFunction& mug)
154 { gasMu_[regionIdx] = mug; }
155
161 void setGasFormationVolumeFactor(unsigned regionIdx, const SamplingPoints& samplePoints)
162 {
163 SamplingPoints tmp(samplePoints);
164 auto it = tmp.begin();
165 const auto& endIt = tmp.end();
166 for (; it != endIt; ++ it)
167 std::get<1>(*it) = 1.0/std::get<1>(*it);
168
169 inverseGasB_[regionIdx].setContainerOfTuples(tmp);
170 assert(inverseGasB_[regionIdx].monotonic());
171 }
172
176 void initEnd()
177 {
178 // calculate the final 2D functions which are used for interpolation.
179 size_t numRegions = gasMu_.size();
180 for (unsigned regionIdx = 0; regionIdx < numRegions; ++ regionIdx) {
181 // calculate the table which stores the inverse of the product of the gas
182 // formation volume factor and the gas viscosity
183 const auto& gasMu = gasMu_[regionIdx];
184 const auto& invGasB = inverseGasB_[regionIdx];
185 assert(gasMu.numSamples() == invGasB.numSamples());
186
187 std::vector<Scalar> pressureValues(gasMu.numSamples());
188 std::vector<Scalar> invGasBMuValues(gasMu.numSamples());
189 for (unsigned pIdx = 0; pIdx < gasMu.numSamples(); ++pIdx) {
190 pressureValues[pIdx] = invGasB.xAt(pIdx);
191 invGasBMuValues[pIdx] = invGasB.valueAt(pIdx) * (1.0/gasMu.valueAt(pIdx));
192 }
193
194 inverseGasBMu_[regionIdx].setXYContainers(pressureValues, invGasBMuValues);
195 }
196 }
197
201 unsigned numRegions() const
202 { return gasReferenceDensity_.size(); }
203
207 template <class Evaluation>
208 Evaluation internalEnergy(unsigned,
209 const Evaluation&,
210 const Evaluation&,
211 const Evaluation&) const
212 {
213 throw std::runtime_error("Requested the enthalpy of gas but the thermal option is not enabled");
214 }
215
219 template <class Evaluation>
220 Evaluation viscosity(unsigned regionIdx,
221 const Evaluation& temperature,
222 const Evaluation& pressure,
223 const Evaluation& /*Rv*/,
224 const Evaluation& /*Rvw*/) const
225 { return saturatedViscosity(regionIdx, temperature, pressure); }
226
230 template <class Evaluation>
231 Evaluation saturatedViscosity(unsigned regionIdx,
232 const Evaluation& /*temperature*/,
233 const Evaluation& pressure) const
234 {
235 const Evaluation& invBg = inverseGasB_[regionIdx].eval(pressure, /*extrapolate=*/true);
236 const Evaluation& invMugBg = inverseGasBMu_[regionIdx].eval(pressure, /*extrapolate=*/true);
237
238 return invBg/invMugBg;
239 }
240
244 template <class Evaluation>
245 Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
246 const Evaluation& temperature,
247 const Evaluation& pressure,
248 const Evaluation& /*Rv*/,
249 const Evaluation& /*Rvw*/) const
250 { return saturatedInverseFormationVolumeFactor(regionIdx, temperature, pressure); }
251
255 template <class Evaluation>
256 Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
257 const Evaluation& /*temperature*/,
258 const Evaluation& pressure) const
259 { return inverseGasB_[regionIdx].eval(pressure, /*extrapolate=*/true); }
260
267 template <class Evaluation>
268 Evaluation saturationPressure(unsigned /*regionIdx*/,
269 const Evaluation& /*temperature*/,
270 const Evaluation& /*Rv*/) const
271 { return 0.0; /* this is dry gas! */ }
272
276 template <class Evaluation>
277 Evaluation saturatedWaterVaporizationFactor(unsigned /*regionIdx*/,
278 const Evaluation& /*temperature*/,
279 const Evaluation& /*pressure*/) const
280 { return 0.0; /* this is non-humid gas! */ }
281
285 template <class Evaluation = Scalar>
286 Evaluation saturatedWaterVaporizationFactor(unsigned /*regionIdx*/,
287 const Evaluation& /*temperature*/,
288 const Evaluation& /*pressure*/,
289 const Evaluation& /*saltConcentration*/) const
290 { return 0.0; }
291
292
296 template <class Evaluation>
297 Evaluation saturatedOilVaporizationFactor(unsigned /*regionIdx*/,
298 const Evaluation& /*temperature*/,
299 const Evaluation& /*pressure*/,
300 const Evaluation& /*oilSaturation*/,
301 const Evaluation& /*maxOilSaturation*/) const
302 { return 0.0; /* this is dry gas! */ }
303
307 template <class Evaluation>
308 Evaluation saturatedOilVaporizationFactor(unsigned /*regionIdx*/,
309 const Evaluation& /*temperature*/,
310 const Evaluation& /*pressure*/) const
311 { return 0.0; /* this is dry gas! */ }
312
313 template <class Evaluation>
314 Evaluation diffusionCoefficient(const Evaluation& /*temperature*/,
315 const Evaluation& /*pressure*/,
316 unsigned /*compIdx*/) const
317 {
318 throw std::runtime_error("Not implemented: The PVT model does not provide a diffusionCoefficient()");
319 }
320
321 const Scalar gasReferenceDensity(unsigned regionIdx) const
322 { return gasReferenceDensity_[regionIdx]; }
323
324 const std::vector<TabulatedOneDFunction>& inverseGasB() const
325 { return inverseGasB_; }
326
327 const std::vector<TabulatedOneDFunction>& gasMu() const
328 { return gasMu_; }
329
330 const std::vector<TabulatedOneDFunction> inverseGasBMu() const
331 { return inverseGasBMu_; }
332
333 bool operator==(const DryGasPvt<Scalar>& data) const
334 {
335 return gasReferenceDensity_ == data.gasReferenceDensity_ &&
336 inverseGasB_ == data.inverseGasB_ &&
337 gasMu_ == data.gasMu_ &&
338 inverseGasBMu_ == data.inverseGasBMu_;
339 }
340
341private:
342 std::vector<Scalar> gasReferenceDensity_;
343 std::vector<TabulatedOneDFunction> inverseGasB_;
344 std::vector<TabulatedOneDFunction> gasMu_;
345 std::vector<TabulatedOneDFunction> inverseGasBMu_;
346};
347
348} // namespace Opm
349
350#endif
A central place for various physical constants occuring in some equations.
Definition: Constants.hpp:41
This class represents the Pressure-Volume-Temperature relations of the gas phase without vaporized oi...
Definition: DryGasPvt.hpp:50
Evaluation saturatedViscosity(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the dynamic viscosity [Pa s] of oil saturated gas at given pressure.
Definition: DryGasPvt.hpp:231
Evaluation saturationPressure(unsigned, const Evaluation &, const Evaluation &) const
Returns the saturation pressure of the gas phase [Pa] depending on its mass fraction of the oil compo...
Definition: DryGasPvt.hpp:268
bool operator==(const DryGasPvt< Scalar > &data) const
Definition: DryGasPvt.hpp:333
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition: DryGasPvt.hpp:201
void setGasFormationVolumeFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the formation volume factor of dry gas.
Definition: DryGasPvt.hpp:161
Evaluation diffusionCoefficient(const Evaluation &, const Evaluation &, unsigned) const
Definition: DryGasPvt.hpp:314
Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &, const Evaluation &) const
Returns the formation volume factor [-] of the fluid phase.
Definition: DryGasPvt.hpp:245
Evaluation saturatedWaterVaporizationFactor(unsigned, const Evaluation &, const Evaluation &, const Evaluation &) const
Returns the water vaporization factor [m^3/m^3] of water saturated gas.
Definition: DryGasPvt.hpp:286
DryGasPvt()=default
Evaluation internalEnergy(unsigned, const Evaluation &, const Evaluation &, const Evaluation &) const
Returns the specific enthalpy [J/kg] of gas given a set of parameters.
Definition: DryGasPvt.hpp:208
Evaluation saturatedOilVaporizationFactor(unsigned, const Evaluation &, const Evaluation &) const
Returns the oil vaporization factor [m^3/m^3] of the oil phase.
Definition: DryGasPvt.hpp:308
void setNumRegions(size_t numRegions)
Definition: DryGasPvt.hpp:119
const Scalar gasReferenceDensity(unsigned regionIdx) const
Definition: DryGasPvt.hpp:321
Evaluation viscosity(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &, const Evaluation &) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition: DryGasPvt.hpp:220
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the formation volume factor [-] of oil saturated gas at given pressure.
Definition: DryGasPvt.hpp:256
const std::vector< TabulatedOneDFunction > & inverseGasB() const
Definition: DryGasPvt.hpp:324
void initEnd()
Finish initializing the oil phase PVT properties.
Definition: DryGasPvt.hpp:176
const std::vector< TabulatedOneDFunction > inverseGasBMu() const
Definition: DryGasPvt.hpp:330
const std::vector< TabulatedOneDFunction > & gasMu() const
Definition: DryGasPvt.hpp:327
DryGasPvt(const std::vector< Scalar > &gasReferenceDensity, const std::vector< TabulatedOneDFunction > &inverseGasB, const std::vector< TabulatedOneDFunction > &gasMu, const std::vector< TabulatedOneDFunction > &inverseGasBMu)
Definition: DryGasPvt.hpp:57
Evaluation saturatedWaterVaporizationFactor(unsigned, const Evaluation &, const Evaluation &) const
Returns the water vaporization factor [m^3/m^3] of the water phase.
Definition: DryGasPvt.hpp:277
void setMolarMasses(unsigned, Scalar, Scalar, Scalar)
Initialize the reference densities of all fluids for a given PVT region.
Definition: DryGasPvt.hpp:142
void setGasViscosity(unsigned regionIdx, const TabulatedOneDFunction &mug)
Initialize the viscosity of the gas phase.
Definition: DryGasPvt.hpp:153
void setReferenceDensities(unsigned regionIdx, Scalar, Scalar rhoRefGas, Scalar)
Initialize the reference densities of all fluids for a given PVT region.
Definition: DryGasPvt.hpp:131
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: DryGasPvt.hpp:297
Implements a linearly interpolated scalar function that depends on one variable.
Definition: Tabulated1DFunction.hpp:48
Definition: Air_Mesitylene.hpp:34