GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/porousmediumflow/tracer/volumevariables.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 22 31 71.0%
Functions: 29 130 22.3%
Branches: 75 92 81.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 TracerModel
10 * \brief Quantities required by the tracer model in a control volume.
11 */
12 #ifndef DUMUX_TRACER_VOLUME_VARIABLES_HH
13 #define DUMUX_TRACER_VOLUME_VARIABLES_HH
14
15 #include <cassert>
16 #include <array>
17 #include <type_traits>
18
19 #include <dune/common/std/type_traits.hh>
20
21 #include <dumux/porousmediumflow/volumevariables.hh>
22 #include <dumux/material/solidstates/updatesolidvolumefractions.hh>
23
24 namespace Dumux {
25
26 namespace Detail {
27 // helper structs and functions detecting if the user-defined spatial params class
28 // has user-specified functions saturation() for multi-phase tracer.
29 template <typename T, typename ...Ts>
30 using SaturationDetector = decltype(std::declval<T>().spatialParams().saturation(std::declval<Ts>()...));
31
32 template<class T, typename ...Args>
33 static constexpr bool hasSaturation()
34 { return Dune::Std::is_detected<SaturationDetector, T, Args...>::value; }
35
36 } // end namespace Detail
37
38 /*!
39 * \ingroup TracerModel
40 * \brief Contains the quantities which are constant within a
41 * finite volume for the tracer model.
42 */
43 template <class Traits>
44
15/22
✓ Branch 0 taken 240960 times.
✓ Branch 1 taken 52000 times.
✓ Branch 2 taken 240960 times.
✓ Branch 3 taken 52000 times.
✓ Branch 4 taken 120480 times.
✓ Branch 5 taken 100000 times.
✓ Branch 6 taken 120480 times.
✓ Branch 7 taken 260000 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 160000 times.
✓ Branch 10 taken 1014000 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1014000 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 12172000 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 12172000 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 517000 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 517000 times.
56688740 class TracerVolumeVariables
45 : public PorousMediumFlowVolumeVariables<Traits>
46 {
47 using ParentType = PorousMediumFlowVolumeVariables<Traits>;
48 using Scalar = typename Traits::PrimaryVariables::value_type;
49 static constexpr bool useMoles = Traits::ModelTraits::useMoles();
50 using EffDiffModel = typename Traits::EffectiveDiffusivityModel;
51 static constexpr int numFluidComps = ParentType::numFluidComponents();
52
53 public:
54 //! Export the fluid system type
55 using FluidSystem = typename Traits::FluidSystem;
56 //! Export the solid state type
57 using SolidState = typename Traits::SolidState;
58 //! Export the indices
59 using Indices = typename Traits::ModelTraits::Indices;
60
61 /*!
62 * \brief Updates all quantities for a given control volume.
63 *
64 * \param elemSol A vector containing all primary variables connected to the element
65 * \param problem The object specifying the problem which ought to
66 * be simulated
67 * \param element An element which contains part of the control volume
68 * \param scv The sub-control volume
69 */
70 template<class ElemSol, class Problem, class Element, class Scv>
71 25232934 void update(const ElemSol &elemSol,
72 const Problem &problem,
73 const Element &element,
74 const Scv &scv)
75 {
76 // update parent type sets primary variables
77
2/2
✓ Branch 0 taken 9003000 times.
✓ Branch 1 taken 6423680 times.
25232934 ParentType::update(elemSol, problem, element, scv);
78
79
2/2
✓ Branch 0 taken 9003000 times.
✓ Branch 1 taken 6423680 times.
25232934 updateSolidVolumeFractions(elemSol, problem, element, scv, solidState_, numFluidComps);
80
81 // the spatial params special to the tracer model
82
2/2
✓ Branch 0 taken 9003000 times.
✓ Branch 1 taken 6423680 times.
26075718 fluidDensity_ = problem.spatialParams().fluidDensity(element, scv);
83
2/2
✓ Branch 0 taken 9003000 times.
✓ Branch 1 taken 6423680 times.
25232934 fluidMolarMass_ = problem.spatialParams().fluidMolarMass(element, scv);
84
85 if constexpr (Detail::hasSaturation<Problem, Element, Scv>())
86
4/4
✓ Branch 0 taken 9003000 times.
✓ Branch 1 taken 6423680 times.
✓ Branch 2 taken 9003000 times.
✓ Branch 3 taken 6423680 times.
33381712 fluidSaturation_ = problem.spatialParams().saturation(element, scv);
87
88
2/2
✓ Branch 0 taken 43752879 times.
✓ Branch 1 taken 23276199 times.
70942548 for (int compIdx = 0; compIdx < ParentType::numFluidComponents(); ++compIdx)
89 {
90 132372588 moleOrMassFraction_[compIdx] = this->priVars()[compIdx];
91 45709614 diffCoeff_[compIdx] = FluidSystem::binaryDiffusionCoefficient(compIdx, problem, element, scv);
92 45709614 effectiveDiffCoeff_[compIdx] = EffDiffModel::effectiveDiffusionCoefficient(*this, 0, 0, compIdx);
93 }
94 25232934 }
95
96 /*!
97 * \brief Returns the density \f$\mathrm{[kg/m^3]}\f$ the of the fluid phase.
98 *
99 * We always forward to the fluid state with the phaseIdx property (see class description).
100 *
101 * \param phaseIdx The phase index
102 */
103 Scalar density(int phaseIdx = 0) const
104 { return fluidDensity_; }
105
106 /*!
107 * \brief Returns the average molar mass \f$\mathrm{[kg/mol]}\f$ of the fluid phase.
108 *
109 * \param phaseIdx The phase index
110 */
111 Scalar averageMolarMass(int phaseIdx = 0) const
112 { return fluidMolarMass_; }
113
114 /*!
115 * \brief Returns the phase state for the control volume.
116 */
117 const SolidState &solidState() const
118 { return solidState_; }
119
120 /*!
121 * \brief Returns the saturation.
122 *
123 * This method is here for compatibility reasons with other models. The saturation
124 * is always 1.0 in a one-phasic context, if two-phases or richards are considered,
125 * the spatialParams serve as way to pass the saturation from the main-file to the
126 * volVars and then to the localresidual for the tracer model.
127
128 * \param phaseIdx The phase index
129 */
130 Scalar saturation(int phaseIdx = 0) const
131 { return fluidSaturation_ ; }
132
133 /*!
134 * \brief Returns the mobility.
135 *
136 * This method is here for compatibility reasons with other models. The mobility is always 1
137 * for one-phasic models where the velocity field is given
138 *
139 * \param phaseIdx The phase index
140 */
141 Scalar mobility(int phaseIdx = 0) const
142 { return 1.0; }
143
144 /*!
145 * \brief Returns the molar density \f$\mathrm{[mol/m^3]}\f$ the of the fluid phase.
146 *
147 * \param phaseIdx The phase index
148 */
149 Scalar molarDensity(int phaseIdx = 0) const
150
2/2
✓ Branch 0 taken 5858 times.
✓ Branch 1 taken 6868 times.
23941487 { return fluidDensity_/fluidMolarMass_; }
151
152 /*!
153 * \brief Returns the mole fraction \f$\mathrm{[mol/mol]}\f$ of a component in the phase.
154 *
155 * \param phaseIdx The phase index
156 * \param compIdx The index of the component
157 */
158 Scalar moleFraction(int phaseIdx, int compIdx) const
159
4/4
✓ Branch 0 taken 5858 times.
✓ Branch 1 taken 6868 times.
✓ Branch 2 taken 5858 times.
✓ Branch 3 taken 6868 times.
48188854 { return useMoles ? moleOrMassFraction_[compIdx] : moleOrMassFraction_[compIdx]/FluidSystem::molarMass(compIdx)*fluidMolarMass_; }
160
161 /*!
162 * \brief Returns the mass fraction \f$\mathrm{[kg/kg]}\f$ of a component in the phase.
163 *
164 * \param phaseIdx The phase index
165 * \param compIdx The index of the component
166 */
167 Scalar massFraction(int phaseIdx, int compIdx) const
168
9/12
✓ Branch 0 taken 776800 times.
✓ Branch 1 taken 25000 times.
✓ Branch 2 taken 776800 times.
✓ Branch 3 taken 25000 times.
✓ Branch 4 taken 1250000 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 21494000 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 20244000 times.
✗ Branch 9 not taken.
✓ Branch 16 taken 30942 times.
✓ Branch 17 taken 314150 times.
945393318 { return useMoles ? moleOrMassFraction_[compIdx]*FluidSystem::molarMass(compIdx)/fluidMolarMass_ : moleOrMassFraction_[compIdx]; }
169
170 /*!
171 * \brief Returns the concentration \f$\mathrm{[mol/m^3]}\f$ of a component in the phase.
172 *
173 * \param phaseIdx The phase index
174 * \param compIdx The index of the component
175 */
176 Scalar molarity(int phaseIdx, int compIdx) const
177 { return moleFraction(phaseIdx, compIdx)*molarDensity(); }
178
179 /*!
180 * \brief Returns the binary diffusion coefficients for a phase in \f$[m^2/s]\f$.
181 */
182 111158994 Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
183 {
184
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 77103819 times.
111158994 if (phaseIdx != compIIdx) std::swap(compIIdx, compJIdx);
185
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 77103819 times.
111158994 assert(phaseIdx == 0);
186
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 77103819 times.
111158994 assert(phaseIdx == compIIdx);
187 222317988 return diffCoeff_[compJIdx]; }
188
189 /*!
190 * \brief Returns the effective diffusion coefficients for a phase in \f$[m^2/s]\f$.
191 */
192 Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
193 {
194 if (phaseIdx != compIIdx) std::swap(compIIdx, compJIdx);
195 assert(phaseIdx == 0);
196 assert(phaseIdx == compIIdx);
197
24/24
✓ Branch 0 taken 2025858 times.
✓ Branch 1 taken 2026868 times.
✓ Branch 2 taken 2025858 times.
✓ Branch 3 taken 2026868 times.
✓ Branch 4 taken 2020000 times.
✓ Branch 5 taken 2020000 times.
✓ Branch 6 taken 2020000 times.
✓ Branch 7 taken 2020000 times.
✓ Branch 8 taken 2020000 times.
✓ Branch 9 taken 2020000 times.
✓ Branch 10 taken 2020000 times.
✓ Branch 11 taken 2020000 times.
✓ Branch 12 taken 2020000 times.
✓ Branch 13 taken 2020000 times.
✓ Branch 14 taken 2020000 times.
✓ Branch 15 taken 2020000 times.
✓ Branch 16 taken 20000 times.
✓ Branch 17 taken 20000 times.
✓ Branch 18 taken 20000 times.
✓ Branch 19 taken 20000 times.
✓ Branch 20 taken 20000 times.
✓ Branch 21 taken 20000 times.
✓ Branch 22 taken 20000 times.
✓ Branch 23 taken 20000 times.
238474860 return effectiveDiffCoeff_[compJIdx];
198 }
199
200 /*!
201 * \brief Return the average porosity \f$\mathrm{[-]}\f$ within the control volume.
202 */
203 Scalar porosity() const
204
4/8
✓ Branch 0 taken 2026800 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2026800 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 20244000 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 20244000 times.
✗ Branch 9 not taken.
368060438 { return solidState_.porosity(); }
205
206 protected:
207 SolidState solidState_;
208 Scalar fluidDensity_, fluidMolarMass_;
209 Scalar fluidSaturation_ = 1.0;
210
211 std::array<Scalar, numFluidComps> diffCoeff_;
212 std::array<Scalar, numFluidComps> effectiveDiffCoeff_;
213 std::array<Scalar, numFluidComps> moleOrMassFraction_;
214 };
215
216 } // end namespace Dumux
217
218 #endif
219