GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/freeflow/navierstokes/momentum/cvfe/localresidual.hh
Date: 2025-04-19 19:19:10
Exec Total Coverage
Lines: 16 18 88.9%
Functions: 26 29 89.7%
Branches: 4 5 80.0%

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::NavierStokesResidualImpl
11 */
12 #ifndef DUMUX_NAVIERSTOKES_MOMENTUM_CVFE_LOCAL_RESIDUAL_HH
13 #define DUMUX_NAVIERSTOKES_MOMENTUM_CVFE_LOCAL_RESIDUAL_HH
14
15 #include <dune/common/hybridutilities.hh>
16
17 #include <dumux/common/properties.hh>
18 #include <dumux/common/numeqvector.hh>
19
20 #include <dumux/discretization/extrusion.hh>
21 #include <dumux/discretization/method.hh>
22 #include <dumux/assembly/cvfelocalresidual.hh>
23
24 #include <dumux/freeflow/navierstokes/momentum/cvfe/flux.hh>
25
26 namespace Dumux {
27
28 /*!
29 * \ingroup NavierStokesModel
30 * \brief Element-wise calculation of the Navier-Stokes residual for models using CVFE discretizations
31 */
32 template<class TypeTag>
33 class NavierStokesMomentumCVFELocalResidual
34 : public CVFELocalResidual<TypeTag>
35 {
36 using ParentType = CVFELocalResidual<TypeTag>;
37
38 using GridVariables = GetPropType<TypeTag, Properties::GridVariables>;
39
40 using GridVolumeVariables = typename GridVariables::GridVolumeVariables;
41 using ElementVolumeVariables = typename GridVolumeVariables::LocalView;
42 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
43
44 using GridFluxVariablesCache = typename GridVariables::GridFluxVariablesCache;
45 using ElementFluxVariablesCache = typename GridFluxVariablesCache::LocalView;
46
47 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
48 using Problem = GetPropType<TypeTag, Properties::Problem>;
49 using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
50 using FVElementGeometry = typename GridGeometry::LocalView;
51 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
52 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
53 using GridView = typename GridGeometry::GridView;
54 using Element = typename GridView::template Codim<0>::Entity;
55 using ElementBoundaryTypes = GetPropType<TypeTag, Properties::ElementBoundaryTypes>;
56 using Indices = typename GetPropType<TypeTag, Properties::ModelTraits>::Indices;
57 using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
58 using NumEqVector = Dumux::NumEqVector<PrimaryVariables>;
59
60 using Extrusion = Extrusion_t<GridGeometry>;
61
62 using ModelTraits = GetPropType<TypeTag, Properties::ModelTraits>;
63
64 static constexpr auto dim = GridView::dimension;
65
66 using FluxContext = NavierStokesMomentumFluxContext<Problem, FVElementGeometry, ElementVolumeVariables, ElementFluxVariablesCache>;
67 using FluxHelper = NavierStokesMomentumFluxCVFE<GridGeometry, NumEqVector>;
68
69 public:
70 //! Use the parent type's constructor
71
1/2
✓ Branch 1 taken 84000 times.
✗ Branch 2 not taken.
1028247 using ParentType::ParentType;
72
73 /*!
74 * \brief Calculate the storage term of the equation
75 *
76 * \param problem The problem to solve
77 * \param fvGeometry The finite-volume geometry of the element
78 * \param scv The sub-control volume over which we integrate the storage term
79 * \param volVars The volume variables associated with the scv
80 * \param isPreviousStorage If set to true, the storage term is evaluated on the previous time level.
81 *
82 */
83 NumEqVector computeStorage(const Problem& problem,
84 const FVElementGeometry& fvGeometry,
85 const SubControlVolume& scv,
86 const VolumeVariables& volVars,
87 const bool isPreviousStorage) const
88 {
89 return problem.density(fvGeometry.element(), fvGeometry, scv, isPreviousStorage) * volVars.velocity();
90 }
91
92 /*!
93 * \brief Calculate the source term of the equation
94 *
95 * \param problem The problem to solve
96 * \param element The DUNE Codim<0> entity for which the residual
97 * ought to be calculated
98 * \param fvGeometry The finite-volume geometry of the element
99 * \param elemVolVars The volume variables associated with the element stencil
100 * \param scv The sub-control volume over which we integrate the source term
101 *
102 */
103 32455694 NumEqVector computeSource(const Problem& problem,
104 const Element& element,
105 const FVElementGeometry& fvGeometry,
106 const ElementVolumeVariables& elemVolVars,
107 const SubControlVolume& scv) const
108 {
109 32455694 NumEqVector source = ParentType::computeSource(problem, element, fvGeometry, elemVolVars, scv);
110
111 // add rho*g (note that gravity might be zero in case it's disabled in the problem)
112
3/3
✓ Branch 0 taken 4907304 times.
✓ Branch 1 taken 2705130 times.
✓ Branch 2 taken 356454 times.
70888054 source += problem.density(element, fvGeometry, scv) * problem.gravity();
113
114 // Axisymmetric problems in 2D feature an extra source term arising from the transformation to cylindrical coordinates.
115 // See Ferziger/Peric: Computational methods for Fluid Dynamics (2020)
116 // https://doi.org/10.1007/978-3-319-99693-6
117 // Chapter 9.9 and Eq. (9.81) and comment on finite volume methods
118 if constexpr (dim == 2 && isRotationalExtrusion<Extrusion>)
119 {
120 // the radius with respect to the rotation axis
121 3822000 const auto r = scv.center()[Extrusion::radialAxis] - fvGeometry.gridGeometry().bBoxMin()[Extrusion::radialAxis];
122
123 // The velocity term is new with respect to Cartesian coordinates and handled below as a source term
124 // It only enters the balance of the momentum balance in radial direction
125 3822000 source[Extrusion::radialAxis] += -2.0*problem.effectiveViscosity(element, fvGeometry, scv)
126 3822000 * elemVolVars[scv].velocity(Extrusion::radialAxis) / (r*r);
127
128 // Pressure term (needed because we incorporate pressure in terms of a surface integral).
129 // grad(p) becomes div(pI) + (p/r)*n_r in cylindrical coordinates. The second term
130 // is new with respect to Cartesian coordinates and handled below as a source term.
131 3822000 source[Extrusion::radialAxis] += problem.pressure(element, fvGeometry, scv)/r;
132 }
133
134 32455694 return source;
135 }
136
137 /*!
138 * \brief Evaluates the mass flux over a face of a sub control volume.
139 *
140 * \param problem The problem
141 * \param element The element
142 * \param fvGeometry The finite volume geometry context
143 * \param elemVolVars The volume variables for all flux stencil elements
144 * \param scvf The sub control volume face to compute the flux on
145 * \param elemFluxVarsCache The cache related to flux computation
146 */
147 46880908 NumEqVector computeFlux(const Problem& problem,
148 const Element& element,
149 const FVElementGeometry& fvGeometry,
150 const ElementVolumeVariables& elemVolVars,
151 const SubControlVolumeFace& scvf,
152 const ElementFluxVariablesCache& elemFluxVarsCache) const
153 {
154 46880908 FluxContext context(problem, fvGeometry, elemVolVars, elemFluxVarsCache, scvf);
155 FluxHelper fluxHelper;
156
157 46880908 NumEqVector flux(0.0);
158 46880908 flux += fluxHelper.advectiveMomentumFlux(context);
159 46880908 flux += fluxHelper.diffusiveMomentumFlux(context);
160 46880908 flux += fluxHelper.pressureContribution(context);
161 46880908 return flux;
162 }
163 };
164
165 } // end namespace Dumux
166
167 #endif
168