3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
2p1c/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_2P1C_PRIMARY_VARIABLE_SWITCH_HH
26#define DUMUX_2P1C_PRIMARY_VARIABLE_SWITCH_HH
27
28#include <iostream>
29
32
33namespace Dumux {
34
40: public PrimaryVariableSwitch<TwoPOneCPrimaryVariableSwitch>
41{
43 friend ParentType;
44
45public:
46 using ParentType::ParentType;
47
48protected:
49
58 template<class VolumeVariables, class GlobalPosition>
59 bool update_(typename VolumeVariables::PrimaryVariables& priVars,
60 const VolumeVariables& volVars,
61 std::size_t dofIdxGlobal,
62 const GlobalPosition& globalPos)
63 {
64 using Scalar = typename VolumeVariables::PrimaryVariables::value_type;
65 using FluidSystem = typename VolumeVariables::FluidSystem;
66 using Indices = typename VolumeVariables::Indices;
67
68 static constexpr auto formulation = VolumeVariables::priVarFormulation();
69 static_assert( (formulation == TwoPFormulation::p0s1 || formulation == TwoPFormulation::p1s0),
70 "Chosen TwoPFormulation not supported!");
71
72 // evaluate primary variable switch
73 bool wouldSwitch = false;
74 int phasePresence = priVars.state();
75 int newPhasePresence = phasePresence;
76
77 // check if a primary var switch is necessary
78 if (phasePresence == Indices::twoPhases)
79 {
80 Scalar Smin = 0.0;
81 if (this->wasSwitched_[dofIdxGlobal])
82 Smin = -0.01;
83
84 if (volVars.saturation(FluidSystem::gasPhaseIdx) <= Smin)
85 {
86 wouldSwitch = true;
87 // gas phase disappears
88 if (this->verbosity() > 1)
89 std::cout << "Gas phase (" << FluidSystem::phaseName(FluidSystem::gasPhaseIdx)
90 << ") disappears at dof " << dofIdxGlobal
91 << ", coordinates: " << globalPos
92 << ", S_" << FluidSystem::phaseName(FluidSystem::gasPhaseIdx) << ": "
93 << volVars.saturation(FluidSystem::gasPhaseIdx)
94 << std::endl;
95 newPhasePresence = Indices::liquidPhaseOnly;
96
97 priVars[Indices::switchIdx] = volVars.fluidState().temperature();
98 }
99 else if (volVars.saturation(FluidSystem::liquidPhaseIdx) <= Smin)
100 {
101 wouldSwitch = true;
102 // water phase disappears
103 if (this->verbosity() > 1)
104 std::cout << "Liquid phase (" << FluidSystem::phaseName(FluidSystem::liquidPhaseIdx)
105 << ") disappears at dof " << dofIdxGlobal
106 << ", coordinates: " << globalPos
107 << ", S_" << FluidSystem::phaseName(FluidSystem::liquidPhaseIdx) << ": "
108 << volVars.saturation(FluidSystem::liquidPhaseIdx)
109 << std::endl;
110 newPhasePresence = Indices::gasPhaseOnly;
111
112 priVars[Indices::switchIdx] = volVars.fluidState().temperature();
113 }
114
115 }
116 else if (phasePresence == Indices::liquidPhaseOnly)
117 {
118 const Scalar temp = volVars.fluidState().temperature();
119 const Scalar tempVap = volVars.vaporTemperature();
120
121 // if the the temperature would be larger than
122 // the vapor temperature at the given pressure, gas phase appears
123 if (temp >= tempVap)
124 {
125 wouldSwitch = true;
126 // gas phase appears
127 if (this->verbosity() > 1)
128 std::cout << "Gas phase (" << FluidSystem::phaseName(FluidSystem::gasPhaseIdx)
129 << ") appears at dof " << dofIdxGlobal
130 << ", coordinates: " << globalPos
131 << std::endl;
132 newPhasePresence = Indices::twoPhases;
133 if (formulation == TwoPFormulation::p1s0)
134 priVars[Indices::switchIdx] = 0.9999; // liquid phase saturation
135 else
136 priVars[Indices::switchIdx] = 0.0001;
137 }
138 }
139 else if (phasePresence == Indices::gasPhaseOnly)
140 {
141 const Scalar temp = volVars.fluidState().temperature();
142 const Scalar tempVap = volVars.vaporTemperature();
143
144 if (temp < tempVap)
145 {
146 wouldSwitch = true;
147 // liquid phase appears
148 if (this->verbosity() > 1)
149 std::cout << "Liquid phase (" << FluidSystem::phaseName(FluidSystem::liquidPhaseIdx) << ") appears at dof " << dofIdxGlobal
150 << ", coordinates: " << globalPos << std::endl;
151
152 newPhasePresence = Indices::twoPhases;
153 if (formulation == TwoPFormulation::p1s0)
154 priVars[Indices::switchIdx] = 0.0001;
155 else
156 priVars[Indices::switchIdx] = 0.9999;
157 }
158 }
159 priVars.setState(newPhasePresence);
160 this->wasSwitched_[dofIdxGlobal] = wouldSwitch;
161 return phasePresence != newPhasePresence;
162 }
163};
164
165} // end namespace Dumux
166
167#endif
Defines an enumeration for the formulations accepted by the two-phase model.
@ p1s0
first phase saturation and second phase pressure as primary variables
@ p0s1
first phase pressure and second phase saturation as primary variables
Definition: adapt.hh:29
std::string phasePresence() noexcept
I/O name of phase presence.
Definition: name.hh:147
The primary variable switch for the two-phase one-component model.
Definition: 2p1c/primaryvariableswitch.hh:41
bool update_(typename VolumeVariables::PrimaryVariables &priVars, const VolumeVariables &volVars, std::size_t dofIdxGlobal, const GlobalPosition &globalPos)
Performs variable switch at a degree of freedom location.
Definition: 2p1c/primaryvariableswitch.hh:59
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 base class for compositional models.