3.5-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 auto fvGeometry = localView(gridGeometry);
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 fvGeometry.bindElement(element);
91
92 // obtain the data of J in elements I
93 dataJForI.clear();
94
95 // loop over sub control faces
96 for (auto&& scvf : scvfs(fvGeometry))
97 {
98 const auto& stencil = FluxStencil::stencil(element, fvGeometry, scvf);
99
100 // insert our index in the neighbor stencils of the elements in the flux stencil
101 for (auto globalI : stencil)
102 {
103 if (globalI == globalJ)
104 continue;
105
106 auto it = std::find_if(dataJForI.begin(), dataJForI.end(),
107 [globalI](const auto& pair) { return pair.first == globalI; });
108
109 if (it != dataJForI.end())
110 it->second.scvfsJ.push_back(scvf.index());
111 else
112 {
113 if (dataJForI.size() > maxElemStencilSize - 1)
114 DUNE_THROW(Dune::InvalidStateException, "Maximum admissible stencil size (" << maxElemStencilSize-1
115 << ") is surpassed (" << dataJForI.size() << "). "
116 << "Please adjust the GridGeometry traits accordingly!");
117
118 dataJForI.push_back(std::make_pair(globalI, DataJ({globalJ, {scvf.index()}, {}})));
119 }
120 }
121 }
122
123 for (auto&& pair : dataJForI)
124 map_[pair.first].emplace_back(std::move(pair.second));
125 }
126 }
127
128 const std::vector<DataJ>& operator[] (const GridIndexType globalI) const
129 { return map_[globalI]; }
130
131private:
132 Map map_;
133};
134
135} // end namespace Dumux
136
137#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
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:128
The flux stencil specialized for different discretization schemes.
Definition: fluxstencil.hh:45