My Project
TabulatedComponent.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 */
28 #ifndef OPM_TABULATED_COMPONENT_HPP
29 #define OPM_TABULATED_COMPONENT_HPP
30 
31 #include <cmath>
32 #include <limits>
33 #include <cassert>
34 #include <iostream>
35 
37 
38 namespace Opm {
54 template <class ScalarT, class RawComponent, bool useVaporPressure=true>
56 {
57 public:
58  typedef ScalarT Scalar;
59 
60  static const bool isTabulated = true;
61 
72  static void init(Scalar tempMin, Scalar tempMax, unsigned nTemp,
73  Scalar pressMin, Scalar pressMax, unsigned nPress)
74  {
75  tempMin_ = tempMin;
76  tempMax_ = tempMax;
77  nTemp_ = nTemp;
78  pressMin_ = pressMin;
79  pressMax_ = pressMax;
80  nPress_ = nPress;
81  nDensity_ = nPress_;
82 
83  // allocate the arrays
84  vaporPressure_ = new Scalar[nTemp_];
85  minGasDensity__ = new Scalar[nTemp_];
86  maxGasDensity__ = new Scalar[nTemp_];
87  minLiquidDensity__ = new Scalar[nTemp_];
88  maxLiquidDensity__ = new Scalar[nTemp_];
89 
90  gasEnthalpy_ = new Scalar[nTemp_*nPress_];
91  liquidEnthalpy_ = new Scalar[nTemp_*nPress_];
92  gasHeatCapacity_ = new Scalar[nTemp_*nPress_];
93  liquidHeatCapacity_ = new Scalar[nTemp_*nPress_];
94  gasDensity_ = new Scalar[nTemp_*nPress_];
95  liquidDensity_ = new Scalar[nTemp_*nPress_];
96  gasViscosity_ = new Scalar[nTemp_*nPress_];
97  liquidViscosity_ = new Scalar[nTemp_*nPress_];
98  gasThermalConductivity_ = new Scalar[nTemp_*nPress_];
99  liquidThermalConductivity_ = new Scalar[nTemp_*nPress_];
100  gasPressure_ = new Scalar[nTemp_*nDensity_];
101  liquidPressure_ = new Scalar[nTemp_*nDensity_];
102 
103  assert(std::numeric_limits<Scalar>::has_quiet_NaN);
104  Scalar NaN = std::numeric_limits<Scalar>::quiet_NaN();
105 
106  // fill the temperature-pressure arrays
107  for (unsigned iT = 0; iT < nTemp_; ++ iT) {
108  Scalar temperature = iT * (tempMax_ - tempMin_)/(nTemp_ - 1) + tempMin_;
109 
110  try { vaporPressure_[iT] = RawComponent::vaporPressure(temperature); }
111  catch (const std::exception&) { vaporPressure_[iT] = NaN; }
112 
113  Scalar pgMax = maxGasPressure_(iT);
114  Scalar pgMin = minGasPressure_(iT);
115 
116  // fill the temperature, pressure gas arrays
117  for (unsigned iP = 0; iP < nPress_; ++ iP) {
118  Scalar pressure = iP * (pgMax - pgMin)/(nPress_ - 1) + pgMin;
119 
120  unsigned i = iT + iP*nTemp_;
121 
122  try { gasEnthalpy_[i] = RawComponent::gasEnthalpy(temperature, pressure); }
123  catch (const std::exception&) { gasEnthalpy_[i] = NaN; }
124 
125  try { gasHeatCapacity_[i] = RawComponent::gasHeatCapacity(temperature, pressure); }
126  catch (const std::exception&) { gasHeatCapacity_[i] = NaN; }
127 
128  try { gasDensity_[i] = RawComponent::gasDensity(temperature, pressure); }
129  catch (const std::exception&) { gasDensity_[i] = NaN; }
130 
131  try { gasViscosity_[i] = RawComponent::gasViscosity(temperature, pressure); }
132  catch (const std::exception&) { gasViscosity_[i] = NaN; }
133 
134  try { gasThermalConductivity_[i] = RawComponent::gasThermalConductivity(temperature, pressure); }
135  catch (const std::exception&) { gasThermalConductivity_[i] = NaN; }
136  };
137 
138  Scalar plMin = minLiquidPressure_(iT);
139  Scalar plMax = maxLiquidPressure_(iT);
140  for (unsigned iP = 0; iP < nPress_; ++ iP) {
141  Scalar pressure = iP * (plMax - plMin)/(nPress_ - 1) + plMin;
142 
143  unsigned i = iT + iP*nTemp_;
144 
145  try { liquidEnthalpy_[i] = RawComponent::liquidEnthalpy(temperature, pressure); }
146  catch (const std::exception&) { liquidEnthalpy_[i] = NaN; }
147 
148  try { liquidHeatCapacity_[i] = RawComponent::liquidHeatCapacity(temperature, pressure); }
149  catch (const std::exception&) { liquidHeatCapacity_[i] = NaN; }
150 
151  try { liquidDensity_[i] = RawComponent::liquidDensity(temperature, pressure); }
152  catch (const std::exception&) { liquidDensity_[i] = NaN; }
153 
154  try { liquidViscosity_[i] = RawComponent::liquidViscosity(temperature, pressure); }
155  catch (const std::exception&) { liquidViscosity_[i] = NaN; }
156 
157  try { liquidThermalConductivity_[i] = RawComponent::liquidThermalConductivity(temperature, pressure); }
158  catch (const std::exception&) { liquidThermalConductivity_[i] = NaN; }
159  }
160  }
161 
162  // fill the temperature-density arrays
163  for (unsigned iT = 0; iT < nTemp_; ++ iT) {
164  Scalar temperature = iT * (tempMax_ - tempMin_)/(nTemp_ - 1) + tempMin_;
165 
166  // calculate the minimum and maximum values for the gas
167  // densities
168  minGasDensity__[iT] = RawComponent::gasDensity(temperature, minGasPressure_(iT));
169  if (iT < nTemp_ - 1)
170  maxGasDensity__[iT] = RawComponent::gasDensity(temperature, maxGasPressure_(iT + 1));
171  else
172  maxGasDensity__[iT] = RawComponent::gasDensity(temperature, maxGasPressure_(iT));
173 
174  // fill the temperature, density gas arrays
175  for (unsigned iRho = 0; iRho < nDensity_; ++ iRho) {
176  Scalar density =
177  Scalar(iRho)/(nDensity_ - 1) *
178  (maxGasDensity__[iT] - minGasDensity__[iT])
179  +
180  minGasDensity__[iT];
181 
182  unsigned i = iT + iRho*nTemp_;
183 
184  try { gasPressure_[i] = RawComponent::gasPressure(temperature, density); }
185  catch (const std::exception&) { gasPressure_[i] = NaN; };
186  };
187 
188  // calculate the minimum and maximum values for the liquid
189  // densities
190  minLiquidDensity__[iT] = RawComponent::liquidDensity(temperature, minLiquidPressure_(iT));
191  if (iT < nTemp_ - 1)
192  maxLiquidDensity__[iT] = RawComponent::liquidDensity(temperature, maxLiquidPressure_(iT + 1));
193  else
194  maxLiquidDensity__[iT] = RawComponent::liquidDensity(temperature, maxLiquidPressure_(iT));
195 
196  // fill the temperature, density liquid arrays
197  for (unsigned iRho = 0; iRho < nDensity_; ++ iRho) {
198  Scalar density =
199  Scalar(iRho)/(nDensity_ - 1) *
200  (maxLiquidDensity__[iT] - minLiquidDensity__[iT])
201  +
202  minLiquidDensity__[iT];
203 
204  unsigned i = iT + iRho*nTemp_;
205 
206  try { liquidPressure_[i] = RawComponent::liquidPressure(temperature, density); }
207  catch (const std::exception&) { liquidPressure_[i] = NaN; };
208  };
209  }
210  }
211 
215  static const char* name()
216  { return RawComponent::name(); }
217 
221  static Scalar molarMass()
222  { return RawComponent::molarMass(); }
223 
227  static Scalar criticalTemperature()
228  { return RawComponent::criticalTemperature(); }
229 
233  static Scalar criticalPressure()
234  { return RawComponent::criticalPressure(); }
235 
239  static Scalar tripleTemperature()
240  { return RawComponent::tripleTemperature(); }
241 
245  static Scalar triplePressure()
246  { return RawComponent::triplePressure(); }
247 
254  template <class Evaluation>
255  static Evaluation vaporPressure(const Evaluation& temperature)
256  {
257  const Evaluation& result = interpolateT_(vaporPressure_, temperature);
258  if (std::isnan(scalarValue(result)))
259  return RawComponent::vaporPressure(temperature);
260  return result;
261  }
262 
269  template <class Evaluation>
270  static Evaluation gasEnthalpy(const Evaluation& temperature, const Evaluation& pressure)
271  {
272  const Evaluation& result = interpolateGasTP_(gasEnthalpy_,
273  temperature,
274  pressure);
275  if (std::isnan(scalarValue(result)))
276  return RawComponent::gasEnthalpy(temperature, pressure);
277  return result;
278  }
279 
286  template <class Evaluation>
287  static Evaluation liquidEnthalpy(const Evaluation& temperature, const Evaluation& pressure)
288  {
289  const Evaluation& result = interpolateLiquidTP_(liquidEnthalpy_,
290  temperature,
291  pressure);
292  if (std::isnan(scalarValue(result)))
293  return RawComponent::liquidEnthalpy(temperature, pressure);
294  return result;
295  }
296 
303  template <class Evaluation>
304  static Evaluation gasHeatCapacity(const Evaluation& temperature, const Evaluation& pressure)
305  {
306  const Evaluation& result = interpolateGasTP_(gasHeatCapacity_,
307  temperature,
308  pressure);
309  if (std::isnan(scalarValue(result)))
310  return RawComponent::gasHeatCapacity(temperature, pressure);
311  return result;
312  }
313 
320  template <class Evaluation>
321  static Evaluation liquidHeatCapacity(const Evaluation& temperature, const Evaluation& pressure)
322  {
323  const Evaluation& result = interpolateLiquidTP_(liquidHeatCapacity_,
324  temperature,
325  pressure);
326  if (std::isnan(scalarValue(result)))
327  return RawComponent::liquidHeatCapacity(temperature, pressure);
328  return result;
329  }
330 
337  template <class Evaluation>
338  static Evaluation gasInternalEnergy(const Evaluation& temperature, const Evaluation& pressure)
339  { return gasEnthalpy(temperature, pressure) - pressure/gasDensity(temperature, pressure); }
340 
347  template <class Evaluation>
348  static Evaluation liquidInternalEnergy(const Evaluation& temperature, const Evaluation& pressure)
349  { return liquidEnthalpy(temperature, pressure) - pressure/liquidDensity(temperature, pressure); }
350 
357  template <class Evaluation>
358  static Evaluation gasPressure(const Evaluation& temperature, Scalar density)
359  {
360  const Evaluation& result = interpolateGasTRho_(gasPressure_,
361  temperature,
362  density);
363  if (std::isnan(scalarValue(result)))
364  return RawComponent::gasPressure(temperature,
365  density);
366  return result;
367  }
368 
375  template <class Evaluation>
376  static Evaluation liquidPressure(const Evaluation& temperature, Scalar density)
377  {
378  const Evaluation& result = interpolateLiquidTRho_(liquidPressure_,
379  temperature,
380  density);
381  if (std::isnan(scalarValue(result)))
382  return RawComponent::liquidPressure(temperature,
383  density);
384  return result;
385  }
386 
390  static bool gasIsCompressible()
391  { return RawComponent::gasIsCompressible(); }
392 
396  static bool liquidIsCompressible()
397  { return RawComponent::liquidIsCompressible(); }
398 
402  static bool gasIsIdeal()
403  { return RawComponent::gasIsIdeal(); }
404 
405 
413  template <class Evaluation>
414  static Evaluation gasDensity(const Evaluation& temperature, const Evaluation& pressure)
415  {
416  const Evaluation& result = interpolateGasTP_(gasDensity_,
417  temperature,
418  pressure);
419  if (std::isnan(scalarValue(result)))
420  return RawComponent::gasDensity(temperature, pressure);
421  return result;
422  }
423 
431  template <class Evaluation>
432  static Evaluation liquidDensity(const Evaluation& temperature, const Evaluation& pressure)
433  {
434  const Evaluation& result = interpolateLiquidTP_(liquidDensity_,
435  temperature,
436  pressure);
437  if (std::isnan(scalarValue(result)))
438  return RawComponent::liquidDensity(temperature, pressure);
439  return result;
440  }
441 
448  template <class Evaluation>
449  static Evaluation gasViscosity(const Evaluation& temperature, const Evaluation& pressure)
450  {
451  const Evaluation& result = interpolateGasTP_(gasViscosity_,
452  temperature,
453  pressure);
454  if (std::isnan(scalarValue(result)))
455  return RawComponent::gasViscosity(temperature, pressure);
456  return result;
457  }
458 
465  template <class Evaluation>
466  static Evaluation liquidViscosity(const Evaluation& temperature, const Evaluation& pressure)
467  {
468  const Evaluation& result = interpolateLiquidTP_(liquidViscosity_,
469  temperature,
470  pressure);
471  if (std::isnan(scalarValue(result)))
472  return RawComponent::liquidViscosity(temperature, pressure);
473  return result;
474  }
475 
482  template <class Evaluation>
483  static Evaluation gasThermalConductivity(const Evaluation& temperature, const Evaluation& pressure)
484  {
485  const Evaluation& result = interpolateGasTP_(gasThermalConductivity_,
486  temperature,
487  pressure);
488  if (std::isnan(scalarValue(result)))
489  return RawComponent::gasThermalConductivity(temperature, pressure);
490  return result;
491  }
492 
499  template <class Evaluation>
500  static Evaluation liquidThermalConductivity(const Evaluation& temperature, const Evaluation& pressure)
501  {
502  const Evaluation& result = interpolateLiquidTP_(liquidThermalConductivity_,
503  temperature,
504  pressure);
505  if (std::isnan(scalarValue(result)))
506  return RawComponent::liquidThermalConductivity(temperature, pressure);
507  return result;
508  }
509 
510 private:
511  // returns an interpolated value depending on temperature
512  template <class Evaluation>
513  static Evaluation interpolateT_(const Scalar* values, const Evaluation& T)
514  {
515  Evaluation alphaT = tempIdx_(T);
516  if (alphaT < 0 || alphaT >= nTemp_ - 1)
517  return std::numeric_limits<Scalar>::quiet_NaN();
518 
519  size_t iT = static_cast<size_t>(scalarValue(alphaT));
520  alphaT -= iT;
521 
522  return
523  values[iT ]*(1 - alphaT) +
524  values[iT + 1]*( alphaT);
525  }
526 
527  // returns an interpolated value for liquid depending on
528  // temperature and pressure
529  template <class Evaluation>
530  static Evaluation interpolateLiquidTP_(const Scalar* values, const Evaluation& T, const Evaluation& p)
531  {
532  Evaluation alphaT = tempIdx_(T);
533  if (alphaT < 0 || alphaT >= nTemp_ - 1)
534  return std::numeric_limits<Scalar>::quiet_NaN();
535 
536  size_t iT = static_cast<size_t>(scalarValue(alphaT));
537  alphaT -= iT;
538 
539  Evaluation alphaP1 = pressLiquidIdx_(p, iT);
540  Evaluation alphaP2 = pressLiquidIdx_(p, iT + 1);
541 
542  size_t iP1 =
543  static_cast<size_t>(
544  std::max<int>(0, std::min(static_cast<int>(nPress_) - 2,
545  static_cast<int>(scalarValue(alphaP1)))));
546  size_t iP2 =
547  static_cast<size_t>(
548  std::max(0, std::min(static_cast<int>(nPress_) - 2,
549  static_cast<int>(scalarValue(alphaP2)))));
550  alphaP1 -= iP1;
551  alphaP2 -= iP2;
552 
553  return
554  values[(iT ) + (iP1 )*nTemp_]*(1 - alphaT)*(1 - alphaP1) +
555  values[(iT ) + (iP1 + 1)*nTemp_]*(1 - alphaT)*( alphaP1) +
556  values[(iT + 1) + (iP2 )*nTemp_]*( alphaT)*(1 - alphaP2) +
557  values[(iT + 1) + (iP2 + 1)*nTemp_]*( alphaT)*( alphaP2);
558  }
559 
560  // returns an interpolated value for gas depending on
561  // temperature and pressure
562  template <class Evaluation>
563  static Evaluation interpolateGasTP_(const Scalar* values, const Evaluation& T, const Evaluation& p)
564  {
565  Evaluation alphaT = tempIdx_(T);
566  if (alphaT < 0 || alphaT >= nTemp_ - 1)
567  return std::numeric_limits<Scalar>::quiet_NaN();
568 
569  size_t iT =
570  static_cast<size_t>(
571  std::max(0, std::min(static_cast<int>(nTemp_) - 2,
572  static_cast<int>(scalarValue(alphaT)))));
573  alphaT -= iT;
574 
575  Evaluation alphaP1 = pressGasIdx_(p, iT);
576  Evaluation alphaP2 = pressGasIdx_(p, iT + 1);
577  size_t iP1 =
578  static_cast<size_t>(
579  std::max(0, std::min(static_cast<int>(nPress_) - 2,
580  static_cast<int>(scalarValue(alphaP1)))));
581  size_t iP2 =
582  static_cast<size_t>(
583  std::max(0, std::min(static_cast<int>(nPress_) - 2,
584  static_cast<int>(scalarValue(alphaP2)))));
585  alphaP1 -= iP1;
586  alphaP2 -= iP2;
587 
588  return
589  values[(iT ) + (iP1 )*nTemp_]*(1 - alphaT)*(1 - alphaP1) +
590  values[(iT ) + (iP1 + 1)*nTemp_]*(1 - alphaT)*( alphaP1) +
591  values[(iT + 1) + (iP2 )*nTemp_]*( alphaT)*(1 - alphaP2) +
592  values[(iT + 1) + (iP2 + 1)*nTemp_]*( alphaT)*( alphaP2);
593  }
594 
595  // returns an interpolated value for gas depending on
596  // temperature and density
597  template <class Evaluation>
598  static Evaluation interpolateGasTRho_(const Scalar* values, const Evaluation& T, const Evaluation& rho)
599  {
600  Evaluation alphaT = tempIdx_(T);
601  unsigned iT = std::max(0,
602  std::min(static_cast<int>(nTemp_ - 2),
603  static_cast<int>(alphaT)));
604  alphaT -= iT;
605 
606  Evaluation alphaP1 = densityGasIdx_(rho, iT);
607  Evaluation alphaP2 = densityGasIdx_(rho, iT + 1);
608  unsigned iP1 =
609  std::max(0,
610  std::min(static_cast<int>(nDensity_ - 2),
611  static_cast<int>(alphaP1)));
612  unsigned iP2 =
613  std::max(0,
614  std::min(static_cast<int>(nDensity_ - 2),
615  static_cast<int>(alphaP2)));
616  alphaP1 -= iP1;
617  alphaP2 -= iP2;
618 
619  return
620  values[(iT ) + (iP1 )*nTemp_]*(1 - alphaT)*(1 - alphaP1) +
621  values[(iT ) + (iP1 + 1)*nTemp_]*(1 - alphaT)*( alphaP1) +
622  values[(iT + 1) + (iP2 )*nTemp_]*( alphaT)*(1 - alphaP2) +
623  values[(iT + 1) + (iP2 + 1)*nTemp_]*( alphaT)*( alphaP2);
624  }
625 
626  // returns an interpolated value for liquid depending on
627  // temperature and density
628  template <class Evaluation>
629  static Evaluation interpolateLiquidTRho_(const Scalar* values, const Evaluation& T, const Evaluation& rho)
630  {
631  Evaluation alphaT = tempIdx_(T);
632  unsigned iT = std::max<int>(0, std::min<int>(nTemp_ - 2, static_cast<int>(alphaT)));
633  alphaT -= iT;
634 
635  Evaluation alphaP1 = densityLiquidIdx_(rho, iT);
636  Evaluation alphaP2 = densityLiquidIdx_(rho, iT + 1);
637  unsigned iP1 = std::max<int>(0, std::min<int>(nDensity_ - 2, static_cast<int>(alphaP1)));
638  unsigned iP2 = std::max<int>(0, std::min<int>(nDensity_ - 2, static_cast<int>(alphaP2)));
639  alphaP1 -= iP1;
640  alphaP2 -= iP2;
641 
642  return
643  values[(iT ) + (iP1 )*nTemp_]*(1 - alphaT)*(1 - alphaP1) +
644  values[(iT ) + (iP1 + 1)*nTemp_]*(1 - alphaT)*( alphaP1) +
645  values[(iT + 1) + (iP2 )*nTemp_]*( alphaT)*(1 - alphaP2) +
646  values[(iT + 1) + (iP2 + 1)*nTemp_]*( alphaT)*( alphaP2);
647  }
648 
649 
650  // returns the index of an entry in a temperature field
651  template <class Evaluation>
652  static Evaluation tempIdx_(const Evaluation& temperature)
653  {
654  return (nTemp_ - 1)*(temperature - tempMin_)/(tempMax_ - tempMin_);
655  }
656 
657  // returns the index of an entry in a pressure field
658  template <class Evaluation>
659  static Evaluation pressLiquidIdx_(const Evaluation& pressure, size_t tempIdx)
660  {
661  Scalar plMin = minLiquidPressure_(tempIdx);
662  Scalar plMax = maxLiquidPressure_(tempIdx);
663 
664  return (nPress_ - 1)*(pressure - plMin)/(plMax - plMin);
665  }
666 
667  // returns the index of an entry in a temperature field
668  template <class Evaluation>
669  static Evaluation pressGasIdx_(const Evaluation& pressure, size_t tempIdx)
670  {
671  Scalar pgMin = minGasPressure_(tempIdx);
672  Scalar pgMax = maxGasPressure_(tempIdx);
673 
674  return (nPress_ - 1)*(pressure - pgMin)/(pgMax - pgMin);
675  }
676 
677  // returns the index of an entry in a density field
678  template <class Evaluation>
679  static Evaluation densityLiquidIdx_(const Evaluation& density, size_t tempIdx)
680  {
681  Scalar densityMin = minLiquidDensity_(tempIdx);
682  Scalar densityMax = maxLiquidDensity_(tempIdx);
683  return (nDensity_ - 1) * (density - densityMin)/(densityMax - densityMin);
684  }
685 
686  // returns the index of an entry in a density field
687  template <class Evaluation>
688  static Evaluation densityGasIdx_(const Evaluation& density, size_t tempIdx)
689  {
690  Scalar densityMin = minGasDensity_(tempIdx);
691  Scalar densityMax = maxGasDensity_(tempIdx);
692  return (nDensity_ - 1) * (density - densityMin)/(densityMax - densityMin);
693  }
694 
695  // returns the minimum tabulized liquid pressure at a given
696  // temperature index
697  static Scalar minLiquidPressure_(size_t tempIdx)
698  {
699  if (!useVaporPressure)
700  return pressMin_;
701  else
702  return std::max<Scalar>(pressMin_, vaporPressure_[tempIdx] / 1.1);
703  }
704 
705  // returns the maximum tabulized liquid pressure at a given
706  // temperature index
707  static Scalar maxLiquidPressure_(size_t tempIdx)
708  {
709  if (!useVaporPressure)
710  return pressMax_;
711  else
712  return std::max<Scalar>(pressMax_, vaporPressure_[tempIdx] * 1.1);
713  }
714 
715  // returns the minumum tabulized gas pressure at a given
716  // temperature index
717  static Scalar minGasPressure_(size_t tempIdx)
718  {
719  if (!useVaporPressure)
720  return pressMin_;
721  else
722  return std::min<Scalar>(pressMin_, vaporPressure_[tempIdx] / 1.1 );
723  }
724 
725  // returns the maximum tabulized gas pressure at a given
726  // temperature index
727  static Scalar maxGasPressure_(size_t tempIdx)
728  {
729  if (!useVaporPressure)
730  return pressMax_;
731  else
732  return std::min<Scalar>(pressMax_, vaporPressure_[tempIdx] * 1.1);
733  }
734 
735 
736  // returns the minimum tabulized liquid density at a given
737  // temperature index
738  static Scalar minLiquidDensity_(size_t tempIdx)
739  { return minLiquidDensity__[tempIdx]; }
740 
741  // returns the maximum tabulized liquid density at a given
742  // temperature index
743  static Scalar maxLiquidDensity_(size_t tempIdx)
744  { return maxLiquidDensity__[tempIdx]; }
745 
746  // returns the minumum tabulized gas density at a given
747  // temperature index
748  static Scalar minGasDensity_(size_t tempIdx)
749  { return minGasDensity__[tempIdx]; }
750 
751  // returns the maximum tabulized gas density at a given
752  // temperature index
753  static Scalar maxGasDensity_(size_t tempIdx)
754  { return maxGasDensity__[tempIdx]; }
755 
756  // 1D fields with the temperature as degree of freedom
757  static Scalar* vaporPressure_;
758 
759  static Scalar* minLiquidDensity__;
760  static Scalar* maxLiquidDensity__;
761 
762  static Scalar* minGasDensity__;
763  static Scalar* maxGasDensity__;
764 
765  // 2D fields with the temperature and pressure as degrees of
766  // freedom
767  static Scalar* gasEnthalpy_;
768  static Scalar* liquidEnthalpy_;
769 
770  static Scalar* gasHeatCapacity_;
771  static Scalar* liquidHeatCapacity_;
772 
773  static Scalar* gasDensity_;
774  static Scalar* liquidDensity_;
775 
776  static Scalar* gasViscosity_;
777  static Scalar* liquidViscosity_;
778 
779  static Scalar* gasThermalConductivity_;
780  static Scalar* liquidThermalConductivity_;
781 
782  // 2D fields with the temperature and density as degrees of
783  // freedom
784  static Scalar* gasPressure_;
785  static Scalar* liquidPressure_;
786 
787  // temperature, pressure and density ranges
788  static Scalar tempMin_;
789  static Scalar tempMax_;
790  static unsigned nTemp_;
791 
792  static Scalar pressMin_;
793  static Scalar pressMax_;
794  static unsigned nPress_;
795 
796  static Scalar densityMin_;
797  static Scalar densityMax_;
798  static unsigned nDensity_;
799 };
800 
801 template <class Scalar, class RawComponent, bool useVaporPressure>
802 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::vaporPressure_;
803 template <class Scalar, class RawComponent, bool useVaporPressure>
804 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::minLiquidDensity__;
805 template <class Scalar, class RawComponent, bool useVaporPressure>
806 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::maxLiquidDensity__;
807 template <class Scalar, class RawComponent, bool useVaporPressure>
808 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::minGasDensity__;
809 template <class Scalar, class RawComponent, bool useVaporPressure>
810 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::maxGasDensity__;
811 template <class Scalar, class RawComponent, bool useVaporPressure>
812 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::gasEnthalpy_;
813 template <class Scalar, class RawComponent, bool useVaporPressure>
814 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::liquidEnthalpy_;
815 template <class Scalar, class RawComponent, bool useVaporPressure>
816 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::gasHeatCapacity_;
817 template <class Scalar, class RawComponent, bool useVaporPressure>
818 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::liquidHeatCapacity_;
819 template <class Scalar, class RawComponent, bool useVaporPressure>
820 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::gasDensity_;
821 template <class Scalar, class RawComponent, bool useVaporPressure>
822 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::liquidDensity_;
823 template <class Scalar, class RawComponent, bool useVaporPressure>
824 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::gasViscosity_;
825 template <class Scalar, class RawComponent, bool useVaporPressure>
826 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::liquidViscosity_;
827 template <class Scalar, class RawComponent, bool useVaporPressure>
828 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::gasThermalConductivity_;
829 template <class Scalar, class RawComponent, bool useVaporPressure>
830 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::liquidThermalConductivity_;
831 template <class Scalar, class RawComponent, bool useVaporPressure>
832 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::gasPressure_;
833 template <class Scalar, class RawComponent, bool useVaporPressure>
834 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::liquidPressure_;
835 template <class Scalar, class RawComponent, bool useVaporPressure>
836 Scalar TabulatedComponent<Scalar, RawComponent, useVaporPressure>::tempMin_;
837 template <class Scalar, class RawComponent, bool useVaporPressure>
838 Scalar TabulatedComponent<Scalar, RawComponent, useVaporPressure>::tempMax_;
839 template <class Scalar, class RawComponent, bool useVaporPressure>
840 unsigned TabulatedComponent<Scalar, RawComponent, useVaporPressure>::nTemp_;
841 template <class Scalar, class RawComponent, bool useVaporPressure>
842 Scalar TabulatedComponent<Scalar, RawComponent, useVaporPressure>::pressMin_;
843 template <class Scalar, class RawComponent, bool useVaporPressure>
844 Scalar TabulatedComponent<Scalar, RawComponent, useVaporPressure>::pressMax_;
845 template <class Scalar, class RawComponent, bool useVaporPressure>
846 unsigned TabulatedComponent<Scalar, RawComponent, useVaporPressure>::nPress_;
847 template <class Scalar, class RawComponent, bool useVaporPressure>
848 Scalar TabulatedComponent<Scalar, RawComponent, useVaporPressure>::densityMin_;
849 template <class Scalar, class RawComponent, bool useVaporPressure>
850 Scalar TabulatedComponent<Scalar, RawComponent, useVaporPressure>::densityMax_;
851 template <class Scalar, class RawComponent, bool useVaporPressure>
852 unsigned TabulatedComponent<Scalar, RawComponent, useVaporPressure>::nDensity_;
853 
854 
855 } // namespace Opm
856 
857 #endif
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...
A generic class which tabulates all thermodynamic properties of a given component.
Definition: TabulatedComponent.hpp:56
static Evaluation gasThermalConductivity(const Evaluation &temperature, const Evaluation &pressure)
The thermal conductivity of gaseous water .
Definition: TabulatedComponent.hpp:483
static bool gasIsCompressible()
Returns true iff the gas phase is assumed to be compressible.
Definition: TabulatedComponent.hpp:390
static Evaluation liquidPressure(const Evaluation &temperature, Scalar density)
The pressure of liquid in at a given density and temperature.
Definition: TabulatedComponent.hpp:376
static Evaluation gasEnthalpy(const Evaluation &temperature, const Evaluation &pressure)
Specific enthalpy of the gas .
Definition: TabulatedComponent.hpp:270
static Evaluation liquidHeatCapacity(const Evaluation &temperature, const Evaluation &pressure)
Specific isobaric heat capacity of the liquid .
Definition: TabulatedComponent.hpp:321
static Evaluation liquidInternalEnergy(const Evaluation &temperature, const Evaluation &pressure)
Specific internal energy of the liquid .
Definition: TabulatedComponent.hpp:348
static void init(Scalar tempMin, Scalar tempMax, unsigned nTemp, Scalar pressMin, Scalar pressMax, unsigned nPress)
Initialize the tables.
Definition: TabulatedComponent.hpp:72
static Scalar criticalTemperature()
Returns the critical temperature in of the component.
Definition: TabulatedComponent.hpp:227
static Scalar criticalPressure()
Returns the critical pressure in of the component.
Definition: TabulatedComponent.hpp:233
static Scalar molarMass()
The molar mass in of the component.
Definition: TabulatedComponent.hpp:221
static bool liquidIsCompressible()
Returns true iff the liquid phase is assumed to be compressible.
Definition: TabulatedComponent.hpp:396
static Evaluation gasPressure(const Evaluation &temperature, Scalar density)
The pressure of gas in at a given density and temperature.
Definition: TabulatedComponent.hpp:358
static Evaluation liquidViscosity(const Evaluation &temperature, const Evaluation &pressure)
The dynamic viscosity of liquid.
Definition: TabulatedComponent.hpp:466
static Scalar triplePressure()
Returns the pressure in at the component's triple point.
Definition: TabulatedComponent.hpp:245
static Evaluation gasDensity(const Evaluation &temperature, const Evaluation &pressure)
The density of gas at a given pressure and temperature .
Definition: TabulatedComponent.hpp:414
static Evaluation gasInternalEnergy(const Evaluation &temperature, const Evaluation &pressure)
Specific internal energy of the gas .
Definition: TabulatedComponent.hpp:338
static Evaluation gasHeatCapacity(const Evaluation &temperature, const Evaluation &pressure)
Specific isobaric heat capacity of the gas .
Definition: TabulatedComponent.hpp:304
static bool gasIsIdeal()
Returns true iff the gas phase is assumed to be ideal.
Definition: TabulatedComponent.hpp:402
static const char * name()
A human readable name for the component.
Definition: TabulatedComponent.hpp:215
static Evaluation liquidDensity(const Evaluation &temperature, const Evaluation &pressure)
The density of liquid at a given pressure and temperature .
Definition: TabulatedComponent.hpp:432
static Evaluation vaporPressure(const Evaluation &temperature)
The vapor pressure in of the component at a given temperature.
Definition: TabulatedComponent.hpp:255
static Evaluation liquidThermalConductivity(const Evaluation &temperature, const Evaluation &pressure)
The thermal conductivity of liquid water .
Definition: TabulatedComponent.hpp:500
static Evaluation gasViscosity(const Evaluation &temperature, const Evaluation &pressure)
The dynamic viscosity of gas.
Definition: TabulatedComponent.hpp:449
static Evaluation liquidEnthalpy(const Evaluation &temperature, const Evaluation &pressure)
Specific enthalpy of the liquid .
Definition: TabulatedComponent.hpp:287
static Scalar tripleTemperature()
Returns the temperature in at the component's triple point.
Definition: TabulatedComponent.hpp:239