3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
pengrobinsonparamsmixture.hh
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program 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 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
35#ifndef DUMUX_PENG_ROBINSON_PARAMS_MIXTURE_HH
36#define DUMUX_PENG_ROBINSON_PARAMS_MIXTURE_HH
37
38#include <algorithm>
40
41#include "pengrobinsonparams.hh"
42
43namespace Dumux {
44
60template <class Scalar, class FluidSystem, int phaseIdx, bool useSpe5Relations=false>
62 : public PengRobinsonParams<Scalar>
63{
64 enum { numComponents = FluidSystem::numComponents };
65
66 // Peng-Robinson parameters for pure substances
68
69public:
75 template <class FluidState>
76 void updatePure(const FluidState &fluidState)
77 {
78 updatePure(fluidState.temperature(phaseIdx),
79 fluidState.pressure(phaseIdx));
80 }
81
88 void updatePure(Scalar temperature, Scalar pressure)
89 {
92
93 // Calculate the Peng-Robinson parameters of the pure
94 // components
95 //
96 // See: R. Reid, et al.: The Properties of Gases and Liquids,
97 // 4th edition, McGraw-Hill, 1987, p. 43
98 for (int i = 0; i < numComponents; ++i) {
99 Scalar pc = FluidSystem::criticalPressure(i);
100 Scalar omega = FluidSystem::acentricFactor(i);
101 Scalar Tr = temperature/FluidSystem::criticalTemperature(i);
102 Scalar RTc = Constants<Scalar>::R*FluidSystem::criticalTemperature(i);
103
104 Scalar f_omega;
105
106 if (useSpe5Relations) {
107 if (omega < 0.49) f_omega = 0.37464 + omega*(1.54226 + omega*(-0.26992));
108 else f_omega = 0.379642 + omega*(1.48503 + omega*(-0.164423 + omega*0.016666));
109 }
110 else
111 f_omega = 0.37464 + omega*(1.54226 - omega*0.26992);
112
113 Valgrind::CheckDefined(f_omega);
114
115 using std::sqrt;
116 Scalar tmp = 1 + f_omega*(1 - sqrt(Tr));
117 tmp = tmp*tmp;
118
119 Scalar a = 0.4572355*RTc*RTc/pc * tmp;
120 Scalar b = 0.0777961 * RTc / pc;
121 using std::isfinite;
122 assert(isfinite(a));
123 assert(isfinite(b));
124
125 this->pureParams_[i].setA(a);
126 this->pureParams_[i].setB(b);
129 }
130
131 updateACache_();
132 }
133
142 template <class FluidState>
143 void updateMix(const FluidState &fs)
144 {
145 Scalar sumx = 0.0;
146 for (int compIdx = 0; compIdx < numComponents; ++compIdx)
147 sumx += fs.moleFraction(phaseIdx, compIdx);
148 using std::max;
149 sumx = max(1e-10, sumx);
150
151 // Calculate the Peng-Robinson parameters of the mixture
152 //
153 // See: R. Reid, et al.: The Properties of Gases and Liquids,
154 // 4th edition, McGraw-Hill, 1987, p. 82
155 Scalar a = 0;
156 Scalar b = 0;
157 for (int compIIdx = 0; compIIdx < numComponents; ++compIIdx) {
158 Scalar xi = fs.moleFraction(phaseIdx, compIIdx) / sumx;
160 using::std::isfinite;
161 for (int compJIdx = 0; compJIdx < numComponents; ++compJIdx) {
162 Scalar xj = fs.moleFraction(phaseIdx, compJIdx) / sumx;
164
165 // mixing rule from Reid, page 82
166 a += xi * xj * aCache_[compIIdx][compJIdx];
167
168 assert(isfinite(a));
169 }
170
171 // mixing rule from Reid, page 82
172 b += xi * this->pureParams_[compIIdx].b();
173 assert(isfinite(b));
174 }
175
176 this->setA(a);
177 this->setB(b);
178 Valgrind::CheckDefined(this->a());
179 Valgrind::CheckDefined(this->b());
180
181 }
182
193 template <class FluidState>
194 void updateSingleMoleFraction(const FluidState &fs,
195 int compIdx)
196 {
197 updateMix(fs);
198 }
199
204 const PureParams &pureParams(int compIdx) const
205 { return pureParams_[compIdx]; }
206
211 const PureParams &operator[](int compIdx) const
212 {
213 assert(0 <= compIdx && compIdx < numComponents);
214 return pureParams_[compIdx];
215 }
216
221 void checkDefined() const
222 {
223#ifndef NDEBUG
224 for (int i = 0; i < numComponents; ++i)
226
227 Valgrind::CheckDefined(this->a());
228 Valgrind::CheckDefined(this->b());
229#endif
230 };
231
232protected:
233 PureParams pureParams_[numComponents];
234
235private:
236 void updateACache_()
237 {
238 for (int compIIdx = 0; compIIdx < numComponents; ++ compIIdx) {
239 for (int compJIdx = 0; compJIdx < numComponents; ++ compJIdx) {
240 // interaction coefficient as given in SPE5
241 Scalar Psi = FluidSystem::interactionCoefficient(compIIdx, compJIdx);
242 using std::sqrt;
243 aCache_[compIIdx][compJIdx] =
244 sqrt(this->pureParams_[compIIdx].a()
245 * this->pureParams_[compJIdx].a())
246 * (1 - Psi);
247 }
248 }
249 }
250
251 Scalar aCache_[numComponents][numComponents];
252};
253
254} // end namespace
255
256#endif
Base class for Peng-Robinson parameters of a single-component fluid or a mixture.
A central place for various physical constants occuring in some equations.
bool CheckDefined(const T &value)
Make valgrind complain if the object occupied by an object is undefined.
Definition: valgrind.hh:72
Definition: adapt.hh:29
std::string temperature() noexcept
I/O name of temperature for equilibrium models.
Definition: name.hh:51
std::string pressure(int phaseIdx) noexcept
I/O name of pressure for multiphase systems.
Definition: name.hh:34
A central place for various physical constants occuring in some equations.
Definition: constants.hh:39
Stores and provides access to the Peng-Robinson parameters.
Definition: pengrobinsonparams.hh:46
void setA(Scalar value)
Set the attractive parameter 'a' of the Peng-Robinson fluid.
Definition: pengrobinsonparams.hh:80
Scalar a() const
Returns the attractive parameter 'a' of the Peng-Robinson fluid.
Definition: pengrobinsonparams.hh:52
void setB(Scalar value)
Set the repulsive parameter 'b' of the Peng-Robinson fluid.
Definition: pengrobinsonparams.hh:88
Scalar b() const
Returns the repulsive parameter 'b' of the Peng-Robinson fluid.
Definition: pengrobinsonparams.hh:60
The mixing rule for the oil and the gas phases of the SPE5 problem.
Definition: pengrobinsonparamsmixture.hh:63
const PureParams & operator[](int compIdx) const
Returns the Peng-Robinson parameters for a pure component.
Definition: pengrobinsonparamsmixture.hh:211
void updateMix(const FluidState &fs)
Calculates the "a" and "b" Peng-Robinson parameters for the mixture.
Definition: pengrobinsonparamsmixture.hh:143
PureParams pureParams_[numComponents]
Definition: pengrobinsonparamsmixture.hh:230
const PureParams & pureParams(int compIdx) const
Return the Peng-Robinson parameters of a pure substance,.
Definition: pengrobinsonparamsmixture.hh:204
void updateSingleMoleFraction(const FluidState &fs, int compIdx)
Calculates the "a" and "b" Peng-Robinson parameters for the mixture provided that only a single mole ...
Definition: pengrobinsonparamsmixture.hh:194
void updatePure(Scalar temperature, Scalar pressure)
Peng-Robinson parameters for the pure components.
Definition: pengrobinsonparamsmixture.hh:88
void checkDefined() const
If run under valgrind, this method produces an warning if the parameters where not determined correct...
Definition: pengrobinsonparamsmixture.hh:221
void updatePure(const FluidState &fluidState)
Update Peng-Robinson parameters for the pure components.
Definition: pengrobinsonparamsmixture.hh:76