version 3.10-dev
richardsextended/primaryvariableswitch.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
13#ifndef DUMUX_RICHARDSEXTENDED_PRIMARY_VARIABLE_SWITCH_HH
14#define DUMUX_RICHARDSEXTENDED_PRIMARY_VARIABLE_SWITCH_HH
15
20
21namespace Dumux {
22
28: public PrimaryVariableSwitch<ExtendedRichardsPrimaryVariableSwitch>
29{
31 friend ParentType;
32
33public:
34 using ParentType::ParentType;
35
36protected:
37
38 // perform variable switch at a degree of freedom location
39 template<class VolumeVariables, class GlobalPosition>
40 bool update_(typename VolumeVariables::PrimaryVariables& priVars,
41 const VolumeVariables& volVars,
42 std::size_t dofIdxGlobal,
43 const GlobalPosition& globalPos)
44 {
45 using Scalar = typename VolumeVariables::PrimaryVariables::value_type;
46 using Indices = typename VolumeVariables::Indices;
47 using FluidSystem = typename VolumeVariables::FluidSystem;
48
49 static const bool usePriVarSwitch = getParam<bool>("Richards.UsePrimaryVariableSwitch");
50 if (!usePriVarSwitch)
51 return false;
52
53 static constexpr int liquidCompIdx = FluidSystem::liquidPhaseIdx;
54
55 // evaluate primary variable switch
56 bool wouldSwitch = false;
57 int phasePresence = priVars.state();
58 int newPhasePresence = phasePresence;
59
60 // check if a primary var switch is necessary
61 if (phasePresence == Indices::gasPhaseOnly)
62 {
63 // if the mole fraction of water is larger than the one
64 // predicted by a liquid-vapor equilibrium
65 Scalar xnw = volVars.moleFraction(FluidSystem::gasPhaseIdx, liquidCompIdx);
66 Scalar xnwPredicted = FluidSystem::H2O::vaporPressure(volVars.temperature())
67 / volVars.pressure(FluidSystem::gasPhaseIdx);
68
69 Scalar xwMax = 1.0;
70 if (xnw / xnwPredicted > xwMax)
71 wouldSwitch = true;
72 if (this->wasSwitched_[dofIdxGlobal])
73 xwMax *= 1.01;
74
75 // if the ratio of predicted mole fraction to current mole fraction is larger than
76 // 100%, wetting phase appears
77 if (xnw / xnwPredicted > xwMax)
78 {
79 // wetting phase appears
80 if (this->verbosity() > 1)
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;
87 }
88 }
89 else if (phasePresence == Indices::bothPhases)
90 {
91 Scalar Smin = 0.0;
92 if (this->wasSwitched_[dofIdxGlobal])
93 Smin = -0.01;
94
95 if (volVars.saturation(FluidSystem::liquidPhaseIdx) <= Smin)
96 {
97 wouldSwitch = true;
98 // wetting phase disappears
99 newPhasePresence = Indices::gasPhaseOnly;
100 priVars[Indices::switchIdx] = volVars.moleFraction(FluidSystem::gasPhaseIdx, liquidCompIdx);
101
102 if (this->verbosity() > 1)
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;
107 }
108 }
109 else if (phasePresence == Indices::liquidPhaseOnly)
110 {
111 DUNE_THROW(Dune::NotImplemented, "Water phase only phase presence!");
112 }
113
114 priVars.setState(newPhasePresence);
115 this->wasSwitched_[dofIdxGlobal] = wouldSwitch;
116 return phasePresence != newPhasePresence;
117 }
118};
119
120} // end namespace Dumux
121
122#endif
The primary variable switch controlling the phase presence state variable.
Definition: richardsextended/primaryvariableswitch.hh:29
bool update_(typename VolumeVariables::PrimaryVariables &priVars, const VolumeVariables &volVars, std::size_t dofIdxGlobal, const GlobalPosition &globalPos)
Definition: richardsextended/primaryvariableswitch.hh:40
The primary variable switch controlling the phase presence state variable.
Definition: compositional/primaryvariableswitch.hh:49
std::vector< bool > wasSwitched_
Definition: compositional/primaryvariableswitch.hh:433
int verbosity() const
The verbosity level.
Definition: compositional/primaryvariableswitch.hh:271
The primary variable switch base class for compositional models.
A central place for various physical constants occurring in some equations.
Some exceptions thrown in DuMux
std::string phasePresence() noexcept
I/O name of phase presence.
Definition: name.hh:135
Definition: adapt.hh:17
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.