3.3.0
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
intersectionmapper.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2/*****************************************************************************
3 * See the file COPYING for full copying permissions. *
4 * *
5 * This program is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17 *****************************************************************************/
23#ifndef DUMUX_INTERSECTIONITERATOR_HH
24#define DUMUX_INTERSECTIONITERATOR_HH
25
26#include <vector>
27#include <unordered_map>
28
29#include <dune/grid/common/mcmgmapper.hh>
30#include <dune/grid/common/rangegenerators.hh>
31
32
33namespace Dumux {
34
40template<class GridView>
42{
43 using Element = typename GridView::template Codim<0>::Entity;
44 using GridIndexType = typename GridView::IndexSet::IndexType;
45
46 static constexpr int codimIntersection = 1;
47public:
48
49 ConformingGridIntersectionMapper(const GridView& gridView)
50 : gridView_(gridView) { }
51
52 void update()
53 {}
54
56 std::size_t numIntersections() const
57 {
58 return gridView_.size(1);
59 }
60
66 std::size_t numFaces(const Element& element) const
67 {
68 return element.subEntities(1);
69 }
70
71 GridIndexType globalIntersectionIndex(const Element& element, const std::size_t localFaceIdx) const
72 {
73 return gridView_.indexSet().subIndex(element, localFaceIdx, codimIntersection);
74 }
75
76private:
77 const GridView gridView_;
78};
79
85template<class GridView>
87{
88 using Element = typename GridView::template Codim<0>::Entity;
89 using Intersection = typename GridView::Intersection;
90 using GridIndexType = typename GridView::IndexSet::IndexType;
91
92public:
93 NonConformingGridIntersectionMapper(const GridView& gridview)
94 : gridView_(gridview),
95 numIntersections_(gridView_.size(1)),
96 intersectionMapGlobal_(gridView_.size(0))
97 {
98
99 }
100
102 std::size_t numIntersections() const
103 {
104 return numIntersections_;
105 }
106
107 GridIndexType globalIntersectionIndex(const Element& element, const std::size_t localFaceIdx) const
108 {
109 return (intersectionMapGlobal_[index(element)].find(localFaceIdx))->second; //use find() for const function!
110 }
111
112 std::size_t numFaces(const Element& element)
113 {
114 return intersectionMapGlobal_[index(element)].size();
115 }
116
117 void update()
118 {
119 intersectionMapGlobal_.clear();
120 intersectionMapGlobal_.resize(gridView_.size(0));
121
122 int globalIntersectionIdx = 0;
123 for (const auto& element : elements(gridView_))
124 {
125 int eIdx = index(element);
126 int fIdx = 0;
127
128 // run through all intersections with neighbors
129 for (const auto& intersection : intersections(gridView_, element))
130 {
131 if (intersection.neighbor())
132 {
133 auto neighbor = intersection.outside();
134 int eIdxN = index(neighbor);
135
136 if (element.level() > neighbor.level() || (element.level() == neighbor.level() && eIdx < eIdxN))
137 {
138 int fIdxN = 0;
139 for (const auto& intersectionNeighbor : intersections(gridView_, neighbor))
140 {
141 if (intersectionNeighbor.neighbor())
142 {
143 if (intersectionNeighbor.outside() == element)
144 {
145 break;
146 }
147 }
148 fIdxN++;
149 }
150 intersectionMapGlobal_[eIdx][fIdx] = globalIntersectionIdx;
151 intersectionMapGlobal_[eIdxN][fIdxN] = globalIntersectionIdx;
152 globalIntersectionIdx++;
153 }
154 }
155 else
156 {
157 intersectionMapGlobal_[eIdx][fIdx] = globalIntersectionIdx;
158 globalIntersectionIdx++;
159 }
160
161 fIdx++;
162 }
163 }
164 numIntersections_ = globalIntersectionIdx;
165 }
166
167private:
168 GridIndexType index(const Element& element) const
169 {
170 return gridView_.indexSet().index(element);
171 }
172
173 const GridView gridView_;
174 unsigned int numIntersections_;
175 std::vector<std::unordered_map<int, int> > intersectionMapGlobal_;
176};
177
183template<class GridView>
185{
186 using Grid = typename GridView::Grid;
187 enum {dim=Grid::dimension};
188 using Element = typename Grid::template Codim<0>::Entity;
189 using Intersection = typename GridView::Intersection;
190 using ElementMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
191
192public:
193 IntersectionMapper(const GridView& gridview)
194 : gridView_(gridview)
195 , elementMapper_(gridView_, Dune::mcmgElementLayout())
196 , size_(gridView_.size(1))
199 {
200 const auto element = *gridView_.template begin<0>();
201
202 int fIdx = 0;
203 for (const auto& intersection : intersections(gridView_, element))
204 {
205 int idxInInside = intersection.indexInInside();
206
207 standardLocalIdxMap_[idxInInside] = fIdx;
208
209 fIdx++;
210 }
211 }
212
213 const ElementMapper& elementMapper() const
214 {
215 return elementMapper_;
216 }
217
224 int index(const Element& element) const
225 {
226 return elementMapper_.index(element);
227 }
228
236 int subIndex(int elemIdx, int fIdx)
237 {
238 return intersectionMapGlobal_[elemIdx][fIdx];
239 }
240
248 int subIndex(int elemIdx, int fIdx) const
249 {
250 return (intersectionMapGlobal_[elemIdx].find(fIdx))->second;//use find() for const function!
251 }
252
260 int subIndex(const Element& element, int fIdx)
261 {
262 return intersectionMapGlobal_[index(element)][fIdx];
263 }
264
265 int subIndex(const Element& element, int fIdx) const
266 {
267 return intersectionMapGlobal_[index(element)].find(fIdx)->second;//use find() for const function!
268 }
269
270 int maplocal(int elemIdx, int fIdx)
271 {
272 return intersectionMapLocal_[elemIdx][fIdx];
273 }
274
275 int maplocal(int elemIdx, int fIdx) const
276 {
277 return (intersectionMapLocal_[elemIdx].find(fIdx))->second;//use find() for const function!
278 }
279
280
281 int maplocal(const Element& element, int fIdx)
282 {
283 return intersectionMapLocal_[index(element)][fIdx];
284 }
285
286 int maplocal(const Element& element, int fIdx) const
287 {
288 return (intersectionMapLocal_[index(element)].find(fIdx))->second;//use find() for const function!
289 }
290
291 // return number intersections
292 unsigned int size () const
293 {
294 return size_;
295 }
296
297 unsigned int size (int elemIdx) const
298 {
299 return intersectionMapLocal_[elemIdx].size();
300 }
301
302 unsigned int size (const Element& element) const
303 {
304 return intersectionMapLocal_[index(element)].size();
305 }
306
307 void update()
308 {
309 elementMapper_.update();
310
313 intersectionMapLocal_.clear();
315
316 for (const auto& element : elements(gridView_))
317 {
318 int eIdxGlobal = index(element);
319
320 int fIdx = 0;
321 // run through all intersections with neighbors
322 for (const auto& intersection : intersections(gridView_, element))
323 {
324 int indexInInside = intersection.indexInInside();
325 intersectionMapLocal_[eIdxGlobal][fIdx] = indexInInside;
326
327 fIdx++;
328 }
329 }
330
331 int globalIntersectionIdx = 0;
332 for (const auto& element : elements(gridView_))
333 {
334 int eIdxGlobal = index(element);
335
336 int fIdx = 0;
337 // run through all intersections with neighbors
338 for (const auto& intersection : intersections(gridView_, element))
339 {
340 if (intersection.neighbor())
341 {
342 auto neighbor = intersection.outside();
343 int globalIdxNeighbor = index(neighbor);
344
345 if (element.level() > neighbor.level() || (element.level() == neighbor.level() && eIdxGlobal < globalIdxNeighbor))
346 {
347
348 int faceIdxNeighbor = 0;
349 if (size(globalIdxNeighbor) == 2 * dim)
350 {
351 faceIdxNeighbor = standardLocalIdxMap_[intersection.indexInOutside()];
352 }
353 else
354 {
355 for (const auto& intersectionNeighbor : intersections(gridView_, neighbor))
356 {
357 if (intersectionNeighbor.neighbor())
358 {
359 if (intersectionNeighbor.outside() == element)
360 {
361 break;
362 }
363 }
364 faceIdxNeighbor++;
365 }
366 }
367
368 intersectionMapGlobal_[eIdxGlobal][fIdx] = globalIntersectionIdx;
369 intersectionMapGlobal_[globalIdxNeighbor][faceIdxNeighbor] = globalIntersectionIdx;
370 globalIntersectionIdx ++;
371 }
372 }
373 else
374 {
375 intersectionMapGlobal_[eIdxGlobal][fIdx] = globalIntersectionIdx;
376 globalIntersectionIdx ++;
377 }
378 fIdx++;
379 }
380 }
381 size_ = globalIntersectionIdx;
382 }
383
384protected:
385 const GridView gridView_;
386 ElementMapper elementMapper_;
387 unsigned int size_;
388 std::vector<std::unordered_map<int, int> > intersectionMapGlobal_;
389 std::vector<std::unordered_map<int, int> > intersectionMapLocal_;
390 std::unordered_map<int, int> standardLocalIdxMap_;
391};
392
393} // end namespace Dumux
394
395#endif
Definition: adapt.hh:29
Definition: common/pdesolver.hh:35
defines a standard intersection mapper for mapping of global DOFs assigned to faces....
Definition: intersectionmapper.hh:42
std::size_t numFaces(const Element &element) const
The number of faces for a given element.
Definition: intersectionmapper.hh:66
GridIndexType globalIntersectionIndex(const Element &element, const std::size_t localFaceIdx) const
Definition: intersectionmapper.hh:71
std::size_t numIntersections() const
The total number of intersections.
Definition: intersectionmapper.hh:56
ConformingGridIntersectionMapper(const GridView &gridView)
Definition: intersectionmapper.hh:49
void update()
Definition: intersectionmapper.hh:52
defines an intersection mapper for mapping of global DOFs assigned to faces which also works for non-...
Definition: intersectionmapper.hh:87
std::size_t numFaces(const Element &element)
Definition: intersectionmapper.hh:112
std::size_t numIntersections() const
The total number of intersections.
Definition: intersectionmapper.hh:102
NonConformingGridIntersectionMapper(const GridView &gridview)
Definition: intersectionmapper.hh:93
GridIndexType globalIntersectionIndex(const Element &element, const std::size_t localFaceIdx) const
Definition: intersectionmapper.hh:107
void update()
Definition: intersectionmapper.hh:117
defines an intersection mapper for mapping of global DOFs assigned to faces which also works for adap...
Definition: intersectionmapper.hh:185
int maplocal(const Element &element, int fIdx)
Definition: intersectionmapper.hh:281
unsigned int size_
Definition: intersectionmapper.hh:387
int subIndex(const Element &element, int fIdx) const
Definition: intersectionmapper.hh:265
const GridView gridView_
Definition: intersectionmapper.hh:385
unsigned int size(int elemIdx) const
Definition: intersectionmapper.hh:297
int subIndex(const Element &element, int fIdx)
Map interface fIdx'th interface of element to array index.
Definition: intersectionmapper.hh:260
int subIndex(int elemIdx, int fIdx) const
Map interface fIdx'th interface of element index to array index.
Definition: intersectionmapper.hh:248
int subIndex(int elemIdx, int fIdx)
Map interface fIdx'th interface of element index to array index.
Definition: intersectionmapper.hh:236
std::unordered_map< int, int > standardLocalIdxMap_
Definition: intersectionmapper.hh:390
int maplocal(const Element &element, int fIdx) const
Definition: intersectionmapper.hh:286
std::vector< std::unordered_map< int, int > > intersectionMapLocal_
Definition: intersectionmapper.hh:389
unsigned int size() const
Definition: intersectionmapper.hh:292
const ElementMapper & elementMapper() const
Definition: intersectionmapper.hh:213
int maplocal(int elemIdx, int fIdx)
Definition: intersectionmapper.hh:270
int maplocal(int elemIdx, int fIdx) const
Definition: intersectionmapper.hh:275
unsigned int size(const Element &element) const
Definition: intersectionmapper.hh:302
int index(const Element &element) const
Map element to array index.
Definition: intersectionmapper.hh:224
IntersectionMapper(const GridView &gridview)
Definition: intersectionmapper.hh:193
void update()
Definition: intersectionmapper.hh:307
ElementMapper elementMapper_
Definition: intersectionmapper.hh:386
std::vector< std::unordered_map< int, int > > intersectionMapGlobal_
Definition: intersectionmapper.hh:388