GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/freeflow/navierstokes/momentum/cvfe/localresidual.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 16 18 88.9%
Functions: 24 26 92.3%
Branches: 2 4 50.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-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 * \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 the 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 Implementation = GetPropType<TypeTag, Properties::LocalResidual>;
49 using Problem = GetPropType<TypeTag, Properties::Problem>;
50 using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
51 using FVElementGeometry = typename GridGeometry::LocalView;
52 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
53 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
54 using GridView = typename GridGeometry::GridView;
55 using Element = typename GridView::template Codim<0>::Entity;
56 using ElementBoundaryTypes = GetPropType<TypeTag, Properties::ElementBoundaryTypes>;
57 using Indices = typename GetPropType<TypeTag, Properties::ModelTraits>::Indices;
58 using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
59 using NumEqVector = Dumux::NumEqVector<PrimaryVariables>;
60
61 using Extrusion = Extrusion_t<GridGeometry>;
62
63 using ModelTraits = GetPropType<TypeTag, Properties::ModelTraits>;
64
65 static constexpr auto dim = GridView::dimension;
66
67 using FluxContext = NavierStokesMomentumFluxContext<Problem, FVElementGeometry, ElementVolumeVariables, ElementFluxVariablesCache>;
68 using FluxHelper = NavierStokesMomentumFluxCVFE<GridGeometry, NumEqVector>;
69
70 public:
71 //! Use the parent type's constructor
72
2/4
✓ Branch 1 taken 84000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 84000 times.
✗ Branch 5 not taken.
2050836 using ParentType::ParentType;
73
74 /*!
75 * \brief Calculate the source term of the equation
76 *
77 * \param problem The problem to solve
78 * \param fvGeometry The finite-volume geometry of the element
79 * \param scv The sub-control volume over which we integrate the storage term
80 * \param volVars The volume variables associated with the scv
81 * \param isPreviousStorage If set to true, the storage term is evaluated on the previous time level.
82 *
83 */
84 NumEqVector computeStorage(const Problem& problem,
85 const FVElementGeometry& fvGeometry,
86 const SubControlVolume& scv,
87 const VolumeVariables& volVars,
88 const bool isPreviousStorage) const
89 {
90 return problem.density(fvGeometry.element(), fvGeometry, scv, isPreviousStorage) * volVars.velocity();
91 }
92
93 /*!
94 * \brief Calculate the source term of the equation
95 *
96 * \param problem The problem to solve
97 * \param element The DUNE Codim<0> entity for which the residual
98 * ought to be calculated
99 * \param fvGeometry The finite-volume geometry of the element
100 * \param elemVolVars The volume variables associated with the element stencil
101 * \param scv The sub-control volume over which we integrate the source term
102 *
103 */
104 32099240 NumEqVector computeSource(const Problem& problem,
105 const Element& element,
106 const FVElementGeometry& fvGeometry,
107 const ElementVolumeVariables& elemVolVars,
108 const SubControlVolume& scv) const
109 {
110 32099240 NumEqVector source = ParentType::computeSource(problem, element, fvGeometry, elemVolVars, scv);
111
112 // add rho*g (note that gravity might be zero in case it's disabled in the problem)
113 125647592 source += problem.density(element, fvGeometry, scv) * problem.gravity();
114
115 // Axisymmetric problems in 2D feature an extra source terms arising from the transformation to cylindrical coordinates.
116 // See Ferziger/Peric: Computational methods for Fluid Dynamics (2020)
117 // https://doi.org/10.1007/978-3-319-99693-6
118 // Chapter 9.9 and Eq. (9.81) and comment on finite volume methods
119 if constexpr (dim == 2 && isRotationalExtrusion<Extrusion>)
120 {
121 // the radius with respect to the rotation axis
122 22932000 const auto r = scv.center()[Extrusion::radialAxis] - fvGeometry.gridGeometry().bBoxMin()[Extrusion::radialAxis];
123
124 // The velocity term is new with respect to Cartesian coordinates and handled below as a source term
125 // it only enters the balance of the momentum balance in radial direction
126 15288000 source[Extrusion::radialAxis] += -2.0*problem.effectiveViscosity(element, fvGeometry, scv)
127 11466000 * elemVolVars[scv].velocity(Extrusion::radialAxis) / (r*r);
128
129 // Pressure term (needed because we incorporate pressure in terms of a surface integral).
130 // grad(p) becomes div(pI) + (p/r)*n_r in cylindrical coordinates. The second term
131 // is new with respect to Cartesian coordinates and handled below as a source term.
132 11466000 source[Extrusion::radialAxis] += problem.pressure(element, fvGeometry, scv)/r;
133 }
134
135 32099240 return source;
136 }
137
138 /*!
139 * \brief Evaluates the mass flux over a face of a sub control volume.
140 *
141 * \param problem The problem
142 * \param element The element
143 * \param fvGeometry The finite volume geometry context
144 * \param elemVolVars The volume variables for all flux stencil elements
145 * \param scvf The sub control volume face to compute the flux on
146 * \param elemFluxVarsCache The cache related to flux computation
147 */
148 46168000 NumEqVector computeFlux(const Problem& problem,
149 const Element& element,
150 const FVElementGeometry& fvGeometry,
151 const ElementVolumeVariables& elemVolVars,
152 const SubControlVolumeFace& scvf,
153 const ElementFluxVariablesCache& elemFluxVarsCache) const
154 {
155 46168000 FluxContext context(problem, fvGeometry, elemVolVars, elemFluxVarsCache, scvf);
156 FluxHelper fluxHelper;
157
158 46168000 NumEqVector flux(0.0);
159 46168000 flux += fluxHelper.advectiveMomentumFlux(context);
160 46168000 flux += fluxHelper.diffusiveMomentumFlux(context);
161 46168000 flux += fluxHelper.pressureContribution(context);
162 46168000 return flux;
163 }
164 };
165
166 } // end namespace Dumux
167
168 #endif
169