GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/porousmediumflow/2p1c/primaryvariableswitch.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 29 54 53.7%
Functions: 2 2 100.0%
Branches: 28 110 25.5%

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 97585 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 97585 bool wouldSwitch = false;
62 97585 int phasePresence = priVars.state();
63 97585 int newPhasePresence = phasePresence;
64
65 // check if a primary var switch is necessary
66
2/2
✓ Branch 0 taken 277 times.
✓ Branch 1 taken 97308 times.
97585 if (phasePresence == Indices::twoPhases)
67 {
68 277 Scalar Smin = 0.0;
69
6/6
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 241 times.
✓ Branch 2 taken 36 times.
✓ Branch 3 taken 241 times.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 241 times.
831 if (this->wasSwitched_[dofIdxGlobal])
70 36 Smin = -0.01;
71
72
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 266 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 266 times.
554 if (volVars.saturation(FluidSystem::gasPhaseIdx) <= Smin)
73 {
74 11 wouldSwitch = true;
75 // gas phase disappears
76
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 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 11 newPhasePresence = Indices::liquidPhaseOnly;
84
85 44 priVars[Indices::switchIdx] = volVars.fluidState().temperature();
86 }
87
4/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 254 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 254 times.
532 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 97308 times.
✗ Branch 1 not taken.
97308 else if (phasePresence == Indices::liquidPhaseOnly)
105 {
106 194616 const Scalar temp = volVars.fluidState().temperature();
107 97308 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 47 times.
✓ Branch 1 taken 97261 times.
97308 if (temp >= tempVap)
112 {
113 47 wouldSwitch = true;
114 // gas phase appears
115
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
47 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 47 newPhasePresence = Indices::twoPhases;
121 if (formulation == TwoPFormulation::p1s0)
122 94 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 70 times.
✓ Branch 1 taken 97515 times.
97585 priVars.setState(newPhasePresence);
148
4/4
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 97515 times.
✓ Branch 2 taken 70 times.
✓ Branch 3 taken 97515 times.
195170 this->wasSwitched_[dofIdxGlobal] = wouldSwitch;
149 97585 return phasePresence != newPhasePresence;
150 }
151 };
152
153 } // end namespace Dumux
154
155 #endif
156