version 3.10-dev
nonequilibrium.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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
14#ifndef DUMUX_NONEQUILIBRIUM_FLUID_STATE_HH
15#define DUMUX_NONEQUILIBRIUM_FLUID_STATE_HH
16
17#include <cmath>
18#include <algorithm>
19#include <dune/common/exceptions.hh>
20
21namespace Dumux {
22
29template <class ScalarType, class FluidSystem>
31{
32public:
33 static constexpr int numPhases = FluidSystem::numPhases;
34 static constexpr int numComponents = FluidSystem::numComponents;
35
37 using Scalar = ScalarType;
38
39 /*****************************************************
40 * Generic access to fluid properties (No assumptions
41 * on thermodynamic equilibrium required)
42 *****************************************************/
47 int wettingPhase() const { return wPhaseIdx_; }
56 Scalar saturation(int phaseIdx) const
57 { return saturation_[phaseIdx]; }
58
68 Scalar moleFraction(int phaseIdx, int compIdx) const
69 { return moleFraction_[phaseIdx][compIdx]; }
70
71
87 Scalar massFraction(int phaseIdx, int compIdx) const
88 {
89 using std::abs;
90 using std::max;
91 return abs(sumMoleFractions_[phaseIdx])
92 * moleFraction_[phaseIdx][compIdx]
93 * FluidSystem::molarMass(compIdx)
94 / max(1e-40, abs(averageMolarMass_[phaseIdx]));
95 }
96
105 Scalar averageMolarMass(int phaseIdx) const
106 { return averageMolarMass_[phaseIdx]; }
107
117 Scalar molarity(int phaseIdx, int compIdx) const
118 { return molarDensity(phaseIdx)*moleFraction(phaseIdx, compIdx); }
119
123 Scalar fugacityCoefficient(int phaseIdx, int compIdx) const
124 { return fugacityCoefficient_[phaseIdx][compIdx]; }
125
143 Scalar fugacity(int phaseIdx, int compIdx) const
144 {
145 return pressure_[phaseIdx]
146 *fugacityCoefficient_[phaseIdx][compIdx]
147 *moleFraction_[phaseIdx][compIdx];
148 }
149
150 Scalar fugacity(int compIdx) const
151 { return fugacity(0, compIdx); }
152
158 Scalar molarVolume(int phaseIdx) const
159 { return 1.0/molarDensity(phaseIdx); }
160
165 Scalar density(int phaseIdx) const
166 { return density_[phaseIdx]; }
167
176 Scalar molarDensity(int phaseIdx) const
177 { return molarDensity_[phaseIdx]; }
178
182 Scalar temperature(const int phaseIdx) const
183 { return temperature_[phaseIdx]; }
184
189 { return temperatureEquil_ ; }
190
194 Scalar pressure(int phaseIdx) const
195 { return pressure_[phaseIdx]; }
196
201 Scalar partialPressure(int phaseIdx, int compIdx) const
202 {
203 assert(FluidSystem::isGas(phaseIdx));
204 return moleFraction(phaseIdx, compIdx) * pressure(phaseIdx);
205 }
206
210 Scalar enthalpy(int phaseIdx) const
211 { return enthalpy_[phaseIdx]; }
212
220 Scalar internalEnergy(int phaseIdx) const
221 { return enthalpy_[phaseIdx] - pressure(phaseIdx)/density(phaseIdx); }
222
226 Scalar viscosity(int phaseIdx) const
227 { return viscosity_[phaseIdx]; }
228
229 /*****************************************************
230 * Setter methods. Note that these are not part of the
231 * generic FluidState interface but specific for each
232 * implementation...
233 *****************************************************/
237 void setTemperature(int phaseIdx, Scalar value)
238 { temperature_[phaseIdx] = value; }
239
244 { temperatureEquil_ = value; }
245
249 void setPressure(int phaseIdx, Scalar value)
250 { pressure_[phaseIdx] = value; }
251
255 void setSaturation(int phaseIdx, Scalar value)
256 { saturation_[phaseIdx] = value; }
257
261 void setMoleFraction(int phaseIdx, int compIdx, Scalar value)
262 {
263 using std::isfinite;
264 if (isfinite(averageMolarMass_[phaseIdx]))
265 {
266 Scalar delta = value - moleFraction_[phaseIdx][compIdx];
267
268 moleFraction_[phaseIdx][compIdx] = value;
269
270 sumMoleFractions_[phaseIdx] += delta;
271 averageMolarMass_[phaseIdx] += delta*FluidSystem::molarMass(compIdx);
272 }
273 else
274 {
275 moleFraction_[phaseIdx][compIdx] = value;
276
277 // re-calculate the mean molar mass
278 sumMoleFractions_[phaseIdx] = 0.0;
279 averageMolarMass_[phaseIdx] = 0.0;
280 for (int compJIdx = 0; compJIdx < numComponents; ++compJIdx) {
281 sumMoleFractions_[phaseIdx] += moleFraction_[phaseIdx][compJIdx];
282 averageMolarMass_[phaseIdx] += moleFraction_[phaseIdx][compJIdx]*FluidSystem::molarMass(compJIdx);
283 }
284 }
285 }
286
292 void setMassFraction(int phaseIdx, int compIdx, Scalar value)
293 {
294 if (numComponents != 2)
295 DUNE_THROW(Dune::NotImplemented, "This currently only works for 2 components.");
296 else
297 {
298 // calculate average molar mass of the gas phase
299 Scalar M1 = FluidSystem::molarMass(compIdx);
300 Scalar M2 = FluidSystem::molarMass(1-compIdx);
301 Scalar X2 = 1.0-value;
302 Scalar avgMolarMass = M1*M2/(M2 + X2*(M1 - M2));
303
304 moleFraction_[phaseIdx][compIdx] = value * avgMolarMass / M1;
305 moleFraction_[phaseIdx][1-compIdx] = 1.0-moleFraction_[phaseIdx][compIdx];
306
307 // re-calculate the mean molar mass
308 sumMoleFractions_[phaseIdx] = 0.0;
309 averageMolarMass_[phaseIdx] = 0.0;
310 for (int compJIdx = 0; compJIdx < numComponents; ++compJIdx) {
311 sumMoleFractions_[phaseIdx] += moleFraction_[phaseIdx][compJIdx];
312 averageMolarMass_[phaseIdx] += moleFraction_[phaseIdx][compJIdx]*FluidSystem::molarMass(compJIdx);
313 }
314 }
315 }
316
320 void setFugacityCoefficient(int phaseIdx, int compIdx, Scalar value)
321 { fugacityCoefficient_[phaseIdx][compIdx] = value; }
322
326 void setDensity(int phaseIdx, Scalar value)
327 { density_[phaseIdx] = value; }
328
332 void setMolarDensity(int phaseIdx, Scalar value)
333 { molarDensity_[phaseIdx] = value; }
334
338 void setEnthalpy(int phaseIdx, Scalar value)
339 { enthalpy_[phaseIdx] = value; }
340
344 void setViscosity(int phaseIdx, Scalar value)
345 { viscosity_[phaseIdx] = value; }
346
350 void setWettingPhase(int phaseIdx)
351 { wPhaseIdx_ = phaseIdx; }
352
358 template <class FluidState>
359 void assign(const FluidState& fs)
360 {
361 for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
362 {
363 averageMolarMass_[phaseIdx] = 0;
364 sumMoleFractions_[phaseIdx] = 0;
365 for (int compIdx = 0; compIdx < numComponents; ++compIdx)
366 {
367 moleFraction_[phaseIdx][compIdx] = fs.moleFraction(phaseIdx, compIdx);
368 fugacityCoefficient_[phaseIdx][compIdx] = fs.fugacityCoefficient(phaseIdx, compIdx);
369 averageMolarMass_[phaseIdx] += moleFraction_[phaseIdx][compIdx]*FluidSystem::molarMass(compIdx);
370 sumMoleFractions_[phaseIdx] += moleFraction_[phaseIdx][compIdx];
371 }
372 pressure_[phaseIdx] = fs.pressure(phaseIdx);
373 saturation_[phaseIdx] = fs.saturation(phaseIdx);
374 density_[phaseIdx] = fs.density(phaseIdx);
375 molarDensity_[phaseIdx] = fs.molarDensity(phaseIdx);
376 enthalpy_[phaseIdx] = fs.enthalpy(phaseIdx);
377 viscosity_[phaseIdx] = fs.viscosity(phaseIdx);
378 temperature_[phaseIdx] = fs.temperature(phaseIdx);
379 }
380 }
381
382protected:
395
396 // For porous medium flow models, here we ... the index of the wetting
397 // phase (needed for vapor pressure evaluation if kelvin equation is used)
399};
400
401} // end namespace Dumux
402
403#endif
Represents all relevant thermodynamic quantities of a multi-phase, multi-component fluid system witho...
Definition: nonequilibrium.hh:31
Scalar temperatureEquil_
Definition: nonequilibrium.hh:394
ScalarType Scalar
export the scalar type
Definition: nonequilibrium.hh:37
void setPressure(int phaseIdx, Scalar value)
Set the fluid pressure of a phase .
Definition: nonequilibrium.hh:249
Scalar viscosity(int phaseIdx) const
The dynamic viscosity of fluid phase in .
Definition: nonequilibrium.hh:226
Scalar molarDensity_[numPhases]
Definition: nonequilibrium.hh:390
void setMassFraction(int phaseIdx, int compIdx, Scalar value)
Set the mass fraction of a component in a phase and update the average molar mass according to the ...
Definition: nonequilibrium.hh:292
Scalar density(int phaseIdx) const
The mass density of the fluid phase in .
Definition: nonequilibrium.hh:165
Scalar fugacity(int compIdx) const
Definition: nonequilibrium.hh:150
void setDensity(int phaseIdx, Scalar value)
Set the density of a phase .
Definition: nonequilibrium.hh:326
static constexpr int numPhases
Definition: nonequilibrium.hh:33
void setEnthalpy(int phaseIdx, Scalar value)
Set the specific enthalpy of a phase .
Definition: nonequilibrium.hh:338
static constexpr int numComponents
Definition: nonequilibrium.hh:34
int wettingPhase() const
Returns the index of the wetting phase in the fluid-solid configuration (for porous medium systems).
Definition: nonequilibrium.hh:47
void setMolarDensity(int phaseIdx, Scalar value)
Set the molar density of a phase .
Definition: nonequilibrium.hh:332
Scalar pressure(int phaseIdx) const
The pressure of a fluid phase in .
Definition: nonequilibrium.hh:194
Scalar fugacityCoefficient(int phaseIdx, int compIdx) const
The fugacity coefficient of component in fluid phase in .
Definition: nonequilibrium.hh:123
void setTemperature(int phaseIdx, Scalar value)
Set the temperature of a fluid phase.
Definition: nonequilibrium.hh:237
Scalar averageMolarMass(int phaseIdx) const
The average molar mass of phase in .
Definition: nonequilibrium.hh:105
Scalar moleFraction_[numPhases][numComponents]
Definition: nonequilibrium.hh:383
void assign(const FluidState &fs)
Retrieve all parameters from an arbitrary fluid state.
Definition: nonequilibrium.hh:359
void setFugacityCoefficient(int phaseIdx, int compIdx, Scalar value)
Set the fugacity of a component in a phase .
Definition: nonequilibrium.hh:320
void setMoleFraction(int phaseIdx, int compIdx, Scalar value)
Set the mole fraction of a component in a phase .
Definition: nonequilibrium.hh:261
Scalar internalEnergy(int phaseIdx) const
The specific internal energy of a fluid phase in .
Definition: nonequilibrium.hh:220
Scalar temperature(const int phaseIdx) const
The absolute temperature of a fluid phase in .
Definition: nonequilibrium.hh:182
Scalar partialPressure(int phaseIdx, int compIdx) const
The partial pressure of a component in a phase .
Definition: nonequilibrium.hh:201
Scalar pressure_[numPhases]
Definition: nonequilibrium.hh:387
Scalar molarDensity(int phaseIdx) const
The molar density of a fluid phase in .
Definition: nonequilibrium.hh:176
Scalar saturation_[numPhases]
Definition: nonequilibrium.hh:388
Scalar temperature_[numPhases]
Definition: nonequilibrium.hh:393
Scalar molarVolume(int phaseIdx) const
The molar volume of a fluid phase in .
Definition: nonequilibrium.hh:158
Scalar sumMoleFractions_[numPhases]
Definition: nonequilibrium.hh:386
Scalar enthalpy_[numPhases]
Definition: nonequilibrium.hh:391
Scalar density_[numPhases]
Definition: nonequilibrium.hh:389
Scalar fugacity(int phaseIdx, int compIdx) const
The fugacity of component in fluid phase in .
Definition: nonequilibrium.hh:143
void setSaturation(int phaseIdx, Scalar value)
Set the saturation of a phase .
Definition: nonequilibrium.hh:255
void setTemperature(Scalar value)
Set the temperature of all fluid phases.
Definition: nonequilibrium.hh:243
Scalar temperature() const
Get the equilibrium temperature of the fluid phases.
Definition: nonequilibrium.hh:188
Scalar saturation(int phaseIdx) const
Returns the saturation of a fluid phase in .
Definition: nonequilibrium.hh:56
Scalar enthalpy(int phaseIdx) const
The specific enthalpy of a fluid phase in .
Definition: nonequilibrium.hh:210
void setWettingPhase(int phaseIdx)
Set the index of the wetting phase.
Definition: nonequilibrium.hh:350
Scalar averageMolarMass_[numPhases]
Definition: nonequilibrium.hh:385
Scalar molarity(int phaseIdx, int compIdx) const
The molar concentration of component in fluid phase in .
Definition: nonequilibrium.hh:117
int wPhaseIdx_
Definition: nonequilibrium.hh:398
void setViscosity(int phaseIdx, Scalar value)
Set the dynamic viscosity of a phase .
Definition: nonequilibrium.hh:344
Scalar moleFraction(int phaseIdx, int compIdx) const
Returns the molar fraction of the component in fluid phase in .
Definition: nonequilibrium.hh:68
Scalar viscosity_[numPhases]
Definition: nonequilibrium.hh:392
Scalar massFraction(int phaseIdx, int compIdx) const
Returns the mass fraction of component in fluid phase in .
Definition: nonequilibrium.hh:87
Scalar fugacityCoefficient_[numPhases][numComponents]
Definition: nonequilibrium.hh:384
Definition: adapt.hh:17