GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/multidomain/couplingjacobianpattern.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 56 56 100.0%
Functions: 133 136 97.8%
Branches: 136 195 69.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 MultiDomain
10 * \brief Helper function to generate Jacobian pattern for multi domain models
11 */
12 #ifndef DUMUX_MUTLIDOMAIN_COUPLING_JACOBIAN_PATTERN_HH
13 #define DUMUX_MUTLIDOMAIN_COUPLING_JACOBIAN_PATTERN_HH
14
15 #include <type_traits>
16 #include <dune/common/indices.hh>
17 #include <dune/istl/matrixindexset.hh>
18 #include <dumux/discretization/method.hh>
19
20 namespace Dumux {
21
22 /*!
23 * \ingroup MultiDomain
24 * \brief Helper function to generate coupling Jacobian pattern (off-diagonal blocks)
25 * for cell-centered schemes
26 */
27 template<bool isImplicit, class CouplingManager, class GridGeometryI, class GridGeometryJ, std::size_t i, std::size_t j,
28 typename std::enable_if_t<( (GridGeometryI::discMethod == DiscretizationMethods::cctpfa)
29 || (GridGeometryI::discMethod == DiscretizationMethods::ccmpfa) ), int> = 0>
30 368 Dune::MatrixIndexSet getCouplingJacobianPattern(const CouplingManager& couplingManager,
31 Dune::index_constant<i> domainI,
32 const GridGeometryI& gridGeometryI,
33 Dune::index_constant<j> domainJ,
34 const GridGeometryJ& gridGeometryJ)
35 {
36
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
368 const auto numDofsI = gridGeometryI.numDofs();
37
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
368 const auto numDofsJ = gridGeometryJ.numDofs();
38
1/2
✓ Branch 1 taken 148 times.
✗ Branch 2 not taken.
368 Dune::MatrixIndexSet pattern;
39
1/2
✓ Branch 1 taken 148 times.
✗ Branch 2 not taken.
368 pattern.resize(numDofsI, numDofsJ);
40
41 // matrix pattern for implicit Jacobians
42 if (isImplicit)
43 {
44
17/19
✓ Branch 1 taken 144 times.
✓ Branch 2 taken 1903 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 2046 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 940336 times.
✓ Branch 7 taken 1811 times.
✓ Branch 8 taken 39435 times.
✓ Branch 9 taken 555867 times.
✓ Branch 10 taken 998 times.
✓ Branch 11 taken 39435 times.
✓ Branch 12 taken 3536 times.
✓ Branch 13 taken 6 times.
✓ Branch 14 taken 42971 times.
✓ Branch 15 taken 6 times.
✓ Branch 17 taken 3536 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 3536 times.
✗ Branch 21 not taken.
5207584 for (const auto& elementI : elements(gridGeometryI.gridView()))
45 {
46
1/2
✓ Branch 1 taken 601629 times.
✗ Branch 2 not taken.
2675143 const auto& stencil = couplingManager.couplingStencil(domainI, elementI, domainJ);
47
2/4
✓ Branch 1 taken 43963 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 43963 times.
✗ Branch 5 not taken.
5350286 const auto globalI = gridGeometryI.elementMapper().index(elementI);
48
4/4
✓ Branch 0 taken 1568354 times.
✓ Branch 1 taken 945639 times.
✓ Branch 2 taken 1568354 times.
✓ Branch 3 taken 945639 times.
12377139 for (const auto globalJ : stencil)
49
1/2
✓ Branch 1 taken 1568354 times.
✗ Branch 2 not taken.
2175855 pattern.add(globalI, globalJ);
50 }
51 }
52
53 // matrix pattern for explicit Jacobians
54 // -> diagonal matrix, so coupling block is empty
55 // just return the empty pattern
56
57 368 return pattern;
58 }
59
60 /*!
61 * \ingroup MultiDomain
62 * \brief Helper function to generate coupling Jacobian pattern (off-diagonal blocks)
63 * for the staggered scheme (degrees of freedom on cell centers)
64 */
65 template<bool isImplicit, class CouplingManager, class GridGeometryI, class GridGeometryJ, std::size_t i, std::size_t j,
66 typename std::enable_if_t<(GridGeometryI::discMethod == DiscretizationMethods::staggered &&
67 GridGeometryI::isCellCenter()), int> = 0>
68 101 Dune::MatrixIndexSet getCouplingJacobianPattern(const CouplingManager& couplingManager,
69 Dune::index_constant<i> domainI,
70 const GridGeometryI& gridGeometryI,
71 Dune::index_constant<j> domainJ,
72 const GridGeometryJ& gridGeometryJ)
73 {
74 101 Dune::MatrixIndexSet pattern(gridGeometryI.numDofs(), gridGeometryJ.numDofs());
75
76
4/8
✓ Branch 1 taken 67 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 67 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 160515 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 7000 times.
✗ Branch 11 not taken.
612322 for (const auto& elementI : elements(gridGeometryI.gridView()))
77 {
78
2/4
✓ Branch 1 taken 7000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7000 times.
✗ Branch 5 not taken.
605120 const auto ccGlobalI = gridGeometryI.elementMapper().index(elementI);
79
6/6
✓ Branch 1 taken 407624 times.
✓ Branch 2 taken 82392 times.
✓ Branch 3 taken 358324 times.
✓ Branch 4 taken 160448 times.
✓ Branch 5 taken 28756 times.
✓ Branch 6 taken 78056 times.
1589168 for (auto&& faceGlobalJ : couplingManager.couplingStencil(domainI, elementI, domainJ))
80
1/2
✓ Branch 1 taken 358324 times.
✗ Branch 2 not taken.
643304 pattern.add(ccGlobalI, faceGlobalJ);
81 }
82
83 101 return pattern;
84 }
85
86 /*!
87 * \ingroup MultiDomain
88 * \brief Helper function to generate coupling Jacobian pattern (off-diagonal blocks)
89 * for the staggered scheme (degrees of freedom on faces)
90 */
91 template<bool isImplicit, class CouplingManager, class GridGeometryI, class GridGeometryJ, std::size_t i, std::size_t j,
92 typename std::enable_if_t<(GridGeometryI::discMethod == DiscretizationMethods::staggered &&
93 GridGeometryI::isFace()), int> = 0>
94 67 Dune::MatrixIndexSet getCouplingJacobianPattern(const CouplingManager& couplingManager,
95 Dune::index_constant<i> domainI,
96 const GridGeometryI& gridGeometryI,
97 Dune::index_constant<j> domainJ,
98 const GridGeometryJ& gridGeometryJ)
99 {
100 67 Dune::MatrixIndexSet pattern(gridGeometryI.numDofs(), gridGeometryJ.numDofs());
101
102
1/2
✓ Branch 1 taken 33 times.
✗ Branch 2 not taken.
67 auto fvGeometry = localView(gridGeometryI);
103
4/8
✓ Branch 1 taken 33 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 33 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 18369 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 7000 times.
✗ Branch 11 not taken.
321030 for (const auto& elementI : elements(gridGeometryI.gridView()))
104 {
105
1/2
✓ Branch 1 taken 7000 times.
✗ Branch 2 not taken.
160448 fvGeometry.bindElement(elementI);
106
107 // loop over sub control faces
108
4/4
✓ Branch 0 taken 73344 times.
✓ Branch 1 taken 18336 times.
✓ Branch 2 taken 73344 times.
✓ Branch 3 taken 18336 times.
962688 for (auto&& scvf : scvfs(fvGeometry))
109 {
110 641792 const auto faceGlobalI = scvf.dofIndex();
111
4/4
✓ Branch 1 taken 214612 times.
✓ Branch 2 taken 73344 times.
✓ Branch 3 taken 214612 times.
✓ Branch 4 taken 73344 times.
2765648 for (auto&& globalJ : couplingManager.couplingStencil(domainI, scvf, domainJ))
112
1/2
✓ Branch 1 taken 214612 times.
✗ Branch 2 not taken.
1061928 pattern.add(faceGlobalI, globalJ);
113 }
114 }
115
116 67 return pattern;
117 }
118
119 /*!
120 * \ingroup MultiDomain
121 * \brief Helper function to generate coupling Jacobian pattern (off-diagonal blocks)
122 * for the staggered scheme (degrees of freedom on cell centers)
123 */
124 template<bool isImplicit, class CouplingManager, class GridGeometryI, class GridGeometryJ, std::size_t i, std::size_t j,
125 typename std::enable_if_t<(GridGeometryI::discMethod == DiscretizationMethods::fcstaggered), int> = 0>
126 80 Dune::MatrixIndexSet getCouplingJacobianPattern(const CouplingManager& couplingManager,
127 Dune::index_constant<i> domainI,
128 const GridGeometryI& gridGeometryI,
129 Dune::index_constant<j> domainJ,
130 const GridGeometryJ& gridGeometryJ)
131 {
132 86 Dune::MatrixIndexSet pattern(gridGeometryI.numDofs(), gridGeometryJ.numDofs());
133
134
1/2
✓ Branch 1 taken 43 times.
✗ Branch 2 not taken.
80 auto fvGeometry = localView(gridGeometryI);
135
14/19
✓ Branch 1 taken 47 times.
✓ Branch 2 taken 101 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 148 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 209923 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 209923 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✓ Branch 11 taken 992 times.
✓ Branch 12 taken 3536 times.
✓ Branch 13 taken 6 times.
✓ Branch 14 taken 3536 times.
✓ Branch 15 taken 6 times.
✓ Branch 17 taken 3536 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 3536 times.
✗ Branch 21 not taken.
484997 for (const auto& elementI : elements(gridGeometryI.gridView()))
136 {
137
1/2
✓ Branch 1 taken 5778 times.
✗ Branch 2 not taken.
484734 fvGeometry.bindElement(elementI);
138
5/5
✓ Branch 0 taken 12072 times.
✓ Branch 1 taken 846818 times.
✓ Branch 2 taken 210500 times.
✓ Branch 3 taken 843800 times.
✓ Branch 4 taken 210500 times.
2425470 for (const auto& scv : scvs(fvGeometry))
139 {
140 1940736 const auto globalI = scv.dofIndex();
141
1/2
✓ Branch 1 taken 1632 times.
✗ Branch 2 not taken.
1940736 const auto& stencil = couplingManager.couplingStencil(domainI, elementI, scv, domainJ);
142
4/4
✓ Branch 0 taken 907240 times.
✓ Branch 1 taken 855872 times.
✓ Branch 2 taken 907240 times.
✓ Branch 3 taken 855872 times.
7273180 for (const auto globalJ : stencil)
143 {
144
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 901408 times.
✓ Branch 2 taken 5832 times.
✓ Branch 3 taken 540 times.
✓ Branch 4 taken 900868 times.
1451652 assert(globalJ < gridGeometryJ.numDofs());
145
1/2
✓ Branch 1 taken 907240 times.
✗ Branch 2 not taken.
1450972 pattern.add(globalI, globalJ);
146
147
2/2
✓ Branch 0 taken 400 times.
✓ Branch 1 taken 906840 times.
1450972 if (gridGeometryI.isPeriodic())
148 {
149
2/2
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 380 times.
400 if (gridGeometryI.dofOnPeriodicBoundary(globalI))
150 {
151
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 const auto globalIP = gridGeometryI.periodicallyMappedDof(globalI);
152
153
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if (globalI > globalIP)
154
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 pattern.add(globalIP, globalJ);
155 }
156 }
157 }
158 }
159 }
160
161 80 return pattern;
162 }
163
164 /*!
165 * \ingroup MultiDomain
166 * \brief Helper function to generate coupling Jacobian pattern (off-diagonal blocks)
167 * for control-volume finite element schemes (CVFE)
168 */
169 template<bool isImplicit, class CouplingManager, class GridGeometryI, class GridGeometryJ, std::size_t i, std::size_t j,
170 typename std::enable_if_t<DiscretizationMethods::isCVFE<typename GridGeometryI::DiscretizationMethod>, int> = 0>
171 76 Dune::MatrixIndexSet getCouplingJacobianPattern(const CouplingManager& couplingManager,
172 Dune::index_constant<i> domainI,
173 const GridGeometryI& gridGeometryI,
174 Dune::index_constant<j> domainJ,
175 const GridGeometryJ& gridGeometryJ)
176 {
177
4/16
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
80 Dune::MatrixIndexSet pattern;
178
179 // matrix pattern for implicit Jacobians
180 if constexpr (isImplicit)
181 {
182
6/8
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
194 pattern.resize(gridGeometryI.numDofs(), gridGeometryJ.numDofs());
183
1/4
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
100 auto fvGeometry = localView(gridGeometryI);
184
18/21
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 27 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 48125 times.
✓ Branch 7 taken 4 times.
✓ Branch 8 taken 39435 times.
✓ Branch 9 taken 3 times.
✓ Branch 10 taken 101 times.
✓ Branch 11 taken 39435 times.
✓ Branch 12 taken 8224 times.
✓ Branch 13 taken 1 times.
✓ Branch 14 taken 47659 times.
✓ Branch 15 taken 1 times.
✓ Branch 17 taken 8224 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 8224 times.
✗ Branch 21 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
570778 for (const auto& elementI : elements(gridGeometryI.gridView()))
185 {
186
1/2
✓ Branch 1 taken 47759 times.
✗ Branch 2 not taken.
264740 fvGeometry.bindElement(elementI);
187
1/2
✓ Branch 1 taken 56266 times.
✗ Branch 2 not taken.
264740 const auto& stencil = couplingManager.couplingStencil(domainI, elementI, domainJ);
188
4/4
✓ Branch 0 taken 242974 times.
✓ Branch 1 taken 56366 times.
✓ Branch 2 taken 242974 times.
✓ Branch 3 taken 56366 times.
1603599 for (const auto& scv : scvs(fvGeometry))
189 {
190
4/4
✓ Branch 0 taken 167838 times.
✓ Branch 1 taken 242974 times.
✓ Branch 2 taken 167438 times.
✓ Branch 3 taken 242574 times.
8229614 for (const auto globalJ : stencil)
191
1/2
✓ Branch 1 taken 167838 times.
✗ Branch 2 not taken.
2500945 pattern.add(scv.dofIndex(), globalJ);
192
193 }
194 }
195 }
196
197 // matrix pattern for explicit Jacobians
198 // -> diagonal matrix, so coupling block is empty
199 // just return the empty pattern
200
201 76 return pattern;
202 }
203
204 } // end namespace Dumux
205
206 #endif
207