dune-foamgrid 2.8.0
Loading...
Searching...
No Matches
foamgridindexsets.hh
Go to the documentation of this file.
1// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set ts=8 sw=4 et sts=4:
3#ifndef DUNE_FOAMGRID_INDEXSETS_HH
4#define DUNE_FOAMGRID_INDEXSETS_HH
5
10#include <vector>
11#include <list>
12
13#include <dune/common/version.hh>
14
15#include <dune/geometry/type.hh>
16#include <dune/grid/common/indexidset.hh>
17
18#include <dune/foamgrid/foamgrid/foamgridvertex.hh> // for FoamGridEntityImp
19
20namespace Dune {
21
23 template<class GridImp>
25 public IndexSet<GridImp,FoamGridLevelIndexSet<GridImp> >
26 {
27
29 enum {dimgrid = GridImp::dimension};
30
32 enum {dimworld = GridImp::dimensionworld};
33
34 public:
35
36 FoamGridLevelIndexSet(const GridImp& grid, int level)
37 : grid_(&grid), level_(level), numQuads_(0), numTriangles_(0), numEdges_(0), numVertices_(0)
38 {}
39
41 template<int codim>
42 int index (const typename GridImp::Traits::template Codim<codim>::Entity& e) const
43 {
44 return e.impl().target_->levelIndex_;
45 }
46
48 template<int cc>
49 int subIndex (const typename GridImp::Traits::template Codim<cc>::Entity& e,
50 int i,
51 unsigned int codim) const
52 {
53 return e.impl().target_->subLevelIndex(i,codim);
54 }
55
57 int size (int codim) const {
58 if(dimgrid == 2) {
59 switch (codim) {
60 case 0:
61 return numTriangles_ + numQuads_;
62 case 1:
63 return numEdges_;
64 case 2:
65 return numVertices_;
66 }
67 } else { //dimgrid==1
68 switch (codim) {
69 case 0:
70 return numEdges_;
71 case 1:
72 return numVertices_;
73 }
74 }
75
76 return 0;
77 }
78
79
81 int size (GeometryType type) const
82 {
83 if (type.isVertex())
84 return numVertices_;
85 if (type.isLine())
86 return numEdges_;
87 if (type.isTriangle())
88 return numTriangles_;
89 if (type.isQuadrilateral())
90 return numQuads_;
91 return 0;
92 }
93
94
96 const std::vector<GeometryType>& geomTypes (int codim) const
97 {
98 return myTypes_[codim];
99 }
100
102 std::vector<GeometryType> types (int codim) const
103 {
104 assert(codim<=dimgrid);
105 return myTypes_[codim];
106 }
107
112 template<class EntityType>
113 bool contains (const EntityType& e) const
114 {
115 return level_ == e.level();
116 }
117
119 void update()
120 {
121 numQuads_ = 0;
122 numTriangles_ = 0;
123 numEdges_ = 0;
124 numVertices_ = 0;
125
126 // //////////////////////////////
127 // Init the vertex indices
128 // //////////////////////////////
129 typename std::list<FoamGridEntityImp<0, dimgrid, dimworld, typename GridImp::ctype> >::const_iterator vIt;
130 for (vIt = std::get<0>(grid_->entityImps_[level_]).begin();
131 vIt != std::get<0>(grid_->entityImps_[level_]).end();
132 ++vIt)
134 *const_cast<unsigned int*>(&(vIt->levelIndex_)) = numVertices_++;
135
136 // ///////////////////////////////
137 // Init the edges(2d) / element(1d) indices
138 // ///////////////////////////////
139 typename std::list<FoamGridEntityImp<1, dimgrid, dimworld, typename GridImp::ctype> >::const_iterator edIt;
140 for (edIt = std::get<1>(grid_->entityImps_[level_]).begin();
141 edIt != std::get<1>(grid_->entityImps_[level_]).end();
142 ++edIt)
144 *const_cast<unsigned int*>(&(edIt->levelIndex_)) = numEdges_++;
145
146
147 // ///////////////////////////////
148 // Init the element (2d) indices
149 // ///////////////////////////////
150 if(dimgrid == 2) {
151
152 typename std::list<FoamGridEntityImp<dimgrid, dimgrid, dimworld, typename GridImp::ctype> >::const_iterator eIt;
153 for (eIt = std::get<dimgrid>(grid_->entityImps_[level_]).begin();
154 eIt != std::get<dimgrid>(grid_->entityImps_[level_]).end();
155 ++eIt)
157 *const_cast<unsigned int*>(&(eIt->levelIndex_)) = (eIt->type().isTriangle()) ? numTriangles_++ : numQuads_++;
158 }
159
160 // ///////////////////////////////////////////////
161 // Update the list of geometry types present
162 // ///////////////////////////////////////////////
163
164 for (int i = 0; i < dimgrid+1; ++i)
165 myTypes_[i].clear();
166
167 if (numTriangles_>0 && dimgrid == 2)
168 myTypes_[0].push_back(GeometryTypes::simplex(2));
169
170 if (numQuads_>0 && dimgrid == 2)
171 myTypes_[0].push_back(GeometryTypes::cube(2));
172
173 if (numEdges_>0 && dimgrid == 2)
174 myTypes_[1].push_back(GeometryTypes::simplex(1));
175 if (numEdges_>0 && dimgrid == 1)
176 myTypes_[0].push_back(GeometryTypes::simplex(1));
177
178 if (numVertices_>0)
179 myTypes_[dimgrid].push_back(GeometryTypes::simplex(0));
180 }
181
182 private:
183 const GridImp* grid_;
184 int level_;
185
186 int numQuads_;
187 int numTriangles_;
188 int numEdges_;
189 int numVertices_;
190
192 std::array<std::vector<GeometryType>, dimgrid+1> myTypes_;
193
194 };
195
196
197template<class GridImp>
199 public IndexSet<GridImp,FoamGridLeafIndexSet<GridImp> >
200{
201
202 // Grid dimension
203 enum {dimgrid = std::remove_const<GridImp>::type::dimension};
204 // World dimension
205 enum {dimworld = std::remove_const<GridImp>::type::dimensionworld};
206
207public:
208
210 FoamGridLeafIndexSet(const GridImp& g)
211 : grid_(g), numQuads_(0), numTriangles_(0), numEdges_(0), numVertices_(0)
212 {}
213
215 /*
216 We use the RemoveConst to extract the Type from the mutable class,
217 because the const class is not instantiated yet.
218 */
219 template<int codim>
220 int index (const typename GridImp::Traits::template Codim<codim>::Entity& e) const
221 {
222 return e.impl().target_->leafIndex_;
223 }
224
226 template<int cc>
227 int subIndex (const typename GridImp::Traits::template Codim<cc>::Entity& e,
228 int i,
229 unsigned int codim) const
230 {
231 return e.impl().target_->subLeafIndex(i,codim);
232 }
233
235 int size (int codim) const {
236 if(dimgrid == 2) {
237 switch (codim) {
238 case 0:
239 return numTriangles_ + numQuads_;
240 case 1:
241 return numEdges_;
242 case 2:
243 return numVertices_;
244 }
245 } else { //if dimgrid==1
246 switch (codim) {
247 case 0:
248 return numEdges_;
249 case 1:
250 return numVertices_;
251 }
252 }
253
254 return 0;
255 }
256
257
259 int size (GeometryType type) const
260 {
261 if (type.isVertex())
262 return numVertices_;
263 if (type.isLine())
264 return numEdges_;
265 if (type.isTriangle())
266 return numTriangles_;
267 if (type.isQuadrilateral())
268 return numQuads_;
269 return 0;
270 }
271
272
274 const std::vector<GeometryType>& geomTypes (int codim) const
275 {
276 return myTypes_[codim];
277 }
278
280 std::vector<GeometryType> types (int codim) const
281 {
282 assert(codim<=dimgrid);
283 return myTypes_[codim];
284 }
285
287 template<class EntityType>
288 bool contains (const EntityType& e) const
289 {
290 return e.impl().target_->isLeaf();
291 }
292
294 void update()
295 {
296
297 numQuads_ = 0;
298 numTriangles_ = 0;
299 numEdges_ = 0;
300 numVertices_ = 0;
301
302 // ///////////////////////////////
303 // Init codim 0 entity indices
304 // ///////////////////////////////
305 typename GridImp::Traits::template Codim<0>::LeafIterator eIt = grid_.template leafbegin<0>();
306 typename GridImp::Traits::template Codim<0>::LeafIterator eEndIt = grid_.template leafend<0>();
307
308 for (; eIt!=eEndIt; ++eIt){
309 if(eIt->type().isTriangle() && dimgrid == 2)
310 *const_cast<unsigned int*>(&(eIt->impl().target_->leafIndex_)) = numTriangles_++;
311 if(eIt->type().isQuadrilateral() && dimgrid == 2)
312 *const_cast<unsigned int*>(&(eIt->impl().target_->leafIndex_)) = numQuads_++;
313 if(eIt->type().isLine() && dimgrid == 1)
314 *const_cast<unsigned int*>(&(eIt->impl().target_->leafIndex_)) = numEdges_++;
315 }
316
317 // //////////////////////////////
318 // Init the codim 1 entitiy indices
319 // //////////////////////////////
320
321 for (int i=grid_.maxLevel(); i>=0; i--) {
322
323 typename GridImp::Traits::template Codim<1>::LevelIterator edIt = grid_.template lbegin<1>(i);
324 typename GridImp::Traits::template Codim<1>::LevelIterator edEndIt = grid_.template lend<1>(i);
325
326 for (; edIt!=edEndIt; ++edIt) {
327
328 const FoamGridEntityImp<dimgrid-1, dimgrid, dimworld, typename GridImp::ctype>* target = edIt->impl().target_;
329
330 if (target->isLeaf()){
331 // The is a real leaf edge.
332 if(edIt->type().isLine() && dimgrid==2)
333 *const_cast<unsigned int*>(&(target->leafIndex_)) = numEdges_++;
334 if(edIt->type().isVertex() && dimgrid==1)
335 *const_cast<unsigned int*>(&(target->leafIndex_)) = numVertices_++;
336 }
337 else
338 {
339 if(target->nSons_==1)
340 // If there is green refinement an edge might only have
341 // one son. In this case son and father are identical and
342 // we inherit the leafIndex from the son.
343 *const_cast<unsigned int*>(&(target->leafIndex_)) = target->sons_[0]->leafIndex_;
344 }
345 }
346 }
347
348 // //////////////////////////////////////////////
349 // Init the codim 2 entity indices (only in 2d)
350 // //////////////////////////////////////////////
351
352 if(dimgrid==2){
353
354 for (int i=grid_.maxLevel(); i>=0; i--) {
355
356 typename GridImp::Traits::template Codim<dimgrid>::LevelIterator vIt = grid_.template lbegin<dimgrid>(i);
357 typename GridImp::Traits::template Codim<dimgrid>::LevelIterator vEndIt = grid_.template lend<dimgrid>(i);
358
359 for (; vIt!=vEndIt; ++vIt) {
360
362
363 if (target->isLeaf())
364 {
365 if(vIt->type().isVertex() && dimgrid==2)
366 *const_cast<unsigned int*>(&(target->leafIndex_)) = numVertices_++;
367 }
368 else
369 *const_cast<unsigned int*>(&(target->leafIndex_)) = target->sons_[0]->leafIndex_;
370
371 }
372 }
373 }
374
375 // ///////////////////////////////////////////////
376 // Update the list of geometry types present
377 // ///////////////////////////////////////////////
378 for (int i = 0; i < dimgrid+1; ++i)
379 myTypes_[i].clear();
380
381
382 if (numTriangles_>0 && dimgrid == 2)
383 myTypes_[0].push_back(GeometryTypes::simplex(2));
384
385 if (numQuads_>0 && dimgrid == 2)
386 myTypes_[0].push_back(GeometryTypes::cube(2));
387
388 if (numEdges_>0 && dimgrid == 2)
389 myTypes_[1].push_back(GeometryTypes::line);
390 if (numEdges_>0 && dimgrid == 1)
391 myTypes_[0].push_back(GeometryTypes::line);
392
393 if (numVertices_>0)
394 myTypes_[dimgrid].push_back(GeometryTypes::vertex);
395 }
396
397private:
398
399 const GridImp& grid_;
400
401 int numQuads_;
402 int numTriangles_;
403 int numEdges_;
404 int numVertices_;
405
407 std::array<std::vector<GeometryType>, dimgrid+1> myTypes_;
408
409};
410
411
412
413
414template <class GridImp>
416 public IdSet<GridImp,FoamGridIdSet<GridImp>, unsigned int>
417{
418
419 public:
421 typedef unsigned int IdType;
422
423
425 /*
426 We use the std::remove_const to extract the Type from the mutable class,
427 because the const class is not instantiated yet.
428 */
429 template<int cd>
430 IdType id (const typename std::remove_const<GridImp>::type::Traits::template Codim<cd>::Entity& e) const
431 {
432 return e.impl().target_->id_;
433 }
434
435
437 /*
438 We use the std::remove_const to extract the Type from the mutable class,
439 because the const class is not instantiated yet.
440 */
441 IdType subId (const typename std::remove_const<GridImp>::type::Traits::template Codim<0>::Entity& e, int i, int codim) const
442 {
443 return e.impl().subId(i,codim);
444 }
445
446
448 void update() {}
449
450};
451
452} // namespace Dune
453
454
455#endif
Definition: dgffoam.cc:6
Definition: foamgridindexsets.hh:26
const std::vector< GeometryType > & geomTypes(int codim) const
Deliver all geometry types used in this grid.
Definition: foamgridindexsets.hh:96
bool contains(const EntityType &e) const
Return true if the given entity is contained in the index set.
Definition: foamgridindexsets.hh:113
int index(const typename GridImp::Traits::template Codim< codim >::Entity &e) const
get index of an entity
Definition: foamgridindexsets.hh:42
FoamGridLevelIndexSet(const GridImp &grid, int level)
Definition: foamgridindexsets.hh:36
int size(int codim) const
get number of entities of given codim, type and on this level
Definition: foamgridindexsets.hh:57
int subIndex(const typename GridImp::Traits::template Codim< cc >::Entity &e, int i, unsigned int codim) const
get index of subentity of an entity
Definition: foamgridindexsets.hh:49
int size(GeometryType type) const
get number of entities of given codim, type and on this level
Definition: foamgridindexsets.hh:81
void update()
Set up the index set.
Definition: foamgridindexsets.hh:119
std::vector< GeometryType > types(int codim) const
Deliver all geometry types used in this grid.
Definition: foamgridindexsets.hh:102
Definition: foamgridindexsets.hh:200
int size(GeometryType type) const
get number of entities of given codim, type and on this level
Definition: foamgridindexsets.hh:259
const std::vector< GeometryType > & geomTypes(int codim) const
Deliver all geometry types used in this grid.
Definition: foamgridindexsets.hh:274
int subIndex(const typename GridImp::Traits::template Codim< cc >::Entity &e, int i, unsigned int codim) const
get index of subentity of an entity
Definition: foamgridindexsets.hh:227
std::vector< GeometryType > types(int codim) const
Deliver all geometry types used in this grid.
Definition: foamgridindexsets.hh:280
bool contains(const EntityType &e) const
Return true if the given entity is contained in the index set.
Definition: foamgridindexsets.hh:288
int size(int codim) const
get number of entities of given codim, type and on this level
Definition: foamgridindexsets.hh:235
void update()
Definition: foamgridindexsets.hh:294
FoamGridLeafIndexSet(const GridImp &g)
Copy constructor.
Definition: foamgridindexsets.hh:210
int index(const typename GridImp::Traits::template Codim< codim >::Entity &e) const
get index of an entity
Definition: foamgridindexsets.hh:220
Definition: foamgridindexsets.hh:417
IdType subId(const typename std::remove_const< GridImp >::type::Traits::template Codim< 0 >::Entity &e, int i, int codim) const
get id of subEntity
Definition: foamgridindexsets.hh:441
IdType id(const typename std::remove_const< GridImp >::type::Traits::template Codim< cd >::Entity &e) const
get id of an entity
Definition: foamgridindexsets.hh:430
unsigned int IdType
define the type used for persistent indices
Definition: foamgridindexsets.hh:421
void update()
Definition: foamgridindexsets.hh:448
The actual entity implementation.
Definition: foamgridvertex.hh:47