My Project
Loading...
Searching...
No Matches
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 This file is part of the Open Porous Media project (OPM).
5
6 OPM 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 2 of the License, or
9 (at your option) any later version.
10
11 OPM 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 OPM. If not, see <http://www.gnu.org/licenses/>.
18
19 Consult the COPYING file in the top-level source directory of this
20 module for the precise wording of the license and the list of
21 copyright holders.
22*/
27#ifndef OPM_PENG_ROBINSON_PARAMS_MIXTURE_HPP
28#define OPM_PENG_ROBINSON_PARAMS_MIXTURE_HPP
29
31
34
35#include <algorithm>
36
37namespace Opm
38{
39
57template <class Scalar, class FluidSystem, unsigned phaseIdx, bool useSpe5Relations=false>
59 : public PengRobinsonParams<Scalar>
60{
61 enum { numComponents = FluidSystem::numComponents };
62
63 // Peng-Robinson parameters for pure substances
65
67
68public:
69
73 Scalar getaCache(unsigned compIIdx, unsigned compJIdx ) const
74 {
75 return aCache_[compIIdx][compJIdx];
76 }
77
81 template <class FluidState>
82 void updatePure(const FluidState& fluidState)
83 {
84 updatePure(fluidState.temperature(phaseIdx),
85 fluidState.pressure(phaseIdx));
86 }
87
93 void updatePure(Scalar temperature, Scalar pressure)
94 {
95 Valgrind::CheckDefined(temperature);
96 Valgrind::CheckDefined(pressure);
97
98 // Calculate the Peng-Robinson parameters of the pure
99 // components
100 //
101 // See: R. Reid, et al.: The Properties of Gases and Liquids,
102 // 4th edition, McGraw-Hill, 1987, p. 43
103 for (unsigned i = 0; i < numComponents; ++i) {
104 Scalar pc = FluidSystem::criticalPressure(i);
105 Scalar omega = FluidSystem::acentricFactor(i);
106 Scalar Tr = temperature/FluidSystem::criticalTemperature(i);
107 Scalar RTc = Constants<Scalar>::R*FluidSystem::criticalTemperature(i);
108
109 Scalar f_omega;
110
111 if (omega < 0.49)
112 f_omega = 0.37464 + omega*(1.54226 + omega*(-0.26992));
113 else
114 f_omega = 0.379642 + omega*(1.48503 + omega*(-0.164423 + omega*0.016666));
115
116 Valgrind::CheckDefined(f_omega);
117
118 Scalar tmp = 1 + f_omega*(1 - sqrt(Tr));
119 tmp = tmp*tmp;
120
121 Scalar newA = 0.4572355*RTc*RTc/pc * tmp;
122 Scalar newB = 0.0777961 * RTc / pc;
123 assert(std::isfinite(scalarValue(newA)));
124 assert(std::isfinite(scalarValue(newB)));
125
126 this->pureParams_[i].setA(newA);
127 this->pureParams_[i].setB(newB);
128 Valgrind::CheckDefined(this->pureParams_[i].a());
129 Valgrind::CheckDefined(this->pureParams_[i].b());
130 }
131
132 updateACache_();
133 }
134
142 template <class FluidState>
143 void updateMix(const FluidState& fs)
144 {
145 using FlashEval = typename FluidState::Scalar;
146
147 // Calculate the Peng-Robinson parameters of the mixture
148 //
149 // See: R. Reid, et al.: The Properties of Gases and Liquids,
150 // 4th edition, McGraw-Hill, 1987, p. 82
151 FlashEval newA = 0;
152 FlashEval newB = 0;
153 for (unsigned compIIdx = 0; compIIdx < numComponents; ++compIIdx) {
154 const FlashEval moleFracI = fs.moleFraction(phaseIdx, compIIdx);
155 FlashEval xi = max(0.0, min(1.0, moleFracI));
156 Valgrind::CheckDefined(xi);
157
158 for (unsigned compJIdx = 0; compJIdx < numComponents; ++compJIdx) {
159 const FlashEval moleFracJ = fs.moleFraction(phaseIdx, compJIdx );
160 FlashEval xj = max(0.0, min(1.0, moleFracJ));
161 Valgrind::CheckDefined(xj);
162
163 // mixing rule from Reid, page 82
164 newA += xi * xj * aCache_[compIIdx][compJIdx];
165
166 assert(std::isfinite(scalarValue(newA)));
167 }
168
169 // mixing rule from Reid, page 82
170 newB += max(0.0, xi) * this->pureParams_[compIIdx].b();
171 assert(std::isfinite(scalarValue(newB)));
172 }
173
174 // assert(newB > 0);
175 this->setA(decay<Scalar>(newA));
176 this->setB(decay<Scalar>(newB));
177
178 Valgrind::CheckDefined(this->a());
179 Valgrind::CheckDefined(this->b());
180
181 }
182
191 template <class FluidState>
192 void updateSingleMoleFraction(const FluidState& fs,
193 unsigned /*compIdx*/)
194 {
195 updateMix(fs);
196 }
197
201 const PureParams& pureParams(unsigned compIdx) const
202 { return pureParams_[compIdx]; }
203
207 const PureParams& operator[](unsigned compIdx) const
208 {
209 assert(compIdx < numComponents);
210 return pureParams_[compIdx];
211 }
212
217 void checkDefined() const
218 {
219#ifndef NDEBUG
220 for (unsigned i = 0; i < numComponents; ++i)
221 pureParams_[i].checkDefined();
222
223 Valgrind::CheckDefined(this->a());
224 Valgrind::CheckDefined(this->b());
225#endif
226 }
227
228protected:
229 PureParams pureParams_[numComponents]{};
230
231private:
232 void updateACache_()
233 {
234 for (unsigned compIIdx = 0; compIIdx < numComponents; ++ compIIdx) {
235 for (unsigned compJIdx = 0; compJIdx < numComponents; ++ compJIdx) {
236 // interaction coefficient as given in SPE5
237 Scalar Psi = FluidSystem::interactionCoefficient(compIIdx, compJIdx);
238
239 aCache_[compIIdx][compJIdx] =
240 sqrt(this->pureParams_[compIIdx].a()
241 * this->pureParams_[compJIdx].a())
242 * (1 - Psi);
243 }
244 }
245 }
246
247 Scalar aCache_[numComponents][numComponents]{};
248};
249
250
251} // namespace Opm
252
253#endif
A central place for various physical constants occuring in some equations.
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...
Stores and provides access to the Peng-Robinson parameters.
A central place for various physical constants occuring in some equations.
Definition Constants.hpp:41
The mixing rule for the oil and the gas phases of the SPE5 problem.
Definition PengRobinsonParamsMixture.hpp:60
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:192
void updatePure(Scalar temperature, Scalar pressure)
Peng-Robinson parameters for the pure components.
Definition PengRobinsonParamsMixture.hpp:93
void updatePure(const FluidState &fluidState)
Update Peng-Robinson parameters for the pure components.
Definition PengRobinsonParamsMixture.hpp:82
Scalar getaCache(unsigned compIIdx, unsigned compJIdx) const
TODO.
Definition PengRobinsonParamsMixture.hpp:73
void checkDefined() const
If run under valgrind, this method produces an warning if the parameters where not determined correct...
Definition PengRobinsonParamsMixture.hpp:217
void updateMix(const FluidState &fs)
Calculates the "a" and "b" Peng-Robinson parameters for the mixture.
Definition PengRobinsonParamsMixture.hpp:143
const PureParams & pureParams(unsigned compIdx) const
Return the Peng-Robinson parameters of a pure substance,.
Definition PengRobinsonParamsMixture.hpp:201
const PureParams & operator[](unsigned compIdx) const
Returns the Peng-Robinson parameters for a pure component.
Definition PengRobinsonParamsMixture.hpp:207
Stores and provides access to the Peng-Robinson parameters.
Definition PengRobinsonParams.hpp:44
Scalar a() const
Returns the attractive parameter 'a' of the Peng-Robinson fluid.
Definition PengRobinsonParams.hpp:50
void setB(Scalar value)
Set the repulsive parameter 'b' of the Peng-Robinson fluid.
Definition PengRobinsonParams.hpp:83
Scalar b() const
Returns the repulsive parameter 'b' of the Peng-Robinson fluid.
Definition PengRobinsonParams.hpp:57
void setA(Scalar value)
Set the attractive parameter 'a' of the Peng-Robinson fluid.
Definition PengRobinsonParams.hpp:76
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Definition MathToolbox.hpp:51