38 bool update_(
typename VolumeVariables::PrimaryVariables& priVars,
39 const VolumeVariables& volVars,
40 IndexType dofIdxGlobal,
41 const GlobalPosition& globalPos)
43 using Scalar =
typename VolumeVariables::PrimaryVariables::value_type;
45 using FluidSystem =
typename VolumeVariables::FluidSystem;
46 static constexpr int phase0Idx = FluidSystem::phase0Idx;
47 static constexpr int phase1Idx = FluidSystem::phase1Idx;
48 static constexpr int comp0Idx = FluidSystem::comp0Idx;
49 static constexpr int comp1Idx = FluidSystem::comp1Idx;
51 static constexpr auto numComponents = VolumeVariables::numFluidComponents();
52 static constexpr bool useMoles = VolumeVariables::useMoles();
53 static_assert(useMoles || numComponents < 3,
"!useMoles is only implemented for numComponents < 3.");
54 static constexpr auto numMajorComponents = VolumeVariables::numFluidPhases();
55 static constexpr auto formulation = VolumeVariables::priVarFormulation();
57 "Chosen TwoPFormulation not supported!");
59 using Indices =
typename VolumeVariables::Indices;
60 static constexpr int switchIdx = Indices::switchIdx;
63 bool wouldSwitch =
false;
64 int phasePresence = priVars.state();
65 int newPhasePresence = phasePresence;
68 if (phasePresence == Indices::bothPhases)
75 if (volVars.saturation(phase0Idx) <= Smin)
80 std::cout <<
"First phase (" << FluidSystem::phaseName(phase0Idx) <<
")"
81 <<
" disappears at dof " << dofIdxGlobal
82 <<
", coordinates: " << globalPos
83 <<
", S_" << FluidSystem::phaseName(phase0Idx) <<
": " << volVars.saturation(phase0Idx)
85 newPhasePresence = Indices::secondPhaseOnly;
89 priVars[switchIdx] = volVars.moleFraction(phase1Idx, comp0Idx);
91 priVars[switchIdx] = volVars.massFraction(phase1Idx, comp0Idx);
95 for (
int compIdx = numMajorComponents; compIdx < numComponents; ++compIdx)
96 priVars[compIdx] = volVars.moleFraction(phase1Idx, compIdx);
98 for (
int compIdx = numMajorComponents; compIdx < numComponents; ++compIdx)
99 priVars[compIdx] = volVars.massFraction(phase1Idx, compIdx);
103 else if (volVars.saturation(phase1Idx) <= Smin)
108 std::cout <<
"Second phase (" << FluidSystem::phaseName(phase1Idx) <<
")"
109 <<
" disappears at dof " << dofIdxGlobal
110 <<
", coordinates: " << globalPos
111 <<
", S_" << FluidSystem::phaseName(phase1Idx) <<
": " << volVars.saturation(phase1Idx)
113 newPhasePresence = Indices::firstPhaseOnly;
117 priVars[switchIdx] = volVars.moleFraction(phase0Idx, comp1Idx);
119 priVars[switchIdx] = volVars.massFraction(phase0Idx, comp1Idx);
122 else if (phasePresence == Indices::secondPhaseOnly)
127 for (
int compIdx = 0; compIdx < numComponents; compIdx++)
128 x0Sum += volVars.moleFraction(phase0Idx, compIdx);
139 std::cout <<
"Second phase (" << FluidSystem::phaseName(phase0Idx) <<
")"
140 <<
" appears at dof " << dofIdxGlobal
141 <<
", coordinates: " << globalPos
142 <<
", sum x^i_" << FluidSystem::phaseName(phase0Idx) <<
": " << x0Sum
144 newPhasePresence = Indices::bothPhases;
148 priVars[switchIdx] = 0.0001;
150 priVars[switchIdx] = 0.9999;
153 for (
int compIdx = numMajorComponents; compIdx < numComponents; ++compIdx)
154 priVars[compIdx] = volVars.moleFraction(phase0Idx,compIdx);
157 else if (phasePresence == Indices::firstPhaseOnly)
163 for (
int compIdx = 0; compIdx < numComponents; compIdx++)
164 x1Sum += volVars.moleFraction(phase1Idx, compIdx);
175 std::cout <<
"Second phase (" << FluidSystem::phaseName(phase1Idx) <<
")"
176 <<
" appears at dof " << dofIdxGlobal
177 <<
", coordinates: " << globalPos
178 <<
", sum x^i_" << FluidSystem::phaseName(phase1Idx) <<
": " << x1Sum
180 newPhasePresence = Indices::bothPhases;
183 priVars[switchIdx] = 0.9999;
185 priVars[switchIdx] = 0.0001;
189 priVars.setState(newPhasePresence);
191 return phasePresence != newPhasePresence;