PengRobinsonParamsMixture.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) 2011-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 */
25 #ifndef OPM_PENG_ROBINSON_PARAMS_MIXTURE_HPP
26 #define OPM_PENG_ROBINSON_PARAMS_MIXTURE_HPP
27 
28 #include <algorithm>
30 
31 #include "PengRobinsonParams.hpp"
32 
33 namespace Opm
34 {
35 
53 template <class Scalar, class FluidSystem, unsigned phaseIdx, bool useSpe5Relations=false>
55  : public PengRobinsonParams<Scalar>
56 {
57  enum { numComponents = FluidSystem::numComponents };
58 
59  // Peng-Robinson parameters for pure substances
61 
62  // the ideal gas constant
63  static const Scalar R;
64 
65 public:
69  template <class FluidState>
70  void updatePure(const FluidState &fluidState)
71  {
72  updatePure(fluidState.temperature(phaseIdx),
73  fluidState.pressure(phaseIdx));
74  }
75 
81  void updatePure(Scalar temperature, Scalar pressure)
82  {
83  Valgrind::CheckDefined(temperature);
84  Valgrind::CheckDefined(pressure);
85 
86  // Calculate the Peng-Robinson parameters of the pure
87  // components
88  //
89  // See: R. Reid, et al.: The Properties of Gases and Liquids,
90  // 4th edition, McGraw-Hill, 1987, p. 43
91  for (unsigned i = 0; i < numComponents; ++i) {
92  Scalar pc = FluidSystem::criticalPressure(i);
93  Scalar omega = FluidSystem::acentricFactor(i);
94  Scalar Tr = temperature/FluidSystem::criticalTemperature(i);
95  Scalar RTc = R*FluidSystem::criticalTemperature(i);
96 
97  Scalar f_omega;
98 
99  if (useSpe5Relations) {
100  if (omega < 0.49) f_omega = 0.37464 + omega*(1.54226 + omega*(-0.26992));
101  else f_omega = 0.379642 + omega*(1.48503 + omega*(-0.164423 + omega*0.016666));
102  }
103  else
104  f_omega = 0.37464 + omega*(1.54226 - omega*0.26992);
105 
106  Valgrind::CheckDefined(f_omega);
107 
108  Scalar tmp = 1 + f_omega*(1 - std::sqrt(Tr));
109  tmp = tmp*tmp;
110 
111  Scalar a = 0.4572355*RTc*RTc/pc * tmp;
112  Scalar b = 0.0777961 * RTc / pc;
113  assert(std::isfinite(a));
114  assert(std::isfinite(b));
115 
116  this->pureParams_[i].setA(a);
117  this->pureParams_[i].setB(b);
120  }
121 
122  updateACache_();
123  }
124 
132  template <class FluidState>
133  void updateMix(const FluidState &fs)
134  {
135  Scalar sumx = 0.0;
136  for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx)
137  sumx += fs.moleFraction(phaseIdx, compIdx);
138  sumx = std::max(1e-10, sumx);
139 
140  // Calculate the Peng-Robinson parameters of the mixture
141  //
142  // See: R. Reid, et al.: The Properties of Gases and Liquids,
143  // 4th edition, McGraw-Hill, 1987, p. 82
144  Scalar a = 0;
145  Scalar b = 0;
146  for (unsigned compIIdx = 0; compIIdx < numComponents; ++compIIdx) {
147  Scalar xi = std::max(0.0, std::min(1.0, fs.moleFraction(phaseIdx, compIIdx)));
149 
150  for (unsigned compJIdx = 0; compJIdx < numComponents; ++compJIdx) {
151  Scalar xj = std::max(0.0, std::min(1.0, fs.moleFraction(phaseIdx, compJIdx)));
153 
154  // mixing rule from Reid, page 82
155  a += xi * xj * aCache_[compIIdx][compJIdx];
156 
157  assert(std::isfinite(a));
158  }
159 
160  // mixing rule from Reid, page 82
161  b += std::max(0.0, xi) * this->pureParams_[compIIdx].b();
162  assert(std::isfinite(b));
163  }
164 
165  // assert(b > 0);
166  this->setA(a);
167  this->setB(b);
168 
169  Valgrind::CheckDefined(this->a());
170  Valgrind::CheckDefined(this->b());
171 
172  }
173 
182  template <class FluidState>
183  void updateSingleMoleFraction(const FluidState &fs,
184  unsigned /*compIdx*/)
185  {
186  updateMix(fs);
187  }
188 
192  const PureParams &pureParams(unsigned compIdx) const
193  { return pureParams_[compIdx]; }
194 
198  const PureParams &operator[](unsigned compIdx) const
199  {
200  assert(0 <= compIdx && compIdx < numComponents);
201  return pureParams_[compIdx];
202  }
203 
208  void checkDefined() const
209  {
210 #ifndef NDEBUG
211  for (unsigned i = 0; i < numComponents; ++i)
213 
214  Valgrind::CheckDefined(this->a());
215  Valgrind::CheckDefined(this->b());
216 #endif
217  }
218 
219 protected:
220  PureParams pureParams_[numComponents];
221 
222 private:
223  void updateACache_()
224  {
225  for (unsigned compIIdx = 0; compIIdx < numComponents; ++ compIIdx) {
226  for (unsigned compJIdx = 0; compJIdx < numComponents; ++ compJIdx) {
227  // interaction coefficient as given in SPE5
228  Scalar Psi = FluidSystem::interactionCoefficient(compIIdx, compJIdx);
229 
230  aCache_[compIIdx][compJIdx] =
231  std::sqrt(this->pureParams_[compIIdx].a()
232  * this->pureParams_[compJIdx].a())
233  * (1 - Psi);
234  }
235  }
236  }
237 
238  Scalar aCache_[numComponents][numComponents];
239 };
240 
241 template <class Scalar, class FluidSystem, unsigned phaseIdx, bool useSpe5Relations>
242 const Scalar PengRobinsonParamsMixture<Scalar, FluidSystem, phaseIdx, useSpe5Relations>::R = Opm::Constants<Scalar>::R;
243 
244 } // namespace Opm
245 
246 #endif
void checkDefined() const
If run under valgrind, this method produces an warning if the parameters where not determined correct...
Definition: PengRobinsonParamsMixture.hpp:208
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
Definition: Air_Mesitylene.hpp:31
void updatePure(const FluidState &fluidState)
Update Peng-Robinson parameters for the pure components.
Definition: PengRobinsonParamsMixture.hpp:70
The mixing rule for the oil and the gas phases of the SPE5 problem.
Definition: PengRobinsonParamsMixture.hpp:54
Stores and provides access to the Peng-Robinson parameters.
Definition: PengRobinsonParams.hpp:42
Stores and provides access to the Peng-Robinson parameters.
Evaluation< Scalar, VarSetTag, numVars > max(const Evaluation< Scalar, VarSetTag, numVars > &x1, const Evaluation< Scalar, VarSetTag, numVars > &x2)
Definition: Math.hpp:114
Evaluation< Scalar, VarSetTag, numVars > sqrt(const Evaluation< Scalar, VarSetTag, numVars > &x)
Definition: Math.hpp:278
const PureParams & pureParams(unsigned compIdx) const
Return the Peng-Robinson parameters of a pure substance,.
Definition: PengRobinsonParamsMixture.hpp:192
const PureParams & operator[](unsigned compIdx) const
Returns the Peng-Robinson parameters for a pure component.
Definition: PengRobinsonParamsMixture.hpp:198
A central place for various physical constants occuring in some equations.
Scalar a() const
Returns the attractive parameter 'a' of the Peng-Robinson fluid.
Definition: PengRobinsonParams.hpp:49
PureParams pureParams_[numComponents]
Definition: PengRobinsonParamsMixture.hpp:220
void updateMix(const FluidState &fs)
Calculates the "a" and "b" Peng-Robinson parameters for the mixture.
Definition: PengRobinsonParamsMixture.hpp:133
Evaluation< Scalar, VarSetTag, numVars > min(const Evaluation< Scalar, VarSetTag, numVars > &x1, const Evaluation< Scalar, VarSetTag, numVars > &x2)
Definition: Math.hpp:61
void updatePure(Scalar temperature, Scalar pressure)
Peng-Robinson parameters for the pure components.
Definition: PengRobinsonParamsMixture.hpp:81
void updateSingleMoleFraction(const FluidState &fs, unsigned)
Calculates the "a" and "b" Peng-Robinson parameters for the mixture provided that only a single mole ...
Definition: PengRobinsonParamsMixture.hpp:183
void setB(Scalar value)
Set the repulsive parameter 'b' of the Peng-Robinson fluid.
Definition: PengRobinsonParams.hpp:82
Scalar b() const
Returns the repulsive parameter 'b' of the Peng-Robinson fluid.
Definition: PengRobinsonParams.hpp:56
void setA(Scalar value)
Set the attractive parameter 'a' of the Peng-Robinson fluid.
Definition: PengRobinsonParams.hpp:75
A central place for various physical constants occuring in some equations.
Definition: Constants.hpp:39