3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
spe5parametercache.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 *****************************************************************************/
24#ifndef SPE5_PARAMETER_CACHE_HH
25#define SPE5_PARAMETER_CACHE_HH
26
27#include <cassert>
28
31
34
35namespace Dumux {
36
42template <class Scalar, class FluidSystem>
44 : public ParameterCacheBase<Spe5ParameterCache<Scalar, FluidSystem> >
45{
48
50
51 enum { numPhases = FluidSystem::numPhases };
52
53 enum { wPhaseIdx = FluidSystem::wPhaseIdx };
54 enum { oPhaseIdx = FluidSystem::oPhaseIdx };
55 enum { gPhaseIdx = FluidSystem::gPhaseIdx };
56
57public:
58 // types of the parameter objects for each phase
59 using OilPhaseParams = PengRobinsonParamsMixture<Scalar, FluidSystem, oPhaseIdx, /*useSpe5=*/true>;
60 using GasPhaseParams = PengRobinsonParamsMixture<Scalar, FluidSystem, gPhaseIdx, /*useSpe5=*/true>;
61
66 {
67 for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
68 VmUpToDate_[phaseIdx] = false;
69 }
70
78 template <class FluidState>
79 void updatePhase(const FluidState &fs,
80 int phaseIdx,
81 int except = ParentType::None)
82 {
83 updateEosParams(fs, phaseIdx, except);
84
85 // if we don't need to recalculate the molar volume, we exit
86 // here
87 if (VmUpToDate_[phaseIdx])
88 return;
89
90 // update the phase's molar volume
91 updateMolarVolume_(fs, phaseIdx);
92 }
93
107 template <class FluidState>
108 void updateSingleMoleFraction(const FluidState &fs,
109 int phaseIdx,
110 int compIdx)
111 {
112 if (phaseIdx == oPhaseIdx)
114 else if (phaseIdx == gPhaseIdx)
116
117 // update the phase's molar volume
118 updateMolarVolume_(fs, phaseIdx);
119 }
120
125 Scalar a(int phaseIdx) const
126 {
127 switch (phaseIdx)
128 {
129 case oPhaseIdx: return oilPhaseParams_.a();
130 case gPhaseIdx: return gasPhaseParams_.a();
131 default:
132 DUNE_THROW(Dune::InvalidStateException,
133 "The a() parameter is only defined for "
134 "oil and gas phases");
135 }
136 }
137
142 Scalar b(int phaseIdx) const
143 {
144 switch (phaseIdx)
145 {
146 case oPhaseIdx: return oilPhaseParams_.b();
147 case gPhaseIdx: return gasPhaseParams_.b();
148 default:
149 DUNE_THROW(Dune::InvalidStateException,
150 "The b() parameter is only defined for "
151 "oil and gas phases");
152 }
153 }
154
162 Scalar aPure(int phaseIdx, int compIdx) const
163 {
164 switch (phaseIdx)
165 {
166 case oPhaseIdx: return oilPhaseParams_.pureParams(compIdx).a();
167 case gPhaseIdx: return gasPhaseParams_.pureParams(compIdx).a();
168 default:
169 DUNE_THROW(Dune::InvalidStateException,
170 "The a() parameter is only defined for "
171 "oil and gas phases");
172 }
173 }
174
181 Scalar bPure(int phaseIdx, int compIdx) const
182 {
183 switch (phaseIdx)
184 {
185 case oPhaseIdx: return oilPhaseParams_.pureParams(compIdx).b();
186 case gPhaseIdx: return gasPhaseParams_.pureParams(compIdx).b();
187 default:
188 DUNE_THROW(Dune::InvalidStateException,
189 "The b() parameter is only defined for "
190 "oil and gas phases");
191 }
192 }
193
198 Scalar molarVolume(int phaseIdx) const
199 {
200 assert(VmUpToDate_[phaseIdx]);
201 return Vm_[phaseIdx];
202 }
203
204
210 { return oilPhaseParams_; }
211
217 { return gasPhaseParams_; }
218
223 template <class FluidState>
224 void updateEosParams(const FluidState &fs,
225 int phaseIdx,
226 int exceptQuantities = ParentType::None)
227 {
228 if (!(exceptQuantities & ParentType::Temperature))
229 {
230 updatePure_(fs, phaseIdx);
231 updateMix_(fs, phaseIdx);
232 VmUpToDate_[phaseIdx] = false;
233 }
234 else if (!(exceptQuantities & ParentType::Composition))
235 {
236 updateMix_(fs, phaseIdx);
237 VmUpToDate_[phaseIdx] = false;
238 }
239 else if (!(exceptQuantities & ParentType::Pressure)) {
240 VmUpToDate_[phaseIdx] = false;
241 }
242 }
243
244protected:
251 template <class FluidState>
252 void updatePure_(const FluidState &fs, int phaseIdx)
253 {
254 Scalar T = fs.temperature(phaseIdx);
255 Scalar p = fs.pressure(phaseIdx);
256
257 switch (phaseIdx)
258 {
259 case oPhaseIdx: oilPhaseParams_.updatePure(T, p); break;
260 case gPhaseIdx: gasPhaseParams_.updatePure(T, p); break;
261 }
262 }
263
271 template <class FluidState>
272 void updateMix_(const FluidState &fs, int phaseIdx)
273 {
274 switch (phaseIdx)
275 {
276 case oPhaseIdx:
278 break;
279 case gPhaseIdx:
281 break;
282 case wPhaseIdx:
283 break;
284 }
285 }
286
287 template <class FluidState>
288 void updateMolarVolume_(const FluidState &fs,
289 int phaseIdx)
290 {
291 VmUpToDate_[phaseIdx] = true;
292
293 // calculate molar volume of the phase (we will need this for the
294 // fugacity coefficients and the density anyway)
295 switch (phaseIdx) {
296 case gPhaseIdx: {
297 // calculate molar volumes for the given composition. although
298 // this isn't a Peng-Robinson parameter strictly speaking, the
299 // molar volume appears in basically every quantity the fluid
300 // system can get queried, so it is okay to calculate it
301 // here...
302 Vm_[gPhaseIdx] =
304 *this,
305 phaseIdx,
306 /*isGasPhase=*/true);
307 break;
308 }
309 case oPhaseIdx: {
310 // calculate molar volumes for the given composition. although
311 // this isn't a Peng-Robinson parameter strictly speaking, the
312 // molar volume appears in basically every quantity the fluid
313 // system can get queried, so it is okay to calculate it
314 // here...
315 Vm_[oPhaseIdx] =
317 *this,
318 phaseIdx,
319 /*isGasPhase=*/false);
320 break;
321 }
322 case wPhaseIdx: {
323 // Density of water in the stock tank (i.e. atmospheric
324 // pressure) is specified as 62.4 lb/ft^3 by the SPE-5
325 // paper. Also 1 lb = 0.4535923 and 1 ft = 0.3048 m.
326 const Scalar stockTankWaterDensity = 62.4 * 0.45359237 / 0.028316847;
327 // Water compressibility is specified as 3.3e-6 per psi
328 // overpressure, where 1 psi = 6894.7573 Pa
329 Scalar overPressure = fs.pressure(wPhaseIdx) - 1.013e5; // [Pa]
330 Scalar waterDensity =
331 stockTankWaterDensity * (1 + 3.3e-6*overPressure/6894.7573);
332
333 // convert water density [kg/m^3] to molar volume [m^3/mol]
334 Vm_[wPhaseIdx] = fs.averageMolarMass(wPhaseIdx)/waterDensity;
335 break;
336 }
337 default:
338 DUNE_THROW(Dune::InvalidStateException, "invalid phaseIdx " << phaseIdx);
339 }
340 }
341
342 bool VmUpToDate_[numPhases];
343 Scalar Vm_[numPhases];
344
347};
348
349} // end namespace Dumux
350
351#endif
Material properties of pure water .
The mixing rule for the oil and the gas phases of the SPE5 problem.
Implements the Peng-Robinson equation of state for liquids and gases.
The base class of the parameter cache classes for fluid systems.
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
Implements the Peng-Robinson equation of state for liquids and gases.
Definition: pengrobinson.hh:60
static Scalar computeMolarVolume(const FluidState &fs, Params &params, int phaseIdx, bool isGasPhase, bool handleUnphysicalPhase=true)
Computes molar volumes where the Peng-Robinson EOS is true.
Definition: pengrobinson.hh:156
Scalar a() const
Returns the attractive parameter 'a' of the Peng-Robinson fluid.
Definition: pengrobinsonparams.hh:50
Scalar b() const
Returns the repulsive parameter 'b' of the Peng-Robinson fluid.
Definition: pengrobinsonparams.hh:58
void updateMix(const FluidState &fs)
Calculates the "a" and "b" Peng-Robinson parameters for the mixture.
Definition: pengrobinsonparamsmixture.hh:136
const PureParams & pureParams(int compIdx) const
Return the Peng-Robinson parameters of a pure substance,.
Definition: pengrobinsonparamsmixture.hh:192
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:182
void updatePure(const FluidState &fluidState)
Update Peng-Robinson parameters for the pure components.
Definition: pengrobinsonparamsmixture.hh:76
The base class of the parameter cache classes for fluid systems.
Definition: parametercachebase.hh:35
@ Composition
Definition: parametercachebase.hh:41
@ Pressure
Definition: parametercachebase.hh:40
@ Temperature
Definition: parametercachebase.hh:39
@ None
Definition: parametercachebase.hh:38
Specifies the parameters required by the SPE5 problem which are despondent on the thermodynamic state...
Definition: spe5parametercache.hh:45
bool VmUpToDate_[numPhases]
Definition: spe5parametercache.hh:342
Scalar b(int phaseIdx) const
The Peng-Robinson co-volume for a phase.
Definition: spe5parametercache.hh:142
const GasPhaseParams & gasPhaseParams() const
Returns the Peng-Robinson mixture parameters for the gas phase.
Definition: spe5parametercache.hh:216
Scalar aPure(int phaseIdx, int compIdx) const
The Peng-Robinson attractive parameter for a pure component given the same temperature and pressure o...
Definition: spe5parametercache.hh:162
void updateMolarVolume_(const FluidState &fs, int phaseIdx)
Definition: spe5parametercache.hh:288
void updatePhase(const FluidState &fs, int phaseIdx, int except=ParentType::None)
Update all parameters required by the fluid system to calculate some quantities for the phase.
Definition: spe5parametercache.hh:79
Scalar Vm_[numPhases]
Definition: spe5parametercache.hh:343
Scalar a(int phaseIdx) const
The Peng-Robinson attractive parameter for a phase.
Definition: spe5parametercache.hh:125
void updateEosParams(const FluidState &fs, int phaseIdx, int exceptQuantities=ParentType::None)
Update all parameters required by the equation of state to calculate some quantities for the phase.
Definition: spe5parametercache.hh:224
void updatePure_(const FluidState &fs, int phaseIdx)
Update all parameters of a phase which only depend on temperature and/or pressure.
Definition: spe5parametercache.hh:252
const OilPhaseParams & oilPhaseParams() const
Returns the Peng-Robinson mixture parameters for the oil phase.
Definition: spe5parametercache.hh:209
Spe5ParameterCache()
The constructor.
Definition: spe5parametercache.hh:65
GasPhaseParams gasPhaseParams_
Definition: spe5parametercache.hh:346
OilPhaseParams oilPhaseParams_
Definition: spe5parametercache.hh:345
void updateMix_(const FluidState &fs, int phaseIdx)
Update all parameters of a phase which depend on the fluid composition. It is assumed that updatePure...
Definition: spe5parametercache.hh:272
void updateSingleMoleFraction(const FluidState &fs, int phaseIdx, int compIdx)
Update all cached parameters of a specific fluid phase which depend on the mole fraction of a single ...
Definition: spe5parametercache.hh:108
Scalar molarVolume(int phaseIdx) const
Returns the molar volume of a phase .
Definition: spe5parametercache.hh:198
Scalar bPure(int phaseIdx, int compIdx) const
The Peng-Robinson co-volume for a pure component given the same temperature and pressure of the phase...
Definition: spe5parametercache.hh:181