GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/freeflow/compositional/volumevariables.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 59 59 100.0%
Functions: 58 58 100.0%
Branches: 67 109 61.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-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 FreeflowNCModel
10 *
11 * \copydoc Dumux::FreeflowNCVolumeVariables
12 */
13 #ifndef DUMUX_FREEFLOW_NC_VOLUMEVARIABLES_HH
14 #define DUMUX_FREEFLOW_NC_VOLUMEVARIABLES_HH
15
16 #include <array>
17 #include <dune/common/exceptions.hh>
18 #include <dumux/freeflow/volumevariables.hh>
19
20 namespace Dumux {
21
22 /*!
23 * \ingroup FreeflowNCModel
24 * \brief Volume variables for the single-phase, multi-component free-flow model.
25 */
26 template <class Traits>
27
1/2
✓ Branch 1 taken 83008 times.
✗ Branch 2 not taken.
91058 class FreeflowNCVolumeVariables : public FreeFlowVolumeVariables< Traits, FreeflowNCVolumeVariables<Traits> >
28 {
29 using ThisType = FreeflowNCVolumeVariables<Traits>;
30 using ParentType = FreeFlowVolumeVariables<Traits, ThisType>;
31
32 using Scalar = typename Traits::PrimaryVariables::value_type;
33
34 static constexpr bool useMoles = Traits::ModelTraits::useMoles();
35 static constexpr int numFluidComps = ParentType::numFluidComponents();
36 using DiffusionCoefficients = typename Traits::DiffusionType::DiffusionCoefficientsContainer;
37
38 public:
39 //! export the underlying fluid system
40 using FluidSystem = typename Traits::FluidSystem;
41 //! export the fluid state type
42 using FluidState = typename Traits::FluidState;
43 //! export the indices type
44 using Indices = typename Traits::ModelTraits::Indices;
45
46 /*!
47 * \brief Update all quantities for a given control volume
48 *
49 * \param elemSol A vector containing all primary variables connected to the element
50 * \param problem The object specifying the problem which ought to
51 * be simulated
52 * \param element An element which contains part of the control volume
53 * \param scv The sub-control volume
54 */
55 template<class ElementSolution, class Problem, class Element, class SubControlVolume>
56 40941936 void update(const ElementSolution &elemSol,
57 const Problem &problem,
58 const Element &element,
59 const SubControlVolume& scv)
60 {
61 40941936 ParentType::update(elemSol, problem, element, scv);
62
63 40941936 completeFluidState(elemSol, problem, element, scv, fluidState_);
64
65 typename FluidSystem::ParameterCache paramCache;
66 paramCache.updateAll(fluidState_);
67
68 84004962 auto getDiffusionCoefficient = [&](int phaseIdx, int compIIdx, int compJIdx)
69 {
70 43063026 return FluidSystem::binaryDiffusionCoefficient(this->fluidState_,
71 paramCache,
72 0,
73 compIIdx,
74 compJIdx);
75 };
76
77 40941936 diffCoefficient_.update(getDiffusionCoefficient);
78 40941936 }
79
80 /*!
81 * \brief Update the fluid state
82 */
83 template<class ElementSolution, class Problem, class Element, class SubControlVolume>
84 40941936 static void completeFluidState(const ElementSolution& elemSol,
85 const Problem& problem,
86 const Element& element,
87 const SubControlVolume& scv,
88 FluidState& fluidState)
89 {
90 40941936 fluidState.setTemperature(ParentType::temperature(elemSol, problem, element, scv));
91 40941936 fluidState.setPressure(0, elemSol[0][Indices::pressureIdx]);
92
93 // saturation in a single phase is always 1 and thus redundant
94 // to set. But since we use the fluid state shared by the
95 // immiscible multi-phase models, so we have to set it here...
96 40941936 fluidState.setSaturation(0, 1.0);
97
98 40941936 Scalar sumFracMinorComp = 0.0;
99
100
2/2
✓ Branch 0 taken 42001506 times.
✓ Branch 1 taken 40939986 times.
82945392 for(int compIdx = 1; compIdx < ParentType::numFluidComponents(); ++compIdx)
101 {
102 // temporary add 1.0 to remove spurious differences in mole fractions
103 // which are below the numerical accuracy
104 42003456 Scalar moleOrMassFraction = elemSol[0][Indices::conti0EqIdx+compIdx] + 1.0;
105 42003456 moleOrMassFraction = moleOrMassFraction - 1.0;
106 if(useMoles)
107 41999556 fluidState.setMoleFraction(0, compIdx, moleOrMassFraction);
108 else
109 3900 fluidState.setMassFraction(0, compIdx, moleOrMassFraction);
110 42003456 sumFracMinorComp += moleOrMassFraction;
111 }
112 if(useMoles)
113 40938036 fluidState.setMoleFraction(0, 0, 1.0 - sumFracMinorComp);
114 else
115 3900 fluidState.setMassFraction(0, 0, 1.0 - sumFracMinorComp);
116
117 typename FluidSystem::ParameterCache paramCache;
118 40941936 paramCache.updateAll(fluidState);
119
120 40941936 Scalar value = FluidSystem::density(fluidState, paramCache, 0);
121 40941936 fluidState.setDensity(0, value);
122
123 40941936 value = FluidSystem::molarDensity(fluidState, paramCache, 0);
124 40941936 fluidState.setMolarDensity(0, value);
125
126 40941936 value = FluidSystem::viscosity(fluidState, paramCache, 0);
127 40941936 fluidState.setViscosity(0, value);
128
129 // compute and set the enthalpy
130 40941936 const Scalar h = ParentType::enthalpy(fluidState, paramCache);
131 40941936 fluidState.setEnthalpy(0, h);
132 40941936 }
133
134 /*!
135 * \brief Return the effective pressure \f$\mathrm{[Pa]}\f$ of a given phase within
136 * the control volume.
137 */
138 48955015 Scalar pressure(int phaseIdx = 0) const
139 48735247 { return fluidState_.pressure(0); }
140
141 /*!
142 * \brief Return the mass density \f$\mathrm{[kg/m^3]}\f$ of a given phase within the
143 * control volume.
144 */
145 946656518 Scalar density(int phaseIdx = 0) const
146
28/48
✓ Branch 10 taken 58968055 times.
✓ Branch 11 taken 55981282 times.
✓ Branch 13 taken 2767555 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 13625 times.
✓ Branch 17 taken 20650 times.
✓ Branch 19 taken 14075 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 7025 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 25 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 25 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 25 times.
✗ Branch 32 not taken.
✓ Branch 33 taken 25 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 25 times.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✓ Branch 45 taken 25 times.
✗ Branch 46 not taken.
✓ Branch 47 taken 25 times.
✗ Branch 48 not taken.
✓ Branch 49 taken 25 times.
✗ Branch 50 not taken.
✓ Branch 51 taken 25 times.
✗ Branch 52 not taken.
✓ Branch 2 taken 19400255 times.
✓ Branch 3 taken 15471315 times.
✓ Branch 4 taken 18293660 times.
✓ Branch 5 taken 52013199 times.
✓ Branch 8 taken 60938241 times.
✓ Branch 9 taken 63373607 times.
✓ Branch 12 taken 11461310 times.
✓ Branch 6 taken 3420776 times.
✓ Branch 15 taken 14450 times.
✓ Branch 7 taken 1765905 times.
✓ Branch 18 taken 14400 times.
✓ Branch 24 taken 6200 times.
889880325 { return fluidState_.density(0); }
147
148 /*!
149 * \brief Return temperature \f$\mathrm{[K]}\f$ inside the sub-control volume.
150 *
151 * Note that we assume thermodynamic equilibrium, i.e. the
152 * temperatures of the rock matrix and of all fluid phases are
153 * identical.
154 */
155 25821102 Scalar temperature() const
156 25714328 { return fluidState_.temperature(); }
157
158 /*!
159 * \brief Return the effective dynamic viscosity \f$\mathrm{[Pa s]}\f$ of the fluid within the
160 * control volume.
161 */
162 25845924 Scalar effectiveViscosity() const
163 25845924 { return viscosity(); }
164
165 /*!
166 * \brief Return the dynamic viscosity \f$\mathrm{[Pa s]}\f$ of the fluid within the
167 * control volume.
168 */
169 225062714 Scalar viscosity(int phaseIdx = 0) const
170
15/34
✓ Branch 2 taken 4506693 times.
✓ Branch 3 taken 15498810 times.
✓ Branch 4 taken 20675 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 13025 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 13225 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 25 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 25 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 25 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 25 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 25 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 25 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✓ Branch 30 taken 25 times.
✗ Branch 31 not taken.
✓ Branch 32 taken 25 times.
✗ Branch 33 not taken.
✓ Branch 0 taken 1420056 times.
✓ Branch 1 taken 25051546 times.
210863340 { return fluidState_.viscosity(0); }
171
172 /*!
173 * \brief Returns the mass fraction of a component in the phase \f$\mathrm{[-]}\f$
174 *
175 * \param phaseIdx the index of the phase
176 * \param compIdx the index of the component
177 */
178 157212352 Scalar massFraction(int phaseIdx, int compIdx) const
179 80846497 { return fluidState_.massFraction(0, compIdx); }
180
181 /*!
182 * \brief Returns the mass fraction of a component in the phase \f$\mathrm{[-]}\f$
183 *
184 * \param compIdx the index of the component
185 */
186 282736 Scalar massFraction(int compIdx) const
187 282736 { return fluidState_.massFraction(0, compIdx); }
188
189 /*!
190 * \brief Returns the mole fraction of a component in the phase \f$\mathrm{[-]}\f$
191 *
192 * \param phaseIdx the index of the phase
193 * \param compIdx the index of the component
194 */
195 1222404 Scalar moleFraction(int phaseIdx, int compIdx) const
196
4/4
✓ Branch 0 taken 174604 times.
✓ Branch 1 taken 86084 times.
✓ Branch 2 taken 96283 times.
✓ Branch 3 taken 79853 times.
1051400 { return fluidState_.moleFraction(0, compIdx); }
197
198 /*!
199 * \brief Returns the mole fraction of a component in the phase \f$\mathrm{[-]}\f$
200 *
201 * \param compIdx the index of the component
202 */
203 206600952 Scalar moleFraction(int compIdx) const
204
5/5
✓ Branch 2 taken 17396420 times.
✓ Branch 3 taken 9690820 times.
✓ Branch 4 taken 7578420 times.
✓ Branch 5 taken 1144060 times.
✓ Branch 1 taken 14139960 times.
206318816 { return fluidState_.moleFraction(0, compIdx); }
205
206 /*!
207 * \brief Returns the mass density of a given phase \f$\mathrm{[kg/m^3]}\f$
208 */
209 149494036 Scalar molarDensity(int phaseIdx = 0) const
210
3/4
✓ Branch 0 taken 270887 times.
✓ Branch 1 taken 165937 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 171004 times.
149356168 { return fluidState_.molarDensity(0); }
211
212 /*!
213 * \brief Returns the molar mass of a given component.
214 *
215 * \param compIdx the index of the component
216 */
217 Scalar molarMass(int compIdx) const
218 { return FluidSystem::molarMass(compIdx); }
219
220 /*!
221 * \brief Returns the average molar mass \f$\mathrm{[kg/mol]}\f$ of the fluid phase.
222 *
223 * \param phaseIdx The phase index
224 */
225 8456080 Scalar averageMolarMass(const int phaseIdx = 0) const
226 8456080 { return fluidState_.averageMolarMass(phaseIdx); }
227
228 /*!
229 * \brief Returns the binary diffusion coefficients for a phase in \f$[m^2/s]\f$.
230 */
231 182337653 Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
232 142853782 { return diffCoefficient_(0, compIIdx, compJIdx); }
233
234 /*!
235 * \brief Returns the effective diffusion coefficients for a phase in \f$[m^2/s]\f$.
236 */
237 39483871 Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
238
6/6
✓ Branch 0 taken 250584 times.
✓ Branch 1 taken 4195625 times.
✓ Branch 2 taken 10232110 times.
✓ Branch 3 taken 6452576 times.
✓ Branch 4 taken 20800 times.
✓ Branch 5 taken 20800 times.
39483871 { return diffusionCoefficient(0, compIIdx, compJIdx); }
239
240 /*!
241 * \brief Return the fluid state of the control volume.
242 */
243 70688752 const FluidState& fluidState() const
244
3/4
✓ Branch 0 taken 12248 times.
✓ Branch 1 taken 72 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 48356 times.
150777488 { return fluidState_; }
245
246 protected:
247 FluidState fluidState_;
248 // Binary diffusion coefficient
249 DiffusionCoefficients diffCoefficient_;
250 };
251
252 } // end namespace Dumux
253
254 #endif
255