14#ifndef DUMUX_MISCIBLE_MULTIPHASE_COMPOSITION_HH
15#define DUMUX_MISCIBLE_MULTIPHASE_COMPOSITION_HH
17#include <dune/common/fvector.hh>
18#include <dune/common/fmatrix.hh>
45template <
class Scalar,
class Flu
idSystem>
48 static constexpr int numPhases = FluidSystem::numPhases;
49 static constexpr int numComponents = FluidSystem::numComponents;
50 static const int numMajorComponents = FluidSystem::numPhases;
68 template <
class Flu
idState,
class ParameterCache>
69 static void solve(FluidState &fluidState,
70 ParameterCache ¶mCache,
71 int knownPhaseIdx = 0)
78 for (
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
79 assert(FluidSystem::isIdealMixture(phaseIdx));
86 Dune::FieldVector<Scalar, numComponents-numMajorComponents> xKnown(0.0);
87 for (
int knownCompIdx = 0; knownCompIdx < numComponents-numMajorComponents; ++knownCompIdx)
89 xKnown[knownCompIdx] = fluidState.moleFraction(knownPhaseIdx, knownCompIdx + numMajorComponents);
93 for (
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
94 paramCache.updatePhase(fluidState, phaseIdx);
99 for (
int compIdx = 0; compIdx < numComponents; ++compIdx) {
100 Scalar fugCoeff = FluidSystem::fugacityCoefficient(fluidState, paramCache, phaseIdx, compIdx);
101 fluidState.setFugacityCoefficient(phaseIdx, compIdx, fugCoeff);
108 Dune::FieldMatrix<Scalar, numComponents*numPhases, numComponents*numPhases> M(0.0);
109 Dune::FieldVector<Scalar, numComponents*numPhases> x(0.0);
110 Dune::FieldVector<Scalar, numComponents*numPhases> b(0.0);
114 for (
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
115 int rowIdx = numComponents*(numPhases - 1) + phaseIdx;
118 for (
int compIdx = 0; compIdx < numComponents; ++compIdx) {
119 int colIdx = phaseIdx*numComponents + compIdx;
121 M[rowIdx][colIdx] = 1.0;
128 for(
int knownCompIdx = 0; knownCompIdx < numComponents-numMajorComponents; ++knownCompIdx)
130 int rowIdx = numComponents + numPhases + knownCompIdx;
131 int colIdx = knownPhaseIdx*numComponents + knownCompIdx + numMajorComponents;
132 M[rowIdx][colIdx] = 1.0;
133 b[rowIdx] = xKnown[knownCompIdx];
138 for (
int compIdx = 0; compIdx < numComponents; ++compIdx)
140 int col1Idx = compIdx;
141 const auto entryPhase0 = fluidState.fugacityCoefficient(0, compIdx)*fluidState.pressure(0);
143 for (
unsigned int phaseIdx = 1; phaseIdx < numPhases; ++phaseIdx)
145 int rowIdx = (phaseIdx - 1)*numComponents + compIdx;
146 int col2Idx = phaseIdx*numComponents + compIdx;
147 M[rowIdx][col1Idx] = entryPhase0;
148 M[rowIdx][col2Idx] = -fluidState.fugacityCoefficient(phaseIdx, compIdx)*fluidState.pressure(phaseIdx);
153 for (
int compIdx = 0; compIdx < numComponents; compIdx++)
156 if (compIdx < numMajorComponents)
165 try { M.solve(x, b); }
166 catch (
const Dune::FMatrixError& e) {
168 "MiscibleMultiPhaseComposition: Failed to solve the linear equation system for the phase composition.");
173 for (
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
174 for (
int compIdx = 0; compIdx < numComponents; ++compIdx) {
175 int rowIdx = phaseIdx*numComponents + compIdx;
176 fluidState.setMoleFraction(phaseIdx, compIdx, x[rowIdx]);
178 paramCache.updateComposition(fluidState, phaseIdx);
181 fluidState.setDensity(phaseIdx, value);
184 fluidState.setMolarDensity(phaseIdx, value);
Computes the composition of all phases of a N-phase, N-component fluid system assuming that all N pha...
Definition: misciblemultiphasecomposition.hh:47
static void solve(FluidState &fluidState, ParameterCache ¶mCache, int knownPhaseIdx=0)
Computes the composition of all phases of a N-phase, N-component fluid system assuming that all N pha...
Definition: misciblemultiphasecomposition.hh:69
Exception thrown if a fixable numerical problem occurs.
Definition: exceptions.hh:27
Some exceptions thrown in DuMux
std::string molarDensity(int phaseIdx) noexcept
I/O name of molar density for multiphase systems.
Definition: name.hh:71
std::string density(int phaseIdx) noexcept
I/O name of density for multiphase systems.
Definition: name.hh:53