GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/porousmediumflow/richardsextended/primaryvariableswitch.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 26 43 60.5%
Functions: 2 2 100.0%
Branches: 33 66 50.0%

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 ExtendedRichardsModel
10 * \brief The primary variable switch for the extended Richards model.
11 */
12
13 #ifndef DUMUX_RICHARDSEXTENDED_PRIMARY_VARIABLE_SWITCH_HH
14 #define DUMUX_RICHARDSEXTENDED_PRIMARY_VARIABLE_SWITCH_HH
15
16 #include <dumux/common/exceptions.hh>
17 #include <dumux/common/parameters.hh>
18 #include <dumux/material/constants.hh>
19 #include <dumux/porousmediumflow/compositional/primaryvariableswitch.hh>
20
21 namespace Dumux {
22
23 /*!
24 * \ingroup RichardsModel
25 * \brief The primary variable switch controlling the phase presence state variable.
26 */
27 class ExtendedRichardsPrimaryVariableSwitch
28 : public PrimaryVariableSwitch<ExtendedRichardsPrimaryVariableSwitch>
29 {
30 using ParentType = PrimaryVariableSwitch<ExtendedRichardsPrimaryVariableSwitch>;
31 friend ParentType;
32
33 public:
34 using ParentType::ParentType;
35
36 protected:
37
38 // perform variable switch at a degree of freedom location
39 template<class VolumeVariables, class GlobalPosition>
40 37470 bool update_(typename VolumeVariables::PrimaryVariables& priVars,
41 const VolumeVariables& volVars,
42 std::size_t dofIdxGlobal,
43 const GlobalPosition& globalPos)
44 {
45 using Scalar = typename VolumeVariables::PrimaryVariables::value_type;
46 using Indices = typename VolumeVariables::Indices;
47 using FluidSystem = typename VolumeVariables::FluidSystem;
48
49
4/6
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 37468 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
37470 static const bool usePriVarSwitch = getParam<bool>("Richards.UsePrimaryVariableSwitch");
50
1/2
✓ Branch 0 taken 37470 times.
✗ Branch 1 not taken.
37470 if (!usePriVarSwitch)
51 return false;
52
53 static constexpr int liquidCompIdx = FluidSystem::liquidPhaseIdx;
54
55 // evaluate primary variable switch
56 37470 bool wouldSwitch = false;
57 37470 int phasePresence = priVars.state();
58 37470 int newPhasePresence = phasePresence;
59
60 // check if a primary var switch is necessary
61
2/2
✓ Branch 0 taken 344 times.
✓ Branch 1 taken 37126 times.
37470 if (phasePresence == Indices::gasPhaseOnly)
62 {
63 // if the mole fraction of water is larger than the one
64 // predicted by a liquid-vapor equilibrium
65 344 Scalar xnw = volVars.moleFraction(FluidSystem::gasPhaseIdx, liquidCompIdx);
66 688 Scalar xnwPredicted = FluidSystem::H2O::vaporPressure(volVars.temperature())
67
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 344 times.
344 / volVars.pressure(FluidSystem::gasPhaseIdx);
68
69 344 Scalar xwMax = 1.0;
70
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 344 times.
344 if (xnw / xnwPredicted > xwMax)
71 wouldSwitch = true;
72
6/6
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 333 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 333 times.
✓ Branch 4 taken 11 times.
✓ Branch 5 taken 333 times.
1032 if (this->wasSwitched_[dofIdxGlobal])
73 11 xwMax *= 1.01;
74
75 // if the ratio of predicted mole fraction to current mole fraction is larger than
76 // 100%, wetting phase appears
77
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 344 times.
344 if (xnw / xnwPredicted > xwMax)
78 {
79 // wetting phase appears
80 if (this->verbosity() > 1)
81 std::cout << "Liquid phase appears at dof " << dofIdxGlobal
82 << ", coordinates: " << globalPos << ", xnw / xnwPredicted * 100: "
83 << xnw / xnwPredicted * 100 << "%"
84 << ", at x_n^w: " << priVars[Indices::switchIdx] << std::endl;
85 newPhasePresence = Indices::bothPhases;
86 priVars[Indices::switchIdx] = 0.0;
87 }
88 }
89
1/2
✓ Branch 0 taken 37126 times.
✗ Branch 1 not taken.
37126 else if (phasePresence == Indices::bothPhases)
90 {
91 37126 Scalar Smin = 0.0;
92
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 37126 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 37126 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 37126 times.
111378 if (this->wasSwitched_[dofIdxGlobal])
93 Smin = -0.01;
94
95
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 37115 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 37115 times.
74252 if (volVars.saturation(FluidSystem::liquidPhaseIdx) <= Smin)
96 {
97 11 wouldSwitch = true;
98 // wetting phase disappears
99 11 newPhasePresence = Indices::gasPhaseOnly;
100
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
22 priVars[Indices::switchIdx] = volVars.moleFraction(FluidSystem::gasPhaseIdx, liquidCompIdx);
101
102
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (this->verbosity() > 1)
103 std::cout << "Liquid phase disappears at dof " << dofIdxGlobal
104 << ", coordinates: " << globalPos << ", sw: "
105 << volVars.saturation(FluidSystem::liquidPhaseIdx)
106 << ", x_n^w: " << priVars[Indices::switchIdx] << std::endl;
107 }
108 }
109 else if (phasePresence == Indices::liquidPhaseOnly)
110 {
111 DUNE_THROW(Dune::NotImplemented, "Water phase only phase presence!");
112 }
113
114
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 37459 times.
37470 priVars.setState(newPhasePresence);
115
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 37459 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 37459 times.
74940 this->wasSwitched_[dofIdxGlobal] = wouldSwitch;
116 37470 return phasePresence != newPhasePresence;
117 }
118 };
119
120 } // end namespace Dumux
121
122 #endif
123