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  Copyright (C) 2009-2013 by Andreas Lauser
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 2 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 */
26 #ifndef OPM_TABULATED_COMPONENT_HPP
27 #define OPM_TABULATED_COMPONENT_HPP
28 
29 #include <cmath>
30 #include <limits>
31 #include <cassert>
32 #include <iostream>
33 
34 #include <opm/common/Exceptions.hpp>
35 #include <opm/common/ErrorMacros.hpp>
36 
38 
39 namespace Opm {
55 template <class ScalarT, class RawComponent, bool useVaporPressure=true>
57 {
58 public:
59  typedef ScalarT Scalar;
60 
61  static const bool isTabulated = true;
62 
73  static void init(Scalar tempMin, Scalar tempMax, unsigned nTemp,
74  Scalar pressMin, Scalar pressMax, unsigned nPress)
75  {
76  tempMin_ = tempMin;
77  tempMax_ = tempMax;
78  nTemp_ = nTemp;
79  pressMin_ = pressMin;
80  pressMax_ = pressMax;
81  nPress_ = nPress;
82  nDensity_ = nPress_;
83 
84  // allocate the arrays
85  vaporPressure_ = new Scalar[nTemp_];
86  minGasDensity__ = new Scalar[nTemp_];
87  maxGasDensity__ = new Scalar[nTemp_];
88  minLiquidDensity__ = new Scalar[nTemp_];
89  maxLiquidDensity__ = new Scalar[nTemp_];
90 
91  gasEnthalpy_ = new Scalar[nTemp_*nPress_];
92  liquidEnthalpy_ = new Scalar[nTemp_*nPress_];
93  gasHeatCapacity_ = new Scalar[nTemp_*nPress_];
94  liquidHeatCapacity_ = new Scalar[nTemp_*nPress_];
95  gasDensity_ = new Scalar[nTemp_*nPress_];
96  liquidDensity_ = new Scalar[nTemp_*nPress_];
97  gasViscosity_ = new Scalar[nTemp_*nPress_];
98  liquidViscosity_ = new Scalar[nTemp_*nPress_];
99  gasThermalConductivity_ = new Scalar[nTemp_*nPress_];
100  liquidThermalConductivity_ = new Scalar[nTemp_*nPress_];
101  gasPressure_ = new Scalar[nTemp_*nDensity_];
102  liquidPressure_ = new Scalar[nTemp_*nDensity_];
103 
104  assert(std::numeric_limits<Scalar>::has_quiet_NaN);
105  Scalar NaN = std::numeric_limits<Scalar>::quiet_NaN();
106 
107  // fill the temperature-pressure arrays
108  for (unsigned iT = 0; iT < nTemp_; ++ iT) {
109  Scalar temperature = iT * (tempMax_ - tempMin_)/(nTemp_ - 1) + tempMin_;
110 
111  try { vaporPressure_[iT] = RawComponent::vaporPressure(temperature); }
112  catch (std::exception) { vaporPressure_[iT] = NaN; }
113 
114  Scalar pgMax = maxGasPressure_(iT);
115  Scalar pgMin = minGasPressure_(iT);
116 
117  // fill the temperature, pressure gas arrays
118  for (unsigned iP = 0; iP < nPress_; ++ iP) {
119  Scalar pressure = iP * (pgMax - pgMin)/(nPress_ - 1) + pgMin;
120 
121  unsigned i = iT + iP*nTemp_;
122 
123  try { gasEnthalpy_[i] = RawComponent::gasEnthalpy(temperature, pressure); }
124  catch (std::exception) { gasEnthalpy_[i] = NaN; }
125 
126  try { gasHeatCapacity_[i] = RawComponent::gasHeatCapacity(temperature, pressure); }
127  catch (std::exception) { gasHeatCapacity_[i] = NaN; }
128 
129  try { gasDensity_[i] = RawComponent::gasDensity(temperature, pressure); }
130  catch (std::exception) { gasDensity_[i] = NaN; }
131 
132  try { gasViscosity_[i] = RawComponent::gasViscosity(temperature, pressure); }
133  catch (std::exception) { gasViscosity_[i] = NaN; }
134 
135  try { gasThermalConductivity_[i] = RawComponent::gasThermalConductivity(temperature, pressure); }
136  catch (std::exception) { gasThermalConductivity_[i] = NaN; }
137  };
138 
139  Scalar plMin = minLiquidPressure_(iT);
140  Scalar plMax = maxLiquidPressure_(iT);
141  for (unsigned iP = 0; iP < nPress_; ++ iP) {
142  Scalar pressure = iP * (plMax - plMin)/(nPress_ - 1) + plMin;
143 
144  unsigned i = iT + iP*nTemp_;
145 
146  try { liquidEnthalpy_[i] = RawComponent::liquidEnthalpy(temperature, pressure); }
147  catch (std::exception) { liquidEnthalpy_[i] = NaN; }
148 
149  try { liquidHeatCapacity_[i] = RawComponent::liquidHeatCapacity(temperature, pressure); }
150  catch (std::exception) { liquidHeatCapacity_[i] = NaN; }
151 
152  try { liquidDensity_[i] = RawComponent::liquidDensity(temperature, pressure); }
153  catch (std::exception) { liquidDensity_[i] = NaN; }
154 
155  try { liquidViscosity_[i] = RawComponent::liquidViscosity(temperature, pressure); }
156  catch (std::exception) { liquidViscosity_[i] = NaN; }
157 
158  try { liquidThermalConductivity_[i] = RawComponent::liquidThermalConductivity(temperature, pressure); }
159  catch (std::exception) { liquidThermalConductivity_[i] = NaN; }
160  }
161  }
162 
163  // fill the temperature-density arrays
164  for (unsigned iT = 0; iT < nTemp_; ++ iT) {
165  Scalar temperature = iT * (tempMax_ - tempMin_)/(nTemp_ - 1) + tempMin_;
166 
167  // calculate the minimum and maximum values for the gas
168  // densities
169  minGasDensity__[iT] = RawComponent::gasDensity(temperature, minGasPressure_(iT));
170  if (iT < nTemp_ - 1)
171  maxGasDensity__[iT] = RawComponent::gasDensity(temperature, maxGasPressure_(iT + 1));
172  else
173  maxGasDensity__[iT] = RawComponent::gasDensity(temperature, maxGasPressure_(iT));
174 
175  // fill the temperature, density gas arrays
176  for (unsigned iRho = 0; iRho < nDensity_; ++ iRho) {
177  Scalar density =
178  Scalar(iRho)/(nDensity_ - 1) *
179  (maxGasDensity__[iT] - minGasDensity__[iT])
180  +
181  minGasDensity__[iT];
182 
183  unsigned i = iT + iRho*nTemp_;
184 
185  try { gasPressure_[i] = RawComponent::gasPressure(temperature, density); }
186  catch (std::exception) { gasPressure_[i] = NaN; };
187  };
188 
189  // calculate the minimum and maximum values for the liquid
190  // densities
191  minLiquidDensity__[iT] = RawComponent::liquidDensity(temperature, minLiquidPressure_(iT));
192  if (iT < nTemp_ - 1)
193  maxLiquidDensity__[iT] = RawComponent::liquidDensity(temperature, maxLiquidPressure_(iT + 1));
194  else
195  maxLiquidDensity__[iT] = RawComponent::liquidDensity(temperature, maxLiquidPressure_(iT));
196 
197  // fill the temperature, density liquid arrays
198  for (unsigned iRho = 0; iRho < nDensity_; ++ iRho) {
199  Scalar density =
200  Scalar(iRho)/(nDensity_ - 1) *
201  (maxLiquidDensity__[iT] - minLiquidDensity__[iT])
202  +
203  minLiquidDensity__[iT];
204 
205  unsigned i = iT + iRho*nTemp_;
206 
207  try { liquidPressure_[i] = RawComponent::liquidPressure(temperature, density); }
208  catch (std::exception) { liquidPressure_[i] = NaN; };
209  };
210  }
211  }
212 
216  static const char *name()
217  { return RawComponent::name(); }
218 
222  static Scalar molarMass()
223  { return RawComponent::molarMass(); }
224 
228  static Scalar criticalTemperature()
229  { return RawComponent::criticalTemperature(); }
230 
234  static Scalar criticalPressure()
235  { return RawComponent::criticalPressure(); }
236 
240  static Scalar tripleTemperature()
241  { return RawComponent::tripleTemperature(); }
242 
246  static Scalar triplePressure()
247  { return RawComponent::triplePressure(); }
248 
255  template <class Evaluation>
256  static Evaluation vaporPressure(const Evaluation& temperature)
257  {
258  typedef MathToolbox<Evaluation> Toolbox;
259 
260  const Evaluation& result = interpolateT_(vaporPressure_, temperature);
261  if (std::isnan(Toolbox::value(result)))
262  return RawComponent::vaporPressure(temperature);
263  return result;
264  }
265 
272  template <class Evaluation>
273  static Evaluation gasEnthalpy(const Evaluation& temperature, const Evaluation& pressure)
274  {
275  typedef MathToolbox<Evaluation> Toolbox;
276 
277  const Evaluation& result = interpolateGasTP_(gasEnthalpy_,
278  temperature,
279  pressure);
280  if (std::isnan(Toolbox::value(result)))
281  return RawComponent::gasEnthalpy(temperature, pressure);
282  return result;
283  }
284 
291  template <class Evaluation>
292  static Evaluation liquidEnthalpy(const Evaluation& temperature, const Evaluation& pressure)
293  {
294  typedef MathToolbox<Evaluation> Toolbox;
295 
296  const Evaluation& result = interpolateLiquidTP_(liquidEnthalpy_,
297  temperature,
298  pressure);
299  if (std::isnan(Toolbox::value(result)))
300  return RawComponent::liquidEnthalpy(temperature, pressure);
301  return result;
302  }
303 
310  template <class Evaluation>
311  static Evaluation gasHeatCapacity(const Evaluation& temperature, const Evaluation& pressure)
312  {
313  typedef MathToolbox<Evaluation> Toolbox;
314 
315  const Evaluation& result = interpolateGasTP_(gasHeatCapacity_,
316  temperature,
317  pressure);
318  if (std::isnan(Toolbox::value(result)))
319  return RawComponent::gasHeatCapacity(temperature, pressure);
320  return result;
321  }
322 
329  template <class Evaluation>
330  static Evaluation liquidHeatCapacity(const Evaluation& temperature, const Evaluation& pressure)
331  {
332  typedef MathToolbox<Evaluation> Toolbox;
333 
334  const Evaluation& result = interpolateLiquidTP_(liquidHeatCapacity_,
335  temperature,
336  pressure);
337  if (std::isnan(Toolbox::value(result)))
338  return RawComponent::liquidHeatCapacity(temperature, pressure);
339  return result;
340  }
341 
348  template <class Evaluation>
349  static Evaluation gasInternalEnergy(const Evaluation& temperature, const Evaluation& pressure)
350  { return gasEnthalpy(temperature, pressure) - pressure/gasDensity(temperature, pressure); }
351 
358  template <class Evaluation>
359  static Evaluation liquidInternalEnergy(const Evaluation& temperature, const Evaluation& pressure)
360  { return liquidEnthalpy(temperature, pressure) - pressure/liquidDensity(temperature, pressure); }
361 
368  template <class Evaluation>
369  static Evaluation gasPressure(const Evaluation& temperature, Scalar density)
370  {
371  typedef MathToolbox<Evaluation> Toolbox;
372 
373  const Evaluation& result = interpolateGasTRho_(gasPressure_,
374  temperature,
375  density);
376  if (std::isnan(Toolbox::value(result)))
377  return RawComponent::gasPressure(temperature,
378  density);
379  return result;
380  }
381 
388  template <class Evaluation>
389  static Evaluation liquidPressure(const Evaluation& temperature, Scalar density)
390  {
391  typedef MathToolbox<Evaluation> Toolbox;
392 
393  const Evaluation& result = interpolateLiquidTRho_(liquidPressure_,
394  temperature,
395  density);
396  if (std::isnan(Toolbox::value(result)))
397  return RawComponent::liquidPressure(temperature,
398  density);
399  return result;
400  }
401 
405  static bool gasIsCompressible()
406  { return RawComponent::gasIsCompressible(); }
407 
411  static bool liquidIsCompressible()
412  { return RawComponent::liquidIsCompressible(); }
413 
417  static bool gasIsIdeal()
418  { return RawComponent::gasIsIdeal(); }
419 
420 
428  template <class Evaluation>
429  static Evaluation gasDensity(const Evaluation& temperature, const Evaluation& pressure)
430  {
431  typedef MathToolbox<Evaluation> Toolbox;
432 
433  const Evaluation& result = interpolateGasTP_(gasDensity_,
434  temperature,
435  pressure);
436  if (std::isnan(Toolbox::value(result)))
437  return RawComponent::gasDensity(temperature, pressure);
438  return result;
439  }
440 
448  template <class Evaluation>
449  static Evaluation liquidDensity(const Evaluation& temperature, const Evaluation& pressure)
450  {
451  typedef MathToolbox<Evaluation> Toolbox;
452 
453  const Evaluation& result = interpolateLiquidTP_(liquidDensity_,
454  temperature,
455  pressure);
456  if (std::isnan(Toolbox::value(result)))
457  return RawComponent::liquidDensity(temperature, pressure);
458  return result;
459  }
460 
467  template <class Evaluation>
468  static Evaluation gasViscosity(const Evaluation& temperature, const Evaluation& pressure)
469  {
470  typedef MathToolbox<Evaluation> Toolbox;
471 
472  const Evaluation& result = interpolateGasTP_(gasViscosity_,
473  temperature,
474  pressure);
475  if (std::isnan(Toolbox::value(result)))
476  return RawComponent::gasViscosity(temperature, pressure);
477  return result;
478  }
479 
486  template <class Evaluation>
487  static Evaluation liquidViscosity(const Evaluation& temperature, const Evaluation& pressure)
488  {
489  typedef MathToolbox<Evaluation> Toolbox;
490 
491  const Evaluation& result = interpolateLiquidTP_(liquidViscosity_,
492  temperature,
493  pressure);
494  if (std::isnan(Toolbox::value(result)))
495  return RawComponent::liquidViscosity(temperature, pressure);
496  return result;
497  }
498 
505  template <class Evaluation>
506  static Evaluation gasThermalConductivity(const Evaluation& temperature, const Evaluation& pressure)
507  {
508  typedef MathToolbox<Evaluation> Toolbox;
509 
510  const Evaluation& result = interpolateGasTP_(gasThermalConductivity_,
511  temperature,
512  pressure);
513  if (std::isnan(Toolbox::value(result)))
514  return RawComponent::gasThermalConductivity(temperature, pressure);
515  return result;
516  }
517 
524  template <class Evaluation>
525  static Evaluation liquidThermalConductivity(const Evaluation& temperature, const Evaluation& pressure)
526  {
527  typedef MathToolbox<Evaluation> Toolbox;
528 
529  const Evaluation& result = interpolateLiquidTP_(liquidThermalConductivity_,
530  temperature,
531  pressure);
532  if (std::isnan(Toolbox::value(result)))
533  return RawComponent::liquidThermalConductivity(temperature, pressure);
534  return result;
535  }
536 
537 private:
538  // returns an interpolated value depending on temperature
539  template <class Evaluation>
540  static Evaluation interpolateT_(const Scalar *values, const Evaluation& T)
541  {
542  typedef Opm::MathToolbox<Evaluation> Toolbox;
543 
544  Evaluation alphaT = tempIdx_(T);
545  if (alphaT < 0 || alphaT >= nTemp_ - 1)
546  return std::numeric_limits<Scalar>::quiet_NaN();
547 
548  unsigned iT = (unsigned) Toolbox::value(alphaT);
549  alphaT -= iT;
550 
551  return
552  values[iT ]*(1 - alphaT) +
553  values[iT + 1]*( alphaT);
554  }
555 
556  // returns an interpolated value for liquid depending on
557  // temperature and pressure
558  template <class Evaluation>
559  static Evaluation interpolateLiquidTP_(const Scalar *values, const Evaluation& T, const Evaluation& p)
560  {
561  typedef MathToolbox<Evaluation> Toolbox;
562 
563  Evaluation alphaT = tempIdx_(T);
564  if (alphaT < 0 || alphaT >= nTemp_ - 1) {
565  return Toolbox::createConstant(std::numeric_limits<Scalar>::quiet_NaN());
566  }
567 
568  size_t iT =
569  std::max<size_t>(0,
570  std::min<size_t>(nTemp_ - 2,
571  static_cast<size_t>(Toolbox::value(alphaT))));
572  alphaT -= iT;
573 
574  Evaluation alphaP1 = pressLiquidIdx_(p, iT);
575  Evaluation alphaP2 = pressLiquidIdx_(p, iT + 1);
576 
577  size_t iP1 =
578  std::max<size_t>(0,
579  std::min<size_t>(nPress_ - 2,
580  static_cast<size_t>(Toolbox::value(alphaP1))));
581  size_t iP2 =
582  std::max<size_t>(0,
583  std::min<size_t>(nPress_ - 2,
584  static_cast<size_t>(Toolbox::value(alphaP2))));
585  alphaP1 -= iP1;
586  alphaP2 -= iP2;
587 
588 #if 0 && !defined NDEBUG
589  if(!(0 <= alphaT && alphaT <= 1.0))
590  OPM_THROW(NumericalProblem, "Temperature out of range: "
591  << "T=" << T << " range: [" << tempMin_ << ", " << tempMax_ << "]");
592  if(!(0 <= alphaP1 && alphaP1 <= 1.0))
593  OPM_THROW(NumericalProblem, "First liquid pressure out of range: "
594  << "p=" << p << " range: [" << minLiquidPressure_(tempIdx_(T)) << ", " << maxLiquidPressure_(tempIdx_(T)) << "]");
595  if(!(0 <= alphaP2 && alphaP2 <= 1.0))
596  OPM_THROW(NumericalProblem, "Second liquid pressure out of range: "
597  << "p=" << p << " range: [" << minLiquidPressure_(tempIdx_(T) + 1) << ", " << maxLiquidPressure_(tempIdx_(T) + 1) << "]");
598 #endif
599 
600  return
601  values[(iT ) + (iP1 )*nTemp_]*(1 - alphaT)*(1 - alphaP1) +
602  values[(iT ) + (iP1 + 1)*nTemp_]*(1 - alphaT)*( alphaP1) +
603  values[(iT + 1) + (iP2 )*nTemp_]*( alphaT)*(1 - alphaP2) +
604  values[(iT + 1) + (iP2 + 1)*nTemp_]*( alphaT)*( alphaP2);
605  }
606 
607  // returns an interpolated value for gas depending on
608  // temperature and pressure
609  template <class Evaluation>
610  static Evaluation interpolateGasTP_(const Scalar *values, const Evaluation& T, const Evaluation& p)
611  {
612  typedef MathToolbox<Evaluation> Toolbox;
613 
614  Evaluation alphaT = tempIdx_(T);
615  if (alphaT < 0 || alphaT >= nTemp_ - 1) {
616  return Toolbox::createConstant(std::numeric_limits<Scalar>::quiet_NaN());
617  }
618 
619  size_t iT =
620  std::max<size_t>(0,
621  std::min<size_t>(nTemp_ - 2,
622  static_cast<size_t>(Toolbox::value(alphaT))));
623  alphaT -= iT;
624 
625  Evaluation alphaP1 = pressGasIdx_(p, iT);
626  Evaluation alphaP2 = pressGasIdx_(p, iT + 1);
627  size_t iP1 =
628  std::max<size_t>(0, std::min<size_t>(nPress_ - 2,
629  static_cast<size_t>(Toolbox::value(alphaP1))));
630  size_t iP2 =
631  std::max<size_t>(0,
632  std::min<size_t>(nPress_ - 2,
633  static_cast<size_t>(Toolbox::value(alphaP2))));
634  alphaP1 -= iP1;
635  alphaP2 -= iP2;
636 
637 #if 0 && !defined NDEBUG
638  if(!(0 <= alphaT && alphaT <= 1.0))
639  OPM_THROW(NumericalProblem, "Temperature out of range: "
640  << "T=" << T << " range: [" << tempMin_ << ", " << tempMax_ << "]");
641  if(!(0 <= alphaP1 && alphaP1 <= 1.0))
642  OPM_THROW(NumericalProblem, "First gas pressure out of range: "
643  << "p=" << p << " range: [" << minGasPressure_(tempIdx_(T)) << ", " << maxGasPressure_(tempIdx_(T)) << "]");
644  if(!(0 <= alphaP2 && alphaP2 <= 1.0))
645  OPM_THROW(NumericalProblem, "Second gas pressure out of range: "
646  << "p=" << p << " range: [" << minGasPressure_(tempIdx_(T) + 1) << ", " << maxGasPressure_(tempIdx_(T) + 1) << "]");
647 #endif
648 
649  return
650  values[(iT ) + (iP1 )*nTemp_]*(1 - alphaT)*(1 - alphaP1) +
651  values[(iT ) + (iP1 + 1)*nTemp_]*(1 - alphaT)*( alphaP1) +
652  values[(iT + 1) + (iP2 )*nTemp_]*( alphaT)*(1 - alphaP2) +
653  values[(iT + 1) + (iP2 + 1)*nTemp_]*( alphaT)*( alphaP2);
654  }
655 
656  // returns an interpolated value for gas depending on
657  // temperature and density
658  template <class Evaluation>
659  static Evaluation interpolateGasTRho_(const Scalar *values, const Evaluation& T, const Evaluation& rho)
660  {
661  Evaluation alphaT = tempIdx_(T);
662  unsigned iT = std::max<int>(0, std::min<int>(nTemp_ - 2, (int) alphaT));
663  alphaT -= iT;
664 
665  Evaluation alphaP1 = densityGasIdx_(rho, iT);
666  Evaluation alphaP2 = densityGasIdx_(rho, iT + 1);
667  unsigned iP1 = std::max<int>(0, std::min<int>(nDensity_ - 2, (int) alphaP1));
668  unsigned iP2 = std::max<int>(0, std::min<int>(nDensity_ - 2, (int) alphaP2));
669  alphaP1 -= iP1;
670  alphaP2 -= iP2;
671 
672  return
673  values[(iT ) + (iP1 )*nTemp_]*(1 - alphaT)*(1 - alphaP1) +
674  values[(iT ) + (iP1 + 1)*nTemp_]*(1 - alphaT)*( alphaP1) +
675  values[(iT + 1) + (iP2 )*nTemp_]*( alphaT)*(1 - alphaP2) +
676  values[(iT + 1) + (iP2 + 1)*nTemp_]*( alphaT)*( alphaP2);
677  }
678 
679  // returns an interpolated value for liquid depending on
680  // temperature and density
681  template <class Evaluation>
682  static Evaluation interpolateLiquidTRho_(const Scalar *values, const Evaluation& T, const Evaluation& rho)
683  {
684  Evaluation alphaT = tempIdx_(T);
685  unsigned iT = std::max<int>(0, std::min<int>(nTemp_ - 2, (int) alphaT));
686  alphaT -= iT;
687 
688  Evaluation alphaP1 = densityLiquidIdx_(rho, iT);
689  Evaluation alphaP2 = densityLiquidIdx_(rho, iT + 1);
690  unsigned iP1 = std::max<int>(0, std::min<int>(nDensity_ - 2, (int) alphaP1));
691  unsigned iP2 = std::max<int>(0, std::min<int>(nDensity_ - 2, (int) alphaP2));
692  alphaP1 -= iP1;
693  alphaP2 -= iP2;
694 
695  return
696  values[(iT ) + (iP1 )*nTemp_]*(1 - alphaT)*(1 - alphaP1) +
697  values[(iT ) + (iP1 + 1)*nTemp_]*(1 - alphaT)*( alphaP1) +
698  values[(iT + 1) + (iP2 )*nTemp_]*( alphaT)*(1 - alphaP2) +
699  values[(iT + 1) + (iP2 + 1)*nTemp_]*( alphaT)*( alphaP2);
700  }
701 
702 
703  // returns the index of an entry in a temperature field
704  template <class Evaluation>
705  static Evaluation tempIdx_(const Evaluation& temperature)
706  {
707  return (nTemp_ - 1)*(temperature - tempMin_)/(tempMax_ - tempMin_);
708  }
709 
710  // returns the index of an entry in a pressure field
711  template <class Evaluation>
712  static Evaluation pressLiquidIdx_(const Evaluation& pressure, size_t tempIdx)
713  {
714  Scalar plMin = minLiquidPressure_(tempIdx);
715  Scalar plMax = maxLiquidPressure_(tempIdx);
716 
717  return (nPress_ - 1)*(pressure - plMin)/(plMax - plMin);
718  }
719 
720  // returns the index of an entry in a temperature field
721  template <class Evaluation>
722  static Evaluation pressGasIdx_(const Evaluation& pressure, size_t tempIdx)
723  {
724  Scalar pgMin = minGasPressure_(tempIdx);
725  Scalar pgMax = maxGasPressure_(tempIdx);
726 
727  return (nPress_ - 1)*(pressure - pgMin)/(pgMax - pgMin);
728  }
729 
730  // returns the index of an entry in a density field
731  template <class Evaluation>
732  static Evaluation densityLiquidIdx_(const Evaluation& density, size_t tempIdx)
733  {
734  Scalar densityMin = minLiquidDensity_(tempIdx);
735  Scalar densityMax = maxLiquidDensity_(tempIdx);
736  return (nDensity_ - 1) * (density - densityMin)/(densityMax - densityMin);
737  }
738 
739  // returns the index of an entry in a density field
740  template <class Evaluation>
741  static Evaluation densityGasIdx_(const Evaluation& density, size_t tempIdx)
742  {
743  Scalar densityMin = minGasDensity_(tempIdx);
744  Scalar densityMax = maxGasDensity_(tempIdx);
745  return (nDensity_ - 1) * (density - densityMin)/(densityMax - densityMin);
746  }
747 
748  // returns the minimum tabulized liquid pressure at a given
749  // temperature index
750  static Scalar minLiquidPressure_(size_t tempIdx)
751  {
752  if (!useVaporPressure)
753  return pressMin_;
754  else
755  return std::max<Scalar>(pressMin_, vaporPressure_[tempIdx] / 1.1);
756  }
757 
758  // returns the maximum tabulized liquid pressure at a given
759  // temperature index
760  static Scalar maxLiquidPressure_(size_t tempIdx)
761  {
762  if (!useVaporPressure)
763  return pressMax_;
764  else
765  return std::max<Scalar>(pressMax_, vaporPressure_[tempIdx] * 1.1);
766  }
767 
768  // returns the minumum tabulized gas pressure at a given
769  // temperature index
770  static Scalar minGasPressure_(size_t tempIdx)
771  {
772  if (!useVaporPressure)
773  return pressMin_;
774  else
775  return std::min<Scalar>(pressMin_, vaporPressure_[tempIdx] / 1.1 );
776  }
777 
778  // returns the maximum tabulized gas pressure at a given
779  // temperature index
780  static Scalar maxGasPressure_(size_t tempIdx)
781  {
782  if (!useVaporPressure)
783  return pressMax_;
784  else
785  return std::min<Scalar>(pressMax_, vaporPressure_[tempIdx] * 1.1);
786  }
787 
788 
789  // returns the minimum tabulized liquid density at a given
790  // temperature index
791  static Scalar minLiquidDensity_(size_t tempIdx)
792  { return minLiquidDensity__[tempIdx]; }
793 
794  // returns the maximum tabulized liquid density at a given
795  // temperature index
796  static Scalar maxLiquidDensity_(size_t tempIdx)
797  { return maxLiquidDensity__[tempIdx]; }
798 
799  // returns the minumum tabulized gas density at a given
800  // temperature index
801  static Scalar minGasDensity_(size_t tempIdx)
802  { return minGasDensity__[tempIdx]; }
803 
804  // returns the maximum tabulized gas density at a given
805  // temperature index
806  static Scalar maxGasDensity_(size_t tempIdx)
807  { return maxGasDensity__[tempIdx]; }
808 
809  // 1D fields with the temperature as degree of freedom
810  static Scalar *vaporPressure_;
811 
812  static Scalar *minLiquidDensity__;
813  static Scalar *maxLiquidDensity__;
814 
815  static Scalar *minGasDensity__;
816  static Scalar *maxGasDensity__;
817 
818  // 2D fields with the temperature and pressure as degrees of
819  // freedom
820  static Scalar *gasEnthalpy_;
821  static Scalar *liquidEnthalpy_;
822 
823  static Scalar *gasHeatCapacity_;
824  static Scalar *liquidHeatCapacity_;
825 
826  static Scalar *gasDensity_;
827  static Scalar *liquidDensity_;
828 
829  static Scalar *gasViscosity_;
830  static Scalar *liquidViscosity_;
831 
832  static Scalar *gasThermalConductivity_;
833  static Scalar *liquidThermalConductivity_;
834 
835  // 2D fields with the temperature and density as degrees of
836  // freedom
837  static Scalar *gasPressure_;
838  static Scalar *liquidPressure_;
839 
840  // temperature, pressure and density ranges
841  static Scalar tempMin_;
842  static Scalar tempMax_;
843  static unsigned nTemp_;
844 
845  static Scalar pressMin_;
846  static Scalar pressMax_;
847  static unsigned nPress_;
848 
849  static Scalar densityMin_;
850  static Scalar densityMax_;
851  static unsigned nDensity_;
852 };
853 
854 template <class Scalar, class RawComponent, bool useVaporPressure>
855 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::vaporPressure_;
856 template <class Scalar, class RawComponent, bool useVaporPressure>
857 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::minLiquidDensity__;
858 template <class Scalar, class RawComponent, bool useVaporPressure>
859 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::maxLiquidDensity__;
860 template <class Scalar, class RawComponent, bool useVaporPressure>
861 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::minGasDensity__;
862 template <class Scalar, class RawComponent, bool useVaporPressure>
863 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::maxGasDensity__;
864 template <class Scalar, class RawComponent, bool useVaporPressure>
865 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::gasEnthalpy_;
866 template <class Scalar, class RawComponent, bool useVaporPressure>
867 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::liquidEnthalpy_;
868 template <class Scalar, class RawComponent, bool useVaporPressure>
869 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::gasHeatCapacity_;
870 template <class Scalar, class RawComponent, bool useVaporPressure>
871 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::liquidHeatCapacity_;
872 template <class Scalar, class RawComponent, bool useVaporPressure>
873 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::gasDensity_;
874 template <class Scalar, class RawComponent, bool useVaporPressure>
875 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::liquidDensity_;
876 template <class Scalar, class RawComponent, bool useVaporPressure>
877 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::gasViscosity_;
878 template <class Scalar, class RawComponent, bool useVaporPressure>
879 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::liquidViscosity_;
880 template <class Scalar, class RawComponent, bool useVaporPressure>
881 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::gasThermalConductivity_;
882 template <class Scalar, class RawComponent, bool useVaporPressure>
883 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::liquidThermalConductivity_;
884 template <class Scalar, class RawComponent, bool useVaporPressure>
885 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::gasPressure_;
886 template <class Scalar, class RawComponent, bool useVaporPressure>
887 Scalar* TabulatedComponent<Scalar, RawComponent, useVaporPressure>::liquidPressure_;
888 template <class Scalar, class RawComponent, bool useVaporPressure>
889 Scalar TabulatedComponent<Scalar, RawComponent, useVaporPressure>::tempMin_;
890 template <class Scalar, class RawComponent, bool useVaporPressure>
891 Scalar TabulatedComponent<Scalar, RawComponent, useVaporPressure>::tempMax_;
892 template <class Scalar, class RawComponent, bool useVaporPressure>
893 unsigned TabulatedComponent<Scalar, RawComponent, useVaporPressure>::nTemp_;
894 template <class Scalar, class RawComponent, bool useVaporPressure>
895 Scalar TabulatedComponent<Scalar, RawComponent, useVaporPressure>::pressMin_;
896 template <class Scalar, class RawComponent, bool useVaporPressure>
897 Scalar TabulatedComponent<Scalar, RawComponent, useVaporPressure>::pressMax_;
898 template <class Scalar, class RawComponent, bool useVaporPressure>
899 unsigned TabulatedComponent<Scalar, RawComponent, useVaporPressure>::nPress_;
900 template <class Scalar, class RawComponent, bool useVaporPressure>
901 Scalar TabulatedComponent<Scalar, RawComponent, useVaporPressure>::densityMin_;
902 template <class Scalar, class RawComponent, bool useVaporPressure>
903 Scalar TabulatedComponent<Scalar, RawComponent, useVaporPressure>::densityMax_;
904 template <class Scalar, class RawComponent, bool useVaporPressure>
905 unsigned TabulatedComponent<Scalar, RawComponent, useVaporPressure>::nDensity_;
906 
907 
908 } // namespace Opm
909 
910 #endif
static const char * name()
A human readable name for the component.
Definition: TabulatedComponent.hpp:216
static void init(Scalar tempMin, Scalar tempMax, unsigned nTemp, Scalar pressMin, Scalar pressMax, unsigned nPress)
Initialize the tables.
Definition: TabulatedComponent.hpp:73
static bool gasIsCompressible()
Returns true iff the gas phase is assumed to be compressible.
Definition: TabulatedComponent.hpp:405
static Evaluation vaporPressure(const Evaluation &temperature)
The vapor pressure in of the component at a given temperature.
Definition: TabulatedComponent.hpp:256
static Evaluation gasHeatCapacity(const Evaluation &temperature, const Evaluation &pressure)
Specific isobaric heat capacity of the gas .
Definition: TabulatedComponent.hpp:311
static Scalar tripleTemperature()
Returns the temperature in at the component's triple point.
Definition: TabulatedComponent.hpp:240
Definition: MathToolbox.hpp:39
Definition: Air_Mesitylene.hpp:31
static Evaluation liquidDensity(const Evaluation &temperature, const Evaluation &pressure)
The density of liquid at a given pressure and temperature .
Definition: TabulatedComponent.hpp:449
static Evaluation gasThermalConductivity(const Evaluation &temperature, const Evaluation &pressure)
The thermal conductivity of gaseous water .
Definition: TabulatedComponent.hpp:506
static Evaluation liquidHeatCapacity(const Evaluation &temperature, const Evaluation &pressure)
Specific isobaric heat capacity of the liquid .
Definition: TabulatedComponent.hpp:330
static Scalar molarMass()
The molar mass in of the component.
Definition: TabulatedComponent.hpp:222
static Evaluation gasPressure(const Evaluation &temperature, Scalar density)
The pressure of gas in at a given density and temperature.
Definition: TabulatedComponent.hpp:369
static Evaluation liquidInternalEnergy(const Evaluation &temperature, const Evaluation &pressure)
Specific internal energy of the liquid .
Definition: TabulatedComponent.hpp:359
static Scalar triplePressure()
Returns the pressure in at the component's triple point.
Definition: TabulatedComponent.hpp:246
static Scalar criticalPressure()
Returns the critical pressure in of the component.
Definition: TabulatedComponent.hpp:234
static Scalar criticalTemperature()
Returns the critical temperature in of the component.
Definition: TabulatedComponent.hpp:228
static bool gasIsIdeal()
Returns true iff the gas phase is assumed to be ideal.
Definition: TabulatedComponent.hpp:417
A generic class which tabulates all thermodynamic properties of a given component.
Definition: TabulatedComponent.hpp:56
static Evaluation liquidEnthalpy(const Evaluation &temperature, const Evaluation &pressure)
Specific enthalpy of the liquid .
Definition: TabulatedComponent.hpp:292
static Evaluation gasInternalEnergy(const Evaluation &temperature, const Evaluation &pressure)
Specific internal energy of the gas .
Definition: TabulatedComponent.hpp:349
static const bool isTabulated
Definition: TabulatedComponent.hpp:61
static bool liquidIsCompressible()
Returns true iff the liquid phase is assumed to be compressible.
Definition: TabulatedComponent.hpp:411
static Evaluation gasEnthalpy(const Evaluation &temperature, const Evaluation &pressure)
Specific enthalpy of the gas .
Definition: TabulatedComponent.hpp:273
static Evaluation liquidPressure(const Evaluation &temperature, Scalar density)
The pressure of liquid in at a given density and temperature.
Definition: TabulatedComponent.hpp:389
ScalarT Scalar
Definition: TabulatedComponent.hpp:59
static Evaluation gasDensity(const Evaluation &temperature, const Evaluation &pressure)
The density of gas at a given pressure and temperature .
Definition: TabulatedComponent.hpp:429
static Evaluation gasViscosity(const Evaluation &temperature, const Evaluation &pressure)
The dynamic viscosity of gas.
Definition: TabulatedComponent.hpp:468
static Evaluation liquidViscosity(const Evaluation &temperature, const Evaluation &pressure)
The dynamic viscosity of liquid.
Definition: TabulatedComponent.hpp:487
static Evaluation liquidThermalConductivity(const Evaluation &temperature, const Evaluation &pressure)
The thermal conductivity of liquid water .
Definition: TabulatedComponent.hpp:525
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...