Dune Core Modules (2.9.0)

entityinfo.hh
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
10#include <dune/grid/spgrid/direction.hh>
11#include <dune/grid/spgrid/gridlevel.hh>
12
13namespace Dune
14{
15
16 namespace __SPGrid
17 {
18
19 // EntityInfo
20 // ----------
21
22 template< class Grid, int codim >
23 class EntityInfo
24 {
25 typedef EntityInfo< Grid, codim > This;
26
27 public:
28 typedef SPGridLevel< typename std::remove_const< Grid >::type > GridLevel;
29
30 static const int dimension = GridLevel::dimension;
31 static const int codimension = codim;
32 static const int mydimension = dimension - codimension;
33
34 private:
35 typedef SPEntityDirection< dimension, mydimension > EntityDirection;
36
37 public:
38 typedef typename EntityDirection::Direction Direction;
39
40 typedef typename GridLevel::MultiIndex MultiIndex;
41 typedef typename GridLevel::GlobalVector GlobalVector;
42
43 typedef typename GridLevel::Traits Traits;
44
45 typedef typename GridLevel::template Codim< codimension >::GeometryCache GeometryCache;
46
47 EntityInfo ()
48 : gridLevel_( nullptr ),
49 partitionNumber_( std::numeric_limits< unsigned int >::max() )
50 {}
51
52 EntityInfo ( const GridLevel &gridLevel )
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
87 const GeometryCache &geometryCache () const
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
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:30
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:402
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:81
Dune namespace.
Definition: alignedallocator.hh:13
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)