version 3.10-dev
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// 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_2P1C_PRIMARY_VARIABLE_SWITCH_HH
14#define DUMUX_2P1C_PRIMARY_VARIABLE_SWITCH_HH
15
16#include <iostream>
17
20
21namespace Dumux {
22
28: public PrimaryVariableSwitch<TwoPOneCPrimaryVariableSwitch>
29{
31 friend ParentType;
32
33public:
34 using ParentType::ParentType;
35
36protected:
37
46 template<class VolumeVariables, class GlobalPosition>
47 bool update_(typename VolumeVariables::PrimaryVariables& priVars,
48 const VolumeVariables& volVars,
49 std::size_t dofIdxGlobal,
50 const GlobalPosition& globalPos)
51 {
52 using Scalar = typename VolumeVariables::PrimaryVariables::value_type;
53 using FluidSystem = typename VolumeVariables::FluidSystem;
54 using Indices = typename VolumeVariables::Indices;
55
56 static constexpr auto formulation = VolumeVariables::priVarFormulation();
57 static_assert( (formulation == TwoPFormulation::p0s1 || formulation == TwoPFormulation::p1s0),
58 "Chosen TwoPFormulation not supported!");
59
60 // evaluate primary variable switch
61 bool wouldSwitch = false;
62 int phasePresence = priVars.state();
63 int newPhasePresence = phasePresence;
64
65 // check if a primary var switch is necessary
66 if (phasePresence == Indices::twoPhases)
67 {
68 Scalar Smin = 0.0;
69 if (this->wasSwitched_[dofIdxGlobal])
70 Smin = -0.01;
71
72 if (volVars.saturation(FluidSystem::gasPhaseIdx) <= Smin)
73 {
74 wouldSwitch = true;
75 // gas phase disappears
76 if (this->verbosity() > 1)
77 std::cout << "Gas phase (" << FluidSystem::phaseName(FluidSystem::gasPhaseIdx)
78 << ") disappears at dof " << dofIdxGlobal
79 << ", coordinates: " << globalPos
80 << ", S_" << FluidSystem::phaseName(FluidSystem::gasPhaseIdx) << ": "
81 << volVars.saturation(FluidSystem::gasPhaseIdx)
82 << std::endl;
83 newPhasePresence = Indices::liquidPhaseOnly;
84
85 priVars[Indices::switchIdx] = volVars.fluidState().temperature();
86 }
87 else if (volVars.saturation(FluidSystem::liquidPhaseIdx) <= Smin)
88 {
89 wouldSwitch = true;
90 // water phase disappears
91 if (this->verbosity() > 1)
92 std::cout << "Liquid phase (" << FluidSystem::phaseName(FluidSystem::liquidPhaseIdx)
93 << ") disappears at dof " << dofIdxGlobal
94 << ", coordinates: " << globalPos
95 << ", S_" << FluidSystem::phaseName(FluidSystem::liquidPhaseIdx) << ": "
96 << volVars.saturation(FluidSystem::liquidPhaseIdx)
97 << std::endl;
98 newPhasePresence = Indices::gasPhaseOnly;
99
100 priVars[Indices::switchIdx] = volVars.fluidState().temperature();
101 }
102
103 }
104 else if (phasePresence == Indices::liquidPhaseOnly)
105 {
106 const Scalar temp = volVars.fluidState().temperature();
107 const Scalar tempVap = volVars.vaporTemperature();
108
109 // if the the temperature would be larger than
110 // the vapor temperature at the given pressure, gas phase appears
111 if (temp >= tempVap)
112 {
113 wouldSwitch = true;
114 // gas phase appears
115 if (this->verbosity() > 1)
116 std::cout << "Gas phase (" << FluidSystem::phaseName(FluidSystem::gasPhaseIdx)
117 << ") appears at dof " << dofIdxGlobal
118 << ", coordinates: " << globalPos
119 << std::endl;
120 newPhasePresence = Indices::twoPhases;
121 if (formulation == TwoPFormulation::p1s0)
122 priVars[Indices::switchIdx] = 0.9999; // liquid phase saturation
123 else
124 priVars[Indices::switchIdx] = 0.0001;
125 }
126 }
127 else if (phasePresence == Indices::gasPhaseOnly)
128 {
129 const Scalar temp = volVars.fluidState().temperature();
130 const Scalar tempVap = volVars.vaporTemperature();
131
132 if (temp < tempVap)
133 {
134 wouldSwitch = true;
135 // liquid phase appears
136 if (this->verbosity() > 1)
137 std::cout << "Liquid phase (" << FluidSystem::phaseName(FluidSystem::liquidPhaseIdx) << ") appears at dof " << dofIdxGlobal
138 << ", coordinates: " << globalPos << std::endl;
139
140 newPhasePresence = Indices::twoPhases;
141 if (formulation == TwoPFormulation::p1s0)
142 priVars[Indices::switchIdx] = 0.0001;
143 else
144 priVars[Indices::switchIdx] = 0.9999;
145 }
146 }
147 priVars.setState(newPhasePresence);
148 this->wasSwitched_[dofIdxGlobal] = wouldSwitch;
149 return phasePresence != newPhasePresence;
150 }
151};
152
153} // end namespace Dumux
154
155#endif
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 for the two-phase one-component model.
Definition: 2p1c/primaryvariableswitch.hh:29
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:47
The primary variable switch base class for compositional models.
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
std::string phasePresence() noexcept
I/O name of phase presence.
Definition: name.hh:135
Definition: adapt.hh:17