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 CCDiscretization | ||
10 | * \brief Stores the face indices corresponding to the neighbors of an element | ||
11 | * that contribute to the derivative calculation. This is used for | ||
12 | * finite-volume schemes with symmetric sparsity pattern in the global matrix. | ||
13 | */ | ||
14 | #ifndef DUMUX_CC_CONNECTIVITY_MAP_HH | ||
15 | #define DUMUX_CC_CONNECTIVITY_MAP_HH | ||
16 | |||
17 | #include <vector> | ||
18 | #include <utility> | ||
19 | #include <algorithm> | ||
20 | |||
21 | #include <dune/common/exceptions.hh> | ||
22 | #include <dune/common/reservedvector.hh> | ||
23 | |||
24 | #include <dumux/common/indextraits.hh> | ||
25 | #include <dumux/discretization/fluxstencil.hh> | ||
26 | |||
27 | namespace Dumux { | ||
28 | |||
29 | /*! | ||
30 | * \ingroup CCDiscretization | ||
31 | * \brief A simple version of the connectivity map for cellcentered schemes. | ||
32 | * This implementation works for schemes in which for a given cell I only | ||
33 | * those cells J have to be prepared in whose stencil the cell I appears. | ||
34 | * This means that for the flux calculations in the cells J (in order to compute | ||
35 | * the derivatives with respect to cell I), we do not need data on any additional cells J | ||
36 | * to compute these fluxes. The same holds for scvfs in the cells J, i.e. we need only those | ||
37 | * scvfs in the cells J in which the cell I is in the stencil. | ||
38 | */ | ||
39 | template<class GridGeometry> | ||
40 |
9/16✗ Branch 0 not taken.
✓ Branch 1 taken 122 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 105 times.
✓ Branch 4 taken 33 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 36 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 8 times.
✓ Branch 9 taken 13 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 4 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
|
872 | class CCSimpleConnectivityMap |
41 | { | ||
42 | using FVElementGeometry = typename GridGeometry::LocalView; | ||
43 | using GridView = typename GridGeometry::GridView; | ||
44 | using GridIndexType = typename IndexTraits<GridView>::GridIndex; | ||
45 | using FluxStencil = Dumux::FluxStencil<FVElementGeometry>; | ||
46 | static constexpr int maxElemStencilSize = GridGeometry::maxElementStencilSize; | ||
47 | |||
48 | 7155003 | struct DataJ | |
49 | { | ||
50 | GridIndexType globalJ; | ||
51 | typename FluxStencil::ScvfStencilIForJ scvfsJ; | ||
52 | // A list of additional scvfs is needed for compatibility | ||
53 | // reasons with more complex connectivity maps (see mpfa) | ||
54 | typename FluxStencil::ScvfStencilIForJ additionalScvfs; | ||
55 | }; | ||
56 | |||
57 | using Map = std::vector<std::vector<DataJ>>; | ||
58 | |||
59 | public: | ||
60 | |||
61 | /*! | ||
62 | * \brief Initialize the ConnectivityMap object. | ||
63 | * | ||
64 | * \param gridGeometry The grid's finite volume geometry. | ||
65 | */ | ||
66 | 632 | void update(const GridGeometry& gridGeometry) | |
67 | { | ||
68 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 48 times.
|
632 | map_.clear(); |
69 | 1270 | map_.resize(gridGeometry.gridView().size(0)); | |
70 | |||
71 | // container to store for each element J the elements I which have J in their flux stencil | ||
72 | 646 | Dune::ReservedVector<std::pair<GridIndexType, DataJ>, maxElemStencilSize> dataJForI; | |
73 |
1/4✓ Branch 1 taken 247 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
731 | auto fvGeometry = localView(gridGeometry); |
74 |
18/21✓ Branch 1 taken 247 times.
✓ Branch 2 taken 1598264 times.
✓ Branch 3 taken 102 times.
✓ Branch 4 taken 111364 times.
✓ Branch 5 taken 108 times.
✓ Branch 6 taken 315592 times.
✓ Branch 7 taken 2117 times.
✓ Branch 8 taken 20661 times.
✓ Branch 9 taken 23 times.
✓ Branch 10 taken 77 times.
✓ Branch 11 taken 22837 times.
✓ Branch 12 taken 233009 times.
✓ Branch 13 taken 77 times.
✓ Branch 14 taken 253670 times.
✓ Branch 15 taken 77 times.
✓ Branch 17 taken 233009 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 233009 times.
✗ Branch 21 not taken.
✓ Branch 25 taken 14 times.
✗ Branch 26 not taken.
|
6490971 | for (const auto& element : elements(gridGeometry.gridView())) |
75 | { | ||
76 | // We are looking for the elements I, for which this element J is in the flux stencil | ||
77 |
5/6✓ Branch 0 taken 1734 times.
✓ Branch 1 taken 257863 times.
✓ Branch 2 taken 1734 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 257862 times.
✗ Branch 5 not taken.
|
6942316 | const auto globalJ = gridGeometry.elementMapper().index(element); |
78 |
2/3✓ Branch 0 taken 1734 times.
✓ Branch 1 taken 577654 times.
✗ Branch 2 not taken.
|
3471158 | fvGeometry.bindElement(element); |
79 | |||
80 | // obtain the data of J in elements I | ||
81 | 3471158 | dataJForI.clear(); | |
82 | |||
83 | // loop over sub control faces | ||
84 |
4/4✓ Branch 0 taken 10726759 times.
✓ Branch 1 taken 2144879 times.
✓ Branch 2 taken 10726759 times.
✓ Branch 3 taken 2144879 times.
|
25081697 | for (auto&& scvf : scvfs(fvGeometry)) |
85 | { | ||
86 |
2/6✓ Branch 1 taken 81670 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 41364 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
18274151 | const auto& stencil = FluxStencil::stencil(element, fvGeometry, scvf); |
87 | |||
88 | // insert our index in the neighbor stencils of the elements in the flux stencil | ||
89 |
4/4✓ Branch 0 taken 22760507 times.
✓ Branch 1 taken 10726759 times.
✓ Branch 2 taken 2919954 times.
✓ Branch 3 taken 712286 times.
|
91821882 | for (auto globalI : stencil) |
90 | { | ||
91 |
2/2✓ Branch 0 taken 12033748 times.
✓ Branch 1 taken 10726759 times.
|
37808049 | if (globalI == globalJ) |
92 | continue; | ||
93 | |||
94 |
6/6✓ Branch 0 taken 1416818 times.
✓ Branch 1 taken 10616930 times.
✓ Branch 2 taken 1416818 times.
✓ Branch 3 taken 10616930 times.
✓ Branch 4 taken 1416818 times.
✓ Branch 5 taken 10616930 times.
|
59410314 | auto it = std::find_if(dataJForI.begin(), dataJForI.end(), |
95 | ✗ | [globalI](const auto& pair) { return pair.first == globalI; }); | |
96 | |||
97 |
4/4✓ Branch 0 taken 1416818 times.
✓ Branch 1 taken 10616930 times.
✓ Branch 2 taken 1416818 times.
✓ Branch 3 taken 10616930 times.
|
39606876 | if (it != dataJForI.end()) |
98 |
1/2✓ Branch 1 taken 1416818 times.
✗ Branch 2 not taken.
|
1999552 | it->second.scvfsJ.push_back(scvf.index()); |
99 | else | ||
100 | { | ||
101 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10616930 times.
|
17803886 | if (dataJForI.size() > maxElemStencilSize - 1) |
102 | ✗ | DUNE_THROW(Dune::InvalidStateException, "Maximum admissible stencil size (" << maxElemStencilSize-1 | |
103 | << ") is surpassed (" << dataJForI.size() << "). " | ||
104 | << "Please adjust the GridGeometry traits accordingly!"); | ||
105 | |||
106 |
2/6✓ Branch 1 taken 709326 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 709326 times.
✗ Branch 5 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
|
18785650 | dataJForI.push_back(std::make_pair(globalI, DataJ({globalJ, {scvf.index()}, {}}))); |
107 | } | ||
108 | } | ||
109 | } | ||
110 | |||
111 |
2/2✓ Branch 0 taken 10616930 times.
✓ Branch 1 taken 2144879 times.
|
28217360 | for (auto&& pair : dataJForI) |
112 |
2/4✓ Branch 1 taken 2684618 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2684618 times.
✗ Branch 5 not taken.
|
35607772 | map_[pair.first].emplace_back(std::move(pair.second)); |
113 | } | ||
114 | 632 | } | |
115 | |||
116 | const std::vector<DataJ>& operator[] (const GridIndexType globalI) const | ||
117 |
18/18✓ Branch 0 taken 9911048 times.
✓ Branch 1 taken 2989453 times.
✓ Branch 2 taken 13923118 times.
✓ Branch 3 taken 4019974 times.
✓ Branch 4 taken 5680774 times.
✓ Branch 5 taken 1339560 times.
✓ Branch 6 taken 35009438 times.
✓ Branch 7 taken 6254663 times.
✓ Branch 8 taken 36955076 times.
✓ Branch 9 taken 6481596 times.
✓ Branch 10 taken 5478776 times.
✓ Branch 11 taken 1017870 times.
✓ Branch 12 taken 1864434 times.
✓ Branch 13 taken 481898 times.
✓ Branch 16 taken 20892 times.
✓ Branch 17 taken 5781 times.
✓ Branch 18 taken 20892 times.
✓ Branch 19 taken 5781 times.
|
892652594 | { return map_[globalI]; } |
118 | |||
119 | private: | ||
120 | Map map_; | ||
121 | }; | ||
122 | |||
123 | } // end namespace Dumux | ||
124 | |||
125 | #endif | ||
126 |