40 bool update_(
typename VolumeVariables::PrimaryVariables& priVars,
41 const VolumeVariables& volVars,
42 std::size_t dofIdxGlobal,
43 const GlobalPosition& globalPos)
45 using Scalar =
typename VolumeVariables::PrimaryVariables::value_type;
46 using Indices =
typename VolumeVariables::Indices;
47 using FluidSystem =
typename VolumeVariables::FluidSystem;
49 static const bool usePriVarSwitch =
getParam<bool>(
"Richards.UsePrimaryVariableSwitch");
53 static constexpr int liquidCompIdx = FluidSystem::liquidPhaseIdx;
56 bool wouldSwitch =
false;
57 int phasePresence = priVars.state();
58 int newPhasePresence = phasePresence;
61 if (phasePresence == Indices::gasPhaseOnly)
65 Scalar xnw = volVars.moleFraction(FluidSystem::gasPhaseIdx, liquidCompIdx);
66 Scalar xnwPredicted = FluidSystem::H2O::vaporPressure(volVars.temperature())
67 / volVars.pressure(FluidSystem::gasPhaseIdx);
70 if (xnw / xnwPredicted > xwMax)
77 if (xnw / xnwPredicted > xwMax)
81 std::cout <<
"Liquid phase appears at dof " << dofIdxGlobal
82 <<
", coordinates: " << globalPos <<
", xnw / xnwPredicted * 100: "
83 << xnw / xnwPredicted * 100 <<
"%"
84 <<
", at x_n^w: " << priVars[Indices::switchIdx] << std::endl;
85 newPhasePresence = Indices::bothPhases;
86 priVars[Indices::switchIdx] = 0.0;
89 else if (phasePresence == Indices::bothPhases)
95 if (volVars.saturation(FluidSystem::liquidPhaseIdx) <= Smin)
99 newPhasePresence = Indices::gasPhaseOnly;
100 priVars[Indices::switchIdx] = volVars.moleFraction(FluidSystem::gasPhaseIdx, liquidCompIdx);
103 std::cout <<
"Liquid phase disappears at dof " << dofIdxGlobal
104 <<
", coordinates: " << globalPos <<
", sw: "
105 << volVars.saturation(FluidSystem::liquidPhaseIdx)
106 <<
", x_n^w: " << priVars[Indices::switchIdx] << std::endl;
109 else if (phasePresence == Indices::liquidPhaseOnly)
111 DUNE_THROW(Dune::NotImplemented,
"Water phase only phase presence!");
114 priVars.setState(newPhasePresence);
116 return phasePresence != newPhasePresence;