dune-spgrid 2.7
entityinfo.hh
Go to the documentation of this file.
1#ifndef DUNE_SPGRID_ENTITYINFO_HH
2#define DUNE_SPGRID_ENTITYINFO_HH
3
4#include <algorithm>
5#include <limits>
6#include <type_traits>
7
8#include <dune/grid/common/gridenums.hh>
9
12
13namespace Dune
14{
15
16 namespace __SPGrid
17 {
18
19 // EntityInfo
20 // ----------
21
22 template< class Grid, int codim >
24 {
26
27 public:
29
30 static const int dimension = GridLevel::dimension;
31 static const int codimension = codim;
32 static const int mydimension = dimension - codimension;
33
34 private:
36
37 public:
39
42
43 typedef typename GridLevel::Traits Traits;
44
45 typedef typename GridLevel::template Codim< codimension >::GeometryCache GeometryCache;
46
48 : gridLevel_( nullptr ),
49 partitionNumber_( std::numeric_limits< unsigned int >::max() )
50 {}
51
53 : gridLevel_( &gridLevel ),
54 partitionNumber_( std::numeric_limits< unsigned int >::max() )
55 {}
56
57 EntityInfo ( const GridLevel &gridLevel, const MultiIndex &id, unsigned int partitionNumber )
58 : gridLevel_( &gridLevel ),
59 id_( id ),
60 direction_( id ),
61 partitionNumber_( partitionNumber )
62 {}
63
64 // access member data
65
66 const GridLevel &gridLevel () const { assert( gridLevel_ ); return *gridLevel_; }
67
68 const MultiIndex &id () const { return id_; }
69 MultiIndex &id () { return id_; }
70
71 Direction direction () const { return direction_; }
72
73 unsigned int partitionNumber () const { return partitionNumber_; }
74
75 // convenience to implement entity
76
77 bool equals ( const This &other ) const
78 {
79 return (gridLevel_ == other.gridLevel_) && (id() == other.id());
80 }
81
82 PartitionType partitionType () const
83 {
84 return gridLevel().template partitionType< codimension >( id(), partitionNumber() );
85 }
86
88 {
89 return gridLevel().template geometryCache< codimension >( direction() );
90 }
91
92 // hierarchic traversal
93
94 bool hasFather () const
95 {
96 return ((codim == 0) || gridLevel().refinement().hasFather( id() ));
97 }
98
99 void up ()
100 {
101 const Grid &grid = gridLevel().grid();
102 const int level = gridLevel().level();
103 gridLevel().refinement().father( id() );
104 gridLevel_ = &grid.gridLevel( level-1 );
105 }
106
107 void down ()
108 {
109 const Grid &grid = gridLevel().grid();
110 const int level = gridLevel().level();
111 gridLevel_ = &grid.gridLevel( level+1 );
112 gridLevel().refinement().firstChild( id() );
113 }
114
115 bool nextChild ()
116 {
117 return gridLevel().refinement().nextChild( id() );
118 }
119
120 // manipulation methods
121
122 void update ()
123 {
124 assert( std::find( id().begin(), id().end(), std::numeric_limits< int >::max() ) == id().end() );
125 assert( gridLevel().template partition< All_Partition >().contains( id(), partitionNumber() ) );
126 direction_ = EntityDirection( id() );
127 }
128
129 void update ( unsigned int partitionNumber )
130 {
131 partitionNumber_ = partitionNumber;
132 update();
133 }
134
135 private:
136 const GridLevel *gridLevel_;
137 MultiIndex id_;
138 EntityDirection direction_;
139 unsigned int partitionNumber_;
140 };
141
142 } // namespace __SPGrid
143
144} // namespace Dune
145
146#endif // #ifndef DUNE_SPGRID_ENTITYINFO_HH
STL namespace.
Dune::SPMultiIndex< dim > max(const Dune::SPMultiIndex< dim > &a, const Dune::SPMultiIndex< dim > &b)
Definition: multiindex.hh:305
Definition: iostream.hh:7
Definition: direction.hh:18
Definition: entityinfo.hh:24
MultiIndex & id()
Definition: entityinfo.hh:69
EntityInfo(const GridLevel &gridLevel, const MultiIndex &id, unsigned int partitionNumber)
Definition: entityinfo.hh:57
const GeometryCache & geometryCache() const
Definition: entityinfo.hh:87
void up()
Definition: entityinfo.hh:99
const GridLevel & gridLevel() const
Definition: entityinfo.hh:66
static const int codimension
Definition: entityinfo.hh:31
void update()
Definition: entityinfo.hh:122
PartitionType partitionType() const
Definition: entityinfo.hh:82
EntityInfo()
Definition: entityinfo.hh:47
static const int dimension
Definition: entityinfo.hh:30
bool hasFather() const
Definition: entityinfo.hh:94
unsigned int partitionNumber() const
Definition: entityinfo.hh:73
const MultiIndex & id() const
Definition: entityinfo.hh:68
void update(unsigned int partitionNumber)
Definition: entityinfo.hh:129
GridLevel::GlobalVector GlobalVector
Definition: entityinfo.hh:41
bool equals(const This &other) const
Definition: entityinfo.hh:77
Direction direction() const
Definition: entityinfo.hh:71
GridLevel::Traits Traits
Definition: entityinfo.hh:43
GridLevel::MultiIndex MultiIndex
Definition: entityinfo.hh:40
EntityDirection::Direction Direction
Definition: entityinfo.hh:38
bool nextChild()
Definition: entityinfo.hh:115
EntityInfo(const GridLevel &gridLevel)
Definition: entityinfo.hh:52
SPGridLevel< typename std::remove_const< Grid >::type > GridLevel
Definition: entityinfo.hh:28
GridLevel::template Codim< codimension >::GeometryCache GeometryCache
Definition: entityinfo.hh:45
void down()
Definition: entityinfo.hh:107
static const int mydimension
Definition: entityinfo.hh:32
Definition: gridlevel.hh:35
const Refinement & refinement() const
Definition: gridlevel.hh:85
static const int dimension
Definition: gridlevel.hh:45
std::remove_const< Grid >::type::Traits Traits
Definition: gridlevel.hh:49
int level() const
Definition: gridlevel.hh:83
ReferenceCube::GlobalVector GlobalVector
Definition: gridlevel.hh:55
const Grid & grid() const
Definition: gridlevel.hh:82