All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 Opm::ParameterCacheBase<Spe5ParameterCache<Scalar, FluidSystem> >
47 {
50 
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 Opm::PengRobinsonParamsMixture<Scalar, FluidSystem, oilPhaseIdx, /*useSpe5=*/true> OilPhaseParams;
63  typedef Opm::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  OPM_THROW(std::logic_error,
118  "The a() parameter is only defined for "
119  "oil and gas phases");
120  };
121  }
122 
128  Scalar b(unsigned phaseIdx) const
129  {
130  switch (phaseIdx)
131  {
132  case oilPhaseIdx: return oilPhaseParams_.b();
133  case gasPhaseIdx: return gasPhaseParams_.b();
134  default:
135  OPM_THROW(std::logic_error,
136  "The b() parameter is only defined for "
137  "oil and gas phases");
138  };
139  }
140 
149  Scalar aPure(unsigned phaseIdx, unsigned compIdx) const
150  {
151  switch (phaseIdx)
152  {
153  case oilPhaseIdx: return oilPhaseParams_.pureParams(compIdx).a();
154  case gasPhaseIdx: return gasPhaseParams_.pureParams(compIdx).a();
155  default:
156  OPM_THROW(std::logic_error,
157  "The a() parameter is only defined for "
158  "oil and gas phases");
159  };
160  }
161 
169  Scalar bPure(unsigned phaseIdx, unsigned compIdx) const
170  {
171  switch (phaseIdx)
172  {
173  case oilPhaseIdx: return oilPhaseParams_.pureParams(compIdx).b();
174  case gasPhaseIdx: return gasPhaseParams_.pureParams(compIdx).b();
175  default:
176  OPM_THROW(std::logic_error,
177  "The b() parameter is only defined for "
178  "oil and gas phases");
179  };
180  }
181 
187  Scalar molarVolume(unsigned phaseIdx) const
188  { assert(VmUpToDate_[phaseIdx]); return Vm_[phaseIdx]; }
189 
190 
196  { return oilPhaseParams_; }
197 
203  { return gasPhaseParams_; }
204 
213  template <class FluidState>
214  void updateEosParams(const FluidState& fluidState,
215  unsigned phaseIdx,
216  int exceptQuantities = ParentType::None)
217  {
218  if (!(exceptQuantities & ParentType::Temperature))
219  {
220  updatePure_(fluidState, phaseIdx);
221  updateMix_(fluidState, phaseIdx);
222  VmUpToDate_[phaseIdx] = false;
223  }
224  else if (!(exceptQuantities & ParentType::Composition))
225  {
226  updateMix_(fluidState, phaseIdx);
227  VmUpToDate_[phaseIdx] = false;
228  }
229  else if (!(exceptQuantities & ParentType::Pressure)) {
230  VmUpToDate_[phaseIdx] = false;
231  }
232  }
233 
234 protected:
241  template <class FluidState>
242  void updatePure_(const FluidState& fluidState, unsigned phaseIdx)
243  {
244  Scalar T = fluidState.temperature(phaseIdx);
245  Scalar p = fluidState.pressure(phaseIdx);
246 
247  switch (phaseIdx)
248  {
249  case oilPhaseIdx: oilPhaseParams_.updatePure(T, p); break;
250  case gasPhaseIdx: gasPhaseParams_.updatePure(T, p); break;
251  //case waterPhaseIdx: waterPhaseParams_.updatePure(phaseIdx, temperature, pressure);break;
252  }
253  }
254 
262  template <class FluidState>
263  void updateMix_(const FluidState& fluidState, unsigned phaseIdx)
264  {
265  Valgrind::CheckDefined(fluidState.averageMolarMass(phaseIdx));
266  switch (phaseIdx)
267  {
268  case oilPhaseIdx:
269  oilPhaseParams_.updateMix(fluidState);
270  break;
271  case gasPhaseIdx:
272  gasPhaseParams_.updateMix(fluidState);
273  break;
274  case waterPhaseIdx:
275  break;
276  }
277  }
278 
279  template <class FluidState>
280  void updateMolarVolume_(const FluidState& fluidState,
281  unsigned phaseIdx)
282  {
283  VmUpToDate_[phaseIdx] = true;
284 
285  // calculate molar volume of the phase (we will need this for the
286  // fugacity coefficients and the density anyway)
287  switch (phaseIdx) {
288  case gasPhaseIdx: {
289  // calculate molar volumes for the given composition. although
290  // this isn't a Peng-Robinson parameter strictly speaking, the
291  // molar volume appears in basically every quantity the fluid
292  // system can get queried, so it is okay to calculate it
293  // here...
294  Vm_[gasPhaseIdx] =
296  *this,
297  phaseIdx,
298  /*isGasPhase=*/true);
299  break;
300  }
301  case oilPhaseIdx: {
302  // calculate molar volumes for the given composition. although
303  // this isn't a Peng-Robinson parameter strictly speaking, the
304  // molar volume appears in basically every quantity the fluid
305  // system can get queried, so it is okay to calculate it
306  // here...
307  Vm_[oilPhaseIdx] =
309  *this,
310  phaseIdx,
311  /*isGasPhase=*/false);
312 
313  break;
314  }
315  case waterPhaseIdx: {
316  // Density of water in the stock tank (i.e. atmospheric
317  // pressure) is specified as 62.4 lb/ft^3 by the SPE-5
318  // paper. Also 1 lb = 0.4535923 and 1 ft = 0.3048 m.
319  const Scalar stockTankWaterDensity = 62.4 * 0.45359237 / 0.028316847;
320  // Water compressibility is specified as 3.3e-6 per psi
321  // overpressure, where 1 psi = 6894.7573 Pa
322  Scalar overPressure = fluidState.pressure(waterPhaseIdx) - 1.013e5; // [Pa]
323  Scalar waterDensity =
324  stockTankWaterDensity * (1 + 3.3e-6*overPressure/6894.7573);
325 
326  // convert water density [kg/m^3] to molar volume [m^3/mol]
327  Vm_[waterPhaseIdx] = fluidState.averageMolarMass(waterPhaseIdx)/waterDensity;
328  break;
329  };
330  };
331  }
332 
333  bool VmUpToDate_[numPhases];
334  Scalar Vm_[numPhases];
335 
336  OilPhaseParams oilPhaseParams_;
337  GasPhaseParams gasPhaseParams_;
338 };
339 
340 } // namespace Opm
341 
342 #endif
The mixing rule for the oil and the gas phases of the SPE5 problem.
Definition: PengRobinsonParamsMixture.hpp:58
Implements the Peng-Robinson equation of state for liquids and gases.
Definition: PengRobinson.hpp:56
Opm::PengRobinsonParamsMixture< Scalar, FluidSystem, oilPhaseIdx, true > OilPhaseParams
The cached parameters for the oil phase.
Definition: Spe5ParameterCache.hpp:61
const GasPhaseParams & gasPhaseParams() const
Returns the Peng-Robinson mixture parameters for the gas phase.
Definition: Spe5ParameterCache.hpp:202
void updateMix(const FluidState &fs)
Calculates the &quot;a&quot; and &quot;b&quot; Peng-Robinson parameters for the mixture.
Definition: PengRobinsonParamsMixture.hpp:139
Scalar a(unsigned phaseIdx) const
The Peng-Robinson attractive parameter for a phase.
Definition: Spe5ParameterCache.hpp:110
Specifies the parameter cache used by the SPE-5 fluid system.
Definition: Spe5ParameterCache.hpp:45
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:169
const OilPhaseParams & oilPhaseParams() const
Returns the Peng-Robinson mixture parameters for the oil phase.
Definition: Spe5ParameterCache.hpp:195
Opm::PengRobinsonParamsMixture< Scalar, FluidSystem, gasPhaseIdx, true > GasPhaseParams
The cached parameters for the gas phase.
Definition: Spe5ParameterCache.hpp:63
Material properties of pure water .
The temperature has not been modified.
Definition: ParameterCacheBase.hpp:48
Implements the Peng-Robinson equation of state for liquids and gases.
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:149
The compositions have not been modified.
Definition: ParameterCacheBase.hpp:54
void updatePure(const FluidState &fluidState)
Update Peng-Robinson parameters for the pure components.
Definition: PengRobinsonParamsMixture.hpp:76
Scalar b(unsigned phaseIdx) const
The Peng-Robinson covolume for a phase.
Definition: Spe5ParameterCache.hpp:128
All quantities have been (potentially) modified.
Definition: ParameterCacheBase.hpp:45
Scalar b() const
Returns the repulsive parameter &#39;b&#39; of the Peng-Robinson fluid.
Definition: PengRobinsonParams.hpp:57
The pressures have not been modified.
Definition: ParameterCacheBase.hpp:51
The base class of the parameter caches of fluid systems.
Definition: ParameterCacheBase.hpp:37
void updatePure_(const FluidState &fluidState, unsigned phaseIdx)
Update all parameters of a phase which only depend on temperature and/or pressure.
Definition: Spe5ParameterCache.hpp:242
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:214
const PureParams & pureParams(unsigned compIdx) const
Return the Peng-Robinson parameters of a pure substance,.
Definition: PengRobinsonParamsMixture.hpp:200
void updateSingleMoleFraction(const FluidState &fs, unsigned)
Calculates the &quot;a&quot; and &quot;b&quot; Peng-Robinson parameters for the mixture provided that only a single mole ...
Definition: PengRobinsonParamsMixture.hpp:191
The mixing rule for the oil and the gas phases of the SPE5 problem.
void updatePhase(const FluidState &fluidState, unsigned phaseIdx, int exceptQuantities=ParentType::None)
Update all cached parameters of a specific fluid phase.
Definition: Spe5ParameterCache.hpp:75
The base class of the parameter caches of fluid systems.
Scalar molarVolume(unsigned phaseIdx) const
Returns the molar volume of a phase [m^3/mol].
Definition: Spe5ParameterCache.hpp:187
Scalar a() const
Returns the attractive parameter &#39;a&#39; of the Peng-Robinson fluid.
Definition: PengRobinsonParams.hpp:50
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
void updateMix_(const FluidState &fluidState, unsigned phaseIdx)
Update all parameters of a phase which depend on the fluid composition.
Definition: Spe5ParameterCache.hpp:263
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