GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/freeflow/navierstokes/mass/1pnc/localresidual.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 16 16 100.0%
Functions: 0 0 -%
Branches: 13 14 92.9%

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 * \copydoc Dumux::NavierStokesMassOnePNCLocalResidual
11 */
12 #ifndef DUMUX_NAVIERSTOKES_MASS_1PNC_LOCAL_RESIDUAL_HH
13 #define DUMUX_NAVIERSTOKES_MASS_1PNC_LOCAL_RESIDUAL_HH
14
15 #include <dumux/common/numeqvector.hh>
16 #include <dumux/common/properties.hh>
17 #include <dumux/discretization/method.hh>
18 #include <dumux/discretization/defaultlocaloperator.hh>
19
20 namespace Dumux {
21
22 /*!
23 * \ingroup NavierStokesModel
24 * \brief Element-wise calculation of the Navier-Stokes residual for multicomponent single-phase flow.
25 */
26 template<class TypeTag>
27 class NavierStokesMassOnePNCLocalResidual
28 : public DiscretizationDefaultLocalOperator<TypeTag>
29 {
30 using ParentType = DiscretizationDefaultLocalOperator<TypeTag>;
31 using GridVariables = GetPropType<TypeTag, Properties::GridVariables>;
32
33 using GridVolumeVariables = typename GridVariables::GridVolumeVariables;
34 using ElementVolumeVariables = typename GridVolumeVariables::LocalView;
35 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
36
37 using GridFluxVariablesCache = typename GridVariables::GridFluxVariablesCache;
38 using ElementFluxVariablesCache = typename GridFluxVariablesCache::LocalView;
39
40 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
41 using Problem = GetPropType<TypeTag, Properties::Problem>;
42 using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
43 using FVElementGeometry = typename GridGeometry::LocalView;
44 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
45 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
46 using GridView = typename GridGeometry::GridView;
47 using Element = typename GridView::template Codim<0>::Entity;
48 using FluxVariables = GetPropType<TypeTag, Properties::FluxVariables>;
49 using ModelTraits = GetPropType<TypeTag, Properties::ModelTraits>;
50 using NumEqVector = Dumux::NumEqVector<GetPropType<TypeTag, Properties::PrimaryVariables>>;
51
52 static_assert(GridGeometry::discMethod == DiscretizationMethods::cctpfa, "");
53 static constexpr bool useMoles = ModelTraits::useMoles();
54 static constexpr auto numComponents = ModelTraits::numFluidComponents();
55
56 static constexpr int replaceCompEqIdx = ModelTraits::replaceCompEqIdx();
57 static constexpr bool useTotalMassBalance = replaceCompEqIdx < numComponents;
58
59 public:
60 //! Use the parent type's constructor
61
1/2
✓ Branch 1 taken 335280 times.
✗ Branch 2 not taken.
335280 using ParentType::ParentType;
62
63 /*!
64 * \brief Calculate the storage term of the equation
65 */
66 7580676 NumEqVector computeStorage(const Problem& problem,
67 const SubControlVolume& scv,
68 const VolumeVariables& volVars) const
69 {
70 7580676 NumEqVector storage(0.0);
71
72 7580676 const Scalar density = useMoles ? volVars.molarDensity() : volVars.density();
73
74 // compute storage term of all components
75
4/4
✓ Branch 0 taken 7764276 times.
✓ Branch 1 taken 3790338 times.
✓ Branch 2 taken 7764276 times.
✓ Branch 3 taken 3790338 times.
19318890 for (int compIdx = 0; compIdx < numComponents; ++compIdx)
76 {
77
4/4
✓ Branch 0 taken 3278000 times.
✓ Branch 1 taken 3094400 times.
✓ Branch 2 taken 3278000 times.
✓ Branch 3 taken 3094400 times.
15528552 const int eqIdx = compIdx;
78
79 15528552 const Scalar massOrMoleFraction = useMoles ? volVars.moleFraction(compIdx) : volVars.massFraction(compIdx);
80 15528552 const Scalar s = density * massOrMoleFraction;
81
82
4/4
✓ Branch 0 taken 3278000 times.
✓ Branch 1 taken 3094400 times.
✓ Branch 2 taken 3278000 times.
✓ Branch 3 taken 3094400 times.
12744800 if (eqIdx != ModelTraits::replaceCompEqIdx())
83 9339752 storage[eqIdx] += s;
84 }
85
86 // in case one balance is substituted by the total mass balance
87 if constexpr (useTotalMassBalance)
88 6188800 storage[ModelTraits::replaceCompEqIdx()] = volVars.density();
89
90 // consider energy storage for non-isothermal models
91 if constexpr (ModelTraits::enableEnergyBalance())
92 2056008 storage[ModelTraits::Indices::energyEqIdx] = volVars.density() * volVars.internalEnergy();
93
94 871868 return storage;
95 }
96
97 /*!
98 * \brief Evaluates the mass or mole flux over a face of a sub control volume.
99 *
100 * \param problem The problem
101 * \param element The element
102 * \param fvGeometry The finite volume geometry context
103 * \param elemVolVars The volume variables for all flux stencil elements
104 * \param scvf The sub control volume face to compute the flux on
105 * \param elemFluxVarsCache The cache related to flux computation
106 */
107 18901302 NumEqVector computeFlux(const Problem& problem,
108 const Element& element,
109 const FVElementGeometry& fvGeometry,
110 const ElementVolumeVariables& elemVolVars,
111 const SubControlVolumeFace& scvf,
112 const ElementFluxVariablesCache& elemFluxVarsCache) const
113 {
114 FluxVariables fluxVars;
115 18901302 fluxVars.init(problem, element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache);
116 18901302 return fluxVars.flux(0);
117 }
118 };
119
120 } // end namespace Dumux
121
122 #endif
123