dune-fem  2.4.1-rc
geogridpart/entity.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_GRIDPART_GEOGRIDPART_ENTITY_HH
2 #define DUNE_FEM_GRIDPART_GEOGRIDPART_ENTITY_HH
3 
4 #include <type_traits>
5 #include <utility>
6 
7 #include <dune/grid/common/entity.hh>
8 #include <dune/grid/common/gridenums.hh>
9 
13 
14 namespace Dune
15 {
16 
17  namespace Fem
18  {
19 
20  // GeoEntity
21  // ---------
22 
23  template< int codim, int dim, class GridFamily >
24  class GeoEntity
25  : public DefaultGridPartEntity < codim, dim, GridFamily >
26  {
27  typedef typename std::remove_const< GridFamily >::type::Traits Traits;
28 
29  public:
30  static const int codimension = codim;
31  static const int dimension = std::remove_const< GridFamily >::type::dimension;
32  static const int mydimension = dimension - codimension;
33  static const int dimensionworld = std::remove_const< GridFamily >::type::dimensionworld;
34 
35  typedef typename std::remove_const< GridFamily >::type::ctype ctype;
36 
37  typedef typename Traits::template Codim< codimension >::EntitySeed EntitySeed;
38  typedef typename Traits::template Codim< codimension >::Geometry Geometry;
39 
40  private:
41  typedef typename Traits::HostGridPartType HostGridPartType;
42  typedef typename Traits::CoordFunctionType CoordFunctionType;
43 
44  typedef typename Geometry::Implementation GeometryImplType;
45 
47 
48  public:
49  typedef typename HostGridPartType::template Codim< codimension >::EntityType HostEntityType;
50 
51  GeoEntity () = default;
52 
53  GeoEntity ( const CoordFunctionType &coordFunction, HostEntityType hostEntity )
54  : coordFunction_( &coordFunction ),
55  hostEntity_( std::move( hostEntity ) )
56  {}
57 
58  GeometryType type () const
59  {
60  return hostEntity().type();
61  }
62 
63  PartitionType partitionType () const
64  {
65  return hostEntity().partitionType();
66  }
67 
68  Geometry geometry () const
69  {
70  if( !geo_ )
71  {
72  CoordVectorType coords( coordFunction(), hostEntity() );
73  geo_ = GeometryImplType( type(), coords );
74  }
75  return Geometry( geo_ );
76  }
77 
78  EntitySeed seed () const { return EntitySeed( hostEntity().seed() ); }
79 
80  bool equals ( const GeoEntity &rhs ) const
81  {
82  return hostEntity() == rhs.hostEntity();
83  }
84 
85  const CoordFunctionType &coordFunction () const
86  {
87  assert( coordFunction_ );
88  return *coordFunction_;
89  }
90 
91  const HostEntityType &hostEntity () const
92  {
93  return hostEntity_;
94  }
95 
96  private:
97  const CoordFunctionType *coordFunction_ = nullptr;
98  HostEntityType hostEntity_;
99 
100  mutable GeometryImplType geo_;
101  };
102 
103 
104 
105  // GeoEntity for codimension 0
106  // ---------------------------
107 
108  template< int dim, class GridFamily >
109  class GeoEntity< 0, dim, GridFamily >
110  : public DefaultGridPartEntity < 0, dim, GridFamily >
111  {
112  typedef typename std::remove_const< GridFamily >::type::Traits Traits;
113 
114  public:
115  static const int codimension = 0;
116  static const int dimension = std::remove_const< GridFamily >::type::dimension;
117  static const int mydimension = dimension - codimension;
118  static const int dimensionworld = std::remove_const< GridFamily >::type::dimensionworld;
119 
120  typedef typename std::remove_const< GridFamily >::type::ctype ctype;
121 
122  typedef typename Traits::template Codim< codimension >::EntitySeed EntitySeed;
123  typedef typename Traits::template Codim< codimension >::Geometry Geometry;
124  typedef typename Traits::template Codim< codimension >::LocalGeometry LocalGeometry;
125 
126  typedef typename Traits::HierarchicIterator HierarchicIterator;
127  typedef typename Traits::LeafIntersectionIterator LeafIntersectionIterator;
128  typedef typename Traits::LevelIntersectionIterator LevelIntersectionIterator;
129 
130  private:
131  typedef typename Traits::HostGridPartType HostGridPartType;
132  typedef typename Traits::CoordFunctionType CoordFunctionType;
133 
134  typedef typename Geometry::Implementation GeometryImplType;
135 
137 
138  public:
139  typedef typename HostGridPartType::template Codim< codimension >::EntityType HostEntityType;
140 
141  GeoEntity () = default;
142 
143  GeoEntity ( const CoordFunctionType &coordFunction, HostEntityType hostEntity )
144  : coordFunction_( &coordFunction ),
145  hostEntity_( std::move( hostEntity ) )
146  {}
147 
148  template< class LocalFunction >
149  GeoEntity ( const GeoEntity &other, const LocalFunction &localCoordFunction )
150  : coordFunction_( other.coordFunction_ ),
151  hostEntity_( other.hostEntity_ )
152  {
154  geo_ = GeometryImplType( type(), coords );
155  }
156 
157  GeometryType type () const
158  {
159  return hostEntity().type();
160  }
161 
162  PartitionType partitionType () const
163  {
164  return hostEntity().partitionType();
165  }
166 
167  Geometry geometry () const
168  {
169  if( !geo_ )
170  {
171  CoordVectorType coords( coordFunction(), hostEntity() );
172  geo_ = GeometryImplType( type(), coords );
173  }
174  return Geometry( geo_ );
175  }
176 
177  EntitySeed seed () const { return EntitySeed( hostEntity().seed() ); }
178 
179  template< int codim >
180  int count () const
181  {
182  return hostEntity().template count< codim >();
183  }
184 
185  unsigned int subEntities ( unsigned int codim ) const { return hostEntity().subEntities( codim ); }
186 
187  template< int codim >
188  typename Traits::template Codim< codim >::Entity
189  subEntity ( int i ) const
190  {
191  typedef typename Traits::template Codim< codim >::Entity::Implementation EntityImpl;
192  return EntityImpl( *coordFunction_, make_entity( hostEntity().template subEntity< codim >( i ) ) );
193  }
194 
196  {
197  return hostEntity().hasBoundaryIntersections();
198  }
199 
200  bool equals ( const GeoEntity &rhs ) const
201  {
202  return hostEntity() == rhs.hostEntity();
203  }
204 
205  const CoordFunctionType &coordFunction () const
206  {
207  assert( coordFunction_ );
208  return *coordFunction_;
209  }
210 
211  const HostEntityType &hostEntity () const
212  {
213  return hostEntity_;
214  }
215 
216  void setHostEntity ( const HostEntityType &hostEntity )
217  {
218  hostEntity_ = &hostEntity;
219  }
220 
221  private:
222  const CoordFunctionType *coordFunction_ = nullptr;
223  HostEntityType hostEntity_;
224 
225  mutable GeometryImplType geo_;
226  };
227 
228  } // namespace Fem
229 
230 } // namespace Dune
231 
232 #endif // #ifndef DUNE_FEM_GRIDPART_GEOGRIDPART_ENTITY_HH
HostGridPartType::template Codim< codimension >::EntityType HostEntityType
Definition: geogridpart/entity.hh:139
int count() const
Definition: geogridpart/entity.hh:180
unsigned int subEntities(unsigned int codim) const
Definition: geogridpart/entity.hh:185
static const int mydimension
Definition: geogridpart/entity.hh:32
PartitionType partitionType() const
Definition: geogridpart/entity.hh:162
GeometryType type() const
Definition: geogridpart/entity.hh:157
Definition: cornerstorage.hh:147
Traits::LevelIntersectionIterator LevelIntersectionIterator
Definition: geogridpart/entity.hh:128
Geometry geometry() const
Definition: geogridpart/entity.hh:68
const CoordFunctionType & coordFunction() const
Definition: geogridpart/entity.hh:205
const HostEntityType & hostEntity() const
Definition: geogridpart/entity.hh:211
GeoEntity(const CoordFunctionType &coordFunction, HostEntityType hostEntity)
Definition: geogridpart/entity.hh:53
const CoordFunctionType & coordFunction() const
Definition: geogridpart/entity.hh:85
const HostEntityType & hostEntity() const
Definition: geogridpart/entity.hh:91
GeometryType type() const
Definition: geogridpart/entity.hh:58
static const int codimension
Definition: geogridpart/entity.hh:30
Traits::template Codim< codimension >::Geometry Geometry
Definition: geogridpart/entity.hh:123
Traits::template Codim< codim >::Entity subEntity(int i) const
Definition: geogridpart/entity.hh:189
interface for local functions
Definition: localfunction.hh:41
Traits::template Codim< codimension >::Geometry Geometry
Definition: geogridpart/entity.hh:38
bool hasBoundaryIntersections() const
Definition: geogridpart/entity.hh:195
bool equals(const GeoEntity &rhs) const
Definition: geogridpart/entity.hh:80
Traits::template Codim< codimension >::EntitySeed EntitySeed
Definition: geogridpart/entity.hh:37
Dune::EntityPointer< Grid, Implementation >::Entity make_entity(const Dune::EntityPointer< Grid, Implementation > &entityPointer)
Definition: compatibility.hh:23
HostGridPartType::template Codim< codimension >::EntityType HostEntityType
Definition: geogridpart/entity.hh:49
Traits::template Codim< codimension >::LocalGeometry LocalGeometry
Definition: geogridpart/entity.hh:124
Traits::template Codim< codimension >::EntitySeed EntitySeed
Definition: geogridpart/entity.hh:122
std::remove_const< GridFamily >::type::ctype ctype
Definition: geogridpart/entity.hh:120
Definition: coordinate.hh:4
GeoEntity(const CoordFunctionType &coordFunction, HostEntityType hostEntity)
Definition: geogridpart/entity.hh:143
Traits::LeafIntersectionIterator LeafIntersectionIterator
Definition: geogridpart/entity.hh:127
bool equals(const GeoEntity &rhs) const
Definition: geogridpart/entity.hh:200
std::remove_const< GridFamily >::type::ctype ctype
Definition: geogridpart/entity.hh:35
static const int dimension
Definition: geogridpart/entity.hh:31
Geometry geometry() const
Definition: geogridpart/entity.hh:167
STL namespace.
std::remove_const< GridFamily >::type::Traits Traits
Definition: defaultgridpartentity.hh:46
std::remove_const< GridFamily >::type::Traits Traits
Definition: defaultgridpartentity.hh:24
static const int dimensionworld
Definition: geogridpart/entity.hh:33
Definition: geogridpart/entity.hh:24
void move(ArrayInterface< T > &array, const unsigned int oldOffset, const unsigned int newOffset, const unsigned int length)
Definition: array_inline.hh:38
void setHostEntity(const HostEntityType &hostEntity)
Definition: geogridpart/entity.hh:216
EntitySeed seed() const
Definition: geogridpart/entity.hh:177
Definition: defaultgridpartentity.hh:21
PartitionType partitionType() const
Definition: geogridpart/entity.hh:63
EntitySeed seed() const
Definition: geogridpart/entity.hh:78
Definition: cornerstorage.hh:191
GeoEntity(const GeoEntity &other, const LocalFunction &localCoordFunction)
Definition: geogridpart/entity.hh:149
Traits::HierarchicIterator HierarchicIterator
Definition: geogridpart/entity.hh:126