WetHumidGasPvt.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_WET_HUMID_GAS_PVT_HPP
28#define OPM_WET_HUMID_GAS_PVT_HPP
29
33
34#if HAVE_ECL_INPUT
35#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
36#include <opm/input/eclipse/EclipseState/Tables/TableManager.hpp>
37
38#endif
39
40#if HAVE_OPM_COMMON
41#include <opm/common/OpmLog/OpmLog.hpp>
42#endif
43
44namespace Opm {
45
50template <class Scalar>
52{
53 using SamplingPoints = std::vector<std::pair<Scalar, Scalar>>;
54
55public:
58
60 {
61 vapPar1_ = 0.0;
62 }
63
64 WetHumidGasPvt(const std::vector<Scalar>& gasReferenceDensity,
65 const std::vector<Scalar>& oilReferenceDensity,
66 const std::vector<Scalar>& waterReferenceDensity,
67 const std::vector<TabulatedTwoDFunction>& inverseGasBRvwSat,
68 const std::vector<TabulatedTwoDFunction>& inverseGasBRvSat,
69 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasB,
70 const std::vector<TabulatedTwoDFunction>& gasMuRvwSat,
71 const std::vector<TabulatedTwoDFunction>& gasMuRvSat,
72 const std::vector<TabulatedTwoDFunction>& inverseGasBMuRvwSat,
73 const std::vector<TabulatedTwoDFunction>& inverseGasBMuRvSat,
74 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasBMu,
75 const std::vector<TabulatedOneDFunction>& saturatedWaterVaporizationFactorTable,
76 const std::vector<TabulatedTwoDFunction>& saturatedWaterVaporizationSaltFactorTable,
77 const std::vector<TabulatedOneDFunction>& saturatedOilVaporizationFactorTable,
78 const std::vector<TabulatedOneDFunction>& saturationPressure,
79 Scalar vapPar1)
80 : gasReferenceDensity_(gasReferenceDensity)
81 , oilReferenceDensity_(oilReferenceDensity)
82 , waterReferenceDensity_(waterReferenceDensity)
83 , inverseGasBRvwSat_(inverseGasBRvwSat) // inverse of Bg evaluated at saturated water-gas ratio (Rvw) values; pvtg
84 , inverseGasBRvSat_(inverseGasBRvSat) // inverse of Bg evaluated at saturated oil-gas ratio (Rv) values; pvtgw
85 , inverseSaturatedGasB_(inverseSaturatedGasB) // evaluated at saturated water-gas ratio (Rvw) and oil-gas ratio (Rv) values; pvtgw
86 , gasMuRvwSat_(gasMuRvwSat) // Mug evaluated at saturated water-gas ratio (Rvw) values; pvtg
87 , gasMuRvSat_(gasMuRvSat) // Mug evaluated at saturated oil-gas ratio (Rv) values; pvtgw
88 , inverseGasBMuRvwSat_(inverseGasBMuRvwSat) // Bg^-1*Mug evaluated at saturated water-gas ratio (Rvw) values; pvtg
89 , inverseGasBMuRvSat_(inverseGasBMuRvSat) // Bg^-1*Mug evaluated at saturated oil-gas ratio (Rv) values; pvtgw
90 , inverseSaturatedGasBMu_(inverseSaturatedGasBMu) //pvtgw
91 , saturatedWaterVaporizationFactorTable_(saturatedWaterVaporizationFactorTable) //pvtgw
92 , saturatedWaterVaporizationSaltFactorTable_(saturatedWaterVaporizationSaltFactorTable) //rwgsalt
93 , saturatedOilVaporizationFactorTable_(saturatedOilVaporizationFactorTable) //pvtg
94 , saturationPressure_(saturationPressure)
95 , vapPar1_(vapPar1)
96 {
97 }
98
99
100#if HAVE_ECL_INPUT
106 void initFromState(const EclipseState& eclState, const Schedule& schedule)
107 {
108 const auto& pvtgwTables = eclState.getTableManager().getPvtgwTables();
109 const auto& pvtgTables = eclState.getTableManager().getPvtgTables();
110 const auto& densityTable = eclState.getTableManager().getDensityTable();
111
112 assert(pvtgwTables.size() == densityTable.size());
113 assert(pvtgTables.size() == densityTable.size());
114
115 size_t numRegions = pvtgwTables.size();
117
118 for (unsigned regionIdx = 0; regionIdx < numRegions; ++ regionIdx) {
119 Scalar rhoRefO = densityTable[regionIdx].oil;
120 Scalar rhoRefG = densityTable[regionIdx].gas;
121 Scalar rhoRefW = densityTable[regionIdx].water;
122
123 setReferenceDensities(regionIdx, rhoRefO, rhoRefG, rhoRefW);
124 }
125
126 enableRwgSalt_ = !eclState.getTableManager().getRwgSaltTables().empty();
127 if (enableRwgSalt_)
128 {
129 const auto& rwgsaltTables = eclState.getTableManager().getRwgSaltTables();
130
131 for (unsigned regionIdx = 0; regionIdx < numRegions; ++ regionIdx) {
132 const auto& rwgsaltTable = rwgsaltTables[regionIdx];
133 const auto& saturatedTable = rwgsaltTable.getSaturatedTable();
134 assert(saturatedTable.numRows() > 1);
135
136 auto& waterVaporizationFac = saturatedWaterVaporizationSaltFactorTable_[regionIdx];
137 for (unsigned outerIdx = 0; outerIdx < saturatedTable.numRows(); ++ outerIdx) {
138 const auto& underSaturatedTable = rwgsaltTable.getUnderSaturatedTable(outerIdx);
139 Scalar pg = saturatedTable.get("PG" , outerIdx);
140 waterVaporizationFac.appendXPos(pg);
141
142 size_t numRows = underSaturatedTable.numRows();
143 for (size_t innerIdx = 0; innerIdx < numRows; ++ innerIdx) {
144 Scalar saltConcentration = underSaturatedTable.get("C_SALT" , innerIdx);
145 Scalar rvwSat= underSaturatedTable.get("RVW" , innerIdx);
146
147 waterVaporizationFac.appendSamplePoint(outerIdx, saltConcentration, rvwSat);
148 }
149 }
150 }
151 }
152
153 // Table PVTGW
154 for (unsigned regionIdx = 0; regionIdx < numRegions; ++ regionIdx) {
155 const auto& pvtgwTable = pvtgwTables[regionIdx];
156
157 const auto& saturatedTable = pvtgwTable.getSaturatedTable();
158 assert(saturatedTable.numRows() > 1);
159
160 // PVTGW table contains values at saturated Rv
161 auto& gasMuRvSat = gasMuRvSat_[regionIdx];
162 auto& invGasBRvSat = inverseGasBRvSat_[regionIdx];
163 auto& invSatGasB = inverseSaturatedGasB_[regionIdx];
164 auto& invSatGasBMu = inverseSaturatedGasBMu_[regionIdx];
165 auto& waterVaporizationFac = saturatedWaterVaporizationFactorTable_[regionIdx];
166
167 waterVaporizationFac.setXYArrays(saturatedTable.numRows(),
168 saturatedTable.getColumn("PG"),
169 saturatedTable.getColumn("RW"));
170
171 std::vector<Scalar> invSatGasBArray;
172 std::vector<Scalar> invSatGasBMuArray;
173
174 // extract the table for the gas viscosity and formation volume factors
175 for (unsigned outerIdx = 0; outerIdx < saturatedTable.numRows(); ++ outerIdx) {
176 Scalar pg = saturatedTable.get("PG" , outerIdx);
177 Scalar B = saturatedTable.get("BG" , outerIdx);
178 Scalar mu = saturatedTable.get("MUG" , outerIdx);
179
180 invGasBRvSat.appendXPos(pg);
181 gasMuRvSat.appendXPos(pg);
182
183 invSatGasBArray.push_back(1.0/B);
184 invSatGasBMuArray.push_back(1.0/(mu*B));
185
186 assert(invGasBRvSat.numX() == outerIdx + 1);
187 assert(gasMuRvSat.numX() == outerIdx + 1);
188
189 const auto& underSaturatedTable = pvtgwTable.getUnderSaturatedTable(outerIdx);
190 size_t numRows = underSaturatedTable.numRows();
191 for (size_t innerIdx = 0; innerIdx < numRows; ++ innerIdx) {
192 Scalar Rw = underSaturatedTable.get("RW" , innerIdx);
193 Scalar Bg = underSaturatedTable.get("BG" , innerIdx);
194 Scalar mug = underSaturatedTable.get("MUG" , innerIdx);
195
196 invGasBRvSat.appendSamplePoint(outerIdx, Rw, 1.0/Bg);
197 gasMuRvSat.appendSamplePoint(outerIdx, Rw, mug);
198 }
199 }
200
201 {
202 std::vector<double> tmpPressure = saturatedTable.getColumn("PG").vectorCopy( );
203
204 invSatGasB.setXYContainers(tmpPressure, invSatGasBArray);
205 invSatGasBMu.setXYContainers(tmpPressure, invSatGasBMuArray);
206 }
207
208 // make sure to have at least two sample points per gas pressure value
209 for (unsigned xIdx = 0; xIdx < invGasBRvSat.numX(); ++xIdx) {
210 // a single sample point is definitely needed
211 assert(invGasBRvSat.numY(xIdx) > 0);
212
213 // everything is fine if the current table has two or more sampling points
214 // for a given mole fraction
215 if (invGasBRvSat.numY(xIdx) > 1)
216 continue;
217
218 // find the master table which will be used as a template to extend the
219 // current line. We define master table as the first table which has values
220 // for undersaturated gas...
221 size_t masterTableIdx = xIdx + 1;
222 for (; masterTableIdx < saturatedTable.numRows(); ++masterTableIdx)
223 {
224 if (pvtgwTable.getUnderSaturatedTable(masterTableIdx).numRows() > 1)
225 break;
226 }
227
228 if (masterTableIdx >= saturatedTable.numRows())
229 throw std::runtime_error("PVTGW tables are invalid: The last table must exhibit at least one "
230 "entry for undersaturated gas!");
231
232
233 // extend the current table using the master table.
234 extendPvtgwTable_(regionIdx,
235 xIdx,
236 pvtgwTable.getUnderSaturatedTable(xIdx),
237 pvtgwTable.getUnderSaturatedTable(masterTableIdx));
238 }
239 }
240
241 // Table PVTG
242 for (unsigned regionIdx = 0; regionIdx < numRegions; ++ regionIdx) {
243 const auto& pvtgTable = pvtgTables[regionIdx];
244
245 const auto& saturatedTable = pvtgTable.getSaturatedTable();
246 assert(saturatedTable.numRows() > 1);
247 // PVTG table contains values at saturated Rvw
248 auto& gasMuRvwSat = gasMuRvwSat_[regionIdx];
249 auto& invGasBRvwSat = inverseGasBRvwSat_[regionIdx];
250 auto& invSatGasB = inverseSaturatedGasB_[regionIdx];
251 auto& invSatGasBMu = inverseSaturatedGasBMu_[regionIdx];
252 auto& oilVaporizationFac = saturatedOilVaporizationFactorTable_[regionIdx];
253
254 oilVaporizationFac.setXYArrays(saturatedTable.numRows(),
255 saturatedTable.getColumn("PG"),
256 saturatedTable.getColumn("RV"));
257
258 std::vector<Scalar> invSatGasBArray;
259 std::vector<Scalar> invSatGasBMuArray;
260
262 for (unsigned outerIdx = 0; outerIdx < saturatedTable.numRows(); ++ outerIdx) {
263 Scalar pg = saturatedTable.get("PG" , outerIdx);
264 Scalar B = saturatedTable.get("BG" , outerIdx);
265 Scalar mu = saturatedTable.get("MUG" , outerIdx);
266
267 invGasBRvwSat.appendXPos(pg);
268 gasMuRvwSat.appendXPos(pg);
269
270 invSatGasBArray.push_back(1.0/B);
271 invSatGasBMuArray.push_back(1.0/(mu*B));
272
273 assert(invGasBRvwSat.numX() == outerIdx + 1);
274 assert(gasMuRvwSat.numX() == outerIdx + 1);
275
276 const auto& underSaturatedTable = pvtgTable.getUnderSaturatedTable(outerIdx);
277 size_t numRows = underSaturatedTable.numRows();
278 for (size_t innerIdx = 0; innerIdx < numRows; ++ innerIdx) {
279 Scalar Rv = underSaturatedTable.get("RV" , innerIdx);
280 Scalar Bg = underSaturatedTable.get("BG" , innerIdx);
281 Scalar mug = underSaturatedTable.get("MUG" , innerIdx);
282
283 invGasBRvwSat.appendSamplePoint(outerIdx, Rv, 1.0/Bg);
284 gasMuRvwSat.appendSamplePoint(outerIdx, Rv, mug);
285 }
286 }
287
288 {
289 std::vector<double> tmpPressure = saturatedTable.getColumn("PG").vectorCopy( );
290
291 invSatGasB.setXYContainers(tmpPressure, invSatGasBArray);
292 invSatGasBMu.setXYContainers(tmpPressure, invSatGasBMuArray);
293 }
294
295 // make sure to have at least two sample points per gas pressure value
296 for (unsigned xIdx = 0; xIdx < invGasBRvwSat.numX(); ++xIdx) {
297 // a single sample point is definitely needed
298 assert(invGasBRvwSat.numY(xIdx) > 0);
299
300 // everything is fine if the current table has two or more sampling points
301 // for a given mole fraction
302 if (invGasBRvwSat.numY(xIdx) > 1)
303 continue;
304
305 // find the master table which will be used as a template to extend the
306 // current line. We define master table as the first table which has values
307 // for undersaturated gas...
308 size_t masterTableIdx = xIdx + 1;
309 for (; masterTableIdx < saturatedTable.numRows(); ++masterTableIdx)
310 {
311 if (pvtgTable.getUnderSaturatedTable(masterTableIdx).numRows() > 1)
312 break;
313 }
314
315 if (masterTableIdx >= saturatedTable.numRows())
316 throw std::runtime_error("PVTG tables are invalid: The last table must exhibit at least one "
317 "entry for undersaturated gas!");
318
319
320 // extend the current table using the master table.
321 extendPvtgTable_(regionIdx,
322 xIdx,
323 pvtgTable.getUnderSaturatedTable(xIdx),
324 pvtgTable.getUnderSaturatedTable(masterTableIdx));
325 }
326 }
327 vapPar1_ = 0.0;
328 const auto& oilVap = schedule[0].oilvap();
329 if (oilVap.getType() == OilVaporizationProperties::OilVaporization::VAPPARS) {
330 vapPar1_ = oilVap.vap1();
331 }
332
333 initEnd();
334 }
335
336private:
337 void extendPvtgwTable_(unsigned regionIdx,
338 unsigned xIdx,
339 const SimpleTable& curTable,
340 const SimpleTable& masterTable)
341 {
342 std::vector<double> RvArray = curTable.getColumn("RW").vectorCopy();
343 std::vector<double> gasBArray = curTable.getColumn("BG").vectorCopy();
344 std::vector<double> gasMuArray = curTable.getColumn("MUG").vectorCopy();
345
346 auto& invGasBRvSat = inverseGasBRvSat_[regionIdx];
347 auto& gasMuRvSat = gasMuRvSat_[regionIdx];
348
349 for (size_t newRowIdx = 1; newRowIdx < masterTable.numRows(); ++ newRowIdx) {
350 const auto& RVColumn = masterTable.getColumn("RW");
351 const auto& BGColumn = masterTable.getColumn("BG");
352 const auto& viscosityColumn = masterTable.getColumn("MUG");
353
354 // compute the gas pressure for the new entry
355 Scalar diffRv = RVColumn[newRowIdx] - RVColumn[newRowIdx - 1];
356 Scalar newRv = RvArray.back() + diffRv;
357
358 // calculate the compressibility of the master table
359 Scalar B1 = BGColumn[newRowIdx];
360 Scalar B2 = BGColumn[newRowIdx - 1];
361 Scalar x = (B1 - B2)/( (B1 + B2)/2.0 );
362
363 // calculate the gas formation volume factor which exhibits the same
364 // "compressibility" for the new value of Rv
365 Scalar newBg = gasBArray.back()*(1.0 + x/2.0)/(1.0 - x/2.0);
366
367 // calculate the "viscosibility" of the master table
368 Scalar mu1 = viscosityColumn[newRowIdx];
369 Scalar mu2 = viscosityColumn[newRowIdx - 1];
370 Scalar xMu = (mu1 - mu2)/( (mu1 + mu2)/2.0 );
371
372 // calculate the gas formation volume factor which exhibits the same
373 // compressibility for the new pressure
374 Scalar newMug = gasMuArray.back()*(1.0 + xMu/2)/(1.0 - xMu/2.0);
375
376 // append the new values to the arrays which we use to compute the additional
377 // values ...
378 RvArray.push_back(newRv);
379 gasBArray.push_back(newBg);
380 gasMuArray.push_back(newMug);
381
382 // ... and register them with the internal table objects
383 invGasBRvSat.appendSamplePoint(xIdx, newRv, 1.0/newBg);
384 gasMuRvSat.appendSamplePoint(xIdx, newRv, newMug);
385 }
386 }
387 void extendPvtgTable_(unsigned regionIdx,
388 unsigned xIdx,
389 const SimpleTable& curTable,
390 const SimpleTable& masterTable)
391 {
392 std::vector<double> RvArray = curTable.getColumn("RV").vectorCopy();
393 std::vector<double> gasBArray = curTable.getColumn("BG").vectorCopy();
394 std::vector<double> gasMuArray = curTable.getColumn("MUG").vectorCopy();
395
396 auto& invGasBRvwSat= inverseGasBRvwSat_[regionIdx];
397 auto& gasMuRvwSat = gasMuRvwSat_[regionIdx];
398
399 for (size_t newRowIdx = 1; newRowIdx < masterTable.numRows(); ++ newRowIdx) {
400 const auto& RVColumn = masterTable.getColumn("RV");
401 const auto& BGColumn = masterTable.getColumn("BG");
402 const auto& viscosityColumn = masterTable.getColumn("MUG");
403
404 // compute the gas pressure for the new entry
405 Scalar diffRv = RVColumn[newRowIdx] - RVColumn[newRowIdx - 1];
406 Scalar newRv = RvArray.back() + diffRv;
407
408 // calculate the compressibility of the master table
409 Scalar B1 = BGColumn[newRowIdx];
410 Scalar B2 = BGColumn[newRowIdx - 1];
411 Scalar x = (B1 - B2)/( (B1 + B2)/2.0 );
412
413 // calculate the gas formation volume factor which exhibits the same
414 // "compressibility" for the new value of Rv
415 Scalar newBg = gasBArray.back()*(1.0 + x/2.0)/(1.0 - x/2.0);
416
417 // calculate the "viscosibility" of the master table
418 Scalar mu1 = viscosityColumn[newRowIdx];
419 Scalar mu2 = viscosityColumn[newRowIdx - 1];
420 Scalar xMu = (mu1 - mu2)/( (mu1 + mu2)/2.0 );
421
422 // calculate the gas formation volume factor which exhibits the same
423 // compressibility for the new pressure
424 Scalar newMug = gasMuArray.back()*(1.0 + xMu/2)/(1.0 - xMu/2.0);
425
426 // append the new values to the arrays which we use to compute the additional
427 // values ...
428 RvArray.push_back(newRv);
429 gasBArray.push_back(newBg);
430 gasMuArray.push_back(newMug);
431
432 // ... and register them with the internal table objects
433 invGasBRvwSat.appendSamplePoint(xIdx, newRv, 1.0/newBg);
434 gasMuRvwSat.appendSamplePoint(xIdx, newRv, newMug);
435 }
436 }
437
438public:
439#endif // HAVE_ECL_INPUT
440
442 {
443 waterReferenceDensity_.resize(numRegions);
444 oilReferenceDensity_.resize(numRegions);
445 gasReferenceDensity_.resize(numRegions);
446 inverseGasBRvwSat_.resize(numRegions, TabulatedTwoDFunction{TabulatedTwoDFunction::InterpolationPolicy::RightExtreme});
447 inverseGasBRvSat_.resize(numRegions, TabulatedTwoDFunction{TabulatedTwoDFunction::InterpolationPolicy::RightExtreme});
448 inverseGasBMuRvwSat_.resize(numRegions, TabulatedTwoDFunction{TabulatedTwoDFunction::InterpolationPolicy::RightExtreme});
449 inverseGasBMuRvSat_.resize(numRegions, TabulatedTwoDFunction{TabulatedTwoDFunction::InterpolationPolicy::RightExtreme});
450 inverseSaturatedGasB_.resize(numRegions);
451 inverseSaturatedGasBMu_.resize(numRegions);
452 gasMuRvwSat_.resize(numRegions, TabulatedTwoDFunction{TabulatedTwoDFunction::InterpolationPolicy::RightExtreme});
453 gasMuRvSat_.resize(numRegions, TabulatedTwoDFunction{TabulatedTwoDFunction::InterpolationPolicy::RightExtreme});
454 saturatedWaterVaporizationFactorTable_.resize(numRegions);
455 saturatedWaterVaporizationSaltFactorTable_.resize(numRegions, TabulatedTwoDFunction{TabulatedTwoDFunction::InterpolationPolicy::RightExtreme});
456 saturatedOilVaporizationFactorTable_.resize(numRegions);
457 saturationPressure_.resize(numRegions);
458 }
459
463 void setReferenceDensities(unsigned regionIdx,
464 Scalar rhoRefOil,
465 Scalar rhoRefGas,
466 Scalar rhoRefWater)
467 {
468 waterReferenceDensity_[regionIdx] = rhoRefWater;
469 oilReferenceDensity_[regionIdx] = rhoRefOil;
470 gasReferenceDensity_[regionIdx] = rhoRefGas;
471 }
472
478 void setSaturatedGasWaterVaporizationFactor(unsigned regionIdx, const SamplingPoints& samplePoints)
479 { saturatedWaterVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
480
486 void setSaturatedGasOilVaporizationFactor(unsigned regionIdx, const SamplingPoints& samplePoints)
487 { saturatedOilVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
488
489
493 void initEnd()
494 {
495
496 //PVTGW
497 // calculate the final 2D functions which are used for interpolation.
498 size_t numRegions = gasMuRvSat_.size();
499 for (unsigned regionIdx = 0; regionIdx < numRegions; ++ regionIdx) {
500 // calculate the table which stores the inverse of the product of the gas
501 // formation volume factor and the gas viscosity
502 const auto& gasMuRvSat = gasMuRvSat_[regionIdx];
503 const auto& invGasBRvSat = inverseGasBRvSat_[regionIdx];
504 assert(gasMuRvSat.numX() == invGasBRvSat.numX());
505
506 auto& invGasBMuRvSat = inverseGasBMuRvSat_[regionIdx];
507 auto& invSatGasB = inverseSaturatedGasB_[regionIdx];
508 auto& invSatGasBMu = inverseSaturatedGasBMu_[regionIdx];
509
510 std::vector<Scalar> satPressuresArray;
511 std::vector<Scalar> invSatGasBArray;
512 std::vector<Scalar> invSatGasBMuArray;
513 for (size_t pIdx = 0; pIdx < gasMuRvSat.numX(); ++pIdx) {
514 invGasBMuRvSat.appendXPos(gasMuRvSat.xAt(pIdx));
515
516 assert(gasMuRvSat.numY(pIdx) == invGasBRvSat.numY(pIdx));
517
518 size_t numRw = gasMuRvSat.numY(pIdx);
519 for (size_t RwIdx = 0; RwIdx < numRw; ++RwIdx)
520 invGasBMuRvSat.appendSamplePoint(pIdx,
521 gasMuRvSat.yAt(pIdx, RwIdx),
522 invGasBRvSat.valueAt(pIdx, RwIdx)
523 / gasMuRvSat.valueAt(pIdx, RwIdx));
524
525 // the sampling points in UniformXTabulated2DFunction are always sorted
526 // in ascending order. Thus, the value for saturated gas is the last one
527 // (i.e., the one with the largest Rw value)
528 satPressuresArray.push_back(gasMuRvSat.xAt(pIdx));
529 invSatGasBArray.push_back(invGasBRvSat.valueAt(pIdx, numRw - 1));
530 invSatGasBMuArray.push_back(invGasBMuRvSat.valueAt(pIdx, numRw - 1));
531 }
532
533 invSatGasB.setXYContainers(satPressuresArray, invSatGasBArray);
534 invSatGasBMu.setXYContainers(satPressuresArray, invSatGasBMuArray);
535 }
536
537 //PVTG
538 // calculate the final 2D functions which are used for interpolation.
539 //size_t numRegions = gasMuRvwSat_.size();
540 for (unsigned regionIdx = 0; regionIdx < numRegions; ++ regionIdx) {
541 // calculate the table which stores the inverse of the product of the gas
542 // formation volume factor and the gas viscosity
543 const auto& gasMuRvwSat = gasMuRvwSat_[regionIdx];
544 const auto& invGasBRvwSat = inverseGasBRvwSat_[regionIdx];
545 assert(gasMuRvwSat.numX() == invGasBRvwSat.numX());
546
547 auto& invGasBMuRvwSat = inverseGasBMuRvwSat_[regionIdx];
548 auto& invSatGasB = inverseSaturatedGasB_[regionIdx];
549 auto& invSatGasBMu = inverseSaturatedGasBMu_[regionIdx];
550
551 std::vector<Scalar> satPressuresArray;
552 std::vector<Scalar> invSatGasBArray;
553 std::vector<Scalar> invSatGasBMuArray;
554 for (size_t pIdx = 0; pIdx < gasMuRvwSat.numX(); ++pIdx) {
555 invGasBMuRvwSat.appendXPos(gasMuRvwSat.xAt(pIdx));
556
557 assert(gasMuRvwSat.numY(pIdx) == invGasBRvwSat.numY(pIdx));
558
559 size_t numRw = gasMuRvwSat.numY(pIdx);
560 for (size_t RwIdx = 0; RwIdx < numRw; ++RwIdx)
561 invGasBMuRvwSat.appendSamplePoint(pIdx,
562 gasMuRvwSat.yAt(pIdx, RwIdx),
563 invGasBRvwSat.valueAt(pIdx, RwIdx)
564 / gasMuRvwSat.valueAt(pIdx, RwIdx));
565
566 // the sampling points in UniformXTabulated2DFunction are always sorted
567 // in ascending order. Thus, the value for saturated gas is the last one
568 // (i.e., the one with the largest Rw value)
569 satPressuresArray.push_back(gasMuRvwSat.xAt(pIdx));
570 invSatGasBArray.push_back(invGasBRvwSat.valueAt(pIdx, numRw - 1));
571 invSatGasBMuArray.push_back(invGasBMuRvwSat.valueAt(pIdx, numRw - 1));
572 }
573
574 invSatGasB.setXYContainers(satPressuresArray, invSatGasBArray);
575 invSatGasBMu.setXYContainers(satPressuresArray, invSatGasBMuArray);
576
577 updateSaturationPressure_(regionIdx);
578 }
579 }
580
584 unsigned numRegions() const
585 { return gasReferenceDensity_.size(); }
586
590 template <class Evaluation>
591 Evaluation internalEnergy(unsigned,
592 const Evaluation&,
593 const Evaluation&,
594 const Evaluation&) const
595 {
596 throw std::runtime_error("Requested the enthalpy of gas but the thermal option is not enabled");
597 }
598
602 template <class Evaluation>
603 Evaluation viscosity(unsigned regionIdx,
604 const Evaluation& /*temperature*/,
605 const Evaluation& pressure,
606 const Evaluation& Rv,
607 const Evaluation& Rvw) const
608 {
609 const Evaluation& temperature = 1E30;
610
611 if (Rv >= (1.0 - 1e-10)*saturatedOilVaporizationFactor(regionIdx, temperature, pressure)) {
612 const Evaluation& invBg = inverseGasBRvSat_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
613 const Evaluation& invMugBg = inverseGasBMuRvSat_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
614 return invBg/invMugBg;
615 }
616 else {
617 // for Rv undersaturated viscosity is evaluated at saturated Rvw values
618 const Evaluation& invBg = inverseGasBRvwSat_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true);
619 const Evaluation& invMugBg = inverseGasBMuRvwSat_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true);
620 return invBg/invMugBg;
621 }
622 }
623
627 template <class Evaluation>
628 Evaluation saturatedViscosity(unsigned regionIdx,
629 const Evaluation& /*temperature*/,
630 const Evaluation& pressure) const
631 {
632 const Evaluation& invBg = inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true);
633 const Evaluation& invMugBg = inverseSaturatedGasBMu_[regionIdx].eval(pressure, /*extrapolate=*/true);
634
635 return invBg/invMugBg;
636 }
637
641 // template <class Evaluation>
642 // Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
643 // const Evaluation& /*temperature*/,
644 // const Evaluation& pressure,
645 // const Evaluation& Rw) const
646 // { return inverseGasB_[regionIdx].eval(pressure, Rw, /*extrapolate=*/true); }
647
648 template <class Evaluation>
649 Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
650 const Evaluation& /*temperature*/,
651 const Evaluation& pressure,
652 const Evaluation& Rv,
653 const Evaluation& Rvw) const
654 {
655 const Evaluation& temperature = 1E30;
656
657 if (Rv >= (1.0 - 1e-10)*saturatedOilVaporizationFactor(regionIdx, temperature, pressure)) {
658 return inverseGasBRvSat_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
659 }
660 else {
661 // for Rv undersaturated Bg^-1 is evaluated at saturated Rvw values
662 return inverseGasBRvwSat_[regionIdx].eval(pressure, Rv, /*extrapolate=*/true);
663 }
664
665 }
666
667
671 template <class Evaluation>
672 Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
673 const Evaluation& /*temperature*/,
674 const Evaluation& pressure) const
675 { return inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true); }
676
680 template <class Evaluation>
681 Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
682 const Evaluation& /*temperature*/,
683 const Evaluation& pressure) const
684 {
685 return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
686 }
687
691 template <class Evaluation>
692 Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
693 const Evaluation& /*temperature*/,
694 const Evaluation& pressure,
695 const Evaluation& saltConcentration) const
696 {
697 if (enableRwgSalt_)
698 return saturatedWaterVaporizationSaltFactorTable_[regionIdx].eval(pressure, saltConcentration, /*extrapolate=*/true);
699 else {
700 return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
701 }
702
703 }
704
705 template <class Evaluation>
706 Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
707 const Evaluation& /*temperature*/,
708 const Evaluation& pressure) const
709 {
710 return saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
711 }
712
720 template <class Evaluation>
721 Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
722 const Evaluation& /*temperature*/,
723 const Evaluation& pressure,
724 const Evaluation& oilSaturation,
725 Evaluation maxOilSaturation) const
726 {
727 Evaluation tmp =
728 saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
729
730 // apply the vaporization parameters for the gas phase (cf. the Eclipse VAPPARS
731 // keyword)
732 maxOilSaturation = min(maxOilSaturation, Scalar(1.0));
733 if (vapPar1_ > 0.0 && maxOilSaturation > 0.01 && oilSaturation < maxOilSaturation) {
734 constexpr const Scalar eps = 0.001;
735 const Evaluation& So = max(oilSaturation, eps);
736 tmp *= max(1e-3, pow(So/maxOilSaturation, vapPar1_));
737 }
738
739 return tmp;
740 }
741
749 //PJPE assume dependence on Rv
750 template <class Evaluation>
751 Evaluation saturationPressure(unsigned regionIdx,
752 const Evaluation&,
753 const Evaluation& Rw) const
754 {
755 using Toolbox = MathToolbox<Evaluation>;
756
757 const auto& RwTable = saturatedWaterVaporizationFactorTable_[regionIdx];
758 constexpr const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon()*1e6;
759
760 // use the tabulated saturation pressure function to get a pretty good initial value
761 Evaluation pSat = saturationPressure_[regionIdx].eval(Rw, /*extrapolate=*/true);
762
763 // Newton method to do the remaining work. If the initial
764 // value is good, this should only take two to three
765 // iterations...
766 bool onProbation = false;
767 for (unsigned i = 0; i < 20; ++i) {
768 const Evaluation& f = RwTable.eval(pSat, /*extrapolate=*/true) - Rw;
769 const Evaluation& fPrime = RwTable.evalDerivative(pSat, /*extrapolate=*/true);
770
771 // If the derivative is "zero" Newton will not converge,
772 // so simply return our initial guess.
773 if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
774 return pSat;
775 }
776
777 const Evaluation& delta = f/fPrime;
778
779 pSat -= delta;
780
781 if (pSat < 0.0) {
782 // if the pressure is lower than 0 Pascals, we set it back to 0. if this
783 // happens twice, we give up and just return 0 Pa...
784 if (onProbation)
785 return 0.0;
786
787 onProbation = true;
788 pSat = 0.0;
789 }
790
791 if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat))*eps)
792 return pSat;
793 }
794
795 std::stringstream errlog;
796 errlog << "Finding saturation pressure did not converge:"
797 << " pSat = " << pSat
798 << ", Rw = " << Rw;
799#if HAVE_OPM_COMMON
800 OpmLog::debug("Wet gas saturation pressure", errlog.str());
801#endif
802 throw NumericalIssue(errlog.str());
803 }
804
805 template <class Evaluation>
806 Evaluation diffusionCoefficient(const Evaluation& /*temperature*/,
807 const Evaluation& /*pressure*/,
808 unsigned /*compIdx*/) const
809 {
810 throw std::runtime_error("Not implemented: The PVT model does not provide a diffusionCoefficient()");
811 }
812
813 const Scalar gasReferenceDensity(unsigned regionIdx) const
814 { return gasReferenceDensity_[regionIdx]; }
815
816 const Scalar oilReferenceDensity(unsigned regionIdx) const
817 { return oilReferenceDensity_[regionIdx]; }
818
819 const Scalar waterReferenceDensity(unsigned regionIdx) const
820 { return waterReferenceDensity_[regionIdx]; }
821
822 const std::vector<TabulatedTwoDFunction>& inverseGasB() const {
823 return inverseGasBRvSat_;
824 }
825
826 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasB() const {
827 return inverseSaturatedGasB_;
828 }
829
830 const std::vector<TabulatedTwoDFunction>& gasMu() const {
831 return gasMuRvSat_;
832 }
833
834 const std::vector<TabulatedTwoDFunction>& inverseGasBMu() const {
835 return inverseGasBMuRvSat_;
836 }
837
838 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasBMu() const {
839 return inverseSaturatedGasBMu_;
840 }
841
842 const std::vector<TabulatedOneDFunction>& saturatedWaterVaporizationFactorTable() const {
843 return saturatedWaterVaporizationFactorTable_;
844 }
845
846 const std::vector<TabulatedTwoDFunction>& saturatedWaterVaporizationSaltFactorTable() const {
847 return saturatedWaterVaporizationSaltFactorTable_;
848 }
849
850 const std::vector<TabulatedOneDFunction>& saturatedOilVaporizationFactorTable() const {
851 return saturatedOilVaporizationFactorTable_;
852 }
853
854 const std::vector<TabulatedOneDFunction>& saturationPressure() const {
855 return saturationPressure_;
856 }
857
858 Scalar vapPar1() const {
859 return vapPar1_;
860 }
861
862 bool operator==(const WetHumidGasPvt<Scalar>& data) const
863 {
864 return this->gasReferenceDensity_ == data.gasReferenceDensity_ &&
865 this->oilReferenceDensity_ == data.oilReferenceDensity_ &&
866 this->waterReferenceDensity_ == data.waterReferenceDensity_ &&
867 this->inverseGasB() == data.inverseGasB() &&
868 this->inverseSaturatedGasB() == data.inverseSaturatedGasB() &&
869 this->gasMu() == data.gasMu() &&
870 this->inverseGasBMu() == data.inverseGasBMu() &&
873 this->saturationPressure() == data.saturationPressure() &&
874 this->vapPar1() == data.vapPar1();
875 }
876
877private:
878 void updateSaturationPressure_(unsigned regionIdx)
879 {
880 const auto& oilVaporizationFac = saturatedOilVaporizationFactorTable_[regionIdx];
881
882 // create the taublated function representing saturation pressure depending of
883 // Rv
884 size_t n = oilVaporizationFac.numSamples();
885 Scalar delta = (oilVaporizationFac.xMax() - oilVaporizationFac.xMin())/Scalar(n + 1);
886
887 SamplingPoints pSatSamplePoints;
888 Scalar Rv = 0;
889 for (size_t i = 0; i <= n; ++ i) {
890 Scalar pSat = oilVaporizationFac.xMin() + Scalar(i)*delta;
891 Rv = saturatedOilVaporizationFactor(regionIdx, /*temperature=*/Scalar(1e30), pSat);
892
893 pSatSamplePoints.emplace_back(Rv, pSat);
894 }
895
896 //Prune duplicate Rv values (can occur, and will cause problems in further interpolation)
897 auto x_coord_comparator = [](const auto& a, const auto& b) { return a.first == b.first; };
898 auto last = std::unique(pSatSamplePoints.begin(), pSatSamplePoints.end(), x_coord_comparator);
899 pSatSamplePoints.erase(last, pSatSamplePoints.end());
900
901 saturationPressure_[regionIdx].setContainerOfTuples(pSatSamplePoints);
902 }
903
904 std::vector<Scalar> gasReferenceDensity_;
905 std::vector<Scalar> waterReferenceDensity_;
906 std::vector<Scalar> oilReferenceDensity_;
907 std::vector<TabulatedTwoDFunction> inverseGasBRvwSat_;
908 std::vector<TabulatedTwoDFunction> inverseGasBRvSat_;
909 std::vector<TabulatedOneDFunction> inverseSaturatedGasB_;
910 std::vector<TabulatedTwoDFunction> gasMuRvwSat_;
911 std::vector<TabulatedTwoDFunction> gasMuRvSat_;
912 std::vector<TabulatedTwoDFunction> inverseGasBMuRvwSat_;
913 std::vector<TabulatedTwoDFunction> inverseGasBMuRvSat_;
914 std::vector<TabulatedOneDFunction> inverseSaturatedGasBMu_;
915 std::vector<TabulatedOneDFunction> saturatedWaterVaporizationFactorTable_;
916 std::vector<TabulatedTwoDFunction> saturatedWaterVaporizationSaltFactorTable_;
917 std::vector<TabulatedOneDFunction> saturatedOilVaporizationFactorTable_;
918 std::vector<TabulatedOneDFunction> saturationPressure_;
919
920 bool enableRwgSalt_;
921 Scalar vapPar1_;
922};
923
924} // namespace Opm
925
926#endif
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...
Definition: Exceptions.hpp:46
Implements a linearly interpolated scalar function that depends on one variable.
Definition: Tabulated1DFunction.hpp:48
Implements a scalar function that depends on two variables and which is sampled uniformly in the X di...
Definition: UniformXTabulated2DFunction.hpp:54
This class represents the Pressure-Volume-Temperature relations of the gas phase with vaporized oil a...
Definition: WetHumidGasPvt.hpp:52
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: WetHumidGasPvt.hpp:751
const std::vector< TabulatedTwoDFunction > & inverseGasB() const
Definition: WetHumidGasPvt.hpp:822
const std::vector< TabulatedTwoDFunction > & gasMu() const
Definition: WetHumidGasPvt.hpp:830
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition: WetHumidGasPvt.hpp:584
void setSaturatedGasOilVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil vaporization factor .
Definition: WetHumidGasPvt.hpp:486
Evaluation viscosity(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &Rv, const Evaluation &Rvw) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition: WetHumidGasPvt.hpp:603
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: WetHumidGasPvt.hpp:692
const Scalar waterReferenceDensity(unsigned regionIdx) const
Definition: WetHumidGasPvt.hpp:819
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the formation volume factor [-] of water saturated gas at a given pressure.
Definition: WetHumidGasPvt.hpp:672
void setNumRegions(size_t numRegions)
Definition: WetHumidGasPvt.hpp:441
const Scalar oilReferenceDensity(unsigned regionIdx) const
Definition: WetHumidGasPvt.hpp:816
Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the water vaporization factor [m^3/m^3] of the water phase.
Definition: WetHumidGasPvt.hpp:681
bool operator==(const WetHumidGasPvt< Scalar > &data) const
Definition: WetHumidGasPvt.hpp:862
WetHumidGasPvt()
Definition: WetHumidGasPvt.hpp:59
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: WetHumidGasPvt.hpp:628
WetHumidGasPvt(const std::vector< Scalar > &gasReferenceDensity, const std::vector< Scalar > &oilReferenceDensity, const std::vector< Scalar > &waterReferenceDensity, const std::vector< TabulatedTwoDFunction > &inverseGasBRvwSat, const std::vector< TabulatedTwoDFunction > &inverseGasBRvSat, const std::vector< TabulatedOneDFunction > &inverseSaturatedGasB, const std::vector< TabulatedTwoDFunction > &gasMuRvwSat, const std::vector< TabulatedTwoDFunction > &gasMuRvSat, const std::vector< TabulatedTwoDFunction > &inverseGasBMuRvwSat, const std::vector< TabulatedTwoDFunction > &inverseGasBMuRvSat, const std::vector< TabulatedOneDFunction > &inverseSaturatedGasBMu, const std::vector< TabulatedOneDFunction > &saturatedWaterVaporizationFactorTable, const std::vector< TabulatedTwoDFunction > &saturatedWaterVaporizationSaltFactorTable, const std::vector< TabulatedOneDFunction > &saturatedOilVaporizationFactorTable, const std::vector< TabulatedOneDFunction > &saturationPressure, Scalar vapPar1)
Definition: WetHumidGasPvt.hpp:64
Evaluation internalEnergy(unsigned, const Evaluation &, const Evaluation &, const Evaluation &) const
Returns the specific enthalpy [J/kg] of gas given a set of parameters.
Definition: WetHumidGasPvt.hpp:591
Evaluation diffusionCoefficient(const Evaluation &, const Evaluation &, unsigned) const
Definition: WetHumidGasPvt.hpp:806
Evaluation saturatedOilVaporizationFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &oilSaturation, Evaluation maxOilSaturation) const
Returns the oil vaporization factor [m^3/m^3] of the gas phase.
Definition: WetHumidGasPvt.hpp:721
Scalar vapPar1() const
Definition: WetHumidGasPvt.hpp:858
void setReferenceDensities(unsigned regionIdx, Scalar rhoRefOil, Scalar rhoRefGas, Scalar rhoRefWater)
Initialize the reference densities of all fluids for a given PVT region.
Definition: WetHumidGasPvt.hpp:463
Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &Rv, const Evaluation &Rvw) const
Returns the formation volume factor [-] of the fluid phase.
Definition: WetHumidGasPvt.hpp:649
const Scalar gasReferenceDensity(unsigned regionIdx) const
Definition: WetHumidGasPvt.hpp:813
const std::vector< TabulatedTwoDFunction > & inverseGasBMu() const
Definition: WetHumidGasPvt.hpp:834
const std::vector< TabulatedOneDFunction > & saturatedOilVaporizationFactorTable() const
Definition: WetHumidGasPvt.hpp:850
const std::vector< TabulatedTwoDFunction > & saturatedWaterVaporizationSaltFactorTable() const
Definition: WetHumidGasPvt.hpp:846
Evaluation saturatedOilVaporizationFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Definition: WetHumidGasPvt.hpp:706
const std::vector< TabulatedOneDFunction > & saturationPressure() const
Definition: WetHumidGasPvt.hpp:854
void initEnd()
Finish initializing the gas phase PVT properties.
Definition: WetHumidGasPvt.hpp:493
const std::vector< TabulatedOneDFunction > & inverseSaturatedGasBMu() const
Definition: WetHumidGasPvt.hpp:838
void setSaturatedGasWaterVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the water vaporization factor .
Definition: WetHumidGasPvt.hpp:478
const std::vector< TabulatedOneDFunction > & inverseSaturatedGasB() const
Definition: WetHumidGasPvt.hpp:826
const std::vector< TabulatedOneDFunction > & saturatedWaterVaporizationFactorTable() const
Definition: WetHumidGasPvt.hpp:842
Definition: Air_Mesitylene.hpp:34
ReturnEval_< Evaluation1, Evaluation2 >::type min(const Evaluation1 &arg1, const Evaluation2 &arg2)
Definition: MathToolbox.hpp:346
ReturnEval_< Evaluation1, Evaluation2 >::type max(const Evaluation1 &arg1, const Evaluation2 &arg2)
Definition: MathToolbox.hpp:341
auto scalarValue(const Evaluation &val) -> decltype(MathToolbox< Evaluation >::scalarValue(val))
Definition: MathToolbox.hpp:335
Evaluation abs(const Evaluation &value)
Definition: MathToolbox.hpp:350
ReturnEval_< Evaluation1, Evaluation2 >::type pow(const Evaluation1 &base, const Evaluation2 &exp)
Definition: MathToolbox.hpp:416
Definition: MathToolbox.hpp:50