3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
25#ifndef DUMUX_RICHARDSEXTENDED_PRIMARY_VARIABLE_SWITCH_HH
26#define DUMUX_RICHARDSEXTENDED_PRIMARY_VARIABLE_SWITCH_HH
27
32
33namespace Dumux {
34
40: public PrimaryVariableSwitch<ExtendedRichardsPrimaryVariableSwitch>
41{
43 friend ParentType;
44
45public:
46 using ParentType::ParentType;
47
48protected:
49
50 // perform variable switch at a degree of freedom location
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)
56 {
57 using Scalar = typename VolumeVariables::PrimaryVariables::value_type;
58 using Indices = typename VolumeVariables::Indices;
59 using FluidSystem = typename VolumeVariables::FluidSystem;
60
61 static const bool usePriVarSwitch = getParam<bool>("Problem.UsePrimaryVariableSwitch");
62 if (!usePriVarSwitch)
63 return false;
64
65 static constexpr int liquidCompIdx = FluidSystem::liquidPhaseIdx;
66
67 // evaluate primary variable switch
68 bool wouldSwitch = false;
69 int phasePresence = priVars.state();
70 int newPhasePresence = phasePresence;
71
72 // check if a primary var switch is necessary
73 if (phasePresence == Indices::gasPhaseOnly)
74 {
75 // if the mole fraction of water is larger than the one
76 // predicted by a liquid-vapor equilibrium
77 Scalar xnw = volVars.moleFraction(FluidSystem::gasPhaseIdx, liquidCompIdx);
78 Scalar xnwPredicted = FluidSystem::H2O::vaporPressure(volVars.temperature())
79 / volVars.pressure(FluidSystem::gasPhaseIdx);
80
81 Scalar xwMax = 1.0;
82 if (xnw / xnwPredicted > xwMax)
83 wouldSwitch = true;
84 if (this->wasSwitched_[dofIdxGlobal])
85 xwMax *= 1.01;
86
87 // if the ratio of predicted mole fraction to current mole fraction is larger than
88 // 100%, wetting phase appears
89 if (xnw / xnwPredicted > xwMax)
90 {
91 // wetting phase appears
92 if (this->verbosity() > 1)
93 std::cout << "Liquid phase appears at dof " << dofIdxGlobal
94 << ", coordinates: " << globalPos << ", xnw / xnwPredicted * 100: "
95 << xnw / xnwPredicted * 100 << "%"
96 << ", at x_n^w: " << priVars[Indices::switchIdx] << std::endl;
97 newPhasePresence = Indices::bothPhases;
98 priVars[Indices::switchIdx] = 0.0;
99 }
100 }
101 else if (phasePresence == Indices::bothPhases)
102 {
103 Scalar Smin = 0.0;
104 if (this->wasSwitched_[dofIdxGlobal])
105 Smin = -0.01;
106
107 if (volVars.saturation(FluidSystem::liquidPhaseIdx) <= Smin)
108 {
109 wouldSwitch = true;
110 // wetting phase disappears
111 newPhasePresence = Indices::gasPhaseOnly;
112 priVars[Indices::switchIdx] = volVars.moleFraction(FluidSystem::gasPhaseIdx, liquidCompIdx);
113
114 if (this->verbosity() > 1)
115 std::cout << "Liquid phase disappears at dof " << dofIdxGlobal
116 << ", coordinates: " << globalPos << ", sw: "
117 << volVars.saturation(FluidSystem::liquidPhaseIdx)
118 << ", x_n^w: " << priVars[Indices::switchIdx] << std::endl;
119 }
120 }
121 else if (phasePresence == Indices::liquidPhaseOnly)
122 {
123 DUNE_THROW(Dune::NotImplemented, "Water phase only phase presence!");
124 }
125
126 priVars.setState(newPhasePresence);
127 this->wasSwitched_[dofIdxGlobal] = wouldSwitch;
128 return phasePresence != newPhasePresence;
129 }
130};
131
132} // end namespace Dumux
133
134#endif
Some exceptions thrown in DuMux
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
A central place for various physical constants occurring in some equations.
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
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:61
std::vector< bool > wasSwitched_
Definition: compositional/primaryvariableswitch.hh:445
int verbosity() const
The verbosity level.
Definition: compositional/primaryvariableswitch.hh:283
The primary variable switch controlling the phase presence state variable.
Definition: richardsextended/primaryvariableswitch.hh:41
bool update_(typename VolumeVariables::PrimaryVariables &priVars, const VolumeVariables &volVars, std::size_t dofIdxGlobal, const GlobalPosition &globalPos)
Definition: richardsextended/primaryvariableswitch.hh:52
The primary variable switch base class for compositional models.