GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/freeflow/navierstokes/mass/1pnc/volumevariables.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 56 56 100.0%
Functions: 14 14 100.0%
Branches: 24 29 82.8%

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 NavierStokesModel
10 *
11 * \copydoc Dumux::NavierStokesVolumeVariables
12 */
13 #ifndef DUMUX_NAVIERSTOKES_MASS_1PNC_VOLUME_VARIABLES_HH
14 #define DUMUX_NAVIERSTOKES_MASS_1PNC_VOLUME_VARIABLES_HH
15
16 #include <dumux/freeflow/navierstokes/scalarvolumevariables.hh>
17 #include <dumux/freeflow/navierstokes/energy/volumevariables.hh>
18
19 namespace Dumux {
20
21 /*!
22 * \ingroup NavierStokesModel
23 * \brief Volume variables for the single-phase Navier-Stokes model.
24 */
25 template <class Traits>
26
2/5
✗ Branch 0 not taken.
✓ Branch 1 taken 10955 times.
✓ Branch 4 taken 6420 times.
✗ Branch 5 not taken.
✗ Branch 2 not taken.
407895 class NavierStokesMassOnePNCVolumeVariables
27 : public NavierStokesScalarConservationModelVolumeVariables<Traits>
28 , public NavierStokesEnergyVolumeVariables<Traits, NavierStokesMassOnePNCVolumeVariables<Traits>>
29 {
30 using ParentType = NavierStokesScalarConservationModelVolumeVariables<Traits>;
31 using EnergyVolumeVariables = NavierStokesEnergyVolumeVariables<Traits, NavierStokesMassOnePNCVolumeVariables<Traits>>;
32
33 using Scalar = typename Traits::PrimaryVariables::value_type;
34
35 static constexpr bool useMoles = Traits::ModelTraits::useMoles();
36 using DiffusionCoefficients = typename Traits::DiffusionType::DiffusionCoefficientsContainer;
37
38
39 public:
40 //! export the underlying fluid system
41 using FluidSystem = typename Traits::FluidSystem;
42 //! export the fluid state type
43 using FluidState = typename Traits::FluidState;
44 //! export the diffusion type
45 using MolecularDiffusionType = typename Traits::DiffusionType;
46 //! export the indices type
47 using Indices = typename Traits::ModelTraits::Indices;
48
49 /*!
50 * \brief Update all quantities for a given control volume
51 *
52 * \param elemSol A vector containing all primary variables connected to the element
53 * \param problem The object specifying the problem which ought to
54 * be simulated
55 * \param element An element which contains part of the control volume
56 * \param scv The sub-control volume
57 */
58 template<class ElementSolution, class Problem, class Element, class SubControlVolume>
59 18823427 void update(const ElementSolution &elemSol,
60 const Problem &problem,
61 const Element &element,
62 const SubControlVolume& scv)
63 {
64 18823427 ParentType::update(elemSol, problem, element, scv);
65
66 18823427 completeFluidState(elemSol, problem, element, scv, fluidState_);
67
68 typename FluidSystem::ParameterCache paramCache;
69 paramCache.updateAll(fluidState_);
70
71 38505454 auto getDiffusionCoefficient = [&](int phaseIdx, int compIIdx, int compJIdx)
72 {
73 19682027 return FluidSystem::binaryDiffusionCoefficient(this->fluidState_,
74 paramCache,
75 0,
76 compIIdx,
77 compJIdx);
78 };
79
80 18823427 diffCoefficient_.update(getDiffusionCoefficient);
81 18823427 EnergyVolumeVariables::updateEffectiveThermalConductivity();
82 18823427 }
83
84 /*!
85 * \brief Update the fluid state
86 */
87 template<class ElementSolution, class Problem, class Element, class SubControlVolume>
88 18823427 void completeFluidState(const ElementSolution& elemSol,
89 const Problem& problem,
90 const Element& element,
91 const SubControlVolume& scv,
92 FluidState& fluidState) const
93 {
94 18823427 fluidState.setTemperature(0, EnergyVolumeVariables::getTemperature(elemSol, problem, element, scv));
95 18823427 fluidState.setPressure(0, elemSol[0][Indices::pressureIdx]);
96
97 // saturation in a single phase is always 1 and thus redundant
98 // to set. But since we use the fluid state shared by the
99 // immiscible multi-phase models, so we have to set it here...
100 18823427 fluidState.setSaturation(0, 1.0);
101
102 18823427 Scalar sumFracMinorComp = 0.0;
103
104
2/2
✓ Branch 0 taken 19252727 times.
✓ Branch 1 taken 18823427 times.
38076154 for(int compIdx = 1; compIdx < ParentType::numFluidComponents(); ++compIdx)
105 {
106 // temporary add 1.0 to remove spurious differences in mole fractions
107 // which are below the numerical accuracy
108 19252727 Scalar moleOrMassFraction = elemSol[0][Indices::conti0EqIdx+compIdx] + 1.0;
109 19252727 moleOrMassFraction = moleOrMassFraction - 1.0;
110 if(useMoles)
111 19252727 fluidState.setMoleFraction(0, compIdx, moleOrMassFraction);
112 else
113 fluidState.setMassFraction(0, compIdx, moleOrMassFraction);
114 19252727 sumFracMinorComp += moleOrMassFraction;
115 }
116 if(useMoles)
117 18823427 fluidState.setMoleFraction(0, 0, 1.0 - sumFracMinorComp);
118 else
119 fluidState.setMassFraction(0, 0, 1.0 - sumFracMinorComp);
120
121 typename FluidSystem::ParameterCache paramCache;
122 18823427 paramCache.updateAll(fluidState);
123
124 18823427 Scalar value = FluidSystem::density(fluidState, paramCache, 0);
125 18823427 fluidState.setDensity(0, value);
126
127 18823427 value = FluidSystem::molarDensity(fluidState, paramCache, 0);
128 18823427 fluidState.setMolarDensity(0, value);
129
130 18823427 value = FluidSystem::viscosity(fluidState, paramCache, 0);
131 18823427 fluidState.setViscosity(0, value);
132
133 // compute and set the enthalpy
134 18823427 const Scalar h = EnergyVolumeVariables::enthalpy(fluidState, paramCache);
135 18823427 fluidState.setEnthalpy(0, h);
136 18823427 }
137
138 /*!
139 * \brief Return the effective pressure \f$\mathrm{[Pa]}\f$ of a given phase within
140 * the control volume.
141 */
142 190740 Scalar pressure(int phaseIdx = 0) const
143 190740 { return fluidState_.pressure(0); }
144
145 /*!
146 * \brief Returns the saturation.
147 */
148 Scalar saturation(int phaseIdx = 0) const
149 { return 1.0; }
150
151 /*!
152 * \brief Return the mass density \f$\mathrm{[kg/m^3]}\f$ of a given phase within the
153 * control volume.
154 */
155 178218668 Scalar density(int phaseIdx = 0) const
156
4/4
✓ Branch 1 taken 2303 times.
✓ Branch 2 taken 1222 times.
✓ Branch 5 taken 781 times.
✓ Branch 6 taken 1475 times.
151853388 { return fluidState_.density(0); }
157
158 /*!
159 * \brief Return temperature \f$\mathrm{[K]}\f$ inside the sub-control volume.
160 *
161 */
162 10584241 Scalar temperature() const
163
1/2
✓ Branch 0 taken 5274380 times.
✗ Branch 1 not taken.
10548760 { return fluidState_.temperature(); }
164
165 /*!
166 * \brief Return the effective dynamic viscosity \f$\mathrm{[Pa s]}\f$ of the fluid within the
167 * control volume.
168 */
169 Scalar effectiveViscosity() const
170 { return viscosity(); }
171
172 /*!
173 * \brief Return the dynamic viscosity \f$\mathrm{[Pa s]}\f$ of the fluid within the
174 * control volume.
175 */
176 140703598 Scalar viscosity(int phaseIdx = 0) const
177 71088495 { return fluidState_.viscosity(0); }
178
179 /*!
180 * \brief Returns the mass fraction of a component in the phase \f$\mathrm{[-]}\f$
181 *
182 * \param phaseIdx the index of the phase
183 * \param compIdx the index of the component
184 */
185 28031893 Scalar massFraction(int phaseIdx, int compIdx) const
186 {
187 23243675 return fluidState_.massFraction(0, compIdx);
188 }
189
190 /*!
191 * \brief Returns the mass fraction of a component in the phase \f$\mathrm{[-]}\f$
192 *
193 * \param compIdx the index of the component
194 */
195 263880 Scalar massFraction(int compIdx) const
196 {
197 263880 return fluidState_.massFraction(0, compIdx);
198 }
199
200 /*!
201 * \brief Returns the mole fraction of a component in the phase \f$\mathrm{[-]}\f$
202 *
203 * \param phaseIdx the index of the phase
204 * \param compIdx the index of the component
205 */
206 13280946 Scalar moleFraction(int phaseIdx, int compIdx) const
207 {
208
2/2
✓ Branch 1 taken 5344 times.
✓ Branch 2 taken 6392 times.
13280946 return fluidState_.moleFraction(0, compIdx);
209 }
210
211 /*!
212 * \brief Returns the mole fraction of a component in the phase \f$\mathrm{[-]}\f$
213 *
214 * \param compIdx the index of the component
215 */
216 39177132 Scalar moleFraction(int compIdx) const
217 {
218
4/4
✓ Branch 0 taken 3278000 times.
✓ Branch 1 taken 3094400 times.
✓ Branch 2 taken 3278000 times.
✓ Branch 3 taken 3094400 times.
38832652 return fluidState_.moleFraction(0, compIdx);
219 }
220
221 /*!
222 * \brief Returns the mass density of a given phase \f$\mathrm{[kg/m^3]}\f$
223 */
224 31123722 Scalar molarDensity(int phaseIdx = 0) const
225 {
226
2/2
✓ Branch 1 taken 5344 times.
✓ Branch 2 taken 6392 times.
30913882 return fluidState_.molarDensity(0);
227 }
228
229 /*!
230 * \brief Returns the molar mass of a given component.
231 *
232 * \param compIdx the index of the component
233 */
234 Scalar molarMass(int compIdx) const
235 {
236 return FluidSystem::molarMass(compIdx);
237 }
238
239 /*!
240 * \brief Returns the average molar mass \f$\mathrm{[kg/mol]}\f$ of the fluid phase.
241 *
242 * \param phaseIdx The phase index
243 */
244 1893120 Scalar averageMolarMass(const int phaseIdx = 0) const
245 1893120 { return fluidState_.averageMolarMass(phaseIdx); }
246
247 /*!
248 * \brief Returns the binary diffusion coefficients for a phase in \f$[m^2/s]\f$.
249 */
250 30724989 Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
251 134640 { return diffCoefficient_(0, compIIdx, compJIdx); }
252
253 /*!
254 * \brief Returns the effective diffusion coefficients for a phase in \f$[m^2/s]\f$.
255 */
256 30590349 Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
257
3/4
✓ Branch 0 taken 13287872 times.
✓ Branch 1 taken 4000052 times.
✓ Branch 2 taken 9501632 times.
✗ Branch 3 not taken.
30590349 { return diffusionCoefficient(0, compIIdx, compJIdx); }
258
259 /*!
260 * \brief Return the fluid state of the control volume.
261 */
262 10548760 const FluidState& fluidState() const
263
4/4
✓ Branch 0 taken 2303 times.
✓ Branch 1 taken 1222 times.
✓ Branch 2 taken 781 times.
✓ Branch 3 taken 1475 times.
22648744 { return fluidState_; }
264
265 protected:
266 FluidState fluidState_;
267 // Binary diffusion coefficient
268 DiffusionCoefficients diffCoefficient_;
269 };
270
271 } // end namespace Dumux
272
273 #endif // DUMUX_NAVIERSTOKES_MOMENTUM_VOLUME_VARIABLES_HH
274