My Project
LiveOilPvt.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_LIVE_OIL_PVT_HPP
28#define OPM_LIVE_OIL_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
62 void initFromState(const EclipseState& eclState, const Schedule& schedule);
63
64private:
65 void extendPvtoTable_(unsigned regionIdx,
66 unsigned xIdx,
67 const SimpleTable& curTable,
68 const SimpleTable& masterTable);
69
70public:
71#endif // HAVE_ECL_INPUT
72
73 void setNumRegions(size_t numRegions);
74
78 void setReferenceDensities(unsigned regionIdx,
79 Scalar rhoRefOil,
80 Scalar rhoRefGas,
81 Scalar /*rhoRefWater*/);
82
88 void setSaturatedOilGasDissolutionFactor(unsigned regionIdx, const SamplingPoints& samplePoints)
89 { saturatedGasDissolutionFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
90
101 const SamplingPoints& samplePoints);
102
115 void setInverseOilFormationVolumeFactor(unsigned regionIdx, const TabulatedTwoDFunction& invBo)
116 { inverseOilBTable_[regionIdx] = invBo; }
117
123 void setOilViscosity(unsigned regionIdx, const TabulatedTwoDFunction& muo)
124 { oilMuTable_[regionIdx] = muo; }
125
133 void setSaturatedOilViscosity(unsigned regionIdx,
134 const SamplingPoints& samplePoints);
135
139 void initEnd();
140
144 unsigned numRegions() const
145 { return inverseOilBMuTable_.size(); }
146
150 template <class Evaluation>
151 Evaluation internalEnergy(unsigned,
152 const Evaluation&,
153 const Evaluation&,
154 const Evaluation&) const
155 {
156 throw std::runtime_error("Requested the enthalpy of oil but the thermal option is not enabled");
157 }
158
162 template <class Evaluation>
163 Evaluation viscosity(unsigned regionIdx,
164 const Evaluation& /*temperature*/,
165 const Evaluation& pressure,
166 const Evaluation& Rs) const
167 {
168 // ATTENTION: Rs is the first axis!
169 const Evaluation& invBo = inverseOilBTable_[regionIdx].eval(Rs, pressure, /*extrapolate=*/true);
170 const Evaluation& invMuoBo = inverseOilBMuTable_[regionIdx].eval(Rs, pressure, /*extrapolate=*/true);
171
172 return invBo/invMuoBo;
173 }
174
178 template <class Evaluation>
179 Evaluation saturatedViscosity(unsigned regionIdx,
180 const Evaluation& /*temperature*/,
181 const Evaluation& pressure) const
182 {
183 // ATTENTION: Rs is the first axis!
184 const Evaluation& invBo = inverseSaturatedOilBTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
185 const Evaluation& invMuoBo = inverseSaturatedOilBMuTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
186
187 return invBo/invMuoBo;
188 }
189
193 template <class Evaluation>
194 Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
195 const Evaluation& /*temperature*/,
196 const Evaluation& pressure,
197 const Evaluation& Rs) const
198 {
199 // ATTENTION: Rs is represented by the _first_ axis!
200 return inverseOilBTable_[regionIdx].eval(Rs, pressure, /*extrapolate=*/true);
201 }
202
206 template <class Evaluation>
207 Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
208 const Evaluation& /*temperature*/,
209 const Evaluation& pressure) const
210 {
211 // ATTENTION: Rs is represented by the _first_ axis!
212 return inverseSaturatedOilBTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
213 }
214
218 template <class Evaluation>
219 Evaluation saturatedGasDissolutionFactor(unsigned regionIdx,
220 const Evaluation& /*temperature*/,
221 const Evaluation& pressure) const
222 { return saturatedGasDissolutionFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true); }
223
231 template <class Evaluation>
232 Evaluation saturatedGasDissolutionFactor(unsigned regionIdx,
233 const Evaluation& /*temperature*/,
234 const Evaluation& pressure,
235 const Evaluation& oilSaturation,
236 Evaluation maxOilSaturation) const
237 {
238 Evaluation tmp =
239 saturatedGasDissolutionFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
240
241 // apply the vaporization parameters for the gas phase (cf. the Eclipse VAPPARS
242 // keyword)
243 maxOilSaturation = min(maxOilSaturation, Scalar(1.0));
244 if (vapPar2_ > 0.0 && maxOilSaturation > 0.01 && oilSaturation < maxOilSaturation) {
245 constexpr const Scalar eps = 0.001;
246 const Evaluation& So = max(oilSaturation, eps);
247 tmp *= max(1e-3, pow(So/maxOilSaturation, vapPar2_));
248 }
249
250 return tmp;
251 }
252
259 template <class Evaluation>
260 Evaluation saturationPressure(unsigned regionIdx,
261 const Evaluation&,
262 const Evaluation& Rs) const
263 {
264 typedef MathToolbox<Evaluation> Toolbox;
265
266 const auto& RsTable = saturatedGasDissolutionFactorTable_[regionIdx];
267 constexpr const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon()*1e6;
268
269 // use the saturation pressure function to get a pretty good initial value
270 Evaluation pSat = saturationPressure_[regionIdx].eval(Rs, /*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 (int i = 0; i < 20; ++i) {
277 const Evaluation& f = RsTable.eval(pSat, /*extrapolate=*/true) - Rs;
278 const Evaluation& fPrime = RsTable.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 ", Rs = " + std::to_string(getValue(Rs));
308 OpmLog::debug("Live oil 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 oilReferenceDensity(unsigned regionIdx) const
324 { return oilReferenceDensity_[regionIdx]; }
325
326 const std::vector<TabulatedTwoDFunction>& inverseOilBTable() const
327 { return inverseOilBTable_; }
328
329 const std::vector<TabulatedTwoDFunction>& oilMuTable() const
330 { return oilMuTable_; }
331
332 const std::vector<TabulatedTwoDFunction>& inverseOilBMuTable() const
333 { return inverseOilBMuTable_; }
334
335 const std::vector<TabulatedOneDFunction>& saturatedOilMuTable() const
336 { return saturatedOilMuTable_; }
337
338 const std::vector<TabulatedOneDFunction>& inverseSaturatedOilBTable() const
339 { return inverseSaturatedOilBTable_; }
340
341 const std::vector<TabulatedOneDFunction>& inverseSaturatedOilBMuTable() const
342 { return inverseSaturatedOilBMuTable_; }
343
344 const std::vector<TabulatedOneDFunction>& saturatedGasDissolutionFactorTable() const
345 { return saturatedGasDissolutionFactorTable_; }
346
347 const std::vector<TabulatedOneDFunction>& saturationPressure() const
348 { return saturationPressure_; }
349
350 Scalar vapPar2() const
351 { return vapPar2_; }
352
353private:
354 void updateSaturationPressure_(unsigned regionIdx);
355
356 std::vector<Scalar> gasReferenceDensity_;
357 std::vector<Scalar> oilReferenceDensity_;
358 std::vector<TabulatedTwoDFunction> inverseOilBTable_;
359 std::vector<TabulatedTwoDFunction> oilMuTable_;
360 std::vector<TabulatedTwoDFunction> inverseOilBMuTable_;
361 std::vector<TabulatedOneDFunction> saturatedOilMuTable_;
362 std::vector<TabulatedOneDFunction> inverseSaturatedOilBTable_;
363 std::vector<TabulatedOneDFunction> inverseSaturatedOilBMuTable_;
364 std::vector<TabulatedOneDFunction> saturatedGasDissolutionFactorTable_;
365 std::vector<TabulatedOneDFunction> saturationPressure_;
366
367 Scalar vapPar2_ = 0.0;
368};
369
370} // namespace Opm
371
372#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...
Definition: EclipseState.hpp:55
This class represents the Pressure-Volume-Temperature relations of the oil phas with dissolved gas.
Definition: LiveOilPvt.hpp:51
Evaluation internalEnergy(unsigned, const Evaluation &, const Evaluation &, const Evaluation &) const
Returns the specific enthalpy [J/kg] of oil given a set of parameters.
Definition: LiveOilPvt.hpp:151
void setSaturatedOilFormationVolumeFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil formation volume factor.
Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &Rs) const
Returns the formation volume factor [-] of the fluid phase.
Definition: LiveOilPvt.hpp:194
Evaluation saturatedGasDissolutionFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &oilSaturation, Evaluation maxOilSaturation) const
Returns the gas dissolution factor [m^3/m^3] of the oil phase.
Definition: LiveOilPvt.hpp:232
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the formation volume factor [-] of the fluid phase.
Definition: LiveOilPvt.hpp:207
void setSaturatedOilViscosity(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the phase viscosity for gas saturated oil.
Evaluation saturationPressure(unsigned regionIdx, const Evaluation &, const Evaluation &Rs) const
Returns the saturation pressure of the oil phase [Pa] depending on its mass fraction of the gas compo...
Definition: LiveOilPvt.hpp:260
void setSaturatedOilGasDissolutionFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the gas dissolution factor .
Definition: LiveOilPvt.hpp:88
Evaluation viscosity(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &Rs) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition: LiveOilPvt.hpp:163
void setReferenceDensities(unsigned regionIdx, Scalar rhoRefOil, Scalar rhoRefGas, Scalar)
Initialize the reference densities of all fluids for a given PVT region.
void setOilViscosity(unsigned regionIdx, const TabulatedTwoDFunction &muo)
Initialize the viscosity of the oil phase.
Definition: LiveOilPvt.hpp:123
Evaluation saturatedGasDissolutionFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the gas dissolution factor [m^3/m^3] of the oil phase.
Definition: LiveOilPvt.hpp:219
Evaluation saturatedViscosity(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition: LiveOilPvt.hpp:179
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition: LiveOilPvt.hpp:144
void initEnd()
Finish initializing the oil phase PVT properties.
void setInverseOilFormationVolumeFactor(unsigned regionIdx, const TabulatedTwoDFunction &invBo)
Initialize the function for the oil formation volume factor.
Definition: LiveOilPvt.hpp:115
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