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 | 35820 | 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 35818 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
|
35820 | static const bool usePriVarSwitch = getParam<bool>("Richards.UsePrimaryVariableSwitch"); |
50 |
1/2✓ Branch 0 taken 35820 times.
✗ Branch 1 not taken.
|
35820 | if (!usePriVarSwitch) |
51 | return false; | ||
52 | |||
53 | static constexpr int liquidCompIdx = FluidSystem::liquidPhaseIdx; | ||
54 | |||
55 | // evaluate primary variable switch | ||
56 | 35820 | bool wouldSwitch = false; | |
57 | 35820 | int phasePresence = priVars.state(); | |
58 | 35820 | int newPhasePresence = phasePresence; | |
59 | |||
60 | // check if a primary var switch is necessary | ||
61 |
2/2✓ Branch 0 taken 348 times.
✓ Branch 1 taken 35472 times.
|
35820 | 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 | 348 | Scalar xnw = volVars.moleFraction(FluidSystem::gasPhaseIdx, liquidCompIdx); | |
66 | 696 | Scalar xnwPredicted = FluidSystem::H2O::vaporPressure(volVars.temperature()) | |
67 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 348 times.
|
348 | / volVars.pressure(FluidSystem::gasPhaseIdx); |
68 | |||
69 | 348 | Scalar xwMax = 1.0; | |
70 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 348 times.
|
348 | if (xnw / xnwPredicted > xwMax) |
71 | ✗ | wouldSwitch = true; | |
72 |
6/6✓ Branch 0 taken 11 times.
✓ Branch 1 taken 337 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 337 times.
✓ Branch 4 taken 11 times.
✓ Branch 5 taken 337 times.
|
1044 | 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 348 times.
|
348 | 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 35472 times.
✗ Branch 1 not taken.
|
35472 | else if (phasePresence == Indices::bothPhases) |
90 | { | ||
91 | 35472 | Scalar Smin = 0.0; | |
92 |
3/6✗ Branch 0 not taken.
✓ Branch 1 taken 35472 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 35472 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 35472 times.
|
106416 | if (this->wasSwitched_[dofIdxGlobal]) |
93 | ✗ | Smin = -0.01; | |
94 | |||
95 |
4/4✓ Branch 0 taken 11 times.
✓ Branch 1 taken 35461 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 35461 times.
|
70944 | 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 35809 times.
|
35820 | priVars.setState(newPhasePresence); |
115 |
4/4✓ Branch 0 taken 11 times.
✓ Branch 1 taken 35809 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 35809 times.
|
71640 | this->wasSwitched_[dofIdxGlobal] = wouldSwitch; |
116 | 35820 | return phasePresence != newPhasePresence; | |
117 | } | ||
118 | }; | ||
119 | |||
120 | } // end namespace Dumux | ||
121 | |||
122 | #endif | ||
123 |