GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/assembly/fclocalresidual.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 29 29 100.0%
Functions: 65 88 73.9%
Branches: 7 22 31.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 Assembly
10 * \ingroup FaceCenteredStaggeredDiscretization
11 * \brief Calculates the element-wise residual for the box scheme
12 */
13 #ifndef DUMUX_FACECENTERED_LOCAL_RESIDUAL_HH
14 #define DUMUX_FACECENTERED_LOCAL_RESIDUAL_HH
15
16 #include <dune/geometry/type.hh>
17 #include <dune/istl/matrix.hh>
18
19 #include <dumux/common/numeqvector.hh>
20 #include <dumux/common/properties.hh>
21 #include <dumux/assembly/fvlocalresidual.hh>
22 #include <dumux/discretization/extrusion.hh>
23
24 namespace Dumux {
25
26 /*!
27 * \ingroup Assembly
28 * \ingroup FaceCenteredStaggeredDiscretization
29 * \brief The element-wise residual for the box scheme
30 * \tparam TypeTag the TypeTag
31 */
32 template<class TypeTag>
33 class FaceCenteredLocalResidual : public FVLocalResidual<TypeTag>
34 {
35 using ParentType = FVLocalResidual<TypeTag>;
36 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
37 using Problem = GetPropType<TypeTag, Properties::Problem>;
38 using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
39 using GridView = typename GridGeometry::GridView;
40 using Element = typename GridView::template Codim<0>::Entity;
41 using ElementBoundaryTypes = GetPropType<TypeTag, Properties::ElementBoundaryTypes>;
42 using FVElementGeometry = typename GridGeometry::LocalView;
43 using ElementVolumeVariables = typename GetPropType<TypeTag, Properties::GridVolumeVariables>::LocalView;
44 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
45 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
46 using ElementFluxVariablesCache = typename GetPropType<TypeTag, Properties::GridFluxVariablesCache>::LocalView;
47 using NumEqVector = Dumux::NumEqVector<GetPropType<TypeTag, Properties::PrimaryVariables>>;
48 using Extrusion = Extrusion_t<GridGeometry>;
49
50 public:
51 using ElementResidualVector = typename ParentType::ElementResidualVector;
52
1/2
✓ Branch 1 taken 2574802 times.
✗ Branch 2 not taken.
2605838 using ParentType::ParentType;
53
54 //! evaluate flux residuals for one sub control volume face and add to residual
55 285646218 void evalFlux(ElementResidualVector& residual,
56 const Problem& problem,
57 const Element& element,
58 const FVElementGeometry& fvGeometry,
59 const ElementVolumeVariables& elemVolVars,
60 const ElementBoundaryTypes& elemBcTypes,
61 const ElementFluxVariablesCache& elemFluxVarsCache,
62 const SubControlVolumeFace& scvf) const
63 {
64 285646218 const auto flux = evalFlux(problem, element, fvGeometry, elemVolVars, elemBcTypes, elemFluxVarsCache, scvf);
65
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 279288018 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 279288018 times.
571292436 const auto& insideScv = fvGeometry.scv(scvf.insideScvIdx());
66 856938654 residual[insideScv.localDofIndex()] += flux;
67 285646218 }
68
69 //! evaluate flux residuals for one sub control volume face
70 285646218 NumEqVector evalFlux(const Problem& problem,
71 const Element& element,
72 const FVElementGeometry& fvGeometry,
73 const ElementVolumeVariables& elemVolVars,
74 const ElementBoundaryTypes& elemBcTypes,
75 const ElementFluxVariablesCache& elemFluxVarsCache,
76 const SubControlVolumeFace& scvf) const
77 {
78
2/2
✓ Branch 0 taken 17156648 times.
✓ Branch 1 taken 268489570 times.
285646218 if (elemBcTypes.hasDirichlet())
79 17156648 return this->asImp().maybeHandleDirichletBoundary(problem, element, fvGeometry, elemVolVars, elemBcTypes, elemFluxVarsCache, scvf);
80
81
2/2
✓ Branch 0 taken 2810798 times.
✓ Branch 1 taken 265678772 times.
268489570 if (elemBcTypes.hasNeumann())
82 2810798 return this->asImp().maybeHandleNeumannBoundary(problem, element, fvGeometry, elemVolVars, elemBcTypes, elemFluxVarsCache, scvf);
83
84 265678772 return this->asImp().computeFlux(problem, element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache, elemBcTypes);
85 }
86
87 /*!
88 * \brief Calculate the source term of the equation
89 *
90 * \param problem The problem to solve
91 * \param element The DUNE Codim<0> entity for which the residual
92 * ought to be calculated
93 * \param fvGeometry The finite-volume geometry of the element
94 * \param elemVolVars The volume variables associated with the element stencil
95 * \param scv The sub-control volume over which we integrate the source term
96 * \note This is the default implementation for all models as sources are computed
97 * in the user interface of the problem
98 *
99 */
100 43559688 NumEqVector computeSource(const Problem& problem,
101 const Element& element,
102 const FVElementGeometry& fvGeometry,
103 const ElementVolumeVariables& elemVolVars,
104 const SubControlVolume& scv) const
105 {
106
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
43559688 NumEqVector source(0.0);
107
108 // add contributions from volume flux sources
109
0/8
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
130559528 source += problem.source(element, fvGeometry, elemVolVars, scv)[scv.dofAxis()];
110
111 // add contribution from possible point sources
112
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
43559688 source += problem.scvPointSources(element, fvGeometry, elemVolVars, scv)[scv.dofAxis()];
113
114 43559688 return source;
115 }
116
117 using ParentType::evalStorage;
118
119 /*!
120 * \brief Compute the storage local residual, i.e. the deviation of the
121 * storage term from zero for instationary problems.
122 *
123 * \param residual The residual vector to fill
124 * \param problem The problem to solve
125 * \param element The DUNE Codim<0> entity for which the residual
126 * ought to be calculated
127 * \param fvGeometry The finite-volume geometry of the element
128 * \param prevElemVolVars The volume averaged variables for all
129 * sub-control volumes of the element at the previous time level
130 * \param curElemVolVars The volume averaged variables for all
131 * sub-control volumes of the element at the current time level
132 * \param scv The sub control volume the storage term is integrated over
133 */
134 52411520 void evalStorage(ElementResidualVector& residual,
135 const Problem& problem,
136 const Element& element,
137 const FVElementGeometry& fvGeometry,
138 const ElementVolumeVariables& prevElemVolVars,
139 const ElementVolumeVariables& curElemVolVars,
140 const SubControlVolume& scv) const
141 {
142 52411520 const auto& curVolVars = curElemVolVars[scv];
143 52411520 const auto& prevVolVars = prevElemVolVars[scv];
144
145 // mass balance within the element. this is the
146 // \f$\frac{m}{\partial t}\f$ term if using implicit or explicit
147 // euler as time discretization.
148 //
149
150 //! Compute storage with the model specific storage residual
151 52411520 NumEqVector prevStorage = this->asImp().computeStorage(problem, scv, prevVolVars, true/*isPreviousStorage*/);
152 52411520 NumEqVector storage = this->asImp().computeStorage(problem, scv, curVolVars, false/*isPreviousStorage*/);
153
154 52411520 prevStorage *= prevVolVars.extrusionFactor();
155 52411520 storage *= curVolVars.extrusionFactor();
156
157 52411520 storage -= prevStorage;
158 104823040 storage *= Extrusion::volume(fvGeometry, scv);
159 52411520 storage /= this->timeLoop().timeStepSize();
160
161 157234560 residual[scv.localDofIndex()] += storage;
162 52411520 }
163 };
164
165 } // end namespace Dumux
166
167 #endif
168