26#ifndef DUMUX_MISCIBLE_MULTIPHASE_COMPOSITION_HH
27#define DUMUX_MISCIBLE_MULTIPHASE_COMPOSITION_HH
29#include <dune/common/fvector.hh>
30#include <dune/common/fmatrix.hh>
58template <
class Scalar,
class Flu
idSystem>
61 static constexpr int numPhases = FluidSystem::numPhases;
62 static constexpr int numComponents = FluidSystem::numComponents;
63 static const int numMajorComponents = FluidSystem::numPhases;
81 template <
class Flu
idState,
class ParameterCache>
82 static void solve(FluidState &fluidState,
83 ParameterCache ¶mCache,
84 int knownPhaseIdx = 0)
91 for (
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
92 assert(FluidSystem::isIdealMixture(phaseIdx));
99 Dune::FieldVector<Scalar, numComponents-numMajorComponents> xKnown(0.0);
100 for (
int knownCompIdx = 0; knownCompIdx < numComponents-numMajorComponents; ++knownCompIdx)
102 xKnown[knownCompIdx] = fluidState.moleFraction(knownPhaseIdx, knownCompIdx + numMajorComponents);
106 for (
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
107 paramCache.updatePhase(fluidState, phaseIdx);
112 for (
int compIdx = 0; compIdx < numComponents; ++compIdx) {
113 Scalar fugCoeff = FluidSystem::fugacityCoefficient(fluidState, paramCache, phaseIdx, compIdx);
114 fluidState.setFugacityCoefficient(phaseIdx, compIdx, fugCoeff);
121 Dune::FieldMatrix<Scalar, numComponents*numPhases, numComponents*numPhases> M(0.0);
122 Dune::FieldVector<Scalar, numComponents*numPhases> x(0.0);
123 Dune::FieldVector<Scalar, numComponents*numPhases> b(0.0);
127 for (
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
128 int rowIdx = numComponents*(numPhases - 1) + phaseIdx;
131 for (
int compIdx = 0; compIdx < numComponents; ++compIdx) {
132 int colIdx = phaseIdx*numComponents + compIdx;
134 M[rowIdx][colIdx] = 1.0;
141 for(
int knownCompIdx = 0; knownCompIdx < numComponents-numMajorComponents; ++knownCompIdx)
143 int rowIdx = numComponents + numPhases + knownCompIdx;
144 int colIdx = knownPhaseIdx*numComponents + knownCompIdx + numMajorComponents;
145 M[rowIdx][colIdx] = 1.0;
146 b[rowIdx] = xKnown[knownCompIdx];
151 for (
int compIdx = 0; compIdx < numComponents; ++compIdx)
153 int col1Idx = compIdx;
154 const auto entryPhase0 = fluidState.fugacityCoefficient(0, compIdx)*fluidState.pressure(0);
156 for (
unsigned int phaseIdx = 1; phaseIdx < numPhases; ++phaseIdx)
158 int rowIdx = (phaseIdx - 1)*numComponents + compIdx;
159 int col2Idx = phaseIdx*numComponents + compIdx;
160 M[rowIdx][col1Idx] = entryPhase0;
161 M[rowIdx][col2Idx] = -fluidState.fugacityCoefficient(phaseIdx, compIdx)*fluidState.pressure(phaseIdx);
166 for (
int compIdx = 0; compIdx < numComponents; compIdx++)
169 if (compIdx < numMajorComponents)
178 try { M.solve(x, b); }
179 catch (Dune::FMatrixError & e) {
181 "Matrix for composition of phases could not be solved. \n"
182 "Throwing NumericalProblem for trying with smaller timestep.");
185 std::cerr <<
"Unknown exception thrown!\n";
191 for (
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
192 for (
int compIdx = 0; compIdx < numComponents; ++compIdx) {
193 int rowIdx = phaseIdx*numComponents + compIdx;
194 fluidState.setMoleFraction(phaseIdx, compIdx, x[rowIdx]);
196 paramCache.updateComposition(fluidState, phaseIdx);
199 fluidState.setDensity(phaseIdx, value);
202 fluidState.setMolarDensity(phaseIdx, value);
Some exceptions thrown in DuMux
Some templates to wrap the valgrind macros.
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
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
Exception thrown if a fixable numerical problem occurs.
Definition: exceptions.hh:39
Computes the composition of all phases of a N-phase, N-component fluid system assuming that all N pha...
Definition: misciblemultiphasecomposition.hh:60
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:82