52 bool update_(
typename VolumeVariables::PrimaryVariables& priVars,
53 const VolumeVariables& volVars,
54 std::size_t dofIdxGlobal,
55 const GlobalPosition& globalPos)
57 using Scalar =
typename VolumeVariables::PrimaryVariables::value_type;
58 using Indices =
typename VolumeVariables::Indices;
59 using FluidSystem =
typename VolumeVariables::FluidSystem;
61 static const bool usePriVarSwitch =
getParam<bool>(
"Problem.UsePrimaryVariableSwitch");
65 if (!VolumeVariables::enableWaterDiffusionInAir())
66 DUNE_THROW(Dune::InvalidStateException,
"The Richards primary variable switch only works with water diffusion in air enabled!");
68 static constexpr int liquidCompIdx = FluidSystem::liquidPhaseIdx;
71 bool wouldSwitch =
false;
72 int phasePresence = priVars.state();
73 int newPhasePresence = phasePresence;
76 if (phasePresence == Indices::gasPhaseOnly)
80 Scalar xnw = volVars.moleFraction(FluidSystem::gasPhaseIdx, liquidCompIdx);
81 Scalar xnwPredicted = FluidSystem::H2O::vaporPressure(volVars.temperature())
82 / volVars.pressure(FluidSystem::gasPhaseIdx);
85 if (xnw / xnwPredicted > xwMax)
92 if (xnw / xnwPredicted > xwMax)
96 std::cout <<
"Liquid phase appears at dof " << dofIdxGlobal
97 <<
", coordinates: " << globalPos <<
", xnw / xnwPredicted * 100: "
98 << xnw / xnwPredicted * 100 <<
"%"
99 <<
", at x_n^w: " << priVars[Indices::switchIdx] << std::endl;
100 newPhasePresence = Indices::bothPhases;
101 priVars[Indices::switchIdx] = 0.0;
104 else if (phasePresence == Indices::bothPhases)
110 if (volVars.saturation(FluidSystem::liquidPhaseIdx) <= Smin)
114 newPhasePresence = Indices::gasPhaseOnly;
115 priVars[Indices::switchIdx] = volVars.moleFraction(FluidSystem::gasPhaseIdx, liquidCompIdx);
118 std::cout <<
"Liquid phase disappears at dof " << dofIdxGlobal
119 <<
", coordinates: " << globalPos <<
", sw: "
120 << volVars.saturation(FluidSystem::liquidPhaseIdx)
121 <<
", x_n^w: " << priVars[Indices::switchIdx] << std::endl;
124 else if (phasePresence == Indices::liquidPhaseOnly)
126 DUNE_THROW(Dune::NotImplemented,
"Water phase only phase presence!");
129 priVars.setState(newPhasePresence);
131 return phasePresence != newPhasePresence;