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);
198 Scalar value = FluidSystem::density(fluidState, paramCache, phaseIdx);
199 fluidState.setDensity(phaseIdx, value);
201 value = FluidSystem::molarDensity(fluidState, paramCache, phaseIdx);
202 fluidState.setMolarDensity(phaseIdx, value);