PTFlashParameterCache.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 2022 NORCE.
5 Copyright 2022 SINTEF Digital, Mathematics and Cybernetics.
6
7 This file is part of the Open Porous Media project (OPM).
8
9 OPM is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 2 of the License, or
12 (at your option) any later version.
13
14 OPM is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with OPM. If not, see <http://www.gnu.org/licenses/>.
21
22 Consult the COPYING file in the top-level source directory of this
23 module for the precise wording of the license and the list of
24 copyright holders.
25*/
30#ifndef OPM_PTFlash_PARAMETER_CACHE_HPP
31#define OPM_PTFlash_PARAMETER_CACHE_HPP
32
33#include <cassert>
34
38
39namespace Opm {
40
45template <class Scalar, class FluidSystem>
47 : public Opm::ParameterCacheBase<PTFlashParameterCache<Scalar, FluidSystem> >
48{
52
53 enum { numPhases = FluidSystem::numPhases };
54 enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
55 enum { gasPhaseIdx = FluidSystem::gasPhaseIdx};
56
57public:
59 using OilPhaseParams = Opm::PengRobinsonParamsMixture<Scalar, FluidSystem, oilPhaseIdx, /*useChi=*/false>;
61 using GasPhaseParams = Opm::PengRobinsonParamsMixture<Scalar, FluidSystem, gasPhaseIdx, /*useChi=*/false>;
62
64 {
65 VmUpToDate_[oilPhaseIdx] = false;
66 Valgrind::SetUndefined(Vm_[oilPhaseIdx]);
67 VmUpToDate_[gasPhaseIdx] = false;
68 Valgrind::SetUndefined(Vm_[gasPhaseIdx]);
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 // update the phase's molar volume
80 updateMolarVolume_(fluidState, phaseIdx);
81 }
82
84 template <class FluidState>
85 void updateSingleMoleFraction(const FluidState& fluidState,
86 unsigned phaseIdx,
87 unsigned compIdx)
88 {
89 if (phaseIdx == oilPhaseIdx)
90 oilPhaseParams_.updateSingleMoleFraction(fluidState, compIdx);
91 if (phaseIdx == gasPhaseIdx)
92 gasPhaseParams_.updateSingleMoleFraction(fluidState, compIdx);
93 else
94 return;
95
96 // update the phase's molar volume
97 updateMolarVolume_(fluidState, phaseIdx);
98 }
99
105 Scalar a(unsigned phaseIdx) const
106 {
107 switch (phaseIdx)
108 {
109 case oilPhaseIdx: return oilPhaseParams_.a();
110 case gasPhaseIdx: return gasPhaseParams_.a();
111 default:
112 throw std::logic_error("The a() parameter is only defined for "
113 "oil and gas phases");
114 };
115 }
116
122 Scalar b(unsigned phaseIdx) const
123 {
124 switch (phaseIdx)
125 {
126 case oilPhaseIdx: return oilPhaseParams_.b();
127 case gasPhaseIdx: return gasPhaseParams_.b();
128 default:
129 throw std::logic_error("The b() parameter is only defined for "
130 "oil and gas phase");
131 };
132 }
133
142 Scalar aPure(unsigned phaseIdx, unsigned compIdx) const
143 {
144 switch (phaseIdx)
145 {
146 case oilPhaseIdx: return oilPhaseParams_.pureParams(compIdx).a();
147 case gasPhaseIdx: return gasPhaseParams_.pureParams(compIdx).a();
148 default:
149 throw std::logic_error("The a() parameter is only defined for "
150 "oil and gas phase");
151 };
152 }
153
161 Scalar bPure(unsigned phaseIdx, unsigned compIdx) const
162 {
163 switch (phaseIdx)
164 {
165 case oilPhaseIdx: return oilPhaseParams_.pureParams(compIdx).b();
166 case gasPhaseIdx: return gasPhaseParams_.pureParams(compIdx).b();
167 default:
168 throw std::logic_error("The b() parameter is only defined for "
169 "oil and gas phase");
170 };
171 }
172
173
174
182 Scalar aCache(unsigned phaseIdx, unsigned compIdx, unsigned compJIdx) const
183 {
184 switch (phaseIdx)
185 {
186 case oilPhaseIdx: return oilPhaseParams_.getaCache(compIdx,compJIdx);
187 case gasPhaseIdx: return gasPhaseParams_.getaCache(compIdx,compJIdx);
188 default:
189 throw std::logic_error("The aCache() parameter is only defined for "
190 "oil and gas phase");
191 };
192 }
193
199 Scalar molarVolume(unsigned phaseIdx) const
200 { assert(VmUpToDate_[phaseIdx]); return Vm_[phaseIdx]; }
201
202
208 { return oilPhaseParams_; }
209
215 // { throw std::invalid_argument("gas phase does not exist");}
216 { return gasPhaseParams_; }
217
226 template <class FluidState>
227 void updateEosParams(const FluidState& fluidState,
228 unsigned phaseIdx,
229 int exceptQuantities = ParentType::None)
230 {
231 if (!(exceptQuantities & ParentType::Temperature))
232 {
233 updatePure_(fluidState, phaseIdx);
234 updateMix_(fluidState, phaseIdx);
235 VmUpToDate_[phaseIdx] = false;
236 }
237 else if (!(exceptQuantities & ParentType::Composition))
238 {
239 updateMix_(fluidState, phaseIdx);
240 VmUpToDate_[phaseIdx] = false;
241 }
242 else if (!(exceptQuantities & ParentType::Pressure)) {
243 VmUpToDate_[phaseIdx] = false;
244 }
245 }
246
247protected:
254 template <class FluidState>
255 void updatePure_(const FluidState& fluidState, unsigned phaseIdx)
256 {
257 Scalar T = fluidState.temperature(phaseIdx);
258 Scalar p = fluidState.pressure(phaseIdx);
259
260 switch (phaseIdx)
261 {
262 case oilPhaseIdx: oilPhaseParams_.updatePure(T, p); break;
263 case gasPhaseIdx: gasPhaseParams_.updatePure(T, p); break;
264 }
265 }
266
274 template <class FluidState>
275 void updateMix_(const FluidState& fluidState, unsigned phaseIdx)
276 {
277 Valgrind::CheckDefined(fluidState.averageMolarMass(phaseIdx));
278 switch (phaseIdx)
279 {
280 case oilPhaseIdx:
281 oilPhaseParams_.updateMix(fluidState);
282 break;
283 case gasPhaseIdx:
284 gasPhaseParams_.updateMix(fluidState);
285 break;
286 }
287 }
288
289 template <class FluidState>
290 void updateMolarVolume_(const FluidState& fluidState,
291 unsigned phaseIdx)
292 {
293 VmUpToDate_[phaseIdx] = true;
294
295 // calculate molar volume of the phase (we will need this for the
296 // fugacity coefficients and the density anyway)
297 switch (phaseIdx) {
298 case gasPhaseIdx: {
299 // calculate molar volumes for the given composition. although
300 // this isn't a Peng-Robinson parameter strictly speaking, the
301 // molar volume appears in basically every quantity the fluid
302 // system can get queried, so it is okay to calculate it
303 // here...
304 Vm_[gasPhaseIdx] =
306 *this,
307 phaseIdx,
308 /*isGasPhase=*/true);
309 break;
310 }
311 case oilPhaseIdx: {
312 // calculate molar volumes for the given composition. although
313 // this isn't a Peng-Robinson parameter strictly speaking, the
314 // molar volume appears in basically every quantity the fluid
315 // system can get queried, so it is okay to calculate it
316 // here...
317 Vm_[oilPhaseIdx] =
319 *this,
320 phaseIdx,
321 /*isGasPhase=*/false);
322
323 break;
324 }
325 };
326 }
327
328 bool VmUpToDate_[numPhases];
329 Scalar Vm_[numPhases];
330
333};
334
335} // namespace Opm
336
337#endif
Specifies the parameter cache used by the SPE-5 fluid system.
Definition: PTFlashParameterCache.hpp:48
OilPhaseParams oilPhaseParams_
Definition: PTFlashParameterCache.hpp:331
Scalar Vm_[numPhases]
Definition: PTFlashParameterCache.hpp:329
const OilPhaseParams & oilPhaseParams() const
Returns the Peng-Robinson mixture parameters for the oil phase.
Definition: PTFlashParameterCache.hpp:207
void updatePure_(const FluidState &fluidState, unsigned phaseIdx)
Update all parameters of a phase which only depend on temperature and/or pressure.
Definition: PTFlashParameterCache.hpp:255
Scalar molarVolume(unsigned phaseIdx) const
Returns the molar volume of a phase [m^3/mol].
Definition: PTFlashParameterCache.hpp:199
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: PTFlashParameterCache.hpp:85
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: PTFlashParameterCache.hpp:161
Scalar aCache(unsigned phaseIdx, unsigned compIdx, unsigned compJIdx) const
TODO.
Definition: PTFlashParameterCache.hpp:182
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: PTFlashParameterCache.hpp:275
void updatePhase(const FluidState &fluidState, unsigned phaseIdx, int exceptQuantities=ParentType::None)
Update all cached parameters of a specific fluid phase.
Definition: PTFlashParameterCache.hpp:73
Scalar a(unsigned phaseIdx) const
The Peng-Robinson attractive parameter for a phase.
Definition: PTFlashParameterCache.hpp:105
GasPhaseParams gasPhaseParams_
Definition: PTFlashParameterCache.hpp:332
bool VmUpToDate_[numPhases]
Definition: PTFlashParameterCache.hpp:328
Scalar aPure(unsigned phaseIdx, unsigned compIdx) const
The Peng-Robinson attractive parameter for a pure component given the same temperature and pressure o...
Definition: PTFlashParameterCache.hpp:142
PTFlashParameterCache()
Definition: PTFlashParameterCache.hpp:63
void updateMolarVolume_(const FluidState &fluidState, unsigned phaseIdx)
Definition: PTFlashParameterCache.hpp:290
Scalar b(unsigned phaseIdx) const
The Peng-Robinson covolume for a phase.
Definition: PTFlashParameterCache.hpp:122
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: PTFlashParameterCache.hpp:227
const GasPhaseParams & gasPhaseParams() const
Returns the Peng-Robinson mixture parameters for the gas phase.
Definition: PTFlashParameterCache.hpp:214
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
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
bool CheckDefined(const T &value)
Make valgrind complain if any of the memory occupied by an object is undefined.
Definition: Valgrind.hpp:74
void SetUndefined(const T &value)
Make the memory on which an object resides undefined in valgrind runs.
Definition: Valgrind.hpp:171
Definition: Air_Mesitylene.hpp:34