Dune Core Modules (2.11.0)

foamgridentity.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_ENTITY_HH
4#define DUNE_FOAMGRID_ENTITY_HH
5
10#include <memory>
11#include <array>
12
14
15#include <dune/geometry/type.hh>
16#include <dune/grid/common/gridenums.hh>
18
19#include <dune/foamgrid/foamgrid/foamgridvertex.hh>
21
22namespace Dune {
23
24
25// Forward declarations
26
27template<int codim, int dimentity, class GridImp>
28class FoamGridEntity;
29
30template<int codim, PartitionIteratorType pitype, class GridImp>
31class FoamGridLevelIterator;
32
33template<class GridImp>
34class FoamGridLevelIntersectionIterator;
35
36template<class GridImp>
37class FoamGridLeafIntersectionIterator;
38
39template<class GridImp>
40class FoamGridHierarchicIterator;
41
42
48template<int codim, int dimgrid, class GridImp>
50 public EntityDefaultImplementation <codim, dimgrid, GridImp, FoamGridEntity>
51{
52 template <class GridImp_>
53 friend class FoamGridLevelIndexSet;
54
55 template <class GridImp_>
56 friend class FoamGridLeafIndexSet;
57
58 template <class GridImp_>
59 friend class FoamGridLocalIdSet;
60
61 template <class GridImp_>
62 friend class FoamGridGlobalIdSet;
63
64 private:
65
66 typedef typename GridImp::ctype ctype;
67
68 enum{dimworld = GridImp::dimensionworld};
69
70 public:
71
72 typedef typename GridImp::template Codim<codim>::Geometry Geometry;
73
75 typedef typename GridImp::template Codim<codim>::EntitySeed EntitySeed;
76
77
78
81 target_(target)
82 {}
83
85 FoamGridEntity(const FoamGridEntity& original) :
86 target_(original.target_)
87 {}
88
91 target_(nullptr)
92 {}
93
94
97 {
98 if (this != &original)
99 {
100 target_ = original.target_;
101 }
102 return *this;
103 }
104
105
107 int level () const {
108 return target_->level();
109 }
110
111
115 return target_->partitionType();
116 }
117
118
122 template<int cc> int count () const{
123 return target_->template count<cc>();
124 }
125
126
128 Geometry geometry () const
129 {
130 // we currently only support simplices
131 std::array<FieldVector<ctype, dimworld>, dimgrid-codim+1> coordinates;
132 assert(dimgrid-codim+1 == target_->corners() && "Target entity is not a simplex!");
133 for (int i=0; i<target_->corners(); i++)
134 coordinates[i] = target_->corner(i);
135
136 return Geometry(FoamGridGeometry<dimgrid-codim, dimworld, GridImp>(target_->type(), coordinates));
137 }
138
141 {
142 return EntitySeed(*this);
143 }
144
145 const FoamGridEntityImp<dimgrid-codim, dimgrid, dimworld, ctype>* target_;
146
147
150 {
151 target_ = target;
152 }
153
156 {
157 return target_ == other.target_;
158 }
159
161 GeometryType type () const { return target_->type(); }
162};
163
164
165
166
174template<class GridImp>
175class FoamGridEntity<0, 2, GridImp> :
176 public EntityDefaultImplementation<0, 2, GridImp, FoamGridEntity>
177{
178
179 enum {dimworld = GridImp::dimensionworld};
180 enum {dimgrid = GridImp::dimension};
181
182 private:
183
184 typedef typename GridImp::ctype ctype;
185
186 public:
187
188 typedef typename GridImp::template Codim<0>::Geometry Geometry;
189
190 typedef typename GridImp::template Codim<0>::LocalGeometry LocalGeometry;
191
194
197
200
202 typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed;
203
204 template<int codim>
205 struct Codim
206 {
207 typedef typename GridImp::Traits::template Codim<codim>::Entity Entity;
208 };
209
210 typedef typename GridImp::Traits::template Codim<0>::Entity Entity;
211
212
215 target_(hostEntity)
216 {}
217
218
221 target_(original.target_)
222 {}
223
226 target_(nullptr)
227 {}
228
231 {
232 if (this != &original)
233 {
234 target_ = original.target_;
235 }
236 return *this;
237 }
238
239
241 int level () const
242 {
243 return target_->level_;
244 }
245
246
249 return InteriorEntity;
250 }
251
252
254 Geometry geometry () const
255 {
256 // we currently only support simplices
257 std::array<FieldVector<ctype, dimworld>, dimgrid+1> coordinates;
258 assert(dimgrid+1 == target_->corners() && "Target entity is not a simplex!");
259 for (int i=0; i<target_->corners(); i++)
260 coordinates[i] = target_->vertex_[i]->pos_;
261
262 return Geometry(FoamGridGeometry<dimgrid, dimworld, const GridImp>(target_->type(), coordinates));
263 }
264
267 {
268 return EntitySeed(*this);
269 }
270
271
274 template<int cc>
275 int count () const
276 {
277 static_assert(0<=cc && cc<=2, "Only codimensions with 0 <= cc <= 2 are valid!");
278 return (cc==0) ? 1 : 3;
279 }
280
283 unsigned int count (unsigned int codim) const
284 {
285 assert(codim<=2);
286 return (codim==0) ? 1 : 3;
287 }
288
293 unsigned int subEntities (unsigned int codim) const
294 {
295 assert(codim<=2);
296 return (codim==0) ? 1 : 3;
297 }
298
301 int subId (int i, unsigned int codim) const {
302 assert(codim<=dimgrid);
303 switch (codim) {
304 case 0:
305 return target_->id_;
306 case 1:
307 return target_->facet_[i]->id_;
308 case 2:
309 return target_->vertex_[i]->id_;
310 }
311 DUNE_THROW(GridError, "Non-existing codimension requested!");
312 }
313
315 template<int codim>
316 typename std::enable_if<codim==0, typename Codim<0>::Entity>::type
317 subEntity (int i) const
318 {
319 assert(i==0);
320 return typename Codim<0>::Entity(FoamGridEntity<0, dimgrid, GridImp>(this->target_));
321 }
322
324 template<int codim>
325 typename std::enable_if<codim==1, typename Codim<1>::Entity>::type
326 subEntity (int i) const
327 {
328 assert(i==0 || i==1 || i==2);
329 return typename Codim<1>::Entity(FoamGridEntity<1, dimgrid, GridImp>(this->target_->facet_[i]));
330 }
331
333 template<int codim>
334 typename std::enable_if<codim==2, typename Codim<2>::Entity>::type
335 subEntity (int i) const
336 {
337 assert(i==0 || i==1 || i==2);
338 return typename Codim<2>::Entity(FoamGridEntity<2, dimgrid, GridImp>(this->target_->vertex_[i]));
339 }
340
344 }
345
346
350 }
351
352
355 if(isLeaf())
357 else
359 }
360
361
365 }
366
367
369 bool isLeaf() const {
370 return target_->isLeaf();
371 }
372
374 bool hasFather() const {
375 return level()>0;
376 }
377
378 bool isNew() const
379 {
380 return target_->isNew();
381 }
382
383 bool mightVanish() const
384 {
385 return target_->mightVanish();
386 }
387
390 Entity father () const {
391 return Entity(FoamGridEntity<0, dimgrid, GridImp>(target_->father_));
392 }
393
403 LocalGeometry geometryInFather () const {
405 // Check whether there really is a father
406 if(father==nullptr)
407 DUNE_THROW(GridError, "There is no father Element.");
408
409 // Sanity check
410 if(target_->type().isTriangle()){
411 // Lookup the coordinates within the father
412 // As in the refinement routine the children
413 // are number as follows:
414 // First come the ones located in the corner
415 // ascending with the corner index.
416 // Their first corner (origin in the reference simplex)
417 // is always the corner that is also a corner of the father.
418 // For the element with all corners on the edge midpoints of
419 // the father, the corner are numbered according to the edge indices
420 // of the father.
421 ctype mapping[4][3][2] ={
422 { {0.0,0.0}, {0.5,0.0}, {0.0,0.5} },
423 { {1.0,0.0}, {0.5,0.5}, {0.5,0.0} },
424 { {0.0,1.0}, {0.0,0.5}, {0.5,0.5} },
425 { {0.5,0.0}, {0.5,0.5}, {0.0,0.5} }
426 };
427
428 std::array<FieldVector<ctype, dimgrid>, 3> coordinates;
429
430 for(int corner=0; corner <3; ++corner)
431 for(int entry=0; entry <2; ++entry)
432 coordinates[corner][entry]=
433 mapping[target_->refinementIndex_][corner][entry];
434
435 // return LocalGeomety by value
436 return LocalGeometry(FoamGridGeometry<dimgrid, dimgrid, const GridImp>(target_->type(),
437 coordinates));
438 }else{
439 DUNE_THROW(NotImplemented, "geometryInFather only supported for triangles!");
440 }
441
442 }
443
444
450 { return { target_, maxLevel }; }
451
452
455 { return { maxLevel }; }
456
457
458 // /////////////////////////////////////////
459 // Internal stuff
460 // /////////////////////////////////////////
461
462
465 {
466 target_ = target;
467 }
468
471 {
472 return target_ == other.target_;
473 }
474
476 GeometryType type () const { return target_->type(); }
477
480
481}; // end of FoamGridEntity codim = 0, dimgrid = 2
482
483
484template<class GridImp>
485class FoamGridEntity<0, 1, GridImp> :
486 public EntityDefaultImplementation<0, 1, GridImp, FoamGridEntity>
487{
488
489 enum {dimworld = GridImp::dimensionworld};
490 enum {dimgrid = GridImp::dimension};
491
492 private:
493
494 typedef typename GridImp::ctype ctype;
495
496 public:
497
498 typedef typename GridImp::template Codim<0>::Geometry Geometry;
499
500 typedef typename GridImp::template Codim<0>::LocalGeometry LocalGeometry;
501
503 typedef FoamGridLevelIntersectionIterator<GridImp> LevelIntersectionIterator;
504
506 typedef FoamGridLeafIntersectionIterator<GridImp> LeafIntersectionIterator;
507
509 typedef FoamGridHierarchicIterator<GridImp> HierarchicIterator;
510
512 typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed;
513
514 template<int codim>
515 struct Codim
516 {
517 typedef typename GridImp::Traits::template Codim<codim>::Entity Entity;
518 };
519
520 typedef typename GridImp::Traits::template Codim<0>::Entity Entity;
521
523 explicit FoamGridEntity(const FoamGridEntityImp<dimgrid, dimgrid, dimworld, ctype>* hostEntity) :
524 target_(hostEntity)
525 {}
526
527
529 FoamGridEntity(const FoamGridEntity& original) :
530 target_(original.target_)
531 {}
532
535 target_(nullptr)
536 {}
537
539 FoamGridEntity& operator=(const FoamGridEntity& original)
540 {
541 if (this != &original)
542 {
543 target_ = original.target_;
544 }
545 return *this;
546 }
547
548
550 int level () const
551 {
552 return target_->level_;
553 }
554
555
558 return InteriorEntity;
559 }
560
561
563 Geometry geometry () const
564 {
565 // we currently only support simplices
566 std::array<FieldVector<ctype, dimworld>, dimgrid+1> coordinates;
567 assert(dimgrid+1 == target_->corners() && "Target entity is not a simplex!");
568 for (int i=0; i<target_->corners(); i++)
569 coordinates[i] = target_->corner(i);
570
571 return Geometry(FoamGridGeometry<dimgrid, dimworld, const GridImp>(target_->type(), coordinates));
572 }
573
575 EntitySeed seed () const
576 {
577 return EntitySeed(*this);
578 }
579
580
583 template<int cc>
584 int count () const
585 {
586 static_assert(0<=cc && cc<=1, "Only codimensions with 0 <= cc <= 1 are valid!");
587 return (cc==0) ? 1 : 2;
588 }
589
592 unsigned int count (unsigned int codim) const
593 {
594 assert(codim<=1);
595 return (codim==0) ? 1 : 2;
596 }
597
602 unsigned int subEntities (unsigned int codim) const
603 {
604 assert(codim<=1);
605 return (codim==0) ? 1 : 2;
606 }
607
610 int subId (int i,unsigned int codim) const {
611 assert(codim<=1);
612 switch (codim) {
613 case 0:
614 return target_->id_;
615 case 1:
616 return target_->vertex_[i]->id_;
617 }
618 DUNE_THROW(GridError, "Non-existing codimension requested!");
619 }
620
622 template<int codim>
623 typename std::enable_if<codim==0, typename Codim<0>::Entity>::type
624 subEntity (int i) const
625 {
626 assert(i==0);
627 return typename Codim<0>::Entity(FoamGridEntity<0, dimgrid, GridImp>(this->target_));
628 }
629
631 template<int codim>
632 typename std::enable_if<codim==1, typename Codim<1>::Entity>::type
633 subEntity (int i) const
634 {
635 assert(i==0 || i==1);
636 return typename Codim<1>::Entity(FoamGridEntity<1, dimgrid, GridImp>(this->target_->vertex_[i]));
637 }
638
640 FoamGridLevelIntersectionIterator<GridImp> ilevelbegin () const{
641 return FoamGridLevelIntersectionIterator<GridImp>(target_, 0);
642 }
643
644
646 FoamGridLevelIntersectionIterator<GridImp> ilevelend () const{
647 return FoamGridLevelIntersectionIterator<GridImp>(target_);
648 }
649
650
652 FoamGridLeafIntersectionIterator<GridImp> ileafbegin () const{
653 if(isLeaf())
654 return FoamGridLeafIntersectionIterator<GridImp>(target_,0);
655 else
656 return FoamGridLeafIntersectionIterator<GridImp>(target_);
657 }
658
659
661 FoamGridLeafIntersectionIterator<GridImp> ileafend () const{
662 return FoamGridLeafIntersectionIterator<GridImp>(target_);
663 }
664
665
667 bool isLeaf() const {
668 return target_->isLeaf();
669 }
670
672 bool hasFather() const {
673 return level()>0;
674 }
675
676 bool isNew() const
677 {
678 return target_->isNew();
679 }
680
681 bool mightVanish() const
682 {
683 return target_->mightVanish();
684 }
685
688 Entity father () const {
689 return Entity(FoamGridEntity<0, dimgrid, GridImp>(target_->father_));
690 }
691
701 LocalGeometry geometryInFather () const {
702 FoamGridEntityImp<dimgrid, dimgrid, dimworld, ctype>* father = target_->father_;
703 // Check whether there really is a father
704 if(father==nullptr)
705 DUNE_THROW(GridError, "There is no father Element.");
706
707 // Sanity check
708 if(target_->type().isLine()){
709 // Lookup the coordinates within the father
710 // As in the refinement routine the children
711 // are number as follows:
712 // First come the ones located in the corner
713 // ascending with the corner index.
714 // Their first corner (origin in the reference simplex)
715 // is always the corner that is also a corner of the father.
716 // For the element with all corners on the edge midpoints of
717 // the father, the corner are numbered according to the edge indices
718 // of the father.
719 ctype mapping[2][2] = {{0.0, 0.5}, {0.5, 1.0}};
720
721 std::array<FieldVector<ctype, dimgrid>, 2> coordinates;
722
723 for(int corner=0; corner <2; ++corner)
724 coordinates[corner][0] = mapping[target_->refinementIndex_][corner];
725
726 // return LocalGeomety by value
727 return LocalGeometry(FoamGridGeometry<dimgrid, dimgrid, const GridImp>(target_->type(), coordinates));
728 }
729 else
730 {
731 DUNE_THROW(NotImplemented, "geometryInFather only supported for lines!");
732 }
733 }
734
735
740 FoamGridHierarchicIterator<GridImp> hbegin (int maxLevel) const
741 { return { target_, maxLevel }; }
742
743
745 FoamGridHierarchicIterator<GridImp> hend (int maxLevel) const
746 { return { maxLevel }; }
747
748
749 // /////////////////////////////////////////
750 // Internal stuff
751 // /////////////////////////////////////////
752
753
755 void setToTarget(const FoamGridEntityImp<dimgrid, dimgrid, dimworld, ctype>* target)
756 {
757 target_ = target;
758 }
759
762 {
763 return target_ == other.target_;
764 }
765
767 GeometryType type () const { return target_->type(); }
768
770 const FoamGridEntityImp<dimgrid, dimgrid ,dimworld, ctype>* target_;
771
772}; // end of FoamGridEntity codim = 0, dimgrid = 1
773
774} // namespace Dune
775
776
777#endif
Default Implementations for EntityImp.
Definition: entity.hh:542
unsigned int subEntities(unsigned int codim) const
Number of subentities for a given codimension.
Definition: entity.hh:567
Wrapper class for entities.
Definition: entity.hh:66
Element specialization of FoamGridEntityImp. Element is a grid entity of topological codimension 0 an...
Definition: foamgridelements.hh:18
unsigned int subEntities(unsigned int codim) const
Definition: foamgridentity.hh:293
PartitionType partitionType() const
The partition type for parallel computing.
Definition: foamgridentity.hh:248
FoamGridEntity(const FoamGridEntityImp< dimgrid, dimgrid, dimworld, ctype > *hostEntity)
Constructor for an entity in a given grid level.
Definition: foamgridentity.hh:214
FoamGridLevelIntersectionIterator< GridImp > ilevelbegin() const
First level intersection.
Definition: foamgridentity.hh:342
FoamGridHierarchicIterator< GridImp > HierarchicIterator
Iterator over descendants of the entity.
Definition: foamgridentity.hh:199
FoamGridHierarchicIterator< GridImp > hbegin(int maxLevel) const
Inter-level access to son elements on higher levels<=maxlevel. This is provided for sparsely stored n...
Definition: foamgridentity.hh:449
bool equals(const Dune::FoamGridEntity< 0, dimgrid, GridImp > &other) const
equality
Definition: foamgridentity.hh:470
int subId(int i, unsigned int codim) const
Return index of sub entity with codim = cc and local number i.
Definition: foamgridentity.hh:301
std::enable_if< codim==1, typenameCodim< 1 >::Entity >::type subEntity(int i) const
Access to codim 1 subentities.
Definition: foamgridentity.hh:326
Geometry geometry() const
Geometry of this entity.
Definition: foamgridentity.hh:254
const FoamGridEntityImp< dimgrid, dimgrid,dimworld, ctype > * target_
pointer to the implementation
Definition: foamgridentity.hh:479
FoamGridLeafIntersectionIterator< GridImp > LeafIntersectionIterator
The Iterator over intersections on the leaf level.
Definition: foamgridentity.hh:196
bool hasFather() const
Return true if this element has a father element.
Definition: foamgridentity.hh:374
void setToTarget(const FoamGridEntityImp< dimgrid, dimgrid, dimworld, ctype > *target)
Make this class point to a new FoamGridEntityImp object.
Definition: foamgridentity.hh:464
FoamGridLeafIntersectionIterator< GridImp > ileafend() const
Reference to one past the last leaf intersection.
Definition: foamgridentity.hh:363
FoamGridEntity & operator=(const FoamGridEntity &original)
Definition: foamgridentity.hh:230
FoamGridEntity()
Default constructor.
Definition: foamgridentity.hh:225
FoamGridLevelIntersectionIterator< GridImp > ilevelend() const
Reference to one past the last neighbor.
Definition: foamgridentity.hh:348
unsigned int count(unsigned int codim) const
Return the number of subEntities of codimension cc.
Definition: foamgridentity.hh:283
FoamGridEntity(const FoamGridEntity &original)
Copy constructor.
Definition: foamgridentity.hh:220
std::enable_if< codim==0, typenameCodim< 0 >::Entity >::type subEntity(int i) const
Access to codim 0 subentities.
Definition: foamgridentity.hh:317
Entity father() const
Definition: foamgridentity.hh:390
FoamGridLeafIntersectionIterator< GridImp > ileafbegin() const
First leaf intersection.
Definition: foamgridentity.hh:354
LocalGeometry geometryInFather() const
Location of this element relative to the reference element element of the father. This is sufficient ...
Definition: foamgridentity.hh:403
EntitySeed seed() const
Create EntitySeed.
Definition: foamgridentity.hh:266
std::enable_if< codim==2, typenameCodim< 2 >::Entity >::type subEntity(int i) const
Access to codim 2 subentities.
Definition: foamgridentity.hh:335
int count() const
Return the number of subEntities of codimension cc.
Definition: foamgridentity.hh:275
int level() const
Level of this element.
Definition: foamgridentity.hh:241
bool isLeaf() const
returns true if Entity has NO children
Definition: foamgridentity.hh:369
GeometryType type() const
return the entity's type
Definition: foamgridentity.hh:476
FoamGridHierarchicIterator< GridImp > hend(int maxLevel) const
Returns iterator to one past the last son.
Definition: foamgridentity.hh:454
GridImp::template Codim< 0 >::EntitySeed EntitySeed
The type of the EntitySeed interface class.
Definition: foamgridentity.hh:202
FoamGridLevelIntersectionIterator< GridImp > LevelIntersectionIterator
The Iterator over intersections on this level.
Definition: foamgridentity.hh:193
The implementation of entities in a FoamGrid.
Definition: foamgridentity.hh:51
Geometry geometry() const
geometry of this entity
Definition: foamgridentity.hh:128
FoamGridEntity & operator=(const FoamGridEntity &original)
Definition: foamgridentity.hh:96
void setToTarget(const FoamGridEntityImp< dimgrid-codim, dimgrid, dimworld, ctype > *target)
Definition: foamgridentity.hh:149
int level() const
level of this element
Definition: foamgridentity.hh:107
bool equals(const Dune::FoamGridEntity< codim, dimgrid, GridImp > &other) const
equality
Definition: foamgridentity.hh:155
int count() const
Definition: foamgridentity.hh:122
FoamGridEntity(const FoamGridEntity &original)
Copy constructor.
Definition: foamgridentity.hh:85
PartitionType partitionType() const
The partition type for parallel computing.
Definition: foamgridentity.hh:114
EntitySeed seed() const
Create EntitySeed.
Definition: foamgridentity.hh:140
FoamGridEntity()
Default constructor.
Definition: foamgridentity.hh:90
GeometryType type() const
return the entity's type
Definition: foamgridentity.hh:161
GridImp::template Codim< codim >::EntitySeed EntitySeed
The type of the EntitySeed interface class.
Definition: foamgridentity.hh:75
FoamGridEntity(const FoamGridEntityImp< dimgrid-codim, dimgrid, dimworld, ctype > *target)
Constructor for an entity in a given grid level.
Definition: foamgridentity.hh:80
Iterator over the descendants of an entity.Mesh entities of codimension 0 ("elements") allow to visit...
Definition: foamgridhierarchiciterator.hh:24
Iterator over all element neighborsMesh entities of codimension 0 ("elements") allow to visit all nei...
Definition: foamgridintersectioniterators.hh:28
Definition: foamgridindexsets.hh:26
Definition: foamgridintersectioniterators.hh:239
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:114
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:20
Default exception for dummy implementations.
Definition: exceptions.hh:357
Different resources needed by all grid implementations.
Various macros to work with Dune module version numbers.
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
The FoamGridGeometry class.
#define DUNE_THROW(E,...)
Definition: exceptions.hh:314
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:30
@ InteriorEntity
all interior entities
Definition: gridenums.hh:31
Dune namespace
Definition: alignedallocator.hh:13
Static tag representing a codimension.
Definition: dimension.hh:24
A unique label for each type of element that can occur in a grid.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Feb 14, 23:39, 2026)