Spe5ParameterCache.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  Copyright (C) 2012-2013 by Andreas Lauser
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 2 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy o2f the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 */
25 #ifndef OPM_SPE5_PARAMETER_CACHE_HPP
26 #define OPM_SPE5_PARAMETER_CACHE_HPP
27 
28 #include <cassert>
29 
32 
35 
36 namespace Opm {
37 
42 template <class Scalar, class FluidSystem>
44  : public Opm::ParameterCacheBase<Spe5ParameterCache<Scalar, FluidSystem> >
45 {
48 
50 
51  enum { numPhases = FluidSystem::numPhases };
52 
53  enum { waterPhaseIdx = FluidSystem::waterPhaseIdx };
54  enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
55  enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
56 
57 public:
59  typedef Opm::PengRobinsonParamsMixture<Scalar, FluidSystem, oilPhaseIdx, /*useSpe5=*/true> OilPhaseParams;
61  typedef Opm::PengRobinsonParamsMixture<Scalar, FluidSystem, gasPhaseIdx, /*useSpe5=*/true> GasPhaseParams;
62 
64  {
65  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
66  VmUpToDate_[phaseIdx] = false;
67  Valgrind::SetUndefined(Vm_[phaseIdx]);
68  }
69  }
70 
72  template <class FluidState>
73  void updatePhase(const FluidState &fluidState,
74  unsigned phaseIdx,
75  int exceptQuantities = ParentType::None)
76  {
77  updateEosParams(fluidState, phaseIdx, exceptQuantities);
78 
79  // if we don't need to recalculate the molar volume, we exit
80  // here
81  if (VmUpToDate_[phaseIdx])
82  return;
83 
84  // update the phase's molar volume
85  updateMolarVolume_(fluidState, phaseIdx);
86  }
87 
89  template <class FluidState>
90  void updateSingleMoleFraction(const FluidState &fluidState,
91  unsigned phaseIdx,
92  unsigned compIdx)
93  {
94  if (phaseIdx == oilPhaseIdx)
95  oilPhaseParams_.updateSingleMoleFraction(fluidState, compIdx);
96  else if (phaseIdx == gasPhaseIdx)
97  gasPhaseParams_.updateSingleMoleFraction(fluidState, compIdx);
98 
99  // update the phase's molar volume
100  updateMolarVolume_(fluidState, phaseIdx);
101  }
102 
108  Scalar a(unsigned phaseIdx) const
109  {
110  switch (phaseIdx)
111  {
112  case oilPhaseIdx: return oilPhaseParams_.a();
113  case gasPhaseIdx: return gasPhaseParams_.a();
114  default:
115  OPM_THROW(std::logic_error,
116  "The a() parameter is only defined for "
117  "oil and gas phases");
118  };
119  }
120 
126  Scalar b(unsigned phaseIdx) const
127  {
128  switch (phaseIdx)
129  {
130  case oilPhaseIdx: return oilPhaseParams_.b();
131  case gasPhaseIdx: return gasPhaseParams_.b();
132  default:
133  OPM_THROW(std::logic_error,
134  "The b() parameter is only defined for "
135  "oil and gas phases");
136  };
137  }
138 
147  Scalar aPure(unsigned phaseIdx, unsigned compIdx) const
148  {
149  switch (phaseIdx)
150  {
151  case oilPhaseIdx: return oilPhaseParams_.pureParams(compIdx).a();
152  case gasPhaseIdx: return gasPhaseParams_.pureParams(compIdx).a();
153  default:
154  OPM_THROW(std::logic_error,
155  "The a() parameter is only defined for "
156  "oil and gas phases");
157  };
158  }
159 
167  Scalar bPure(unsigned phaseIdx, unsigned compIdx) const
168  {
169  switch (phaseIdx)
170  {
171  case oilPhaseIdx: return oilPhaseParams_.pureParams(compIdx).b();
172  case gasPhaseIdx: return gasPhaseParams_.pureParams(compIdx).b();
173  default:
174  OPM_THROW(std::logic_error,
175  "The b() parameter is only defined for "
176  "oil and gas phases");
177  };
178  }
179 
185  Scalar molarVolume(unsigned phaseIdx) const
186  { assert(VmUpToDate_[phaseIdx]); return Vm_[phaseIdx]; }
187 
188 
193  const OilPhaseParams &oilPhaseParams() const
194  { return oilPhaseParams_; }
195 
200  const GasPhaseParams &gasPhaseParams() const
201  { return gasPhaseParams_; }
202 
211  template <class FluidState>
212  void updateEosParams(const FluidState &fluidState,
213  unsigned phaseIdx,
214  int exceptQuantities = ParentType::None)
215  {
216  if (!(exceptQuantities & ParentType::Temperature))
217  {
218  updatePure_(fluidState, phaseIdx);
219  updateMix_(fluidState, phaseIdx);
220  VmUpToDate_[phaseIdx] = false;
221  }
222  else if (!(exceptQuantities & ParentType::Composition))
223  {
224  updateMix_(fluidState, phaseIdx);
225  VmUpToDate_[phaseIdx] = false;
226  }
227  else if (!(exceptQuantities & ParentType::Pressure)) {
228  VmUpToDate_[phaseIdx] = false;
229  }
230  }
231 
232 protected:
239  template <class FluidState>
240  void updatePure_(const FluidState &fluidState, unsigned phaseIdx)
241  {
242  Scalar T = fluidState.temperature(phaseIdx);
243  Scalar p = fluidState.pressure(phaseIdx);
244 
245  switch (phaseIdx)
246  {
247  case oilPhaseIdx: oilPhaseParams_.updatePure(T, p); break;
248  case gasPhaseIdx: gasPhaseParams_.updatePure(T, p); break;
249  //case waterPhaseIdx: waterPhaseParams_.updatePure(phaseIdx, temperature, pressure);break;
250  }
251  }
252 
260  template <class FluidState>
261  void updateMix_(const FluidState &fluidState, unsigned phaseIdx)
262  {
263  Valgrind::CheckDefined(fluidState.averageMolarMass(phaseIdx));
264  switch (phaseIdx)
265  {
266  case oilPhaseIdx:
267  oilPhaseParams_.updateMix(fluidState);
268  break;
269  case gasPhaseIdx:
270  gasPhaseParams_.updateMix(fluidState);
271  break;
272  case waterPhaseIdx:
273  break;
274  }
275  }
276 
277  template <class FluidState>
278  void updateMolarVolume_(const FluidState &fluidState,
279  unsigned phaseIdx)
280  {
281  VmUpToDate_[phaseIdx] = true;
282 
283  // calculate molar volume of the phase (we will need this for the
284  // fugacity coefficients and the density anyway)
285  switch (phaseIdx) {
286  case gasPhaseIdx: {
287  // calculate molar volumes for the given composition. although
288  // this isn't a Peng-Robinson parameter strictly speaking, the
289  // molar volume appears in basically every quantity the fluid
290  // system can get queried, so it is okay to calculate it
291  // here...
292  Vm_[gasPhaseIdx] =
294  *this,
295  phaseIdx,
296  /*isGasPhase=*/true);
297  break;
298  }
299  case oilPhaseIdx: {
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_[oilPhaseIdx] =
307  *this,
308  phaseIdx,
309  /*isGasPhase=*/false);
310 
311  break;
312  }
313  case waterPhaseIdx: {
314  // Density of water in the stock tank (i.e. atmospheric
315  // pressure) is specified as 62.4 lb/ft^3 by the SPE-5
316  // paper. Also 1 lb = 0.4535923 and 1 ft = 0.3048 m.
317  const Scalar stockTankWaterDensity = 62.4 * 0.45359237 / 0.028316847;
318  // Water compressibility is specified as 3.3e-6 per psi
319  // overpressure, where 1 psi = 6894.7573 Pa
320  Scalar overPressure = fluidState.pressure(waterPhaseIdx) - 1.013e5; // [Pa]
321  Scalar waterDensity =
322  stockTankWaterDensity * (1 + 3.3e-6*overPressure/6894.7573);
323 
324  // convert water density [kg/m^3] to molar volume [m^3/mol]
325  Vm_[waterPhaseIdx] = fluidState.averageMolarMass(waterPhaseIdx)/waterDensity;
326  break;
327  };
328  };
329  }
330 
331  bool VmUpToDate_[numPhases];
332  Scalar Vm_[numPhases];
333 
334  OilPhaseParams oilPhaseParams_;
335  GasPhaseParams gasPhaseParams_;
336 };
337 
338 } // namespace Opm
339 
340 #endif
Scalar aPure(unsigned phaseIdx, unsigned compIdx) const
The Peng-Robinson attractive parameter for a pure component given the same temperature and pressure o...
Definition: Spe5ParameterCache.hpp:147
void SetUndefined(const T &value OPM_UNUSED)
Make the memory on which an object resides undefined in valgrind runs.
Definition: Valgrind.hpp:138
bool CheckDefined(const T &value OPM_UNUSED)
Make valgrind complain if any of the memory occupied by an object is undefined.
Definition: Valgrind.hpp:74
void updatePure_(const FluidState &fluidState, unsigned phaseIdx)
Update all parameters of a phase which only depend on temperature and/or pressure.
Definition: Spe5ParameterCache.hpp:240
The base class of the parameter caches of fluid systems.
Definition: Air_Mesitylene.hpp:31
void updatePure(const FluidState &fluidState)
Update Peng-Robinson parameters for the pure components.
Definition: PengRobinsonParamsMixture.hpp:70
The mixing rule for the oil and the gas phases of the SPE5 problem.
Definition: PengRobinsonParamsMixture.hpp:54
Implements the Peng-Robinson equation of state for liquids and gases.
GasPhaseParams gasPhaseParams_
Definition: Spe5ParameterCache.hpp:335
Opm::PengRobinsonParamsMixture< Scalar, FluidSystem, gasPhaseIdx, true > GasPhaseParams
The cached parameters for the gas phase.
Definition: Spe5ParameterCache.hpp:61
The compositions have not been modified.
Definition: ParameterCacheBase.hpp:53
const PureParams & pureParams(unsigned compIdx) const
Return the Peng-Robinson parameters of a pure substance,.
Definition: PengRobinsonParamsMixture.hpp:192
static Scalar computeMolarVolume(const FluidState &fs, Params &params, unsigned phaseIdx, bool isGasPhase)
Computes molar volumes where the Peng-Robinson EOS is true.
Definition: PengRobinson.hpp:142
void updateEosParams(const FluidState &fluidState, unsigned phaseIdx, int exceptQuantities=ParentType::None)
Update all parameters required by the equation of state to calculate some quantities for the phase...
Definition: Spe5ParameterCache.hpp:212
Opm::PengRobinsonParamsMixture< Scalar, FluidSystem, oilPhaseIdx, true > OilPhaseParams
The cached parameters for the oil phase.
Definition: Spe5ParameterCache.hpp:59
All quantities have been (potentially) modified.
Definition: ParameterCacheBase.hpp:44
void updatePhase(const FluidState &fluidState, unsigned phaseIdx, int exceptQuantities=ParentType::None)
Update all cached parameters of a specific fluid phase.
Definition: Spe5ParameterCache.hpp:73
bool VmUpToDate_[numPhases]
Definition: Spe5ParameterCache.hpp:331
Scalar a(unsigned phaseIdx) const
The Peng-Robinson attractive parameter for a phase.
Definition: Spe5ParameterCache.hpp:108
Material properties of pure water .
const OilPhaseParams & oilPhaseParams() const
Returns the Peng-Robinson mixture parameters for the oil phase.
Definition: Spe5ParameterCache.hpp:193
Spe5ParameterCache()
Definition: Spe5ParameterCache.hpp:63
Scalar Vm_[numPhases]
Definition: Spe5ParameterCache.hpp:332
void updateMolarVolume_(const FluidState &fluidState, unsigned phaseIdx)
Definition: Spe5ParameterCache.hpp:278
Scalar a() const
Returns the attractive parameter 'a' of the Peng-Robinson fluid.
Definition: PengRobinsonParams.hpp:49
void updateMix(const FluidState &fs)
Calculates the "a" and "b" Peng-Robinson parameters for the mixture.
Definition: PengRobinsonParamsMixture.hpp:133
The mixing rule for the oil and the gas phases of the SPE5 problem.
The temperature has not been modified.
Definition: ParameterCacheBase.hpp:47
OilPhaseParams oilPhaseParams_
Definition: Spe5ParameterCache.hpp:334
Scalar molarVolume(unsigned phaseIdx) const
Returns the molar volume of a phase [m^3/mol].
Definition: Spe5ParameterCache.hpp:185
void updateMix_(const FluidState &fluidState, unsigned phaseIdx)
Update all parameters of a phase which depend on the fluid composition. It is assumed that updatePure...
Definition: Spe5ParameterCache.hpp:261
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:183
Scalar b(unsigned phaseIdx) const
The Peng-Robinson covolume for a phase.
Definition: Spe5ParameterCache.hpp:126
void updateSingleMoleFraction(const FluidState &fluidState, unsigned phaseIdx, unsigned compIdx)
Update all cached parameters of a specific fluid phase which depend on the mole fraction of a single ...
Definition: Spe5ParameterCache.hpp:90
Implements the Peng-Robinson equation of state for liquids and gases.
Definition: PengRobinson.hpp:54
The pressures have not been modified.
Definition: ParameterCacheBase.hpp:50
Scalar b() const
Returns the repulsive parameter 'b' of the Peng-Robinson fluid.
Definition: PengRobinsonParams.hpp:56
Scalar bPure(unsigned phaseIdx, unsigned compIdx) const
The Peng-Robinson covolume for a pure component given the same temperature and pressure of the phase...
Definition: Spe5ParameterCache.hpp:167
Specifies the parameter cache used by the SPE-5 fluid system.
Definition: Spe5ParameterCache.hpp:43
const GasPhaseParams & gasPhaseParams() const
Returns the Peng-Robinson mixture parameters for the gas phase.
Definition: Spe5ParameterCache.hpp:200
The base class of the parameter caches of fluid systems.
Definition: ParameterCacheBase.hpp:36