My Project
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  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_SPE5_PARAMETER_CACHE_HPP
28 #define OPM_SPE5_PARAMETER_CACHE_HPP
29 
30 #include <cassert>
31 
34 
37 
38 namespace Opm {
39 
44 template <class Scalar, class FluidSystem>
46  : public ParameterCacheBase<Spe5ParameterCache<Scalar, FluidSystem> >
47 {
50 
51  typedef ::Opm::PengRobinson<Scalar> PengRobinson;
52 
53  enum { numPhases = FluidSystem::numPhases };
54 
55  enum { waterPhaseIdx = FluidSystem::waterPhaseIdx };
56  enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
57  enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
58 
59 public:
61  typedef PengRobinsonParamsMixture<Scalar, FluidSystem, oilPhaseIdx, /*useSpe5=*/true> OilPhaseParams;
63  typedef PengRobinsonParamsMixture<Scalar, FluidSystem, gasPhaseIdx, /*useSpe5=*/true> GasPhaseParams;
64 
66  {
67  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
68  VmUpToDate_[phaseIdx] = false;
69  Valgrind::SetUndefined(Vm_[phaseIdx]);
70  }
71  }
72 
74  template <class FluidState>
75  void updatePhase(const FluidState& fluidState,
76  unsigned phaseIdx,
77  int exceptQuantities = ParentType::None)
78  {
79  updateEosParams(fluidState, phaseIdx, exceptQuantities);
80 
81  // if we don't need to recalculate the molar volume, we exit
82  // here
83  if (VmUpToDate_[phaseIdx])
84  return;
85 
86  // update the phase's molar volume
87  updateMolarVolume_(fluidState, phaseIdx);
88  }
89 
91  template <class FluidState>
92  void updateSingleMoleFraction(const FluidState& fluidState,
93  unsigned phaseIdx,
94  unsigned compIdx)
95  {
96  if (phaseIdx == oilPhaseIdx)
97  oilPhaseParams_.updateSingleMoleFraction(fluidState, compIdx);
98  else if (phaseIdx == gasPhaseIdx)
99  gasPhaseParams_.updateSingleMoleFraction(fluidState, compIdx);
100 
101  // update the phase's molar volume
102  updateMolarVolume_(fluidState, phaseIdx);
103  }
104 
110  Scalar a(unsigned phaseIdx) const
111  {
112  switch (phaseIdx)
113  {
114  case oilPhaseIdx: return oilPhaseParams_.a();
115  case gasPhaseIdx: return gasPhaseParams_.a();
116  default:
117  throw std::logic_error("The a() parameter is only defined for "
118  "oil and gas phases");
119  };
120  }
121 
127  Scalar b(unsigned phaseIdx) const
128  {
129  switch (phaseIdx)
130  {
131  case oilPhaseIdx: return oilPhaseParams_.b();
132  case gasPhaseIdx: return gasPhaseParams_.b();
133  default:
134  throw std::logic_error("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  throw std::logic_error("The a() parameter is only defined for "
155  "oil and gas phases");
156  };
157  }
158 
166  Scalar bPure(unsigned phaseIdx, unsigned compIdx) const
167  {
168  switch (phaseIdx)
169  {
170  case oilPhaseIdx: return oilPhaseParams_.pureParams(compIdx).b();
171  case gasPhaseIdx: return gasPhaseParams_.pureParams(compIdx).b();
172  default:
173  throw std::logic_error("The b() parameter is only defined for "
174  "oil and gas phases");
175  };
176  }
177 
185  Scalar aCache(unsigned phaseIdx, unsigned compIdx, unsigned compJIdx) const
186  {
187  switch (phaseIdx)
188  {
189  case oilPhaseIdx: return oilPhaseParams_.getaCache(compIdx,compJIdx);
190  case gasPhaseIdx: return gasPhaseParams_.getaCache(compIdx,compJIdx);
191  default:
192  throw std::logic_error("The aCache() parameter is only defined for "
193  "oil and gas phase");
194  };
195  }
196 
202  Scalar molarVolume(unsigned phaseIdx) const
203  { assert(VmUpToDate_[phaseIdx]); return Vm_[phaseIdx]; }
204 
205 
211  { return oilPhaseParams_; }
212 
218  { return gasPhaseParams_; }
219 
228  template <class FluidState>
229  void updateEosParams(const FluidState& fluidState,
230  unsigned phaseIdx,
231  int exceptQuantities = ParentType::None)
232  {
233  if (!(exceptQuantities & ParentType::Temperature))
234  {
235  updatePure_(fluidState, phaseIdx);
236  updateMix_(fluidState, phaseIdx);
237  VmUpToDate_[phaseIdx] = false;
238  }
239  else if (!(exceptQuantities & ParentType::Composition))
240  {
241  updateMix_(fluidState, phaseIdx);
242  VmUpToDate_[phaseIdx] = false;
243  }
244  else if (!(exceptQuantities & ParentType::Pressure)) {
245  VmUpToDate_[phaseIdx] = false;
246  }
247  }
248 
249 protected:
256  template <class FluidState>
257  void updatePure_(const FluidState& fluidState, unsigned phaseIdx)
258  {
259  Scalar T = fluidState.temperature(phaseIdx);
260  Scalar p = fluidState.pressure(phaseIdx);
261 
262  switch (phaseIdx)
263  {
264  case oilPhaseIdx: oilPhaseParams_.updatePure(T, p); break;
265  case gasPhaseIdx: gasPhaseParams_.updatePure(T, p); break;
266  //case waterPhaseIdx: waterPhaseParams_.updatePure(phaseIdx, temperature, pressure);break;
267  }
268  }
269 
277  template <class FluidState>
278  void updateMix_(const FluidState& fluidState, unsigned phaseIdx)
279  {
280  Valgrind::CheckDefined(fluidState.averageMolarMass(phaseIdx));
281  switch (phaseIdx)
282  {
283  case oilPhaseIdx:
284  oilPhaseParams_.updateMix(fluidState);
285  break;
286  case gasPhaseIdx:
287  gasPhaseParams_.updateMix(fluidState);
288  break;
289  case waterPhaseIdx:
290  break;
291  }
292  }
293 
294  template <class FluidState>
295  void updateMolarVolume_(const FluidState& fluidState,
296  unsigned phaseIdx)
297  {
298  VmUpToDate_[phaseIdx] = true;
299 
300  // calculate molar volume of the phase (we will need this for the
301  // fugacity coefficients and the density anyway)
302  switch (phaseIdx) {
303  case gasPhaseIdx: {
304  // calculate molar volumes for the given composition. although
305  // this isn't a Peng-Robinson parameter strictly speaking, the
306  // molar volume appears in basically every quantity the fluid
307  // system can get queried, so it is okay to calculate it
308  // here...
309  Vm_[gasPhaseIdx] =
311  *this,
312  phaseIdx,
313  /*isGasPhase=*/true);
314  break;
315  }
316  case oilPhaseIdx: {
317  // calculate molar volumes for the given composition. although
318  // this isn't a Peng-Robinson parameter strictly speaking, the
319  // molar volume appears in basically every quantity the fluid
320  // system can get queried, so it is okay to calculate it
321  // here...
322  Vm_[oilPhaseIdx] =
324  *this,
325  phaseIdx,
326  /*isGasPhase=*/false);
327 
328  break;
329  }
330  case waterPhaseIdx: {
331  // Density of water in the stock tank (i.e. atmospheric
332  // pressure) is specified as 62.4 lb/ft^3 by the SPE-5
333  // paper. Also 1 lb = 0.4535923 and 1 ft = 0.3048 m.
334  const Scalar stockTankWaterDensity = 62.4 * 0.45359237 / 0.028316847;
335  // Water compressibility is specified as 3.3e-6 per psi
336  // overpressure, where 1 psi = 6894.7573 Pa
337  Scalar overPressure = fluidState.pressure(waterPhaseIdx) - 1.013e5; // [Pa]
338  Scalar waterDensity =
339  stockTankWaterDensity * (1 + 3.3e-6*overPressure/6894.7573);
340 
341  // convert water density [kg/m^3] to molar volume [m^3/mol]
342  Vm_[waterPhaseIdx] = fluidState.averageMolarMass(waterPhaseIdx)/waterDensity;
343  break;
344  };
345  };
346  }
347 
348  bool VmUpToDate_[numPhases];
349  Scalar Vm_[numPhases];
350 
351  OilPhaseParams oilPhaseParams_;
352  GasPhaseParams gasPhaseParams_;
353 };
354 
355 } // namespace Opm
356 
357 #endif
Material properties of pure water .
The base class of the parameter caches of fluid systems.
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 caches of fluid systems.
Definition: ParameterCacheBase.hpp:38
@ Temperature
The temperature has not been modified.
Definition: ParameterCacheBase.hpp:48
@ None
All quantities have been (potentially) modified.
Definition: ParameterCacheBase.hpp:45
@ Pressure
The pressures have not been modified.
Definition: ParameterCacheBase.hpp:51
@ Composition
The compositions have not been modified.
Definition: ParameterCacheBase.hpp:54
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:196
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 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:205
Scalar a() const
Returns the attractive parameter 'a' of the Peng-Robinson fluid.
Definition: PengRobinsonParams.hpp:50
Scalar b() const
Returns the repulsive parameter 'b' of the Peng-Robinson fluid.
Definition: PengRobinsonParams.hpp:57
Implements the Peng-Robinson equation of state for liquids and gases.
Definition: PengRobinson.hpp:56
static FluidState::Scalar computeMolarVolume(const FluidState &fs, Params &params, unsigned phaseIdx, bool isGasPhase)
Computes molar volumes where the Peng-Robinson EOS is true.
Definition: PengRobinson.hpp:144
Specifies the parameter cache used by the SPE-5 fluid system.
Definition: Spe5ParameterCache.hpp:47
void updatePhase(const FluidState &fluidState, unsigned phaseIdx, int exceptQuantities=ParentType::None)
Update all cached parameters of a specific fluid phase.
Definition: Spe5ParameterCache.hpp:75
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 updatePure_(const FluidState &fluidState, unsigned phaseIdx)
Update all parameters of a phase which only depend on temperature and/or pressure.
Definition: Spe5ParameterCache.hpp:257
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:166
PengRobinsonParamsMixture< Scalar, FluidSystem, gasPhaseIdx, true > GasPhaseParams
The cached parameters for the gas phase.
Definition: Spe5ParameterCache.hpp:63
void updateMix_(const FluidState &fluidState, unsigned phaseIdx)
Update all parameters of a phase which depend on the fluid composition.
Definition: Spe5ParameterCache.hpp:278
Scalar aCache(unsigned phaseIdx, unsigned compIdx, unsigned compJIdx) const
TODO.
Definition: Spe5ParameterCache.hpp:185
Scalar molarVolume(unsigned phaseIdx) const
Returns the molar volume of a phase [m^3/mol].
Definition: Spe5ParameterCache.hpp:202
const OilPhaseParams & oilPhaseParams() const
Returns the Peng-Robinson mixture parameters for the oil phase.
Definition: Spe5ParameterCache.hpp:210
Scalar a(unsigned phaseIdx) const
The Peng-Robinson attractive parameter for a phase.
Definition: Spe5ParameterCache.hpp:110
const GasPhaseParams & gasPhaseParams() const
Returns the Peng-Robinson mixture parameters for the gas phase.
Definition: Spe5ParameterCache.hpp:217
Scalar b(unsigned phaseIdx) const
The Peng-Robinson covolume for a phase.
Definition: Spe5ParameterCache.hpp:127
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:229
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:92
PengRobinsonParamsMixture< Scalar, FluidSystem, oilPhaseIdx, true > OilPhaseParams
The cached parameters for the oil phase.
Definition: Spe5ParameterCache.hpp:61