55 bool update_(
typename VolumeVariables::PrimaryVariables& priVars,
56 const VolumeVariables& volVars,
57 IndexType dofIdxGlobal,
58 const GlobalPosition& globalPos)
60 using Scalar =
typename VolumeVariables::PrimaryVariables::value_type;
62 using FluidSystem =
typename VolumeVariables::FluidSystem;
63 static constexpr int phase0Idx = FluidSystem::phase0Idx;
64 static constexpr int phase1Idx = FluidSystem::phase1Idx;
65 static constexpr int comp0Idx = FluidSystem::comp0Idx;
66 static constexpr int comp1Idx = FluidSystem::comp1Idx;
68 static constexpr bool useMoles = VolumeVariables::useMoles();
69 static constexpr auto formulation = VolumeVariables::priVarFormulation();
71 "Chosen TwoPFormulation not supported!");
73 using Indices =
typename VolumeVariables::Indices;
74 static constexpr int switchIdx = Indices::switchIdx;
77 bool wouldSwitch =
false;
78 int phasePresence = priVars.state();
79 int newPhasePresence = phasePresence;
82 typename FluidSystem::ParameterCache paramCache;
85 if (phasePresence == Indices::secondPhaseOnly)
88 Scalar xnw = volVars.moleFraction(phase1Idx, comp0Idx);
89 Scalar xnwMax = FluidSystem::equilibriumMoleFraction(volVars.fluidState(), paramCache, phase1Idx);
103 std::cout <<
"First phase (" << FluidSystem::phaseName(phase0Idx) <<
") appears at dof " << dofIdxGlobal
104 <<
", coordinates: " << globalPos
105 <<
", x^" << FluidSystem::componentName(comp0Idx) <<
"_" << FluidSystem::phaseName(phase1Idx) <<
" > x_equilibrium: "
106 << xnw <<
" > " << xnwMax << std::endl;
107 newPhasePresence = Indices::bothPhases;
109 priVars[switchIdx] = 0.0;
111 priVars[switchIdx] = 1.0;
114 else if (phasePresence == Indices::firstPhaseOnly)
117 Scalar xwn = volVars.moleFraction(phase0Idx, comp1Idx);
118 Scalar xwnMax = FluidSystem::equilibriumMoleFraction(volVars.fluidState(), paramCache, phase0Idx);
132 std::cout <<
"Second phase (" << FluidSystem::phaseName(phase1Idx) <<
") appears at dof " << dofIdxGlobal
133 <<
", coordinates: " << globalPos
134 <<
", x^" << FluidSystem::componentName(comp1Idx) <<
"_" << FluidSystem::phaseName(phase0Idx) <<
" > x_equilibrium: "
135 << xwn <<
" > " << xwnMax << std::endl;
136 newPhasePresence = Indices::bothPhases;
138 priVars[switchIdx] = 0.999;
140 priVars[switchIdx] = 0.001;
144 else if (phasePresence == Indices::bothPhases)
150 if (volVars.saturation(phase1Idx) <= Smin)
155 std::cout <<
"Second phase (" << FluidSystem::phaseName(phase1Idx) <<
") disappears at dof " << dofIdxGlobal
156 <<
", coordinates: " << globalPos
157 <<
", S_" << FluidSystem::phaseName(phase1Idx) <<
": " << volVars.saturation(phase1Idx)
159 newPhasePresence = Indices::firstPhaseOnly;
162 priVars[switchIdx] = volVars.moleFraction(phase0Idx, comp1Idx);
164 priVars[switchIdx] = volVars.massFraction(phase0Idx, comp1Idx);
166 else if (volVars.saturation(phase0Idx) <= Smin)
171 std::cout <<
"First phase (" << FluidSystem::phaseName(phase0Idx) <<
") disappears at dof " << dofIdxGlobal
172 <<
", coordinates: " << globalPos
173 <<
", S_" << FluidSystem::phaseName(phase0Idx) <<
": " << volVars.saturation(phase0Idx)
175 newPhasePresence = Indices::secondPhaseOnly;
178 priVars[switchIdx] = volVars.moleFraction(phase1Idx, comp0Idx);
180 priVars[switchIdx] = volVars.massFraction(phase1Idx, comp0Idx);
184 priVars.setState(newPhasePresence);
186 return phasePresence != newPhasePresence;