GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/assembly/initialsolution.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 20 20 100.0%
Functions: 205 206 99.5%
Branches: 65 94 69.1%

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 * \brief Function to create initial solution vectors
11 */
12 #ifndef DUMUX_ASSEMBLY_INITIAL_SOLUTION_HH
13 #define DUMUX_ASSEMBLY_INITIAL_SOLUTION_HH
14
15 #include <vector>
16 #include <type_traits>
17
18 #include <dumux/discretization/method.hh>
19
20 namespace Dumux {
21
22 /*!
23 * \ingroup Assembly
24 * \brief Set a solution vector to the initial solution provided by the problem
25 */
26 template<class SolutionVector, class Problem>
27 665 void assembleInitialSolution(SolutionVector& sol, const Problem& problem)
28 {
29
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
665 const auto& gg = problem.gridGeometry();
30 using GridGeometry = std::decay_t<decltype(gg)>;
31
32 // box method
33 if constexpr (GridGeometry::discMethod == DiscretizationMethods::box)
34 {
35 231 constexpr int dim = GridGeometry::GridView::dimension;
36
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
402 const auto numDofs = gg.vertexMapper().size();
37 462 const auto numVert = gg.gridView().size(dim);
38 231 sol.resize(numDofs);
39
40 // if there are more dofs than vertices (enriched nodal dofs), we have to
41 // call initial for all dofs at the nodes, coming from all neighboring elements.
42
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 154 times.
231 if (numDofs != numVert)
43 {
44
1/2
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
126 std::vector<bool> dofVisited(numDofs, false);
45
13/19
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 88 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 108 times.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 20 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 52467 times.
✓ Branch 13 taken 20 times.
✓ Branch 14 taken 52467 times.
✓ Branch 15 taken 20 times.
✓ Branch 17 taken 52467 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 52467 times.
✗ Branch 21 not taken.
105234 for (const auto& element : elements(gg.gridView()))
46 {
47
5/5
✓ Branch 0 taken 264 times.
✓ Branch 1 taken 254023 times.
✓ Branch 2 taken 264 times.
✓ Branch 3 taken 201556 times.
✓ Branch 4 taken 52467 times.
508750 for (int i = 0; i < element.subEntities(dim); ++i)
48 {
49
2/4
✓ Branch 1 taken 201468 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 201468 times.
✗ Branch 5 not taken.
806928 const auto dofIdxGlobal = gg.vertexMapper().subIndex(element, i, dim);
50 // forward to implementation if value at dof is not set yet
51
6/6
✓ Branch 0 taken 49443 times.
✓ Branch 1 taken 152289 times.
✓ Branch 2 taken 49443 times.
✓ Branch 3 taken 152289 times.
✓ Branch 4 taken 49443 times.
✓ Branch 5 taken 152289 times.
1210392 if (!dofVisited[dofIdxGlobal])
52 {
53
2/5
✓ Branch 1 taken 49443 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 72 times.
✗ Branch 5 not taken.
99030 sol[dofIdxGlobal] = problem.initial(element.template subEntity<dim>(i));
54 296658 dofVisited[dofIdxGlobal] = true;
55 }
56 }
57 }
58 }
59
60 // otherwise we directly loop over the vertices
61 else
62 {
63
7/8
✓ Branch 2 taken 102444 times.
✓ Branch 3 taken 82 times.
✓ Branch 4 taken 24392 times.
✓ Branch 5 taken 67 times.
✓ Branch 6 taken 16 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 15 times.
✓ Branch 9 taken 22000 times.
271452 for (const auto& vertex : vertices(gg.gridView()))
64
9/12
✓ Branch 1 taken 16168 times.
✓ Branch 2 taken 1026 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4806 times.
✓ Branch 5 taken 1026 times.
✓ Branch 6 taken 16168 times.
✓ Branch 7 taken 4806 times.
✓ Branch 8 taken 1026 times.
✓ Branch 9 taken 16168 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 1026 times.
✗ Branch 12 not taken.
153847 sol[gg.vertexMapper().index(vertex)] = problem.initial(vertex);
65 }
66 }
67
68 // staggered methods
69 else if constexpr (GridGeometry::discMethod == DiscretizationMethods::staggered)
70 {
71 problem.applyInitialSolution(sol);
72 }
73
74 // default: cell-centered methods
75 else
76 {
77 434 sol.resize(gg.numDofs());
78
10/12
✓ Branch 2 taken 1275774 times.
✓ Branch 3 taken 146 times.
✓ Branch 4 taken 39035 times.
✓ Branch 5 taken 94 times.
✓ Branch 6 taken 52 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 146949 times.
✓ Branch 9 taken 52 times.
✓ Branch 10 taken 146949 times.
✓ Branch 11 taken 52 times.
✓ Branch 13 taken 146949 times.
✗ Branch 14 not taken.
4971742 for (const auto& element : elements(gg.gridView()))
79
5/10
✓ Branch 1 taken 146949 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 146949 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 146949 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 146949 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 146949 times.
✗ Branch 14 not taken.
2501676 sol[gg.elementMapper().index(element)] = problem.initial(element);
80 }
81 664 }
82
83 /*!
84 * \ingroup Assembly
85 * \brief Create a solution vector filled with the initial solution provided by the problem
86 */
87 template<class SolutionVector, class Problem>
88 SolutionVector makeInitialSolution(const Problem& problem)
89 {
90 SolutionVector sol;
91 assembleInitialSolution(sol, problem);
92 return sol;
93 }
94
95 } // end namespace Dumux
96
97 #endif
98