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-FileCopyrightText: 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 PorousmediumflowModels | ||
10 | * \brief Base class for the flux variables in porous medium models | ||
11 | */ | ||
12 | |||
13 | #ifndef DUMUX_POROUSMEDIUMFLOW_FLUXVARIABLES_HH | ||
14 | #define DUMUX_POROUSMEDIUMFLOW_FLUXVARIABLES_HH | ||
15 | |||
16 | #include <bitset> | ||
17 | #include <array> | ||
18 | |||
19 | #include <dumux/common/properties.hh> | ||
20 | #include <dumux/flux/fluxvariablesbase.hh> | ||
21 | #include <dumux/flux/upwindscheme.hh> | ||
22 | |||
23 | namespace Dumux { | ||
24 | |||
25 | /*! | ||
26 | * \ingroup PorousmediumflowModels | ||
27 | * \brief The porous medium flux variables class that computes advective / convective, | ||
28 | * molecular diffusive and heat conduction fluxes. | ||
29 | * | ||
30 | * \param TypeTag The type tag for access to type traits | ||
31 | * \param UpScheme The upwind scheme to be applied to advective fluxes | ||
32 | * \note Not all specializations are currently implemented | ||
33 | */ | ||
34 | template<class TypeTag, | ||
35 | class UpScheme = UpwindScheme<GetPropType<TypeTag, Properties::GridGeometry>> > | ||
36 | class PorousMediumFluxVariables | ||
37 | : public FluxVariablesBase<GetPropType<TypeTag, Properties::Problem>, | ||
38 | typename GetPropType<TypeTag, Properties::GridGeometry>::LocalView, | ||
39 | typename GetPropType<TypeTag, Properties::GridVolumeVariables>::LocalView, | ||
40 | typename GetPropType<TypeTag, Properties::GridFluxVariablesCache>::LocalView> | ||
41 | { | ||
42 | using Scalar = GetPropType<TypeTag, Properties::Scalar>; | ||
43 | using ModelTraits = GetPropType<TypeTag, Properties::ModelTraits>; | ||
44 | |||
45 | enum | ||
46 | { | ||
47 | numPhases = ModelTraits::numFluidPhases(), | ||
48 | numComponents = ModelTraits::numFluidComponents() | ||
49 | }; | ||
50 | |||
51 | public: | ||
52 | using UpwindScheme = UpScheme; | ||
53 | using AdvectionType = GetPropType<TypeTag, Properties::AdvectionType>; | ||
54 | using DispersionFluxType = GetPropType<TypeTag, Properties::DispersionFluxType>; | ||
55 | using MolecularDiffusionType = GetPropType<TypeTag, Properties::MolecularDiffusionType>; | ||
56 | using HeatConductionType = GetPropType<TypeTag, Properties::HeatConductionType>; | ||
57 | |||
58 | static constexpr bool enableAdvection = ModelTraits::enableAdvection(); | ||
59 | static constexpr bool enableMolecularDiffusion = ModelTraits::enableMolecularDiffusion(); | ||
60 | static constexpr bool enableCompositionalDispersion = ModelTraits::enableCompositionalDispersion(); | ||
61 | static constexpr bool enableThermalDispersion = ModelTraits::enableThermalDispersion(); | ||
62 | static constexpr bool enableEnergyBalance = ModelTraits::enableEnergyBalance(); | ||
63 | static constexpr bool enableThermalNonEquilibrium = getPropValue<TypeTag, Properties::EnableThermalNonEquilibrium>(); | ||
64 | |||
65 | //! The constructor | ||
66 | 1246030268 | PorousMediumFluxVariables() | |
67 | 1246030268 | { | |
68 | 1246030268 | advFluxIsCached_.reset(); | |
69 |
10/14✓ Branch 1 taken 4828724 times.
✓ Branch 2 taken 62172 times.
✓ Branch 4 taken 17519 times.
✗ Branch 5 not taken.
✓ Branch 9 taken 31952018 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 126 times.
✗ Branch 13 not taken.
✓ Branch 8 taken 309100 times.
✓ Branch 3 taken 340 times.
✓ Branch 6 taken 43859 times.
✗ Branch 7 not taken.
✓ Branch 0 taken 484 times.
✓ Branch 11 taken 3200 times.
|
2488726240 | advFluxBeforeUpwinding_.fill(0.0); |
70 | } | ||
71 | |||
72 | /*! | ||
73 | * \brief Returns the advective flux computed by the respective law. | ||
74 | */ | ||
75 | template<typename FunctionType> | ||
76 | 5727760292 | Scalar advectiveFlux([[maybe_unused]] const int phaseIdx, [[maybe_unused]] const FunctionType& upwindTerm) const | |
77 | { | ||
78 | if constexpr (enableAdvection) | ||
79 | { | ||
80 |
2/2✓ Branch 0 taken 1141543235 times.
✓ Branch 1 taken 1409004729 times.
|
5727760292 | if (!advFluxIsCached_[phaseIdx]) |
81 | { | ||
82 | |||
83 |
3/4✓ Branch 1 taken 24206540 times.
✓ Branch 2 taken 175027284 times.
✗ Branch 0 not taken.
✓ Branch 3 taken 345092 times.
|
3403738662 | advFluxBeforeUpwinding_[phaseIdx] = AdvectionType::flux(this->problem(), |
84 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24206540 times.
|
2912243574 | this->element(), |
85 | 2658441598 | this->fvGeometry(), | |
86 | 800176842 | this->elemVolVars(), | |
87 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24206540 times.
|
2912243574 | this->scvFace(), |
88 | phaseIdx, | ||
89 | 10434480 | this->elemFluxVarsCache()); | |
90 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 199233824 times.
|
2912243574 | advFluxIsCached_.set(phaseIdx, true); |
91 | } | ||
92 | |||
93 | //! Give the upwind scheme access to the cached variables | ||
94 | 5727760292 | return UpwindScheme::apply(*this, upwindTerm, advFluxBeforeUpwinding_[phaseIdx], phaseIdx); | |
95 | } | ||
96 | else | ||
97 | return 0.0; | ||
98 | } | ||
99 | |||
100 | /*! | ||
101 | * \brief Returns the diffusive fluxes computed by the respective law. | ||
102 | */ | ||
103 | 941513400 | Dune::FieldVector<Scalar, numComponents> molecularDiffusionFlux([[maybe_unused]] const int phaseIdx) const | |
104 | { | ||
105 | if constexpr (enableMolecularDiffusion) | ||
106 | 929105400 | return MolecularDiffusionType::flux(this->problem(), | |
107 | 929105400 | this->element(), | |
108 | 928777684 | this->fvGeometry(), | |
109 | 907298908 | this->elemVolVars(), | |
110 | 929105400 | this->scvFace(), | |
111 | phaseIdx, | ||
112 | 929105400 | this->elemFluxVarsCache()); | |
113 | else | ||
114 | ✗ | return Dune::FieldVector<Scalar, numComponents>(0.0); | |
115 | } | ||
116 | |||
117 | /*! | ||
118 | * \brief Returns the compositional dispersion flux computed by the respective law. | ||
119 | */ | ||
120 | 12276600 | Dune::FieldVector<Scalar, numComponents> compositionalDispersionFlux([[maybe_unused]] const int phaseIdx) const | |
121 | { | ||
122 | if constexpr (enableCompositionalDispersion) | ||
123 | { | ||
124 | 12276600 | return DispersionFluxType::compositionalDispersionFlux(this->problem(), | |
125 | 12276600 | this->element(), | |
126 | 12276600 | this->fvGeometry(), | |
127 | 12276600 | this->elemVolVars(), | |
128 | 12276600 | this->scvFace(), | |
129 | phaseIdx, | ||
130 | 12276600 | this->elemFluxVarsCache()); | |
131 | } | ||
132 | else | ||
133 | return Dune::FieldVector<Scalar, numComponents>(0.0); | ||
134 | } | ||
135 | |||
136 | /*! | ||
137 | * \brief Returns the thermal dispersion flux computed by the respective law. | ||
138 | */ | ||
139 | 5622400 | Dune::FieldVector<Scalar, 1> thermalDispersionFlux([[maybe_unused]] const int phaseIdx = 0) const | |
140 | { | ||
141 | if constexpr (enableThermalDispersion) | ||
142 | { | ||
143 | 5622400 | return DispersionFluxType::thermalDispersionFlux(this->problem(), | |
144 | 5622400 | this->element(), | |
145 | 5622400 | this->fvGeometry(), | |
146 | 5622400 | this->elemVolVars(), | |
147 | 5622400 | this->scvFace(), | |
148 | phaseIdx, | ||
149 | 5622400 | this->elemFluxVarsCache()); | |
150 | } | ||
151 | else | ||
152 | return Dune::FieldVector<Scalar, 1>(0.0); | ||
153 | } | ||
154 | |||
155 | /*! | ||
156 | * \brief Returns the conductive flux computed by the respective law. | ||
157 | * \note This overload is used in models considering local thermal equilibrium | ||
158 | */ | ||
159 | 215750205 | Scalar heatConductionFlux() const | |
160 | { | ||
161 | static_assert(!enableThermalNonEquilibrium, "This only works for thermal equilibrium"); | ||
162 | if constexpr (enableEnergyBalance) | ||
163 | 215750205 | return HeatConductionType::flux(this->problem(), | |
164 | 215750205 | this->element(), | |
165 | 214878307 | this->fvGeometry(), | |
166 | 206407331 | this->elemVolVars(), | |
167 | 215750205 | this->scvFace(), | |
168 | 215750205 | this->elemFluxVarsCache()); | |
169 | else | ||
170 | return 0.0; | ||
171 | } | ||
172 | |||
173 | /*! | ||
174 | * \brief Returns the conductive flux computed by the respective law. | ||
175 | * \note This overload is used in models considering local thermal nonequilibrium | ||
176 | */ | ||
177 | 13087660 | Scalar heatConductionFlux([[maybe_unused]] const int phaseIdx) const | |
178 | { | ||
179 | if constexpr (enableEnergyBalance) | ||
180 | 13087660 | return HeatConductionType::flux(this->problem(), | |
181 | 13087660 | this->element(), | |
182 | 13087660 | this->fvGeometry(), | |
183 | 13087660 | this->elemVolVars(), | |
184 | 13087660 | this->scvFace(), | |
185 | phaseIdx, | ||
186 | 13087660 | this->elemFluxVarsCache()); | |
187 | else | ||
188 | return 0.0; | ||
189 | } | ||
190 | |||
191 | private: | ||
192 | //! simple caching if advection flux is used twice with different upwind function | ||
193 | mutable std::bitset<numPhases> advFluxIsCached_; | ||
194 | mutable std::array<Scalar, numPhases> advFluxBeforeUpwinding_; | ||
195 | }; | ||
196 | |||
197 | } // end namespace Dumux | ||
198 | |||
199 | #endif | ||
200 |