GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/freeflow/navierstokes/mass/1pnc/volumevariables.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 45 56 80.4%
Functions: 10 47 21.3%
Branches: 19 36 52.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-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 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 1190088 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 15258896 void update(const ElementSolution &elemSol,
60 const Problem &problem,
61 const Element &element,
62 const SubControlVolume& scv)
63 {
64 15258896 ParentType::update(elemSol, problem, element, scv);
65
66 15258896 completeFluidState(elemSol, problem, element, scv, fluidState_);
67
68 typename FluidSystem::ParameterCache paramCache;
69 15258896 paramCache.updateAll(fluidState_);
70
71 15258896 auto getDiffusionCoefficient = [&](int phaseIdx, int compIIdx, int compJIdx)
72 {
73 16117496 return FluidSystem::binaryDiffusionCoefficient(this->fluidState_,
74 16117496 paramCache,
75 0,
76 compIIdx,
77 compJIdx);
78 };
79
80 15258896 diffCoefficient_.update(getDiffusionCoefficient);
81 15258896 EnergyVolumeVariables::updateEffectiveThermalConductivity();
82 15258896 }
83
84 /*!
85 * \brief Update the fluid state
86 */
87 template<class ElementSolution, class Problem, class Element, class SubControlVolume>
88 15258896 void completeFluidState(const ElementSolution& elemSol,
89 const Problem& problem,
90 const Element& element,
91 const SubControlVolume& scv,
92 FluidState& fluidState) const
93 {
94 20002211 fluidState.setTemperature(0, EnergyVolumeVariables::getTemperature(elemSol, problem, element, scv));
95 45776688 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 15258896 fluidState.setSaturation(0, 1.0);
101
102 15258896 Scalar sumFracMinorComp = 0.0;
103
104
2/2
✓ Branch 0 taken 15688196 times.
✓ Branch 1 taken 15258896 times.
30947092 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 31376392 Scalar moleOrMassFraction = elemSol[0][Indices::conti0EqIdx+compIdx] + 1.0;
109 15688196 moleOrMassFraction = moleOrMassFraction - 1.0;
110 if(useMoles)
111 15688196 fluidState.setMoleFraction(0, compIdx, moleOrMassFraction);
112 else
113 fluidState.setMassFraction(0, compIdx, moleOrMassFraction);
114 15688196 sumFracMinorComp += moleOrMassFraction;
115 }
116 if(useMoles)
117 15258896 fluidState.setMoleFraction(0, 0, 1.0 - sumFracMinorComp);
118 else
119 fluidState.setMassFraction(0, 0, 1.0 - sumFracMinorComp);
120
121 typename FluidSystem::ParameterCache paramCache;
122 15258896 paramCache.updateAll(fluidState);
123
124 15688196 Scalar value = FluidSystem::density(fluidState, paramCache, 0);
125 15688196 fluidState.setDensity(0, value);
126
127 15688196 value = FluidSystem::molarDensity(fluidState, paramCache, 0);
128 15688196 fluidState.setMolarDensity(0, value);
129
130 15688196 value = FluidSystem::viscosity(fluidState, paramCache, 0);
131 25774477 fluidState.setViscosity(0, value);
132
133 // compute and set the enthalpy
134 15258896 const Scalar h = EnergyVolumeVariables::enthalpy(fluidState, paramCache);
135 30517792 fluidState.setEnthalpy(0, h);
136 15258896 }
137
138 /*!
139 * \brief Return the effective pressure \f$\mathrm{[Pa]}\f$ of a given phase within
140 * the control volume.
141 */
142 Scalar pressure(int phaseIdx = 0) const
143 327200 { 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 Scalar density(int phaseIdx = 0) const
156 328719616 { return fluidState_.density(0); }
157
158 /*!
159 * \brief Return temperature \f$\mathrm{[K]}\f$ inside the sub-control volume.
160 *
161 * Note that we assume thermodynamic equilibrium, i.e. the
162 * temperatures of the rock matrix and of all fluid phases are
163 * identical.
164 */
165 Scalar temperature() const
166
2/4
✓ Branch 0 taken 3942400 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3942400 times.
✗ Branch 3 not taken.
15769600 { return fluidState_.temperature(); }
167
168 /*!
169 * \brief Return the effective dynamic viscosity \f$\mathrm{[Pa s]}\f$ of the fluid within the
170 * control volume.
171 */
172 Scalar effectiveViscosity() const
173 { return viscosity(); }
174
175 /*!
176 * \brief Return the dynamic viscosity \f$\mathrm{[Pa s]}\f$ of the fluid within the
177 * control volume.
178 */
179 Scalar viscosity(int phaseIdx = 0) const
180 115186464 { return fluidState_.viscosity(0); }
181
182 /*!
183 * \brief Returns the mass fraction of a component in the phase \f$\mathrm{[-]}\f$
184 *
185 * \param phaseIdx the index of the phase
186 * \param compIdx the index of the component
187 */
188 Scalar massFraction(int phaseIdx, int compIdx) const
189 {
190
1/8
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 18440904 times.
✗ Branch 3 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
55322712 return fluidState_.massFraction(0, compIdx);
191 }
192
193 /*!
194 * \brief Returns the mass fraction of a component in the phase \f$\mathrm{[-]}\f$
195 *
196 * \param compIdx the index of the component
197 */
198 Scalar massFraction(int compIdx) const
199 {
200
2/4
✓ Branch 0 taken 96700 times.
✓ Branch 1 taken 96700 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
225800 return fluidState_.massFraction(0, compIdx);
201 }
202
203 /*!
204 * \brief Returns the mole fraction of a component in the phase \f$\mathrm{[-]}\f$
205 *
206 * \param phaseIdx the index of the phase
207 * \param compIdx the index of the component
208 */
209 Scalar moleFraction(int phaseIdx, int compIdx) const
210 {
211 30289920 return fluidState_.moleFraction(0, compIdx);
212 }
213
214 /*!
215 * \brief Returns the mole fraction of a component in the phase \f$\mathrm{[-]}\f$
216 *
217 * \param compIdx the index of the component
218 */
219 Scalar moleFraction(int compIdx) const
220 {
221
8/12
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 367200 times.
✓ Branch 5 taken 183600 times.
✓ Branch 6 taken 367200 times.
✓ Branch 7 taken 183600 times.
✓ Branch 8 taken 367200 times.
✓ Branch 9 taken 183600 times.
✓ Branch 10 taken 367200 times.
✓ Branch 11 taken 183600 times.
67769696 return fluidState_.moleFraction(0, compIdx);
222 }
223
224 /*!
225 * \brief Returns the mass density of a given phase \f$\mathrm{[kg/m^3]}\f$
226 */
227 Scalar molarDensity(int phaseIdx = 0) const
228 {
229 66300896 return fluidState_.molarDensity(0);
230 }
231
232 /*!
233 * \brief Returns the molar mass of a given component.
234 *
235 * \param compIdx the index of the component
236 */
237 Scalar molarMass(int compIdx) const
238 {
239 return FluidSystem::molarMass(compIdx);
240 }
241
242 /*!
243 * \brief Returns the average molar mass \f$\mathrm{[kg/mol]}\f$ of the fluid phase.
244 *
245 * \param phaseIdx The phase index
246 */
247 Scalar averageMolarMass(const int phaseIdx = 0) const
248 3786240 { return fluidState_.averageMolarMass(phaseIdx); }
249
250 /*!
251 * \brief Returns the binary diffusion coefficients for a phase in \f$[m^2/s]\f$.
252 */
253 Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
254 107500 { return diffCoefficient_(0, compIIdx, compJIdx); }
255
256 /*!
257 * \brief Returns the effective diffusion coefficients for a phase in \f$[m^2/s]\f$.
258 */
259 Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
260
2/2
✓ Branch 2 taken 3786240 times.
✓ Branch 3 taken 3786240 times.
26919520 { return diffusionCoefficient(0, compIIdx, compJIdx); }
261
262 /*!
263 * \brief Return the fluid state of the control volume.
264 */
265 const FluidState& fluidState() const
266
2/4
✓ Branch 0 taken 3942400 times.
✓ Branch 1 taken 3942400 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
15790100 { return fluidState_; }
267
268 protected:
269 FluidState fluidState_;
270 // Binary diffusion coefficient
271 DiffusionCoefficients diffCoefficient_;
272 };
273
274 } // end namespace Dumux
275
276 #endif // DUMUX_NAVIERSTOKES_MOMENTUM_VOLUME_VARIABLES_HH
277