3.5-git
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
32namespace Dumux {
33
39template<class GridView>
41{
42 using Element = typename GridView::template Codim<0>::Entity;
43 using GridIndexType = typename GridView::IndexSet::IndexType;
44
45 static constexpr int codimIntersection = 1;
46public:
47
48 ConformingGridIntersectionMapper(const GridView& gridView)
49 : gridView_(gridView)
50 , indexSet_(&gridView.indexSet())
51 {}
52
53 void update (const GridView& gridView)
54 {
55 gridView_ = gridView;
56 indexSet_ = &gridView_.indexSet();
57 }
58
59 void update (GridView&& gridView)
60 {
61 gridView_ = std::move(gridView);
62 indexSet_ = &gridView_.indexSet();
63 }
64
66 std::size_t numIntersections() const
67 {
68 return gridView_.size(1);
69 }
70
76 std::size_t numFaces(const Element& element) const
77 {
78 return element.subEntities(1);
79 }
80
81 GridIndexType globalIntersectionIndex(const Element& element, const std::size_t localFaceIdx) const
82 {
83 return indexSet_->subIndex(element, localFaceIdx, codimIntersection);
84 }
85
86private:
87 GridView gridView_;
88 const typename GridView::IndexSet* indexSet_;
89};
90
96template<class GridView>
98{
99 using Element = typename GridView::template Codim<0>::Entity;
100 using Intersection = typename GridView::Intersection;
101 using GridIndexType = typename GridView::IndexSet::IndexType;
102
103public:
104 NonConformingGridIntersectionMapper(const GridView& gridview)
105 : gridView_(gridview),
106 indexSet_(&gridView_.indexSet()),
107 numIntersections_(gridView_.size(1)),
108 intersectionMapGlobal_(gridView_.size(0))
109 {
110
111 }
112
114 std::size_t numIntersections() const
115 {
116 return numIntersections_;
117 }
118
119 GridIndexType globalIntersectionIndex(const Element& element, const std::size_t localFaceIdx) const
120 {
121 return (intersectionMapGlobal_[index(element)].find(localFaceIdx))->second; //use find() for const function!
122 }
123
124 std::size_t numFaces(const Element& element)
125 {
126 return intersectionMapGlobal_[index(element)].size();
127 }
128
129 void update (const GridView& gridView)
130 {
131 gridView_ = gridView;
132 indexSet_ = &gridView_.indexSet();
133 update_();
134 }
135
136 void update (GridView&& gridView)
137 {
138 gridView_ = std::move(gridView);
139 indexSet_ = &gridView_.indexSet();
140 update_();
141 }
142
143private:
144 GridIndexType index(const Element& element) const
145 {
146 return indexSet_->index(element);
147 }
148
149 void update_()
150 {
151 intersectionMapGlobal_.clear();
152 intersectionMapGlobal_.resize(gridView_.size(0));
153
154 int globalIntersectionIdx = 0;
155 for (const auto& element : elements(gridView_))
156 {
157 int eIdx = index(element);
158 int fIdx = 0;
159
160 // run through all intersections with neighbors
161 for (const auto& intersection : intersections(gridView_, element))
162 {
163 if (intersection.neighbor())
164 {
165 auto neighbor = intersection.outside();
166 int eIdxN = index(neighbor);
167
168 if (element.level() > neighbor.level() || (element.level() == neighbor.level() && eIdx < eIdxN))
169 {
170 int fIdxN = 0;
171 for (const auto& intersectionNeighbor : intersections(gridView_, neighbor))
172 {
173 if (intersectionNeighbor.neighbor())
174 {
175 if (intersectionNeighbor.outside() == element)
176 {
177 break;
178 }
179 }
180 fIdxN++;
181 }
182 intersectionMapGlobal_[eIdx][fIdx] = globalIntersectionIdx;
183 intersectionMapGlobal_[eIdxN][fIdxN] = globalIntersectionIdx;
184 globalIntersectionIdx++;
185 }
186 }
187 else
188 {
189 intersectionMapGlobal_[eIdx][fIdx] = globalIntersectionIdx;
190 globalIntersectionIdx++;
191 }
192
193 fIdx++;
194 }
195 }
196 numIntersections_ = globalIntersectionIdx;
197 }
198
199 GridView gridView_;
200 const typename GridView::IndexSet* indexSet_;
201 unsigned int numIntersections_;
202 std::vector<std::unordered_map<int, int> > intersectionMapGlobal_;
203};
204
210template<class GridView>
212{
213 using Grid = typename GridView::Grid;
214 enum {dim=Grid::dimension};
215 using Element = typename Grid::template Codim<0>::Entity;
216 using Intersection = typename GridView::Intersection;
217 using ElementMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
218
219public:
220 IntersectionMapper(const GridView& gridview)
221 : gridView_(gridview)
222 , elementMapper_(gridView_, Dune::mcmgElementLayout())
223 , size_(gridView_.size(1))
226 {
227 const auto element = *gridView_.template begin<0>();
228
229 int fIdx = 0;
230 for (const auto& intersection : intersections(gridView_, element))
231 {
232 int idxInInside = intersection.indexInInside();
233
234 standardLocalIdxMap_[idxInInside] = fIdx;
235
236 fIdx++;
237 }
238 }
239
240 const ElementMapper& elementMapper() const
241 {
242 return elementMapper_;
243 }
244
251 int index(const Element& element) const
252 {
253 return elementMapper_.index(element);
254 }
255
263 int subIndex(int elemIdx, int fIdx)
264 {
265 return intersectionMapGlobal_[elemIdx][fIdx];
266 }
267
275 int subIndex(int elemIdx, int fIdx) const
276 {
277 return (intersectionMapGlobal_[elemIdx].find(fIdx))->second;//use find() for const function!
278 }
279
287 int subIndex(const Element& element, int fIdx)
288 {
289 return intersectionMapGlobal_[index(element)][fIdx];
290 }
291
292 int subIndex(const Element& element, int fIdx) const
293 {
294 return intersectionMapGlobal_[index(element)].find(fIdx)->second;//use find() for const function!
295 }
296
297 int maplocal(int elemIdx, int fIdx)
298 {
299 return intersectionMapLocal_[elemIdx][fIdx];
300 }
301
302 int maplocal(int elemIdx, int fIdx) const
303 {
304 return (intersectionMapLocal_[elemIdx].find(fIdx))->second;//use find() for const function!
305 }
306
307
308 int maplocal(const Element& element, int fIdx)
309 {
310 return intersectionMapLocal_[index(element)][fIdx];
311 }
312
313 int maplocal(const Element& element, int fIdx) const
314 {
315 return (intersectionMapLocal_[index(element)].find(fIdx))->second;//use find() for const function!
316 }
317
318 // return number intersections
319 unsigned int size () const
320 {
321 return size_;
322 }
323
324 unsigned int size (int elemIdx) const
325 {
326 return intersectionMapLocal_[elemIdx].size();
327 }
328
329 unsigned int size (const Element& element) const
330 {
331 return intersectionMapLocal_[index(element)].size();
332 }
333
334 void update (const GridView &gridView)
335 {
336 gridView_ = gridView;
337 update_();
338 }
339
340 void update (GridView&& gridView)
341 {
342 gridView_ = std::move(gridView);
343 update_();
344 }
345
346protected:
347 void update_()
348 {
350
353 intersectionMapLocal_.clear();
355
356 for (const auto& element : elements(gridView_))
357 {
358 int eIdxGlobal = index(element);
359
360 int fIdx = 0;
361 // run through all intersections with neighbors
362 for (const auto& intersection : intersections(gridView_, element))
363 {
364 int indexInInside = intersection.indexInInside();
365 intersectionMapLocal_[eIdxGlobal][fIdx] = indexInInside;
366
367 fIdx++;
368 }
369 }
370 int globalIntersectionIdx = 0;
371 for (const auto& element : elements(gridView_))
372 {
373 int eIdxGlobal = index(element);
374
375 int fIdx = 0;
376 // run through all intersections with neighbors
377 for (const auto& intersection : intersections(gridView_, element))
378 {
379 if (intersection.neighbor())
380 {
381 auto neighbor = intersection.outside();
382 int globalIdxNeighbor = index(neighbor);
383
384 if (element.level() > neighbor.level() || (element.level() == neighbor.level() && eIdxGlobal < globalIdxNeighbor))
385 {
386
387 int faceIdxNeighbor = 0;
388 if (size(globalIdxNeighbor) == 2 * dim)
389 {
390 faceIdxNeighbor = standardLocalIdxMap_[intersection.indexInOutside()];
391 }
392 else
393 {
394 for (const auto& intersectionNeighbor : intersections(gridView_, neighbor))
395 {
396 if (intersectionNeighbor.neighbor())
397 {
398 if (intersectionNeighbor.outside() == element)
399 {
400 break;
401 }
402 }
403 faceIdxNeighbor++;
404 }
405 }
406
407 intersectionMapGlobal_[eIdxGlobal][fIdx] = globalIntersectionIdx;
408 intersectionMapGlobal_[globalIdxNeighbor][faceIdxNeighbor] = globalIntersectionIdx;
409 globalIntersectionIdx ++;
410 }
411 }
412 else
413 {
414 intersectionMapGlobal_[eIdxGlobal][fIdx] = globalIntersectionIdx;
415 globalIntersectionIdx ++;
416 }
417 fIdx++;
418 }
419 }
420 size_ = globalIntersectionIdx;
421 }
422 GridView gridView_;
423 ElementMapper elementMapper_;
424 unsigned int size_;
425 std::vector<std::unordered_map<int, int> > intersectionMapGlobal_;
426 std::vector<std::unordered_map<int, int> > intersectionMapLocal_;
427 std::unordered_map<int, int> standardLocalIdxMap_;
428};
429
430} // end namespace Dumux
431
432#endif
Definition: adapt.hh:29
Definition: common/pdesolver.hh:36
defines a standard intersection mapper for mapping of global DOFs assigned to faces....
Definition: intersectionmapper.hh:41
std::size_t numFaces(const Element &element) const
The number of faces for a given element.
Definition: intersectionmapper.hh:76
GridIndexType globalIntersectionIndex(const Element &element, const std::size_t localFaceIdx) const
Definition: intersectionmapper.hh:81
std::size_t numIntersections() const
The total number of intersections.
Definition: intersectionmapper.hh:66
ConformingGridIntersectionMapper(const GridView &gridView)
Definition: intersectionmapper.hh:48
void update(const GridView &gridView)
Definition: intersectionmapper.hh:53
void update(GridView &&gridView)
Definition: intersectionmapper.hh:59
defines an intersection mapper for mapping of global DOFs assigned to faces which also works for non-...
Definition: intersectionmapper.hh:98
std::size_t numFaces(const Element &element)
Definition: intersectionmapper.hh:124
std::size_t numIntersections() const
The total number of intersections.
Definition: intersectionmapper.hh:114
void update(const GridView &gridView)
Definition: intersectionmapper.hh:129
NonConformingGridIntersectionMapper(const GridView &gridview)
Definition: intersectionmapper.hh:104
void update(GridView &&gridView)
Definition: intersectionmapper.hh:136
GridIndexType globalIntersectionIndex(const Element &element, const std::size_t localFaceIdx) const
Definition: intersectionmapper.hh:119
defines an intersection mapper for mapping of global DOFs assigned to faces which also works for adap...
Definition: intersectionmapper.hh:212
int maplocal(const Element &element, int fIdx)
Definition: intersectionmapper.hh:308
unsigned int size_
Definition: intersectionmapper.hh:424
int subIndex(const Element &element, int fIdx) const
Definition: intersectionmapper.hh:292
unsigned int size(int elemIdx) const
Definition: intersectionmapper.hh:324
int subIndex(const Element &element, int fIdx)
Map interface fIdx'th interface of element to array index.
Definition: intersectionmapper.hh:287
int subIndex(int elemIdx, int fIdx) const
Map interface fIdx'th interface of element index to array index.
Definition: intersectionmapper.hh:275
int subIndex(int elemIdx, int fIdx)
Map interface fIdx'th interface of element index to array index.
Definition: intersectionmapper.hh:263
std::unordered_map< int, int > standardLocalIdxMap_
Definition: intersectionmapper.hh:427
int maplocal(const Element &element, int fIdx) const
Definition: intersectionmapper.hh:313
std::vector< std::unordered_map< int, int > > intersectionMapLocal_
Definition: intersectionmapper.hh:426
void update_()
Definition: intersectionmapper.hh:347
void update(const GridView &gridView)
Definition: intersectionmapper.hh:334
void update(GridView &&gridView)
Definition: intersectionmapper.hh:340
unsigned int size() const
Definition: intersectionmapper.hh:319
const ElementMapper & elementMapper() const
Definition: intersectionmapper.hh:240
int maplocal(int elemIdx, int fIdx)
Definition: intersectionmapper.hh:297
int maplocal(int elemIdx, int fIdx) const
Definition: intersectionmapper.hh:302
unsigned int size(const Element &element) const
Definition: intersectionmapper.hh:329
int index(const Element &element) const
Map element to array index.
Definition: intersectionmapper.hh:251
IntersectionMapper(const GridView &gridview)
Definition: intersectionmapper.hh:220
ElementMapper elementMapper_
Definition: intersectionmapper.hh:423
GridView gridView_
Definition: intersectionmapper.hh:422
std::vector< std::unordered_map< int, int > > intersectionMapGlobal_
Definition: intersectionmapper.hh:425