GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/discretization/evalgradients.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 17 18 94.4%
Functions: 7 8 87.5%
Branches: 16 44 36.4%

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 Discretization
10 * \brief free functions for the evaluation of primary variable gradients inside elements.
11 */
12 #ifndef DUMUX_DISCRETIZATION_EVAL_GRADIENTS_HH
13 #define DUMUX_DISCRETIZATION_EVAL_GRADIENTS_HH
14
15 #include <dune/common/exceptions.hh>
16
17 #include <dumux/common/typetraits/state.hh>
18 #include <dumux/common/typetraits/isvalid.hh>
19 #include <dumux/discretization/cellcentered/elementsolution.hh>
20 #include <dumux/discretization/cvfe/elementsolution.hh>
21
22 #include "evalsolution.hh"
23
24 namespace Dumux {
25
26 // some implementation details
27 namespace Detail{
28 /*!
29 * \brief Evaluates the gradient of a control-volume finite element solution to a given global position.
30 * \ingroup Discretization
31 *
32 * \param element The element
33 * \param geometry The element geometry
34 * \param gridGeometry The finite volume grid geometry
35 * \param elemSol The primary variables at the dofs of the element
36 * \param globalPos The global position
37 * \param ignoreState If true, the state of primary variables is ignored
38 *
39 * \return Dune::FieldVector with as many entries as dimension of
40 * the PrimaryVariables object (i.e. numEq). Each entry is
41 * a GlobalCoordinate object holding the priVar gradient.
42 */
43 template<class Element, class GridGeometry, class CVFEElemSol>
44 27802748 auto evalCVFEGradients(const Element& element,
45 const typename Element::Geometry& geometry,
46 const GridGeometry& gridGeometry,
47 const CVFEElemSol& elemSol,
48 const typename Element::Geometry::GlobalCoordinate& globalPos,
49 bool ignoreState = false)
50 {
51 // determine if all states are the same at all vertices
52 using HasState = decltype(isValid(Detail::hasState())(elemSol[0]));
53
3/4
✓ Branch 0 taken 4059776 times.
✓ Branch 1 taken 18138484 times.
✓ Branch 3 taken 4059776 times.
✗ Branch 4 not taken.
27802748 bool allStatesEqual = ignoreState || Detail::allStatesEqual(elemSol, HasState{});
54
55 if (allStatesEqual)
56 {
57 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
58
59 // evaluate gradients using the local finite element basis
60
1/2
✓ Branch 4 taken 22198260 times.
✗ Branch 5 not taken.
83405844 const auto& localBasis = gridGeometry.feCache().get(geometry.type()).localBasis();
61
62 // evaluate the shape function gradients at the scv center
63 using ShapeJacobian = typename std::decay_t< decltype(localBasis) >::Traits::JacobianType;
64
1/2
✓ Branch 1 taken 22198260 times.
✗ Branch 2 not taken.
27802748 const auto localPos = geometry.local(globalPos);
65
1/4
✓ Branch 1 taken 27802714 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
27802748 std::vector< ShapeJacobian > shapeJacobian;
66
1/2
✓ Branch 1 taken 27802714 times.
✗ Branch 2 not taken.
27802748 localBasis.evaluateJacobian(localPos, shapeJacobian);
67
68 // the inverse transposed of the jacobian matrix
69
1/2
✓ Branch 1 taken 2400 times.
✗ Branch 2 not taken.
27802748 const auto jacInvT = geometry.jacobianInverseTransposed(localPos);
70
71 // interpolate the gradients
72 33407236 Dune::FieldVector<GlobalPosition, CVFEElemSol::PrimaryVariables::dimension> result( GlobalPosition(0.0) );
73
4/4
✓ Branch 0 taken 88947262 times.
✓ Branch 1 taken 27802714 times.
✓ Branch 2 taken 88947262 times.
✓ Branch 3 taken 27802714 times.
138948372 for (int i = 0; i < shapeJacobian.size(); ++i)
74 {
75 // the global shape function gradient
76 88947364 GlobalPosition gradN;
77 266842092 jacInvT.mv(shapeJacobian[i][0], gradN);
78
79 // add gradient to global privar gradients
80
2/2
✓ Branch 0 taken 331512318 times.
✓ Branch 1 taken 88947262 times.
420459784 for (unsigned int pvIdx = 0; pvIdx < CVFEElemSol::PrimaryVariables::dimension; ++pvIdx)
81 {
82 331512420 GlobalPosition tmp(gradN);
83 994537260 tmp *= elemSol[i][pvIdx];
84 994536852 result[pvIdx] += tmp;
85 }
86 }
87
88
1/2
✓ Branch 0 taken 27802714 times.
✗ Branch 1 not taken.
55605496 return result;
89 }
90 else
91 {
92 DUNE_THROW(Dune::NotImplemented, "Element dofs have different phase states. Enforce calculation by setting ignoreState to true.");
93 }
94 }
95
96 } // end namespace Detail
97
98 /*!
99 * \brief Evaluates the gradient of a given CVFE element solution to a given global position.
100 * \ingroup Discretization
101 *
102 * \param element The element
103 * \param geometry The element geometry
104 * \param gridGeometry The finite volume grid geometry
105 * \param elemSol The primary variables at the dofs of the element
106 * \param globalPos The global position
107 * \param ignoreState If true, the state of primary variables is ignored
108 */
109 template<class Element, class FVElementGeometry, class PrimaryVariables>
110 auto evalGradients(const Element& element,
111 const typename Element::Geometry& geometry,
112 const typename FVElementGeometry::GridGeometry& gridGeometry,
113 const CVFEElementSolution<FVElementGeometry, PrimaryVariables>& elemSol,
114 const typename Element::Geometry::GlobalCoordinate& globalPos,
115 bool ignoreState = false)
116 {
117
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 4 taken 34 times.
✗ Branch 5 not taken.
27802714 return Detail::evalCVFEGradients(element, geometry, gridGeometry, elemSol, globalPos, ignoreState);
118 }
119
120 /*!
121 * \ingroup Discretization
122 * \brief Evaluates the gradient of a given CCElementSolution to a given global position.
123 * This function is only here for (compilation) compatibility reasons with the box scheme.
124 * The solution within the control volumes is constant and thus gradients are zero.
125 * One can compute gradients towards the sub-control volume faces after reconstructing
126 * the solution on the faces.
127 *
128 * \param element The element
129 * \param geometry The element geometry
130 * \param gridGeometry The finite volume grid geometry
131 * \param elemSol The primary variables at the dofs of the element
132 * \param globalPos The global position
133 * \throws Dune::NotImplemented
134 *
135 * \return Dune::FieldVector with as many entries as dimension of
136 * the PrimaryVariables object (i.e. numEq). Each entry is
137 * a GlobalCoordinate object holding the priVar gradient.
138 */
139 template<class Element, class FVElementGeometry, class PrimaryVariables>
140 Dune::FieldVector<typename Element::Geometry::GlobalCoordinate, PrimaryVariables::dimension>
141 evalGradients(const Element& element,
142 const typename Element::Geometry& geometry,
143 const typename FVElementGeometry::GridGeometry& gridGeometry,
144 const CCElementSolution<FVElementGeometry, PrimaryVariables>& elemSol,
145 const typename Element::Geometry::GlobalCoordinate& globalPos)
146 { DUNE_THROW(Dune::NotImplemented, "General gradient evaluation for cell-centered methods"); }
147
148 } // namespace Dumux
149
150 #endif
151