3.3.0
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
compositionalflash.hh
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program 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 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
25#ifndef DUMUX_COMPOSITIONAL_FLASH_HH
26#define DUMUX_COMPOSITIONAL_FLASH_HH
27
28#include <dune/common/fvector.hh>
29
31
32namespace Dumux {
33
49template <class Scalar, class FluidSystem>
51{
53
54 enum { numPhases = FluidSystem::numPhases,
55 numComponents = FluidSystem::numComponents
56 };
57
58 enum{
59 phase0Idx = FluidSystem::phase0Idx,
60 phase1Idx = FluidSystem::phase1Idx,
61 comp0Idx = FluidSystem::comp0Idx,
62 comp1Idx = FluidSystem::comp1Idx
63 };
64
65public:
66 using ComponentVector = Dune::FieldVector<Scalar, numComponents>;
67 using PhaseVector = Dune::FieldVector<Scalar, numPhases>;
68
69 template<class FluidState>
70 [[deprecated("Use concentrationFlash2p2c without porosity argument. Will be removed after 3.3")]]
71 static void concentrationFlash2p2c(FluidState &fluidState,
72 const Scalar &Z0,
73 const PhaseVector &phasePressure,
74 const Scalar &porosity,
75 const Scalar &temperature)
76 {
77 concentrationFlash2p2c(fluidState, Z0, phasePressure, temperature);
78 }
79
102 template<class FluidState>
103 static void concentrationFlash2p2c(FluidState& fluidState,
104 const Scalar Z0,
105 const PhaseVector& phasePressure,
106 const Scalar temperature)
107 {
108#ifndef NDEBUG
109 // this solver can only handle fluid systems which
110 // assume ideal mixtures of all fluids.
111 for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
112 assert(FluidSystem::isIdealMixture(phaseIdx));
113
114 }
115#endif
116
117 // set the temperature, pressure
118 fluidState.setTemperature(temperature);
119 fluidState.setPressure(phase0Idx, phasePressure[phase0Idx]);
120 fluidState.setPressure(phase1Idx, phasePressure[phase1Idx]);
121
122 // mole equilibrium ratios k for in case first phase is reference phase
123 const Scalar k10 = FluidSystem::fugacityCoefficient(fluidState, phase0Idx, comp0Idx) * fluidState.pressure(phase0Idx)
124 / (FluidSystem::fugacityCoefficient(fluidState, phase1Idx, comp0Idx) * fluidState.pressure(phase1Idx));
125 const Scalar k11 = FluidSystem::fugacityCoefficient(fluidState, phase0Idx, comp1Idx) * fluidState.pressure(phase0Idx)
126 / (FluidSystem::fugacityCoefficient(fluidState, phase1Idx, comp1Idx) * fluidState.pressure(phase1Idx));
127
128 // get mole fraction from equilibrium constants
129 fluidState.setMoleFraction(phase0Idx, comp0Idx, ((1. - k11) / (k10 - k11)));
130 fluidState.setMoleFraction(phase1Idx, comp0Idx, (fluidState.moleFraction(phase0Idx,comp0Idx) * k10));
131 fluidState.setMoleFraction(phase0Idx, comp1Idx, 1.0 - fluidState.moleFraction(phase0Idx,comp0Idx));
132 fluidState.setMoleFraction(phase1Idx, comp1Idx, 1.0 - fluidState.moleFraction(phase1Idx,comp0Idx));
133
134 // mass equilibrium ratios K for in case first phase is reference phase
135 const Scalar K10 = fluidState.massFraction(phase1Idx, comp0Idx) / fluidState.massFraction(phase0Idx, comp0Idx);
136 const Scalar K11 = (1. - fluidState.massFraction(phase1Idx, comp0Idx)) / (1. - fluidState.massFraction(phase0Idx, comp0Idx));
137
138 // phase mass fraction Nu (ratio of phase mass to total phase mass) of first phase
139 const Scalar Nu0 = 1. + ((Z0 * (K10 - 1.)) + ((1. - Z0) * (K11 - 1.))) / ((K11 - 1.) * (K10 - 1.));
140
141 // an array of the phase mass fractions from which we will compute the saturations
142 std::array<Scalar, 2> phaseMassFraction;
143
144 // check phase presence
145 if (Nu0 > 0. && Nu0 < 1.) // two phases present
146 phaseMassFraction[phase0Idx] = Nu0;
147 else if (Nu0 <= 0.) // only second phase present
148 {
149 phaseMassFraction[phase0Idx] = 0.0; // no first phase
150 fluidState.setMassFraction(phase1Idx,comp0Idx, Z0); // assign complete mass dissolved into second phase
151 }
152 else // only first phase present
153 {
154 phaseMassFraction[phase0Idx] = 1.0; // no second phase
155 fluidState.setMassFraction(phase0Idx, comp0Idx, Z0); // assign complete mass dissolved into first phase
156 }
157
158 // complete phase mass fractions
159 phaseMassFraction[phase1Idx] = 1.0 - phaseMassFraction[phase0Idx];
160
161 // get densities with correct composition
162 fluidState.setDensity(phase0Idx, FluidSystem::density(fluidState, phase0Idx));
163 fluidState.setDensity(phase1Idx, FluidSystem::density(fluidState, phase1Idx));
164 fluidState.setMolarDensity(phase0Idx, FluidSystem::molarDensity(fluidState, phase0Idx));
165 fluidState.setMolarDensity(phase1Idx, FluidSystem::molarDensity(fluidState, phase1Idx));
166
167 fluidState.setViscosity(phase0Idx, FluidSystem::viscosity(fluidState, phase0Idx));
168 fluidState.setViscosity(phase1Idx, FluidSystem::viscosity(fluidState, phase1Idx));
169
170 Scalar sw = phaseMassFraction[phase0Idx] / fluidState.density(phase0Idx);
171 sw /= (phaseMassFraction[phase0Idx] / fluidState.density(phase0Idx)
172 + phaseMassFraction[phase1Idx] / fluidState.density(phase1Idx));
173 fluidState.setSaturation(phase0Idx, sw);
174 fluidState.setSaturation(phase1Idx, 1.0-sw);
175 }
176
191 static void concentrationFlash1p2c(FluidState1p2c& fluidState, const Scalar& Z0,const Dune::FieldVector<Scalar,numPhases>
192 phasePressure,const int presentPhaseIdx, const Scalar& temperature)
193 {
194 // set the temperature, pressure
195 fluidState.setTemperature(temperature);
196 fluidState.setPressure(phase0Idx, phasePressure[phase0Idx]);
197 fluidState.setPressure(phase1Idx, phasePressure[phase1Idx]);
198
199 fluidState.setPresentPhaseIdx(presentPhaseIdx);
200 fluidState.setMassFraction(presentPhaseIdx,comp0Idx, Z0);
201
202 // transform mass to mole fractions
203 fluidState.setMoleFraction(presentPhaseIdx, comp0Idx, Z0 / FluidSystem::molarMass(comp0Idx)
204 / (Z0 / FluidSystem::molarMass(comp0Idx) + (1. - Z0) / FluidSystem::molarMass(comp1Idx)));
205
206 fluidState.setAverageMolarMass(presentPhaseIdx,
207 fluidState.massFraction(presentPhaseIdx, comp0Idx) * FluidSystem::molarMass(comp0Idx)
208 + fluidState.massFraction(presentPhaseIdx, comp1Idx) * FluidSystem::molarMass(comp1Idx));
209
210 fluidState.setDensity(presentPhaseIdx, FluidSystem::density(fluidState, presentPhaseIdx));
211 fluidState.setMolarDensity(presentPhaseIdx, FluidSystem::molarDensity(fluidState, presentPhaseIdx));
212
213 fluidState.setViscosity(presentPhaseIdx, FluidSystem::viscosity(fluidState, presentPhaseIdx));
214 }
216
217 template<class FluidState>
218 [[deprecated("Use saturationFlash2p2c without porosity argument. Will be removed after 3.3")]]
219 static void saturationFlash2p2c(FluidState &fluidState,
220 const Scalar &saturation,
221 const PhaseVector &phasePressure,
222 const Scalar &porosity,
223 const Scalar &temperature)
224 {
225 saturationFlash2p2c(fluidState, saturation, phasePressure, temperature);
226 }
227
243 template<class FluidState>
244 static void saturationFlash2p2c(FluidState& fluidState,
245 const Scalar saturation,
246 const PhaseVector& phasePressure,
247 const Scalar temperature)
248 {
249#ifndef NDEBUG
250 // this solver can only handle fluid systems which
251 // assume ideal mixtures of all fluids.
252 for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
253 assert(FluidSystem::isIdealMixture(phaseIdx));
254
255 }
256#endif
257
258 // set the temperature, pressure
259 fluidState.setTemperature(temperature);
260 fluidState.setPressure(phase0Idx, phasePressure[phase0Idx]);
261 fluidState.setPressure(phase1Idx, phasePressure[phase1Idx]);
262
263 // mole equilibrium ratios k for in case first phase is reference phase
264 const Scalar k10 = FluidSystem::fugacityCoefficient(fluidState, phase0Idx, comp0Idx) * fluidState.pressure(phase0Idx)
265 / (FluidSystem::fugacityCoefficient(fluidState, phase1Idx, comp0Idx) * fluidState.pressure(phase1Idx));
266 const Scalar k11 = FluidSystem::fugacityCoefficient(fluidState, phase0Idx, comp1Idx) * fluidState.pressure(phase0Idx)
267 / (FluidSystem::fugacityCoefficient(fluidState, phase1Idx, comp1Idx) * fluidState.pressure(phase1Idx));
268
269 // get mole fraction from equilibrium constants
270 fluidState.setMoleFraction(phase0Idx,comp0Idx, ((1. - k11) / (k10 - k11)));
271 fluidState.setMoleFraction(phase1Idx,comp0Idx, (fluidState.moleFraction(phase0Idx,comp0Idx) * k10));
272 fluidState.setMoleFraction(phase0Idx, comp1Idx, 1.0 - fluidState.moleFraction(phase0Idx,comp0Idx));
273 fluidState.setMoleFraction(phase1Idx, comp1Idx, 1.0 - fluidState.moleFraction(phase1Idx,comp0Idx));
274
275 // get densities with correct composition
276 fluidState.setDensity(phase0Idx, FluidSystem::density(fluidState, phase0Idx));
277 fluidState.setDensity(phase1Idx, FluidSystem::density(fluidState, phase1Idx));
278 fluidState.setMolarDensity(phase0Idx, FluidSystem::molarDensity(fluidState, phase0Idx));
279 fluidState.setMolarDensity(phase1Idx, FluidSystem::molarDensity(fluidState, phase1Idx));
280
281 fluidState.setViscosity(phase0Idx, FluidSystem::viscosity(fluidState, phase0Idx));
282 fluidState.setViscosity(phase1Idx, FluidSystem::viscosity(fluidState, phase1Idx));
283
284 // set saturation
285 fluidState.setSaturation(phase0Idx, saturation);
286 fluidState.setSaturation(phase1Idx, 1.0-saturation);
287 }
289};
290
291} // end namespace Dumux
292
293#endif
Calculates phase state for a single phase but two-component state.
Definition: adapt.hh:29
std::string temperature() noexcept
I/O name of temperature for equilibrium models.
Definition: name.hh:51
std::string saturation(int phaseIdx) noexcept
I/O name of saturation for multiphase systems.
Definition: name.hh:43
std::string viscosity(int phaseIdx) noexcept
I/O name of viscosity for multiphase systems.
Definition: name.hh:74
std::string molarDensity(int phaseIdx) noexcept
I/O name of molar density for multiphase systems.
Definition: name.hh:83
std::string density(int phaseIdx) noexcept
I/O name of density for multiphase systems.
Definition: name.hh:65
std::string porosity() noexcept
I/O name of porosity.
Definition: name.hh:139
Flash calculation routines for compositional sequential models.
Definition: compositionalflash.hh:51
static void saturationFlash2p2c(FluidState &fluidState, const Scalar &saturation, const PhaseVector &phasePressure, const Scalar &porosity, const Scalar &temperature)
Definition: compositionalflash.hh:219
static void saturationFlash2p2c(FluidState &fluidState, const Scalar saturation, const PhaseVector &phasePressure, const Scalar temperature)
2p2c flash for constant p & T if the saturation instead of concentration (feed mass fraction) is know...
Definition: compositionalflash.hh:244
Dune::FieldVector< Scalar, numComponents > ComponentVector
Definition: compositionalflash.hh:66
static void concentrationFlash1p2c(FluidState1p2c &fluidState, const Scalar &Z0, const Dune::FieldVector< Scalar, numPhases > phasePressure, const int presentPhaseIdx, const Scalar &temperature)
The simplest possible update routine for 1p2c "flash" calculations.
Definition: compositionalflash.hh:191
Dune::FieldVector< Scalar, numPhases > PhaseVector
Definition: compositionalflash.hh:67
static void concentrationFlash2p2c(FluidState &fluidState, const Scalar Z0, const PhaseVector &phasePressure, const Scalar temperature)
2p2c Flash for constant p & T if concentration (feed mass fraction) is given.
Definition: compositionalflash.hh:103
static void concentrationFlash2p2c(FluidState &fluidState, const Scalar &Z0, const PhaseVector &phasePressure, const Scalar &porosity, const Scalar &temperature)
Definition: compositionalflash.hh:71
Container for compositional variables in a 1p2c situation.
Definition: pseudo1p2c.hh:44
void setAverageMolarMass(int phaseIdx, Scalar value)
Set the average molar mass of a fluid phase [kg/mol].
Definition: pseudo1p2c.hh:276
void setMassFraction(int phaseIdx, int compIdx, Scalar value)
Sets the mass fraction of a component in a phase.
Definition: pseudo1p2c.hh:216
void setPresentPhaseIdx(int phaseIdx)
Sets the phase Index that is present in this fluidState.
Definition: pseudo1p2c.hh:257
void setPressure(int phaseIdx, Scalar value)
Sets the phase pressure .
Definition: pseudo1p2c.hh:282
void setDensity(int phaseIdx, Scalar value)
Sets the density of a phase .
Definition: pseudo1p2c.hh:235
void setViscosity(int phaseIdx, Scalar value)
Sets the viscosity of a phase .
Definition: pseudo1p2c.hh:203
void setMolarDensity(int phaseIdx, Scalar value)
Set the molar density of a phase .
Definition: pseudo1p2c.hh:247
void setTemperature(Scalar value)
Sets the temperature.
Definition: pseudo1p2c.hh:265
Scalar massFraction(int phaseIdx, int compIdx) const
Returns the mass fraction of component in fluid phase in .
Definition: pseudo1p2c.hh:121
void setMoleFraction(int phaseIdx, int compIdx, Scalar value)
Sets the molar fraction of a component in a fluid phase.
Definition: pseudo1p2c.hh:226