GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/freeflow/navierstokes/mass/1pnc/volumevariables.hh
Date: 2024-09-21 20:52:54
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 */
162 Scalar temperature() const
163
2/4
✓ Branch 0 taken 3942400 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3942400 times.
✗ Branch 3 not taken.
15769600 { 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 Scalar viscosity(int phaseIdx = 0) const
177 115186464 { 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 Scalar massFraction(int phaseIdx, int compIdx) const
186 {
187
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);
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 Scalar massFraction(int compIdx) const
196 {
197
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);
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 Scalar moleFraction(int phaseIdx, int compIdx) const
207 {
208 30289920 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 Scalar moleFraction(int compIdx) const
217 {
218
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);
219 }
220
221 /*!
222 * \brief Returns the mass density of a given phase \f$\mathrm{[kg/m^3]}\f$
223 */
224 Scalar molarDensity(int phaseIdx = 0) const
225 {
226 66300896 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 Scalar averageMolarMass(const int phaseIdx = 0) const
245 3786240 { return fluidState_.averageMolarMass(phaseIdx); }
246
247 /*!
248 * \brief Returns the binary diffusion coefficients for a phase in \f$[m^2/s]\f$.
249 */
250 Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
251 107500 { 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 Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
257
2/2
✓ Branch 2 taken 3786240 times.
✓ Branch 3 taken 3786240 times.
26919520 { return diffusionCoefficient(0, compIIdx, compJIdx); }
258
259 /*!
260 * \brief Return the fluid state of the control volume.
261 */
262 const FluidState& fluidState() const
263
2/4
✓ Branch 0 taken 3942400 times.
✓ Branch 1 taken 3942400 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
15790100 { 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