H2O.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  Copyright (C) 2010 by Jochen Fritz
6 
7  This file is part of the Open Porous Media project (OPM).
8 
9  OPM is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 2 of the License, or
12  (at your option) any later version.
13 
14  OPM is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OPM. If not, see <http://www.gnu.org/licenses/>.
21 */
26 #ifndef OPM_H2O_HPP
27 #define OPM_H2O_HPP
28 
29 #include <cmath>
30 #include <cassert>
31 
33 #include <opm/common/Exceptions.hpp>
34 #include <opm/common/ErrorMacros.hpp>
36 
37 #include "Component.hpp"
38 
39 #include "iapws/Common.hpp"
40 #include "iapws/Region1.hpp"
41 #include "iapws/Region2.hpp"
42 #include "iapws/Region4.hpp"
43 
44 namespace Opm {
45 
59 template <class Scalar>
60 class H2O : public Component<Scalar, H2O<Scalar> >
61 {
66 
67  static const Scalar Rs; // specific gas constant of water
68 
69 public:
73  static const char *name()
74  { return "H2O"; }
75 
79  static const Scalar molarMass()
80  { return Common::molarMass; }
81 
85  static const Scalar acentricFactor()
86  { return Common::acentricFactor; }
87 
91  static const Scalar criticalTemperature()
92  { return Common::criticalTemperature; }
93 
97  static const Scalar criticalPressure()
98  { return Common::criticalPressure; }
99 
104  { return Common::criticalMolarVolume; }
105 
109  static const Scalar tripleTemperature()
110  { return Common::tripleTemperature; }
111 
115  static const Scalar triplePressure()
116  { return Common::triplePressure; }
117 
130  template <class Evaluation>
131  static Evaluation vaporPressure(Evaluation temperature)
132  {
133  if (temperature > criticalTemperature())
134  temperature = criticalTemperature();
135  if (temperature < tripleTemperature())
136  temperature = tripleTemperature();
137 
138  return Region4::saturationPressure(temperature);
139  }
152  template <class Evaluation>
153  static Evaluation vaporTemperature(const Evaluation& pressure)
154  {
155  if (pressure > criticalPressure())
156  pressure = criticalPressure();
157  if (pressure < triplePressure())
158  pressure = triplePressure();
159 
160  return Region4::vaporTemperature(pressure);
161  }
162 
175  template <class Evaluation>
176  static Evaluation gasEnthalpy(const Evaluation& temperature,
177  const Evaluation& pressure)
178  {
179  typedef MathToolbox<Evaluation> Toolbox;
180 
181  if (!Region2::isValid(temperature, pressure))
182  {
183  OPM_THROW(NumericalProblem,
184  "Enthalpy of steam is only implemented for temperatures below 623.15K and "
185  "pressures below 100MPa. (T = " << temperature << ", p=" << pressure);
186  }
187 
188  // regularization
189  if (pressure < triplePressure() - 100) {
190  // We assume an ideal gas for low pressures to avoid the
191  // 0/0 for the gas enthalpy at very low pressures. The
192  // enthalpy of an ideal gas does not exhibit any
193  // dependence on pressure, so we can just return the
194  // specific enthalpy at the point of regularization, i.e.
195  // the triple pressure - 100Pa
196  return enthalpyRegion2_(temperature, Toolbox::createConstant(triplePressure() - 100));
197  }
198  Evaluation pv = vaporPressure(temperature);
199  if (pressure > pv) {
200  // the pressure is too high, in this case we use the slope
201  // of the enthalpy at the vapor pressure to regularize
202  Evaluation dh_dp =
203  Rs*temperature*
204  Region2::tau(temperature)*
205  Region2::dpi_dp(pv)*
206  Region2::ddgamma_dtaudpi(temperature, pv);
207 
208  return
209  enthalpyRegion2_(temperature, pv) +
210  (pressure - pv)*dh_dp;
211  };
212 
213  return enthalpyRegion2_(temperature, pressure);
214  }
215 
228  template <class Evaluation>
229  static Evaluation liquidEnthalpy(const Evaluation& temperature,
230  const Evaluation& pressure)
231  {
232  typedef MathToolbox<Evaluation> Toolbox;
233 
234  if (!Region1::isValid(temperature, pressure))
235  {
236  OPM_THROW(NumericalProblem,
237  "Enthalpy of water is only implemented for temperatures below 623.15K and "
238  "pressures below 100MPa. (T = " << temperature << ", p=" << pressure);
239  }
240 
241  // regularization
242  const Evaluation& pv = vaporPressure(temperature);
243  if (pressure < pv) {
244  // the pressure is too low, in this case we use the slope
245  // of the enthalpy at the vapor pressure to regularize
246  const Evaluation& dh_dp =
247  Rs * temperature*
248  Region1::tau(temperature)*
249  Region1::dpi_dp(Toolbox::value(pv))*
250  Region1::ddgamma_dtaudpi(temperature, pv);
251 
252  return
253  enthalpyRegion1_(temperature, pv) +
254  (pressure - pv)*dh_dp;
255  };
256 
257  return enthalpyRegion1_(temperature, pressure);
258  }
259 
272  template <class Evaluation>
273  static Evaluation gasHeatCapacity(const Evaluation& temperature,
274  const Evaluation& pressure)
275  {
276  if (!Region2::isValid(temperature, pressure))
277  {
278  OPM_THROW(NumericalProblem,
279  "Heat capacity of steam is only implemented for temperatures below 623.15K and "
280  "pressures below 100MPa. (T = " << temperature << ", p=" << pressure);
281  }
282 
283  // regularization
284  if (pressure < triplePressure() - 100)
285  return heatCap_p_Region2_(temperature, Evaluation(triplePressure() - 100));
286  const Evaluation& pv = vaporPressure(temperature);
287  if (pressure > pv)
288  // the pressure is too high, in this case we use the heat
289  // cap at the vapor pressure to regularize
290  return heatCap_p_Region2_(temperature, pv);
291 
292  return heatCap_p_Region2_(temperature, pressure);
293  }
294 
307  template <class Evaluation>
308  static Evaluation liquidHeatCapacity(const Evaluation& temperature,
309  const Evaluation& pressure)
310  {
311  if (!Region1::isValid(temperature, pressure))
312  {
313  OPM_THROW(NumericalProblem,
314  "heat Capacity of water is only implemented for temperatures below 623.15K and "
315  "pressures below 100MPa. (T = " << temperature << ", p=" << pressure);
316  }
317 
318  // regularization
319  const Evaluation& pv = vaporPressure(temperature);
320  if (pressure < pv) {
321  // the pressure is too low, in this case we use the heat capacity at the
322  // vapor pressure to regularize
323  return heatCap_p_Region1_(temperature, pv);
324  };
325 
326  return heatCap_p_Region1_(temperature, pressure);
327  }
328 
341  template <class Evaluation>
342  static Evaluation liquidInternalEnergy(const Evaluation& temperature,
343  const Evaluation& pressure)
344  {
345  if (!Region1::isValid(temperature, pressure))
346  {
347  OPM_THROW(NumericalProblem,
348  "Internal Energy of water is only implemented for temperatures below 623.15K and "
349  "pressures below 100MPa. (T = " << temperature << ", p=" << pressure);
350  }
351 
352 
353  // regularization
354  Scalar pv = vaporPressure(temperature);
355  if (pressure < pv) {
356  // the pressure is too low, in this case we use the slope
357  // of the internal energy at the vapor pressure to
358  // regularize
359 
360  /*
361  // calculate the partial derivative of the internal energy
362  // to the pressure at the vapor pressure.
363  Scalar tau = Region1::tau(temperature);
364  Scalar dgamma_dpi = Region1::dgamma_dpi(temperature, pv);
365  Scalar ddgamma_dtaudpi = Region1::ddgamma_dtaudpi(temperature, pv);
366  Scalar ddgamma_ddpi = Region1::ddgamma_ddpi(temperature, pv);
367  Scalar pi = Region1::pi(pv);
368  Scalar dpi_dp = Region1::dpi_dp(pv);
369  Scalar du_dp =
370  Rs*temperature*
371  (tau*dpi_dp*ddgamma_dtaudpi + dpi_dp*dpi_dp*dgamma_dpi + pi*dpi_dp*ddgamma_ddpi);
372  */
373 
374  // use a straight line for extrapolation. use forward
375  // differences to calculate the partial derivative to the
376  // pressure at the vapor pressure
377  Scalar eps = 1e-7;
378  Scalar uv = internalEnergyRegion1_(temperature, pv);
379  Scalar uvPEps = internalEnergyRegion1_(temperature, pv + eps);
380  Scalar du_dp = (uvPEps - uv)/eps;
381  return uv + du_dp*(pressure - pv);
382  };
383 
384  return internalEnergyRegion1_(temperature, pressure);
385  }
386 
399  template <class Evaluation>
400  static Evaluation gasInternalEnergy(const Evaluation& temperature, const Evaluation& pressure)
401  {
402  if (!Region2::isValid(temperature, pressure))
403  {
404  OPM_THROW(NumericalProblem,
405  "Internal Energy of steam is only implemented for temperatures below 623.15K and "
406  "pressures below 100MPa. (T = " << temperature << ", p=" << pressure);
407  }
408 
409  // regularization
410  if (pressure < triplePressure() - 100) {
411  // We assume an ideal gas for low pressures to avoid the
412  // 0/0 for the internal energy of gas at very low
413  // pressures. The enthalpy of an ideal gas does not
414  // exhibit any dependence on pressure, so we can just
415  // return the specific enthalpy at the point of
416  // regularization, i.e. the triple pressure - 100Pa, and
417  // subtract the work required to change the volume for an
418  // ideal gas.
419  return
420  enthalpyRegion2_(temperature, triplePressure() - 100)
421  -
422  Rs*temperature; // = p*v for an ideal gas!
423  }
424  Scalar pv = vaporPressure(temperature);
425  if (pressure > pv) {
426  // the pressure is too high, in this case we use the slope
427  // of the internal energy at the vapor pressure to
428  // regularize
429 
430  /*
431  // calculate the partial derivative of the internal energy
432  // to the pressure at the vapor pressure.
433  Scalar tau = Region2::tau(temperature);
434  Scalar dgamma_dpi = Region2::dgamma_dpi(temperature, pv);
435  Scalar ddgamma_dtaudpi = Region2::ddgamma_dtaudpi(temperature, pv);
436  Scalar ddgamma_ddpi = Region2::ddgamma_ddpi(temperature, pv);
437  Scalar pi = Region2::pi(pv);
438  Scalar dpi_dp = Region2::dpi_dp(pv);
439  Scalar du_dp =
440  Rs*temperature*
441  (tau*dpi_dp*ddgamma_dtaudpi + dpi_dp*dpi_dp*dgamma_dpi + pi*dpi_dp*ddgamma_ddpi);
442 
443  // use a straight line for extrapolation
444  Scalar uv = internalEnergyRegion2_(temperature, pv);
445  return uv + du_dp*(pressure - pv);
446  */
447 
448  // use a straight line for extrapolation. use backward
449  // differences to calculate the partial derivative to the
450  // pressure at the vapor pressure
451  Scalar eps = 1e-7;
452  Scalar uv = internalEnergyRegion2_(temperature, pv);
453  Scalar uvMEps = internalEnergyRegion2_(temperature, pv - eps);
454  Scalar du_dp = (uv - uvMEps)/eps;
455  return uv + du_dp*(pressure - pv);
456  };
457 
458  return internalEnergyRegion2_(temperature, pressure);
459  }
460 
473  template <class Evaluation>
474  static Evaluation liquidHeatCapacityConstVolume(const Evaluation& temperature,
475  const Evaluation& pressure)
476  {
477  if (!Region1::isValid(temperature, pressure))
478  {
479  OPM_THROW(NumericalProblem,
480  "Heat capacity of water is only implemented for temperatures below 623.15K and "
481  "pressures below 100MPa. (T = " << temperature << ", p=" << pressure);
482  }
483 
484 
485  // regularization
486  Scalar pv = vaporPressure(temperature);
487  if (pressure < pv) {
488  // the pressure is too low, in this case we use the heat cap at the vapor pressure to regularize
489 
490  return heatCap_v_Region1_(temperature, pv);
491  }
492 
493  return heatCap_v_Region1_(temperature, pressure);
494  }
495 
508  template <class Evaluation>
509  static Evaluation gasHeatCapacityConstVolume(const Evaluation& temperature, const Evaluation& pressure)
510  {
511  if (!Region2::isValid(temperature, pressure))
512  {
513  OPM_THROW(NumericalProblem,
514  "Heat capacity of steam is only implemented for temperatures below 623.15K and "
515  "pressures below 100MPa. (T = " << temperature << ", p=" << pressure);
516  }
517 
518  // regularization
519  if (pressure < triplePressure() - 100) {
520  return
521  heatCap_v_Region2_(temperature, triplePressure() - 100);
522  }
523  Scalar pv = vaporPressure(temperature);
524  if (pressure > pv) {
525  return heatCap_v_Region2_(temperature, pv);
526  };
527 
528  return heatCap_v_Region2_(temperature, pressure);
529  }
530 
534  static bool gasIsCompressible()
535  { return true; }
536 
540  static bool liquidIsCompressible()
541  { return true; }
542 
555  template <class Evaluation>
556  static Evaluation gasDensity(const Evaluation& temperature, const Evaluation& pressure)
557  {
558  typedef MathToolbox<Evaluation> Toolbox;
559 
560  if (!Region2::isValid(temperature, pressure))
561  {
562  OPM_THROW(NumericalProblem,
563  "Density of steam is only implemented for temperatures below 623.15K and "
564  "pressures below 100MPa. (T = " << temperature << ", p=" << pressure);
565  }
566 
567  // regularization
568  if (pressure < triplePressure() - 100) {
569  // We assume an ideal gas for low pressures to avoid the
570  // 0/0 for the internal energy and enthalpy.
571  const Evaluation& rho0IAPWS =
572  1.0/volumeRegion2_(temperature,
573  Evaluation(triplePressure() - 100));
574  const Evaluation& rho0Id =
575  IdealGas<Scalar>::density(Evaluation(molarMass()),
576  temperature,
577  Evaluation(triplePressure() - 100));
578  return
579  rho0IAPWS/rho0Id
580  *IdealGas<Scalar>::density(Evaluation(molarMass()),
581  temperature,
582  pressure);
583  }
584  Evaluation pv = vaporPressure(temperature);
585  if (pressure > pv) {
586  // the pressure is too high, in this case we use the slope
587  // of the density energy at the vapor pressure to
588  // regularize
589 
590  // calculate the partial derivative of the specific volume
591  // to the pressure at the vapor pressure.
592  Scalar eps = Toolbox::value(pv)*1e-8;
593  Evaluation v0 = volumeRegion2_(temperature, pv);
594  Evaluation v1 = volumeRegion2_(temperature, pv + eps);
595  Evaluation dv_dp = (v1 - v0)/eps;
596  /*
597  Scalar pi = Region2::pi(pv);
598  Scalar dp_dpi = Region2::dp_dpi(pv);
599  Scalar dgamma_dpi = Region2::dgamma_dpi(temperature, pv);
600  Scalar ddgamma_ddpi = Region2::ddgamma_ddpi(temperature, pv);
601 
602  Scalar RT = Rs*temperature;
603  Scalar dv_dp =
604  RT/(dp_dpi*pv)
605  *
606  (dgamma_dpi + pi*ddgamma_ddpi - v0*dp_dpi/RT);
607  */
608 
609  // calculate the partial derivative of the density to the
610  // pressure at vapor pressure
611  Evaluation drho_dp = - 1/(v0*v0)*dv_dp;
612 
613  // use a straight line for extrapolation
614  return 1.0/v0 + (pressure - pv)*drho_dp;
615  };
616 
617  return 1.0/volumeRegion2_(temperature, pressure);
618  }
619 
623  static bool gasIsIdeal()
624  { return false; }
625 
638  template <class Evaluation>
639  static Evaluation gasPressure(const Evaluation& temperature, Scalar density)
640  {
641  typedef MathToolbox<Evaluation> Toolbox;
642 
643  Valgrind::CheckDefined(temperature);
644  Valgrind::CheckDefined(density);
645 
646  // We use the newton method for this. For the initial value we
647  // assume steam to be an ideal gas
648  Evaluation pressure = IdealGas<Scalar>::pressure(temperature, density/molarMass());
649  Scalar eps = pressure*1e-7;
650 
651  Evaluation deltaP = pressure*2;
652  Valgrind::CheckDefined(pressure);
653  Valgrind::CheckDefined(deltaP);
654  for (int i = 0; i < 5 && std::abs(Toolbox::value(pressure)*1e-9) < std::abs(Toolbox::value(deltaP)); ++i) {
655  Evaluation f = gasDensity(temperature, pressure) - density;
656 
657  Evaluation df_dp;
658  df_dp = gasDensity(temperature, pressure + eps);
659  df_dp -= gasDensity(temperature, pressure - eps);
660  df_dp /= 2*eps;
661 
662  deltaP = - f/df_dp;
663 
664  pressure += deltaP;
665  Valgrind::CheckDefined(pressure);
666  Valgrind::CheckDefined(deltaP);
667  }
668 
669  return pressure;
670  }
671 
684  template <class Evaluation>
685  static Evaluation liquidDensity(const Evaluation& temperature, const Evaluation& pressure)
686  {
687  typedef MathToolbox<Evaluation> Toolbox;
688 
689  if (!Region1::isValid(temperature, pressure))
690  {
691  OPM_THROW(NumericalProblem,
692  "Density of water is only implemented for temperatures below 623.15K and "
693  "pressures below 100MPa. (T = " << temperature << ", p=" << pressure);
694  }
695 
696  // regularization
697  Evaluation pv = vaporPressure(temperature);
698  if (pressure < pv) {
699  // the pressure is too low, in this case we use the slope
700  // of the density at the vapor pressure to regularize
701 
702  // calculate the partial derivative of the specific volume
703  // to the pressure at the vapor pressure.
704  Scalar eps = Toolbox::value(pv)*1e-8;
705  Evaluation v0 = volumeRegion1_(temperature, pv);
706  Evaluation v1 = volumeRegion1_(temperature, pv + eps);
707  Evaluation dv_dp = (v1 - v0)/eps;
708 
709  /*
710  Scalar v0 = volumeRegion1_(temperature, pv);
711  Scalar pi = Region1::pi(pv);
712  Scalar dp_dpi = Region1::dp_dpi(pv);
713  Scalar dgamma_dpi = Region1::dgamma_dpi(temperature, pv);
714  Scalar ddgamma_ddpi = Region1::ddgamma_ddpi(temperature, pv);
715 
716  Scalar RT = Rs*temperature;
717  Scalar dv_dp =
718  RT/(dp_dpi*pv)
719  *
720  (dgamma_dpi + pi*ddgamma_ddpi - v0*dp_dpi/RT);
721  */
722 
723  // calculate the partial derivative of the density to the
724  // pressure at vapor pressure
725  Evaluation drho_dp = - 1/(v0*v0)*dv_dp;
726 
727  // use a straight line for extrapolation
728  return 1.0/v0 + (pressure - pv)*drho_dp;
729  };
730 
731  return 1/volumeRegion1_(temperature, pressure);
732  }
733 
747  template <class Evaluation>
748  static Evaluation liquidPressure(const Evaluation& temperature, Scalar density)
749  {
750  typedef MathToolbox<Evaluation> Toolbox;
751 
752  // We use the Newton method for this. For the initial value we
753  // assume the pressure to be 10% higher than the vapor
754  // pressure
755  Evaluation pressure = 1.1*vaporPressure(temperature);
756  Scalar eps = Toolbox::value(pressure)*1e-7;
757 
758  Evaluation deltaP = pressure*2;
759  for (int i = 0; i < 5 && std::abs(Toolbox::value(pressure)*1e-9) < std::abs(Toolbox::value(deltaP)); ++i) {
760  Evaluation f = liquidDensity(temperature, pressure) - density;
761 
762  Evaluation df_dp;
763  df_dp = liquidDensity(temperature, pressure + eps);
764  df_dp -= liquidDensity(temperature, pressure - eps);
765  df_dp /= 2*eps;
766 
767  deltaP = - f/df_dp;
768 
769  pressure += deltaP;
770  }
771 
772  return pressure;
773  }
774 
789  template <class Evaluation>
790  static Evaluation gasViscosity(const Evaluation& temperature, const Evaluation& pressure)
791  {
792  if (!Region2::isValid(temperature, pressure))
793  {
794  OPM_THROW(NumericalProblem,
795  "Viscosity of steam is only implemented for temperatures below 623.15K and "
796  "pressures below 100MPa. (T = " << temperature << ", p=" << pressure);
797  }
798 
799  Evaluation rho = gasDensity(temperature, pressure);
800  return Common::viscosity(temperature, rho);
801  }
802 
814  template <class Evaluation>
815  static Evaluation liquidViscosity(const Evaluation& temperature, const Evaluation& pressure)
816  {
817  if (!Region1::isValid(temperature, pressure))
818  {
819  OPM_THROW(NumericalProblem,
820  "Viscosity of water is only implemented for temperatures below 623.15K and "
821  "pressures below 100MPa. (T = " << temperature << ", p=" << pressure);
822  };
823 
824  const Evaluation& rho = liquidDensity(temperature, pressure);
825  return Common::viscosity(temperature, rho);
826  }
827 
841  template <class Evaluation>
842  static Evaluation liquidThermalConductivity(const Evaluation& temperature, const Evaluation& pressure)
843  {
844  const Evaluation& rho = liquidDensity(temperature, pressure);
845  return Common::thermalConductivityIAPWS(temperature, rho);
846  }
847 
861  template <class Evaluation>
862  static Evaluation gasThermalConductivity(const Evaluation& temperature, const Evaluation& pressure)
863  {
864  const Evaluation& rho = gasDensity(temperature, pressure);
865  return Common::thermalConductivityIAPWS(temperature, rho);
866  }
867 
868 private:
869  // the unregularized specific enthalpy for liquid water
870  template <class Evaluation>
871  static Evaluation enthalpyRegion1_(const Evaluation& temperature, const Evaluation& pressure)
872  {
873  return
874  Region1::tau(temperature) *
875  Region1::dgamma_dtau(temperature, pressure) *
876  Rs*temperature;
877  }
878 
879  // the unregularized specific isobaric heat capacity
880  template <class Evaluation>
881  static Evaluation heatCap_p_Region1_(const Evaluation& temperature, const Evaluation& pressure)
882  {
883  typedef Opm::MathToolbox<Evaluation> Toolbox;
884  return
885  - Toolbox::pow(Region1::tau(temperature), 2.0) *
886  Region1::ddgamma_ddtau(temperature, pressure) *
887  Rs;
888  }
889 
890  // the unregularized specific isochoric heat capacity
891  template <class Evaluation>
892  static Evaluation heatCap_v_Region1_(const Evaluation& temperature, const Evaluation& pressure)
893  {
894  double tau = Region1::tau(temperature);
895  double num = Region1::dgamma_dpi(temperature, pressure) - tau * Region1::ddgamma_dtaudpi(temperature, pressure);
896  double diff = std::pow(num, 2) / Region1::ddgamma_ddpi(temperature, pressure);
897 
898  return
899  - std::pow(tau, 2 ) *
900  Region1::ddgamma_ddtau(temperature, pressure) * Rs +
901  diff;
902  }
903 
904  // the unregularized specific internal energy for liquid water
905  template <class Evaluation>
906  static Evaluation internalEnergyRegion1_(const Evaluation& temperature, const Evaluation& pressure)
907  {
908  return
909  Rs * temperature *
910  ( Region1::tau(temperature)*Region1::dgamma_dtau(temperature, pressure) -
911  Region1::pi(pressure)*Region1::dgamma_dpi(temperature, pressure));
912  }
913 
914  // the unregularized specific volume for liquid water
915  template <class Evaluation>
916  static Evaluation volumeRegion1_(const Evaluation& temperature, const Evaluation& pressure)
917  {
918  return
919  Region1::pi(pressure)*
920  Region1::dgamma_dpi(temperature, pressure) *
921  Rs * temperature / pressure;
922  }
923 
924  // the unregularized specific enthalpy for steam
925  template <class Evaluation>
926  static Evaluation enthalpyRegion2_(const Evaluation& temperature, const Evaluation& pressure)
927  {
928  return
929  Region2::tau(temperature) *
930  Region2::dgamma_dtau(temperature, pressure) *
931  Rs*temperature;
932  }
933 
934  // the unregularized specific internal energy for steam
935  template <class Evaluation>
936  static Evaluation internalEnergyRegion2_(const Evaluation& temperature, const Evaluation& pressure)
937  {
938  return
939  Rs * temperature *
940  ( Region2::tau(temperature)*Region2::dgamma_dtau(temperature, pressure) -
941  Region2::pi(pressure)*Region2::dgamma_dpi(temperature, pressure));
942  }
943 
944  // the unregularized specific isobaric heat capacity
945  template <class Evaluation>
946  static Evaluation heatCap_p_Region2_(const Evaluation& temperature, const Evaluation& pressure)
947  {
948  typedef MathToolbox<Evaluation> Toolbox;
949 
950  return
951  - Toolbox::pow(Region2::tau(temperature), 2 ) *
952  Region2::ddgamma_ddtau(temperature, pressure) *
953  Rs;
954  }
955 
956  // the unregularized specific isochoric heat capacity
957  template <class Evaluation>
958  static Evaluation heatCap_v_Region2_(const Evaluation& temperature, const Evaluation& pressure)
959  {
960  const Evaluation& tau = Region2::tau(temperature);
961  const Evaluation& pi = Region2::pi(pressure);
962  const Evaluation& num = 1 + pi * Region2::dgamma_dpi(temperature, pressure) + tau * pi * Region2::ddgamma_dtaudpi(temperature, pressure);
963  const Evaluation& diff = num * num / (1 - pi * pi * Region2::ddgamma_ddpi(temperature, pressure));
964  return
965  - std::pow(tau, 2 ) *
966  Region2::ddgamma_ddtau(temperature, pressure) * Rs
967  - diff;
968  }
969 
970  // the unregularized specific volume for steam
971  template <class Evaluation>
972  static Evaluation volumeRegion2_(const Evaluation& temperature, const Evaluation& pressure)
973  {
974  return
975  Region2::pi(pressure)*
976  Region2::dgamma_dpi(temperature, pressure) *
977  Rs * temperature / pressure;
978  }
979 }; // end class
980 
981 template <class Scalar>
982 const Scalar H2O<Scalar>::Rs = Common::Rs;
983 } // namespace Opm
984 
985 #endif
Abstract base class of a pure chemical species.
Definition: Component.hpp:42
static Evaluation ddgamma_ddtau(const Evaluation &temperature, const Evaluation &pressure)
The second partial derivative of the Gibbs free energy to the normalized temperature for IAPWS region...
Definition: Region1.hpp:293
static Evaluation ddgamma_dtaudpi(const Evaluation &temperature, const Evaluation &pressure)
The partial derivative of the Gibbs free energy to the normalized pressure and to the normalized temp...
Definition: Region1.hpp:228
static Evaluation gasHeatCapacityConstVolume(const Evaluation &temperature, const Evaluation &pressure)
Specific isochoric heat capacity of steam and water vapor .
Definition: H2O.hpp:509
static Evaluation liquidInternalEnergy(const Evaluation &temperature, const Evaluation &pressure)
Specific internal energy of liquid water .
Definition: H2O.hpp:342
Material properties of pure water .
Definition: H2O.hpp:60
bool CheckDefined(const T &value OPM_UNUSED)
Make valgrind complain if any of the memory occupied by an object is undefined.
Definition: Valgrind.hpp:74
static Evaluation ddgamma_dtaudpi(const Evaluation &temperature, const Evaluation &pressure)
The partial derivative of the Gibbs free energy to the normalized pressure and to the normalized temp...
Definition: Region2.hpp:247
Implements the equations for region 2 of the IAPWS '97 formulation.
Definition: MathToolbox.hpp:39
static Evaluation vaporPressure(Evaluation temperature)
The vapor pressure in of pure water at a given temperature.
Definition: H2O.hpp:131
Definition: Air_Mesitylene.hpp:31
static bool gasIsCompressible()
Returns true iff the gas phase is assumed to be compressible.
Definition: H2O.hpp:534
static Evaluation ddgamma_ddpi(const Evaluation &temperature, const Evaluation &pressure)
The second partial derivative of the Gibbs free energy to the normalized pressure for IAPWS region 2 ...
Definition: Region2.hpp:283
Scalar Scalar
Definition: Component.hpp:45
static Evaluation dgamma_dpi(const Evaluation &temperature, const Evaluation &pressure)
The partial derivative of the Gibbs free energy to the normalized pressure for IAPWS region 1 (i...
Definition: Region1.hpp:196
static Evaluation thermalConductivityIAPWS(const Evaluation &T, const Evaluation &rho)
Thermal conductivity water (IAPWS) .
Definition: Common.hpp:161
Some templates to wrap the valgrind client request macros.
static Evaluation tau(const Evaluation &temperature)
Returns the reduced temperature (dimensionless) for IAPWS region 2.
Definition: Region2.hpp:81
Implements the equations for region 4 of the IAPWS '97 formulation.
Definition: Region4.hpp:51
Implements relations which are common for all regions of the IAPWS '97 formulation.
Implements the equations for region 4 of the IAPWS '97 formulation.
static Evaluation liquidViscosity(const Evaluation &temperature, const Evaluation &pressure)
The dynamic viscosity of pure water.
Definition: H2O.hpp:815
static const Scalar triplePressure()
Returns the pressure at water's triple point.
Definition: H2O.hpp:115
static Evaluation gasDensity(const Evaluation &temperature, const Evaluation &pressure)
The density of steam in at a given pressure and temperature.
Definition: H2O.hpp:556
Implements the equations for region 1 of the IAPWS '97 formulation.
static const Scalar tripleTemperature()
Returns the temperature at water's triple point.
Definition: H2O.hpp:109
static Evaluation pressure(const Evaluation &temperature, const Evaluation &rhoMolar)
The pressure of the gas in , depending on the molar density and temperature.
Definition: IdealGas.hpp:56
static Evaluation gasThermalConductivity(const Evaluation &temperature, const Evaluation &pressure)
Thermal conductivity of water (IAPWS) .
Definition: H2O.hpp:862
Implements the equations for region 1 of the IAPWS '97 formulation.
Definition: Region1.hpp:49
static Evaluation liquidHeatCapacityConstVolume(const Evaluation &temperature, const Evaluation &pressure)
Specific isochoric heat capacity of liquid water .
Definition: H2O.hpp:474
static Evaluation dgamma_dtau(const Evaluation &temperature, const Evaluation &pressure)
The partial derivative of the Gibbs free energy to the normalized temperature for IAPWS region 1 (i...
Definition: Region1.hpp:165
static Scalar dpi_dp(Scalar)
Returns the derivative of the reduced pressure to the pressure for IAPWS region 1 in ...
Definition: Region1.hpp:114
static Evaluation gasPressure(const Evaluation &temperature, Scalar density)
The pressure of steam in at a given density and temperature.
Definition: H2O.hpp:639
static Evaluation gasInternalEnergy(const Evaluation &temperature, const Evaluation &pressure)
Specific internal energy of steam and water vapor .
Definition: H2O.hpp:400
static Evaluation liquidDensity(const Evaluation &temperature, const Evaluation &pressure)
The density of pure water in at a given pressure and temperature.
Definition: H2O.hpp:685
static const Scalar criticalMolarVolume
Critical molar volume of water .
Definition: Common.hpp:73
static bool gasIsIdeal()
Returns true iff the gas phase is assumed to be ideal.
Definition: H2O.hpp:623
static bool liquidIsCompressible()
Returns true iff the liquid phase is assumed to be compressible.
Definition: H2O.hpp:540
static Evaluation liquidPressure(const Evaluation &temperature, Scalar density)
The pressure of liquid water in at a given density and temperature.
Definition: H2O.hpp:748
Evaluation< Scalar, VarSetTag, numVars > abs(const Evaluation< Scalar, VarSetTag, numVars > &)
Definition: Math.hpp:41
static Scalar dpi_dp(const Evaluation &)
Returns the derivative of the reduced pressure to the pressure for IAPWS region 2 in ...
Definition: Region2.hpp:110
static Evaluation gasHeatCapacity(const Evaluation &temperature, const Evaluation &pressure)
Specific isobaric heat capacity of water steam .
Definition: H2O.hpp:273
static Evaluation vaporTemperature(const Evaluation &pressure)
The vapor temperature in of pure water at a given pressure.
Definition: H2O.hpp:153
static Evaluation tau(const Evaluation &temperature)
Returns the reduced temperature for IAPWS region 1.
Definition: Region1.hpp:86
static bool isValid(const Evaluation &temperature, const Evaluation &pressure)
Returns true if IAPWS region 2 applies for a (temperature, pressure) pair.
Definition: Region2.hpp:61
static const Scalar tripleTemperature
Triple temperature of water .
Definition: Common.hpp:79
static Evaluation liquidHeatCapacity(const Evaluation &temperature, const Evaluation &pressure)
Specific isobaric heat capacity of liquid water .
Definition: H2O.hpp:308
static Evaluation saturationPressure(const Evaluation &temperature)
Returns the saturation pressure in of pure water at a given temperature.
Definition: Region4.hpp:63
static const Scalar acentricFactor()
The acentric factor of water.
Definition: H2O.hpp:85
Relations valid for an ideal gas.
static Evaluation liquidEnthalpy(const Evaluation &temperature, const Evaluation &pressure)
Specific enthalpy of liquid water .
Definition: H2O.hpp:229
static Evaluation vaporTemperature(const Evaluation &pressure)
Returns the saturation temperature in of pure water at a given pressure.
Definition: Region4.hpp:96
static Evaluation pi(const Evaluation &pressure)
Returns the reduced pressure for IAPWS region 1.
Definition: Region1.hpp:105
static Evaluation dgamma_dpi(const Evaluation &temperature, const Evaluation &pressure)
The partial derivative of the Gibbs free energy to the normalized pressure for IAPWS region 2 (i...
Definition: Region2.hpp:212
static const Scalar criticalPressure()
Returns the critical pressure of water.
Definition: H2O.hpp:97
static Evaluation ddgamma_ddpi(const Evaluation &temperature, const Evaluation &pressure)
The second partial derivative of the Gibbs free energy to the normalized pressure for IAPWS region 1 ...
Definition: Region1.hpp:261
static const Scalar criticalTemperature()
Returns the critical temperature of water.
Definition: H2O.hpp:91
static Evaluation gasViscosity(const Evaluation &temperature, const Evaluation &pressure)
The dynamic viscosity of steam.
Definition: H2O.hpp:790
Implements relations which are common for all regions of the IAPWS '97 formulation.
Definition: Common.hpp:54
static Evaluation dgamma_dtau(const Evaluation &temperature, const Evaluation &pressure)
The partial derivative of the Gibbs free energy to the normalized temperature for IAPWS region 2 (i...
Definition: Region2.hpp:171
static const char * name()
A human readable name for the water.
Definition: H2O.hpp:73
Abstract base class of a pure chemical species.
Evaluation< Scalar, VarSetTag, numVars > pow(const Evaluation< Scalar, VarSetTag, numVars > &base, Scalar exp)
Definition: Math.hpp:312
static bool isValid(const Evaluation &temperature, const Evaluation &pressure)
Returns true if IAPWS region 1 applies for a (temperature in , pressure in ) pair.
Definition: Region1.hpp:60
static const Scalar molarMass
The molar mass of water .
Definition: Common.hpp:58
static Evaluation pi(const Evaluation &pressure)
Returns the reduced pressure (dimensionless) for IAPWS region 2.
Definition: Region2.hpp:100
static const Scalar criticalPressure
Critical pressure of water .
Definition: Common.hpp:67
static Evaluation gasEnthalpy(const Evaluation &temperature, const Evaluation &pressure)
Specific enthalpy of water steam .
Definition: H2O.hpp:176
static Evaluation density(const Evaluation &avgMolarMass, const Evaluation &temperature, const Evaluation &pressure)
The density of the gas in , depending on pressure, temperature and average molar mass of the gas...
Definition: IdealGas.hpp:46
static const Scalar criticalTemperature
Critical temperature of water .
Definition: Common.hpp:64
static Evaluation liquidThermalConductivity(const Evaluation &temperature, const Evaluation &pressure)
Thermal conductivity of water (IAPWS) .
Definition: H2O.hpp:842
static const Scalar triplePressure
Triple pressure of water .
Definition: Common.hpp:82
Implements the equations for region 2 of the IAPWS '97 formulation.
Definition: Region2.hpp:50
static Evaluation viscosity(const Evaluation &temperature, const Evaluation &rho)
The dynamic viscosity of pure water.
Definition: Common.hpp:99
static const Scalar criticalMolarVolume()
Returns the molar volume of water at the critical point.
Definition: H2O.hpp:103
static const Scalar acentricFactor
The acentric factor of water .
Definition: Common.hpp:76
static Evaluation ddgamma_ddtau(const Evaluation &temperature, const Evaluation &pressure)
The second partial derivative of the Gibbs free energy to the normalized temperature for IAPWS region...
Definition: Region2.hpp:319
static const Scalar molarMass()
The molar mass in of water.
Definition: H2O.hpp:79