GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/discretization/staggered/freeflow/connectivitymap.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 45 57 78.9%
Functions: 21 50 42.0%
Branches: 95 177 53.7%

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 StaggeredDiscretization
10 * \copydoc Dumux::StaggeredFreeFlowConnectivityMap
11 */
12 #ifndef DUMUX_STAGGERED_FREEFLOW_CONNECTIVITY_MAP_HH
13 #define DUMUX_STAGGERED_FREEFLOW_CONNECTIVITY_MAP_HH
14
15 #include <vector>
16 #include <dumux/common/indextraits.hh>
17
18 namespace Dumux {
19
20 /*!
21 * \ingroup StaggeredDiscretization
22 * \brief Stores the dof indices corresponding to the neighboring cell centers and faces
23 * that contribute to the derivative calculation. Specialization for the staggered free flow model.
24 */
25 template<class GridGeometry>
26
5/10
✗ Branch 0 not taken.
✓ Branch 1 taken 53 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 53 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 53 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 53 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 53 times.
265 class StaggeredFreeFlowConnectivityMap
27 {
28 using GridView = typename GridGeometry::GridView;
29 using FVElementGeometry = typename GridGeometry::LocalView;
30 using SubControlVolumeFace = typename GridGeometry::SubControlVolumeFace;
31
32 using Element = typename GridView::template Codim<0>::Entity;
33 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
34
35 using CellCenterIdxType = typename GridGeometry::DofTypeIndices::CellCenterIdx;
36 using FaceIdxType = typename GridGeometry::DofTypeIndices::FaceIdx;
37
38 using SmallLocalIndex = typename IndexTraits<GridView>::SmallLocalIndex;
39
40 using Stencil = std::vector<GridIndexType>;
41 using Map = std::vector<Stencil>;
42
43 static constexpr SmallLocalIndex upwindSchemeOrder = GridGeometry::upwindSchemeOrder;
44 static constexpr bool useHigherOrder = upwindSchemeOrder > 1;
45
46 public:
47
48 //! Update the map and prepare the stencils
49 53 void update(const GridGeometry& gridGeometry)
50 {
51 106 const auto numDofsCC = gridGeometry.gridView().size(0);
52 106 const auto numDofsFace = gridGeometry.gridView().size(1);
53 53 const auto numBoundaryFacets = gridGeometry.numBoundaryScvf();
54
55 // reinitialize maps
56 106 cellCenterToCellCenterMap_ = Map(numDofsCC);
57 106 cellCenterToFaceMap_ = Map(numDofsCC);
58 106 faceToCellCenterMap_ = Map(2*numDofsFace - numBoundaryFacets);
59
1/2
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
106 faceToFaceMap_ = Map(2*numDofsFace - numBoundaryFacets);
60
61 // restrict the FvGeometry locally
62
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
53 auto fvGeometry = localView(gridGeometry);
63
5/9
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 89769 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 26 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 25 times.
✗ Branch 11 not taken.
179591 for(auto&& element: elements(gridGeometry.gridView()))
64 {
65 // bind the FvGeometry to the element
66
1/2
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
89742 fvGeometry.bindElement(element);
67
68 // loop over sub control faces
69
4/4
✓ Branch 0 taken 359218 times.
✓ Branch 1 taken 89742 times.
✓ Branch 2 taken 359218 times.
✓ Branch 3 taken 89742 times.
538702 for (auto&& scvf : scvfs(fvGeometry))
70 {
71 // handle the cell center dof stencils first
72 718436 const auto dofIdxCellCenter = gridGeometry.elementMapper().index(element);
73
74 // the stencil for cell center dofs w.r.t. to other cell center dofs,
75 // includes all neighboring element indices
76
2/2
✓ Branch 0 taken 353222 times.
✓ Branch 1 taken 5996 times.
359218 if (!scvf.boundary())
77
3/6
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 80 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 80 times.
✗ Branch 8 not taken.
1059666 cellCenterToCellCenterMap_[dofIdxCellCenter].push_back(scvf.outsideScvIdx());
78
79 // the stencil for cell center dofs w.r.t. face dofs, includes the face dof indices of the current element
80
3/6
✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 100 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 100 times.
✗ Branch 8 not taken.
1077654 cellCenterToFaceMap_[dofIdxCellCenter].push_back(scvf.dofIndex());
81
82 // handle the face dof stencils
83 359218 const auto scvfIdx = scvf.index();
84
2/4
✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 100 times.
✗ Branch 5 not taken.
718436 computeFaceToCellCenterStencil_(faceToCellCenterMap_[scvfIdx], fvGeometry, scvf);
85
2/4
✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 100 times.
✗ Branch 5 not taken.
718436 computeFaceToFaceStencil_(faceToFaceMap_[scvfIdx], fvGeometry, scvf);
86 }
87 }
88 53 }
89
90 //! Returns the stencil of a cell center dof w.r.t. other cell center dofs
91 const Stencil& operator() (CellCenterIdxType, CellCenterIdxType, const GridIndexType globalI) const
92 {
93
48/96
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 25 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 25 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 25 times.
✓ Branch 8 taken 25 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 25 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 25 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 25 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 25 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 25 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 25 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 25 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 25 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 25 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 25 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 25 times.
✗ Branch 31 not taken.
✓ Branch 32 taken 25 times.
✗ Branch 33 not taken.
✓ Branch 34 taken 25 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 25 times.
✗ Branch 37 not taken.
✓ Branch 38 taken 25 times.
✗ Branch 39 not taken.
✓ Branch 40 taken 25 times.
✗ Branch 41 not taken.
✓ Branch 42 taken 25 times.
✗ Branch 43 not taken.
✓ Branch 44 taken 25 times.
✗ Branch 45 not taken.
✓ Branch 46 taken 25 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 25 times.
✗ Branch 49 not taken.
✓ Branch 50 taken 25 times.
✗ Branch 51 not taken.
✓ Branch 52 taken 25 times.
✗ Branch 53 not taken.
✓ Branch 54 taken 25 times.
✗ Branch 55 not taken.
✓ Branch 56 taken 25 times.
✗ Branch 57 not taken.
✓ Branch 58 taken 25 times.
✗ Branch 59 not taken.
✓ Branch 60 taken 25 times.
✗ Branch 61 not taken.
✓ Branch 62 taken 25 times.
✗ Branch 63 not taken.
✓ Branch 64 taken 25 times.
✗ Branch 65 not taken.
✓ Branch 66 taken 25 times.
✗ Branch 67 not taken.
✓ Branch 68 taken 25 times.
✗ Branch 69 not taken.
✓ Branch 70 taken 25 times.
✗ Branch 71 not taken.
✓ Branch 72 taken 25 times.
✗ Branch 73 not taken.
✓ Branch 74 taken 25 times.
✗ Branch 75 not taken.
✓ Branch 76 taken 25 times.
✗ Branch 77 not taken.
✓ Branch 78 taken 25 times.
✗ Branch 79 not taken.
✓ Branch 80 taken 25 times.
✗ Branch 81 not taken.
✓ Branch 82 taken 25 times.
✗ Branch 83 not taken.
✓ Branch 84 taken 25 times.
✗ Branch 85 not taken.
✓ Branch 86 taken 25 times.
✗ Branch 87 not taken.
✓ Branch 88 taken 25 times.
✗ Branch 89 not taken.
✓ Branch 90 taken 25 times.
✗ Branch 91 not taken.
✓ Branch 92 taken 25 times.
✗ Branch 93 not taken.
✓ Branch 94 taken 25 times.
✗ Branch 95 not taken.
2901272 return cellCenterToCellCenterMap_[globalI];
94 }
95
96 //! Returns the stencil of a cell center dof w.r.t. face dofs
97 const Stencil& operator() (CellCenterIdxType, FaceIdxType, const GridIndexType globalI) const
98 {
99 179184 return cellCenterToFaceMap_[globalI];
100 }
101
102 //! Returns the stencil of a face dof w.r.t. cell center dofs
103 const Stencil& operator() (FaceIdxType, CellCenterIdxType, const GridIndexType globalI) const
104 {
105 10883552 return faceToCellCenterMap_[globalI];
106 }
107
108 //! Returns the stencil of a face dof w.r.t. other face dofs
109 const Stencil& operator() (FaceIdxType, FaceIdxType, const GridIndexType globalI) const
110 {
111
2/4
✓ Branch 1 taken 12555232 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12555232 times.
✗ Branch 5 not taken.
36710752 return faceToFaceMap_[globalI];
112 }
113
114 private:
115
116 /*
117 * \brief Computes the stencil for face dofs w.r.t to cell center dofs.
118 * Basically, these are the dof indices of the elements adjacent to the face and those of
119 * the elements adjacent to the faces parallel to the own face.
120 */
121 359218 void computeFaceToCellCenterStencil_(Stencil& stencil,
122 const FVElementGeometry& fvGeometry,
123 const SubControlVolumeFace& scvf)
124 {
125 359218 const auto eIdx = scvf.insideScvIdx();
126 359218 stencil.push_back(eIdx);
127
128
2/2
✓ Branch 0 taken 719936 times.
✓ Branch 1 taken 359218 times.
2156808 for (const auto& data : scvf.pairData())
129 {
130
2/2
✓ Branch 0 taken 707484 times.
✓ Branch 1 taken 12252 times.
719936 auto& lateralFace = fvGeometry.scvf(eIdx, data.localLateralFaceIdx);
131
2/2
✓ Branch 0 taken 707644 times.
✓ Branch 1 taken 12292 times.
719936 if (!lateralFace.boundary())
132 {
133 707644 const auto firstParallelElementDofIdx = lateralFace.outsideScvIdx();
134 707644 stencil.push_back(firstParallelElementDofIdx);
135 }
136 }
137 359218 }
138
139 /*
140 * \brief Computes the stencil for face dofs w.r.t to face dofs.
141 * For a full description of the stencil, please see the document under dumux/doc/docextra/staggered
142 */
143 359218 void computeFaceToFaceStencil_(Stencil& stencil,
144 const FVElementGeometry& fvGeometry,
145 const SubControlVolumeFace& scvf)
146 {
147 359218 stencil.push_back(scvf.axisData().oppositeDof);
148 359218 addHigherOrderInAxisDofs_(scvf, stencil, std::integral_constant<bool, useHigherOrder>{});
149
150
2/2
✓ Branch 0 taken 719936 times.
✓ Branch 1 taken 359218 times.
2156808 for (const auto& data : scvf.pairData())
151 {
152 // add normal dofs
153 719936 stencil.push_back(data.lateralPair.first);
154
2/2
✓ Branch 0 taken 707644 times.
✓ Branch 1 taken 12292 times.
719936 if (!scvf.boundary())
155 707644 stencil.push_back(data.lateralPair.second);
156
157 // add parallel dofs
158
2/2
✓ Branch 0 taken 758936 times.
✓ Branch 1 taken 719936 times.
1478872 for (SmallLocalIndex i = 0; i < upwindSchemeOrder; i++)
159 {
160
4/4
✓ Branch 0 taken 84692 times.
✓ Branch 1 taken 674244 times.
✓ Branch 2 taken 84692 times.
✓ Branch 3 taken 674244 times.
1517872 if (data.hasParallelNeighbor[i])
161 1487688 stencil.push_back(data.parallelDofs[i]);
162 }
163 }
164 359218 }
165
166 void addHigherOrderInAxisDofs_(const SubControlVolumeFace& scvf, Stencil& stencil, std::false_type) {}
167
168 void addHigherOrderInAxisDofs_(const SubControlVolumeFace& scvf, Stencil& stencil, std::true_type)
169 {
170 for (SmallLocalIndex i = 0; i < upwindSchemeOrder - 1; i++)
171 {
172 if (scvf.hasBackwardNeighbor(i))
173 stencil.push_back(scvf.axisData().inAxisBackwardDofs[i]);
174
175 if (scvf.hasForwardNeighbor(i))
176 stencil.push_back(scvf.axisData().inAxisForwardDofs[i]);
177 }
178 }
179
180 Map cellCenterToCellCenterMap_;
181 Map cellCenterToFaceMap_;
182 Map faceToCellCenterMap_;
183 Map faceToFaceMap_;
184 };
185
186 } // end namespace Dumux
187
188 #endif
189