version 3.10-dev
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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
23#ifndef DUMUX_PENG_ROBINSON_PARAMS_MIXTURE_HH
24#define DUMUX_PENG_ROBINSON_PARAMS_MIXTURE_HH
25
26#include <algorithm>
28
29#include "pengrobinsonparams.hh"
30
31namespace Dumux {
32
48template <class Scalar, class FluidSystem, int phaseIdx, bool useSpe5Relations=false>
50 : public PengRobinsonParams<Scalar>
51{
52 enum { numComponents = FluidSystem::numComponents };
53
54 // Peng-Robinson parameters for pure substances
56
57public:
63 template <class FluidState>
64 void updatePure(const FluidState &fluidState)
65 {
66 updatePure(fluidState.temperature(phaseIdx),
67 fluidState.pressure(phaseIdx));
68 }
69
76 void updatePure(Scalar temperature, Scalar pressure)
77 {
78 // Calculate the Peng-Robinson parameters of the pure
79 // components
80 //
81 // See: R. Reid, et al.: The Properties of Gases and Liquids,
82 // 4th edition, McGraw-Hill, 1987, p. 43
83 for (int i = 0; i < numComponents; ++i) {
84 Scalar pc = FluidSystem::criticalPressure(i);
85 Scalar omega = FluidSystem::acentricFactor(i);
86 Scalar Tr = temperature/FluidSystem::criticalTemperature(i);
87 Scalar RTc = Constants<Scalar>::R*FluidSystem::criticalTemperature(i);
88
89 Scalar f_omega;
90
91 if (useSpe5Relations) {
92 if (omega < 0.49) f_omega = 0.37464 + omega*(1.54226 + omega*(-0.26992));
93 else f_omega = 0.379642 + omega*(1.48503 + omega*(-0.164423 + omega*0.016666));
94 }
95 else
96 f_omega = 0.37464 + omega*(1.54226 - omega*0.26992);
97
98 using std::sqrt;
99 Scalar tmp = 1 + f_omega*(1 - sqrt(Tr));
100 tmp = tmp*tmp;
101
102 Scalar a = 0.4572355*RTc*RTc/pc * tmp;
103 Scalar b = 0.0777961 * RTc / pc;
104 using std::isfinite;
105 assert(isfinite(a));
106 assert(isfinite(b));
107
108 this->pureParams_[i].setA(a);
109 this->pureParams_[i].setB(b);
110 }
111
112 updateACache_();
113 }
114
123 template <class FluidState>
124 void updateMix(const FluidState &fs)
125 {
126 Scalar sumx = 0.0;
127 for (int compIdx = 0; compIdx < numComponents; ++compIdx)
128 sumx += fs.moleFraction(phaseIdx, compIdx);
129 using std::max;
130 sumx = max(1e-10, sumx);
131
132 // Calculate the Peng-Robinson parameters of the mixture
133 //
134 // See: R. Reid, et al.: The Properties of Gases and Liquids,
135 // 4th edition, McGraw-Hill, 1987, p. 82
136 Scalar a = 0;
137 Scalar b = 0;
138 for (int compIIdx = 0; compIIdx < numComponents; ++compIIdx) {
139 Scalar xi = fs.moleFraction(phaseIdx, compIIdx) / sumx;
140 using::std::isfinite;
141 for (int compJIdx = 0; compJIdx < numComponents; ++compJIdx) {
142 Scalar xj = fs.moleFraction(phaseIdx, compJIdx) / sumx;
143
144 // mixing rule from Reid, page 82
145 a += xi * xj * aCache_[compIIdx][compJIdx];
146
147 assert(isfinite(a));
148 }
149
150 // mixing rule from Reid, page 82
151 b += xi * this->pureParams_[compIIdx].b();
152 assert(isfinite(b));
153 }
154
155 this->setA(a);
156 this->setB(b);
157 }
158
169 template <class FluidState>
170 void updateSingleMoleFraction(const FluidState &fs,
171 int compIdx)
172 {
173 updateMix(fs);
174 }
175
180 const PureParams &pureParams(int compIdx) const
181 { return pureParams_[compIdx]; }
182
187 const PureParams &operator[](int compIdx) const
188 {
189 assert(0 <= compIdx && compIdx < numComponents);
190 return pureParams_[compIdx];
191 }
192
193protected:
194 PureParams pureParams_[numComponents];
195
196private:
197 void updateACache_()
198 {
199 for (int compIIdx = 0; compIIdx < numComponents; ++ compIIdx) {
200 for (int compJIdx = 0; compJIdx < numComponents; ++ compJIdx) {
201 // interaction coefficient as given in SPE5
202 Scalar Psi = FluidSystem::interactionCoefficient(compIIdx, compJIdx);
203 using std::sqrt;
204 aCache_[compIIdx][compJIdx] =
205 sqrt(this->pureParams_[compIIdx].a()
206 * this->pureParams_[compJIdx].a())
207 * (1 - Psi);
208 }
209 }
210 }
211
212 Scalar aCache_[numComponents][numComponents];
213};
214
215} // end namespace
216
217#endif
A central place for various physical constants occurring in some equations.
Definition: constants.hh:27
Stores and provides access to the Peng-Robinson parameters.
Definition: pengrobinsonparams.hh:32
void setA(Scalar value)
Set the attractive parameter 'a' of the Peng-Robinson fluid.
Definition: pengrobinsonparams.hh:54
Scalar a() const
Returns the attractive parameter 'a' of the Peng-Robinson fluid.
Definition: pengrobinsonparams.hh:38
void setB(Scalar value)
Set the repulsive parameter 'b' of the Peng-Robinson fluid.
Definition: pengrobinsonparams.hh:62
Scalar b() const
Returns the repulsive parameter 'b' of the Peng-Robinson fluid.
Definition: pengrobinsonparams.hh:46
The mixing rule for the oil and the gas phases of the SPE5 problem.
Definition: pengrobinsonparamsmixture.hh:51
const PureParams & operator[](int compIdx) const
Returns the Peng-Robinson parameters for a pure component.
Definition: pengrobinsonparamsmixture.hh:187
void updateMix(const FluidState &fs)
Calculates the "a" and "b" Peng-Robinson parameters for the mixture.
Definition: pengrobinsonparamsmixture.hh:124
PureParams pureParams_[numComponents]
Definition: pengrobinsonparamsmixture.hh:194
const PureParams & pureParams(int compIdx) const
Return the Peng-Robinson parameters of a pure substance,.
Definition: pengrobinsonparamsmixture.hh:180
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:170
void updatePure(Scalar temperature, Scalar pressure)
Peng-Robinson parameters for the pure components.
Definition: pengrobinsonparamsmixture.hh:76
void updatePure(const FluidState &fluidState)
Update Peng-Robinson parameters for the pure components.
Definition: pengrobinsonparamsmixture.hh:64
A central place for various physical constants occurring in some equations.
std::string temperature() noexcept
I/O name of temperature for equilibrium models.
Definition: name.hh:39
std::string pressure(int phaseIdx) noexcept
I/O name of pressure for multiphase systems.
Definition: name.hh:22
Definition: adapt.hh:17
Base class for Peng-Robinson parameters of a single-component fluid or a mixture.