Line | Branch | Exec | Source |
---|---|---|---|
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 | // | ||
7 | /*! | ||
8 | * \file | ||
9 | * \ingroup TwoPOneCModel | ||
10 | * \copydoc Dumux::TwoPOneCPrimaryVariableSwitch | ||
11 | */ | ||
12 | |||
13 | #ifndef DUMUX_2P1C_PRIMARY_VARIABLE_SWITCH_HH | ||
14 | #define DUMUX_2P1C_PRIMARY_VARIABLE_SWITCH_HH | ||
15 | |||
16 | #include <iostream> | ||
17 | |||
18 | #include <dumux/porousmediumflow/2p/formulation.hh> | ||
19 | #include <dumux/porousmediumflow/compositional/primaryvariableswitch.hh> | ||
20 | |||
21 | namespace Dumux { | ||
22 | |||
23 | /*! | ||
24 | * \ingroup TwoPOneCModel | ||
25 | * \brief The primary variable switch for the two-phase one-component model | ||
26 | */ | ||
27 | ✗ | class TwoPOneCPrimaryVariableSwitch | |
28 | : public PrimaryVariableSwitch<TwoPOneCPrimaryVariableSwitch> | ||
29 | { | ||
30 | using ParentType = PrimaryVariableSwitch<TwoPOneCPrimaryVariableSwitch>; | ||
31 | friend ParentType; | ||
32 | |||
33 | public: | ||
34 | ✗ | using ParentType::ParentType; | |
35 | |||
36 | protected: | ||
37 | |||
38 | /*! | ||
39 | * \brief Performs variable switch at a degree of freedom location. | ||
40 | * | ||
41 | * \param priVars The primary variables at the given degree of freedom (dof) location. | ||
42 | * \param volVars The volume variables. | ||
43 | * \param dofIdxGlobal The respective dof index. | ||
44 | * \param globalPos The global position of the dof. | ||
45 | */ | ||
46 | template<class VolumeVariables, class GlobalPosition> | ||
47 | 99185 | 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 | 99185 | bool wouldSwitch = false; | |
62 | 99185 | int phasePresence = priVars.state(); | |
63 | 99185 | int newPhasePresence = phasePresence; | |
64 | |||
65 | // check if a primary var switch is necessary | ||
66 |
2/2✓ Branch 0 taken 282 times.
✓ Branch 1 taken 98903 times.
|
99185 | if (phasePresence == Indices::twoPhases) |
67 | { | ||
68 | 282 | Scalar Smin = 0.0; | |
69 |
6/6✓ Branch 0 taken 41 times.
✓ Branch 1 taken 241 times.
✓ Branch 2 taken 41 times.
✓ Branch 3 taken 241 times.
✓ Branch 4 taken 41 times.
✓ Branch 5 taken 241 times.
|
846 | if (this->wasSwitched_[dofIdxGlobal]) |
70 | 41 | Smin = -0.01; | |
71 | |||
72 |
4/4✓ Branch 0 taken 15 times.
✓ Branch 1 taken 267 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 267 times.
|
564 | if (volVars.saturation(FluidSystem::gasPhaseIdx) <= Smin) |
73 | { | ||
74 | 15 | wouldSwitch = true; | |
75 | // gas phase disappears | ||
76 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
|
15 | 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 | 15 | newPhasePresence = Indices::liquidPhaseOnly; | |
84 | |||
85 | 60 | priVars[Indices::switchIdx] = volVars.fluidState().temperature(); | |
86 | } | ||
87 |
4/4✓ Branch 0 taken 12 times.
✓ Branch 1 taken 255 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 255 times.
|
534 | else if (volVars.saturation(FluidSystem::liquidPhaseIdx) <= Smin) |
88 | { | ||
89 | 12 | wouldSwitch = true; | |
90 | // water phase disappears | ||
91 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | 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 | 12 | newPhasePresence = Indices::gasPhaseOnly; | |
99 | |||
100 | 48 | priVars[Indices::switchIdx] = volVars.fluidState().temperature(); | |
101 | } | ||
102 | |||
103 | } | ||
104 |
1/2✓ Branch 0 taken 98903 times.
✗ Branch 1 not taken.
|
98903 | else if (phasePresence == Indices::liquidPhaseOnly) |
105 | { | ||
106 | 197806 | const Scalar temp = volVars.fluidState().temperature(); | |
107 | 98903 | 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 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 98851 times.
|
98903 | if (temp >= tempVap) |
112 | { | ||
113 | 52 | wouldSwitch = true; | |
114 | // gas phase appears | ||
115 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 52 times.
|
52 | 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 | 52 | newPhasePresence = Indices::twoPhases; | |
121 | if (formulation == TwoPFormulation::p1s0) | ||
122 | 104 | 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 |
2/2✓ Branch 0 taken 79 times.
✓ Branch 1 taken 99106 times.
|
99185 | priVars.setState(newPhasePresence); |
148 |
4/4✓ Branch 0 taken 79 times.
✓ Branch 1 taken 99106 times.
✓ Branch 2 taken 79 times.
✓ Branch 3 taken 99106 times.
|
198370 | this->wasSwitched_[dofIdxGlobal] = wouldSwitch; |
149 | 99185 | return phasePresence != newPhasePresence; | |
150 | } | ||
151 | }; | ||
152 | |||
153 | } // end namespace Dumux | ||
154 | |||
155 | #endif | ||
156 |