3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
Loading...
Searching...
No Matches
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{
47 using ParentType = ParameterCacheBase<ThisType>;
48
49 using PengRobinson = Dumux::PengRobinson<Scalar>;
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 Valgrind::SetUndefined(Vm_[phaseIdx]);
70 }
71 }
72
80 template <class FluidState>
81 void updatePhase(const FluidState &fs,
82 int phaseIdx,
83 int except = ParentType::None)
84 {
85 updateEosParams(fs, phaseIdx, except);
86
87 // if we don't need to recalculate the molar volume, we exit
88 // here
89 if (VmUpToDate_[phaseIdx])
90 return;
91
92 // update the phase's molar volume
93 updateMolarVolume_(fs, phaseIdx);
94 }
95
109 template <class FluidState>
110 void updateSingleMoleFraction(const FluidState &fs,
111 int phaseIdx,
112 int compIdx)
113 {
114 if (phaseIdx == oPhaseIdx)
115 oilPhaseParams_.updateSingleMoleFraction(fs, compIdx);
116 else if (phaseIdx == gPhaseIdx)
117 gasPhaseParams_.updateSingleMoleFraction(fs, compIdx);
118
119 // update the phase's molar volume
120 updateMolarVolume_(fs, phaseIdx);
121 }
122
127 Scalar a(int phaseIdx) const
128 {
129 switch (phaseIdx)
130 {
131 case oPhaseIdx: return oilPhaseParams_.a();
132 case gPhaseIdx: return gasPhaseParams_.a();
133 default:
134 DUNE_THROW(Dune::InvalidStateException,
135 "The a() parameter is only defined for "
136 "oil and gas phases");
137 }
138 }
139
144 Scalar b(int phaseIdx) const
145 {
146 switch (phaseIdx)
147 {
148 case oPhaseIdx: return oilPhaseParams_.b();
149 case gPhaseIdx: return gasPhaseParams_.b();
150 default:
151 DUNE_THROW(Dune::InvalidStateException,
152 "The b() parameter is only defined for "
153 "oil and gas phases");
154 }
155 }
156
164 Scalar aPure(int phaseIdx, int compIdx) const
165 {
166 switch (phaseIdx)
167 {
168 case oPhaseIdx: return oilPhaseParams_.pureParams(compIdx).a();
169 case gPhaseIdx: return gasPhaseParams_.pureParams(compIdx).a();
170 default:
171 DUNE_THROW(Dune::InvalidStateException,
172 "The a() parameter is only defined for "
173 "oil and gas phases");
174 }
175 }
176
183 Scalar bPure(int phaseIdx, int compIdx) const
184 {
185 switch (phaseIdx)
186 {
187 case oPhaseIdx: return oilPhaseParams_.pureParams(compIdx).b();
188 case gPhaseIdx: return gasPhaseParams_.pureParams(compIdx).b();
189 default:
190 DUNE_THROW(Dune::InvalidStateException,
191 "The b() parameter is only defined for "
192 "oil and gas phases");
193 }
194 }
195
200 Scalar molarVolume(int phaseIdx) const
201 {
202 assert(VmUpToDate_[phaseIdx]);
203 return Vm_[phaseIdx];
204 }
205
206
212 { return oilPhaseParams_; }
213
219 { return gasPhaseParams_; }
220
225 template <class FluidState>
226 void updateEosParams(const FluidState &fs,
227 int phaseIdx,
228 int exceptQuantities = ParentType::None)
229 {
230 if (!(exceptQuantities & ParentType::Temperature))
231 {
232 updatePure_(fs, phaseIdx);
233 updateMix_(fs, phaseIdx);
234 VmUpToDate_[phaseIdx] = false;
235 }
236 else if (!(exceptQuantities & ParentType::Composition))
237 {
238 updateMix_(fs, phaseIdx);
239 VmUpToDate_[phaseIdx] = false;
240 }
241 else if (!(exceptQuantities & ParentType::Pressure)) {
242 VmUpToDate_[phaseIdx] = false;
243 }
244 }
245
246protected:
253 template <class FluidState>
254 void updatePure_(const FluidState &fs, int phaseIdx)
255 {
256 Scalar T = fs.temperature(phaseIdx);
257 Scalar p = fs.pressure(phaseIdx);
258
259 switch (phaseIdx)
260 {
261 case oPhaseIdx: oilPhaseParams_.updatePure(T, p); break;
262 case gPhaseIdx: gasPhaseParams_.updatePure(T, p); break;
263 }
264 }
265
273 template <class FluidState>
274 void updateMix_(const FluidState &fs, int phaseIdx)
275 {
276 Valgrind::CheckDefined(fs.averageMolarMass(phaseIdx));
277 switch (phaseIdx)
278 {
279 case oPhaseIdx:
280 oilPhaseParams_.updateMix(fs);
281 break;
282 case gPhaseIdx:
283 gasPhaseParams_.updateMix(fs);
284 break;
285 case wPhaseIdx:
286 break;
287 }
288 }
289
290 template <class FluidState>
291 void updateMolarVolume_(const FluidState &fs,
292 int phaseIdx)
293 {
294 VmUpToDate_[phaseIdx] = true;
295
296 // calculate molar volume of the phase (we will need this for the
297 // fugacity coefficients and the density anyway)
298 switch (phaseIdx) {
299 case gPhaseIdx: {
300 // calculate molar volumes for the given composition. although
301 // this isn't a Peng-Robinson parameter strictly speaking, the
302 // molar volume appears in basically every quantity the fluid
303 // system can get queried, so it is okay to calculate it
304 // here...
305 Vm_[gPhaseIdx] =
307 *this,
308 phaseIdx,
309 /*isGasPhase=*/true);
310 break;
311 }
312 case oPhaseIdx: {
313 // calculate molar volumes for the given composition. although
314 // this isn't a Peng-Robinson parameter strictly speaking, the
315 // molar volume appears in basically every quantity the fluid
316 // system can get queried, so it is okay to calculate it
317 // here...
318 Vm_[oPhaseIdx] =
320 *this,
321 phaseIdx,
322 /*isGasPhase=*/false);
323 break;
324 }
325 case wPhaseIdx: {
326 // Density of water in the stock tank (i.e. atmospheric
327 // pressure) is specified as 62.4 lb/ft^3 by the SPE-5
328 // paper. Also 1 lb = 0.4535923 and 1 ft = 0.3048 m.
329 const Scalar stockTankWaterDensity = 62.4 * 0.45359237 / 0.028316847;
330 // Water compressibility is specified as 3.3e-6 per psi
331 // overpressure, where 1 psi = 6894.7573 Pa
332 Scalar overPressure = fs.pressure(wPhaseIdx) - 1.013e5; // [Pa]
333 Scalar waterDensity =
334 stockTankWaterDensity * (1 + 3.3e-6*overPressure/6894.7573);
335
336 // convert water density [kg/m^3] to molar volume [m^3/mol]
337 Vm_[wPhaseIdx] = fs.averageMolarMass(wPhaseIdx)/waterDensity;
338 break;
339 }
340 default:
341 DUNE_THROW(Dune::InvalidStateException, "invalid phaseIdx " << phaseIdx);
342 }
343 }
344
345 bool VmUpToDate_[numPhases];
346 Scalar Vm_[numPhases];
347
350};
351
352} // end namespace Dumux
353
354#endif
Material properties of pure water .
Implements the Peng-Robinson equation of state for liquids and gases.
The mixing rule for the oil and the gas phases of the SPE5 problem.
The base class of the parameter cache classes for fluid systems.
bool CheckDefined(const T &value)
Make valgrind complain if the object occupied by an object is undefined.
Definition valgrind.hh:72
void SetUndefined(const T &value)
Make the memory on which an object resides undefined.
Definition valgrind.hh:102
Definition adapt.hh:29
Implements the Peng-Robinson equation of state for liquids and gases.
Definition pengrobinson.hh:57
static Scalar computeMolarVolume(const FluidState &fs, Params &params, int phaseIdx, bool isGasPhase)
Computes molar volumes where the Peng-Robinson EOS is true.
Definition pengrobinson.hh:143
The mixing rule for the oil and the gas phases of the SPE5 problem.
Definition pengrobinsonparamsmixture.hh:63
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
bool VmUpToDate_[numPhases]
Definition spe5parametercache.hh:345
Scalar b(int phaseIdx) const
The Peng-Robinson co-volume for a phase.
Definition spe5parametercache.hh:144
const GasPhaseParams & gasPhaseParams() const
Returns the Peng-Robinson mixture parameters for the gas phase.
Definition spe5parametercache.hh:218
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:164
void updateMolarVolume_(const FluidState &fs, int phaseIdx)
Definition spe5parametercache.hh:291
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:81
Scalar Vm_[numPhases]
Definition spe5parametercache.hh:346
Scalar a(int phaseIdx) const
The Peng-Robinson attractive parameter for a phase.
Definition spe5parametercache.hh:127
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:226
void updatePure_(const FluidState &fs, int phaseIdx)
Update all parameters of a phase which only depend on temperature and/or pressure.
Definition spe5parametercache.hh:254
const OilPhaseParams & oilPhaseParams() const
Returns the Peng-Robinson mixture parameters for the oil phase.
Definition spe5parametercache.hh:211
Spe5ParameterCache()
The constructor.
Definition spe5parametercache.hh:65
GasPhaseParams gasPhaseParams_
Definition spe5parametercache.hh:349
PengRobinsonParamsMixture< Scalar, ThisType, gPhaseIdx, true > GasPhaseParams
Definition spe5parametercache.hh:60
PengRobinsonParamsMixture< Scalar, ThisType, oPhaseIdx, true > OilPhaseParams
Definition spe5parametercache.hh:59
OilPhaseParams oilPhaseParams_
Definition spe5parametercache.hh:348
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:274
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:110
Scalar molarVolume(int phaseIdx) const
Returns the molar volume of a phase .
Definition spe5parametercache.hh:200
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:183