25#ifndef DUMUX_RICHARDS_PRIMARY_VARIABLE_SWITCH_HH
26#define DUMUX_RICHARDS_PRIMARY_VARIABLE_SWITCH_HH
46 using ParentType::ParentType;
51 template<
class VolumeVariables,
class GlobalPosition>
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;
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;
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;
126 DUNE_THROW(Dune::NotImplemented,
"Water phase only phase presence!");
129 priVars.setState(newPhasePresence);
Some exceptions thrown in DuMux
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
A central place for various physical constants occuring in some equations.
std::string phasePresence() noexcept
I/O name of phase presence.
Definition: name.hh:147
The primary variable switch controlling the phase presence state variable.
Definition: compositional/primaryvariableswitch.hh:60
std::vector< bool > wasSwitched_
Definition: compositional/primaryvariableswitch.hh:463
int verbosity() const
The verbosity level.
Definition: compositional/primaryvariableswitch.hh:301
The primary variable switch controlling the phase presence state variable.
Definition: richards/primaryvariableswitch.hh:41
bool update_(typename VolumeVariables::PrimaryVariables &priVars, const VolumeVariables &volVars, std::size_t dofIdxGlobal, const GlobalPosition &globalPos)
Definition: richards/primaryvariableswitch.hh:52
The primary variable switch base class for compositional models.