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-FileCopyrightText: 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 | 714 | void assembleInitialSolution(SolutionVector& sol, const Problem& problem) | |
28 | { | ||
29 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
714 | 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 | 239 | constexpr int dim = GridGeometry::GridView::dimension; | |
36 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
239 | const auto numDofs = gg.vertexMapper().size(); |
37 | 239 | const auto numVert = gg.gridView().size(dim); | |
38 | 239 | 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 158 times.
|
239 | if (numDofs != numVert) |
43 | { | ||
44 |
1/2✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
42 | std::vector<bool> dofVisited(numDofs, false); |
45 |
8/12✓ Branch 1 taken 20 times.
✓ Branch 2 taken 88 times.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 52467 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 52467 times.
✓ Branch 13 taken 20 times.
✗ Branch 6 not taken.
✓ Branch 3 taken 1 times.
|
210422 | for (const auto& element : elements(gg.gridView())) |
46 | { | ||
47 |
4/5✓ Branch 1 taken 254023 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 201468 times.
✓ Branch 4 taken 52467 times.
✓ Branch 0 taken 264 times.
|
1016444 | for (int i = 0; i < element.subEntities(dim); ++i) |
48 | { | ||
49 |
1/2✓ Branch 1 taken 201468 times.
✗ Branch 2 not taken.
|
403464 | const auto dofIdxGlobal = gg.vertexMapper().subIndex(element, i, dim); |
50 | // forward to implementation if value at dof is not set yet | ||
51 |
2/2✓ Branch 0 taken 49443 times.
✓ Branch 1 taken 152289 times.
|
403464 | if (!dofVisited[dofIdxGlobal]) |
52 | { | ||
53 |
1/5✓ Branch 1 taken 49443 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 3 not taken.
|
98886 | sol[dofIdxGlobal] = problem.initial(element.template subEntity<dim>(i)); |
54 | 98886 | dofVisited[dofIdxGlobal] = true; | |
55 | } | ||
56 | } | ||
57 | } | ||
58 | 42 | } | |
59 | |||
60 | // otherwise we directly loop over the vertices | ||
61 | else | ||
62 | { | ||
63 |
10/13✓ Branch 2 taken 26608 times.
✓ Branch 3 taken 1072 times.
✓ Branch 5 taken 15 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 22000 times.
✓ Branch 14 taken 4806 times.
✗ Branch 15 not taken.
✓ Branch 1 taken 72283 times.
✓ Branch 4 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 8 times.
✓ Branch 11 taken 17194 times.
|
311162 | for (const auto& vertex : vertices(gg.gridView())) |
64 |
4/6✓ Branch 1 taken 1026 times.
✓ Branch 2 taken 16168 times.
✓ Branch 5 taken 17194 times.
✗ Branch 6 not taken.
✓ Branch 3 taken 4806 times.
✗ Branch 4 not taken.
|
148509 | 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 | 475 | sol.resize(gg.numDofs()); | |
78 |
7/9✓ Branch 2 taken 42905 times.
✓ Branch 3 taken 103 times.
✓ Branch 5 taken 60 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 147749 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 147749 times.
✓ Branch 11 taken 60 times.
✓ Branch 1 taken 1253375 times.
|
5120594 | for (const auto& element : elements(gg.gridView())) |
79 |
3/6✓ Branch 1 taken 147749 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 147749 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 147749 times.
✗ Branch 8 not taken.
|
2522818 | sol[gg.elementMapper().index(element)] = problem.initial(element); |
80 | } | ||
81 | 713 | } | |
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 |