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 
183  Scalar molarVolume(unsigned phaseIdx) const
184  { assert(VmUpToDate_[phaseIdx]); return Vm_[phaseIdx]; }
185 
186 
192  { return oilPhaseParams_; }
193 
199  { return gasPhaseParams_; }
200 
209  template <class FluidState>
210  void updateEosParams(const FluidState& fluidState,
211  unsigned phaseIdx,
212  int exceptQuantities = ParentType::None)
213  {
214  if (!(exceptQuantities & ParentType::Temperature))
215  {
216  updatePure_(fluidState, phaseIdx);
217  updateMix_(fluidState, phaseIdx);
218  VmUpToDate_[phaseIdx] = false;
219  }
220  else if (!(exceptQuantities & ParentType::Composition))
221  {
222  updateMix_(fluidState, phaseIdx);
223  VmUpToDate_[phaseIdx] = false;
224  }
225  else if (!(exceptQuantities & ParentType::Pressure)) {
226  VmUpToDate_[phaseIdx] = false;
227  }
228  }
229 
230 protected:
237  template <class FluidState>
238  void updatePure_(const FluidState& fluidState, unsigned phaseIdx)
239  {
240  Scalar T = fluidState.temperature(phaseIdx);
241  Scalar p = fluidState.pressure(phaseIdx);
242 
243  switch (phaseIdx)
244  {
245  case oilPhaseIdx: oilPhaseParams_.updatePure(T, p); break;
246  case gasPhaseIdx: gasPhaseParams_.updatePure(T, p); break;
247  //case waterPhaseIdx: waterPhaseParams_.updatePure(phaseIdx, temperature, pressure);break;
248  }
249  }
250 
258  template <class FluidState>
259  void updateMix_(const FluidState& fluidState, unsigned phaseIdx)
260  {
261  Valgrind::CheckDefined(fluidState.averageMolarMass(phaseIdx));
262  switch (phaseIdx)
263  {
264  case oilPhaseIdx:
265  oilPhaseParams_.updateMix(fluidState);
266  break;
267  case gasPhaseIdx:
268  gasPhaseParams_.updateMix(fluidState);
269  break;
270  case waterPhaseIdx:
271  break;
272  }
273  }
274 
275  template <class FluidState>
276  void updateMolarVolume_(const FluidState& fluidState,
277  unsigned phaseIdx)
278  {
279  VmUpToDate_[phaseIdx] = true;
280 
281  // calculate molar volume of the phase (we will need this for the
282  // fugacity coefficients and the density anyway)
283  switch (phaseIdx) {
284  case gasPhaseIdx: {
285  // calculate molar volumes for the given composition. although
286  // this isn't a Peng-Robinson parameter strictly speaking, the
287  // molar volume appears in basically every quantity the fluid
288  // system can get queried, so it is okay to calculate it
289  // here...
290  Vm_[gasPhaseIdx] =
292  *this,
293  phaseIdx,
294  /*isGasPhase=*/true);
295  break;
296  }
297  case oilPhaseIdx: {
298  // calculate molar volumes for the given composition. although
299  // this isn't a Peng-Robinson parameter strictly speaking, the
300  // molar volume appears in basically every quantity the fluid
301  // system can get queried, so it is okay to calculate it
302  // here...
303  Vm_[oilPhaseIdx] =
305  *this,
306  phaseIdx,
307  /*isGasPhase=*/false);
308 
309  break;
310  }
311  case waterPhaseIdx: {
312  // Density of water in the stock tank (i.e. atmospheric
313  // pressure) is specified as 62.4 lb/ft^3 by the SPE-5
314  // paper. Also 1 lb = 0.4535923 and 1 ft = 0.3048 m.
315  const Scalar stockTankWaterDensity = 62.4 * 0.45359237 / 0.028316847;
316  // Water compressibility is specified as 3.3e-6 per psi
317  // overpressure, where 1 psi = 6894.7573 Pa
318  Scalar overPressure = fluidState.pressure(waterPhaseIdx) - 1.013e5; // [Pa]
319  Scalar waterDensity =
320  stockTankWaterDensity * (1 + 3.3e-6*overPressure/6894.7573);
321 
322  // convert water density [kg/m^3] to molar volume [m^3/mol]
323  Vm_[waterPhaseIdx] = fluidState.averageMolarMass(waterPhaseIdx)/waterDensity;
324  break;
325  };
326  };
327  }
328 
329  bool VmUpToDate_[numPhases];
330  Scalar Vm_[numPhases];
331 
332  OilPhaseParams oilPhaseParams_;
333  GasPhaseParams gasPhaseParams_;
334 };
335 
336 } // namespace Opm
337 
338 #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:191
void updatePure(const FluidState &fluidState)
Update Peng-Robinson parameters for the pure components.
Definition: PengRobinsonParamsMixture.hpp:76
void updateMix(const FluidState &fs)
Calculates the "a" and "b" Peng-Robinson parameters for the mixture.
Definition: PengRobinsonParamsMixture.hpp:139
const PureParams & pureParams(unsigned compIdx) const
Return the Peng-Robinson parameters of a pure substance,.
Definition: PengRobinsonParamsMixture.hpp:200
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:57
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:146
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:238
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:259
Scalar molarVolume(unsigned phaseIdx) const
Returns the molar volume of a phase [m^3/mol].
Definition: Spe5ParameterCache.hpp:183
const OilPhaseParams & oilPhaseParams() const
Returns the Peng-Robinson mixture parameters for the oil phase.
Definition: Spe5ParameterCache.hpp:191
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:198
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:210
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