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