3.1-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
cellcentered/connectivitymap.hh
Go to the documentation of this file.
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
26#ifndef DUMUX_CC_CONNECTIVITY_MAP_HH
27#define DUMUX_CC_CONNECTIVITY_MAP_HH
28
29#include <vector>
30#include <utility>
31#include <algorithm>
32
33#include <dune/common/exceptions.hh>
34#include <dune/common/reservedvector.hh>
35
38
39namespace Dumux {
40
51template<class GridGeometry>
53{
54 using FVElementGeometry = typename GridGeometry::LocalView;
55 using GridView = typename GridGeometry::GridView;
56 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
58 static constexpr int maxElemStencilSize = GridGeometry::maxElementStencilSize;
59
60 struct DataJ
61 {
62 GridIndexType globalJ;
63 typename FluxStencil::ScvfStencilIForJ scvfsJ;
64 // A list of additional scvfs is needed for compatibility
65 // reasons with more complex connectivity maps (see mpfa)
66 typename FluxStencil::ScvfStencilIForJ additionalScvfs;
67 };
68
69 using Map = std::vector<std::vector<DataJ>>;
70
71public:
72
78 void update(const GridGeometry& gridGeometry)
79 {
80 map_.clear();
81 map_.resize(gridGeometry.gridView().size(0));
82
83 // container to store for each element J the elements I which have J in their flux stencil
84 Dune::ReservedVector<std::pair<GridIndexType, DataJ>, maxElemStencilSize> dataJForI;
85
86 for (const auto& element : elements(gridGeometry.gridView()))
87 {
88 // We are looking for the elements I, for which this element J is in the flux stencil
89 const auto globalJ = gridGeometry.elementMapper().index(element);
90
91 auto fvGeometry = localView(gridGeometry);
92 fvGeometry.bindElement(element);
93
94 // obtain the data of J in elements I
95 dataJForI.clear();
96
97 // loop over sub control faces
98 for (auto&& scvf : scvfs(fvGeometry))
99 {
100 const auto& stencil = FluxStencil::stencil(element, fvGeometry, scvf);
101
102 // insert our index in the neighbor stencils of the elements in the flux stencil
103 for (auto globalI : stencil)
104 {
105 if (globalI == globalJ)
106 continue;
107
108 auto it = std::find_if(dataJForI.begin(), dataJForI.end(),
109 [globalI](const auto& pair) { return pair.first == globalI; });
110
111 if (it != dataJForI.end())
112 it->second.scvfsJ.push_back(scvf.index());
113 else
114 {
115 if (dataJForI.size() > maxElemStencilSize - 1)
116 DUNE_THROW(Dune::InvalidStateException, "Maximum admissible stencil size (" << maxElemStencilSize-1
117 << ") is surpassed (" << dataJForI.size() << "). "
118 << "Please adjust the GridGeometry traits accordingly!");
119
120 dataJForI.push_back(std::make_pair(globalI, DataJ({globalJ, {scvf.index()}, {}})));
121 }
122 }
123 }
124
125 for (auto&& pair : dataJForI)
126 map_[pair.first].emplace_back(std::move(pair.second));
127 }
128 }
129
130 const std::vector<DataJ>& operator[] (const GridIndexType globalI) const
131 { return map_[globalI]; }
132
133private:
134 Map map_;
135};
136
137} // end namespace Dumux
138
139#endif
Defines the index types used for grid and local indices.
The flux stencil specialized for different discretization schemes.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:38
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:39
A simple version of the connectivity map for cellcentered schemes. This implementation works for sche...
Definition: cellcentered/connectivitymap.hh:53
void update(const GridGeometry &gridGeometry)
Initialize the ConnectivityMap object.
Definition: cellcentered/connectivitymap.hh:78
const std::vector< DataJ > & operator[](const GridIndexType globalI) const
Definition: cellcentered/connectivitymap.hh:130
The flux stencil specialized for different discretization schemes.
Definition: fluxstencil.hh:45