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 
10 #include <dune/fem/gridpart/common/defaultgridpartentity.hh>
11 #include <dune/fem/gridpart/geogridpart/cornerstorage.hh>
12 
13 namespace Dune
14 {
15 
16   namespace Fem
17   {
18 
19     // GeoEntity
20     // ---------
21 
22     template< int codim, int dim, class GridFamily >
23     class GeoEntity
24     : public DefaultGridPartEntity < codim, dim, GridFamily >
25     {
26       typedef typename std::remove_const< GridFamily >::type::Traits Traits;
27 
28     public:
29       static const int codimension = codim;
30       static const int dimension = std::remove_const< GridFamily >::type::dimension;
31       static const int mydimension = dimension - codimension;
32       static const int dimensionworld = std::remove_const< GridFamily >::type::dimensionworld;
33 
34       typedef typename std::remove_const< GridFamily >::type::ctype ctype;
35 
36       typedef typename Traits::template Codim< codimension >::EntitySeed EntitySeed;
37       typedef typename Traits::template Codim< codimension >::Geometry Geometry;
38 
39     private:
40       typedef typename Traits::HostGridPartType HostGridPartType;
41       typedef typename Traits::CoordFunctionType CoordFunctionType;
42 
43       typedef typename Geometry::Implementation GeometryImplType;
44 
45       typedef GeoCoordVector< mydimension, GridFamily > CoordVectorType;
46 
47     public:
48       typedef typename HostGridPartType::template Codim< codimension >::EntityType HostEntityType;
49 
50       GeoEntity () = default;
51 
GeoEntity(const CoordFunctionType & coordFunction,HostEntityType hostEntity)52       GeoEntity ( const CoordFunctionType &coordFunction, HostEntityType hostEntity )
53       : coordFunction_( &coordFunction ),
54         hostEntity_( std::move( hostEntity ) )
55       {}
56 
type() const57       GeometryType type () const
58       {
59         return hostEntity().type();
60       }
61 
partitionType() const62       PartitionType partitionType () const
63       {
64         return hostEntity().partitionType();
65       }
66 
geometry() const67       Geometry geometry () const
68       {
69         if( !geo_ )
70         {
71           CoordVectorType coords( coordFunction(), hostEntity() );
72           geo_ = GeometryImplType( type(), coords );
73         }
74         return Geometry( geo_ );
75       }
76 
seed() const77       EntitySeed seed () const { return EntitySeed( hostEntity().seed() ); }
78 
equals(const GeoEntity & rhs) const79       bool equals ( const GeoEntity &rhs ) const
80       {
81         return hostEntity() == rhs.hostEntity();
82       }
83 
coordFunction() const84       const CoordFunctionType &coordFunction () const
85       {
86         assert( coordFunction_ );
87         return *coordFunction_;
88       }
89 
hostEntity() const90       const HostEntityType &hostEntity () const
91       {
92         return hostEntity_;
93       }
94 
subEntities(unsigned int cdim) const95       unsigned int subEntities ( unsigned int cdim ) const { return hostEntity().subEntities( cdim ); }
96 
97     private:
98       const CoordFunctionType *coordFunction_ = nullptr;
99       HostEntityType hostEntity_;
100 
101       mutable GeometryImplType geo_;
102     };
103 
104 
105 
106     // GeoEntity for codimension 0
107     // ---------------------------
108 
109     template< int dim, class GridFamily >
110     class GeoEntity< 0, dim, GridFamily >
111     : public DefaultGridPartEntity < 0, dim, GridFamily >
112     {
113       typedef typename std::remove_const< GridFamily >::type::Traits Traits;
114 
115     public:
116       static const int codimension = 0;
117       static const int dimension = std::remove_const< GridFamily >::type::dimension;
118       static const int mydimension = dimension - codimension;
119       static const int dimensionworld = std::remove_const< GridFamily >::type::dimensionworld;
120 
121       typedef typename std::remove_const< GridFamily >::type::ctype ctype;
122 
123       typedef typename Traits::template Codim< codimension >::EntitySeed EntitySeed;
124       typedef typename Traits::template Codim< codimension >::Geometry Geometry;
125       typedef typename Traits::template Codim< codimension >::LocalGeometry LocalGeometry;
126 
127       typedef typename Traits::HierarchicIterator HierarchicIterator;
128       typedef typename Traits::LeafIntersectionIterator LeafIntersectionIterator;
129       typedef typename Traits::LevelIntersectionIterator LevelIntersectionIterator;
130 
131     private:
132       typedef typename Traits::HostGridPartType HostGridPartType;
133       typedef typename Traits::CoordFunctionType CoordFunctionType;
134 
135       typedef typename Geometry::Implementation GeometryImplType;
136 
137       typedef GeoCoordVector< mydimension, GridFamily > CoordVectorType;
138 
139     public:
140       typedef typename HostGridPartType::template Codim< codimension >::EntityType HostEntityType;
141 
142       GeoEntity () = default;
143 
GeoEntity(const CoordFunctionType & coordFunction,HostEntityType hostEntity)144       GeoEntity ( const CoordFunctionType &coordFunction, HostEntityType hostEntity )
145       : coordFunction_( &coordFunction ),
146         hostEntity_( std::move( hostEntity ) )
147       {}
148 
149       template< class LocalFunction >
GeoEntity(const GeoEntity & other,const LocalFunction & localCoordFunction)150       GeoEntity ( const GeoEntity &other, const LocalFunction &localCoordFunction )
151       : coordFunction_( other.coordFunction_ ),
152         hostEntity_( other.hostEntity_ )
153       {
154         GeoLocalCoordVector< mydimension, GridFamily, LocalFunction > coords( localCoordFunction );
155         geo_ = GeometryImplType( type(), coords );
156       }
157 
type() const158       GeometryType type () const
159       {
160         return hostEntity().type();
161       }
162 
partitionType() const163       PartitionType partitionType () const
164       {
165         return hostEntity().partitionType();
166       }
167 
geometry() const168       Geometry geometry () const
169       {
170         if( !geo_ )
171         {
172           CoordVectorType coords( coordFunction(), hostEntity() );
173           geo_ = GeometryImplType( type(), coords );
174         }
175         return Geometry( geo_ );
176       }
177 
seed() const178       EntitySeed seed () const { return EntitySeed( hostEntity().seed() ); }
179 
180       template< int codim >
count() const181       int count () const
182       {
183         return hostEntity().template count< codim >();
184       }
185 
subEntities(unsigned int codim) const186       unsigned int subEntities ( unsigned int codim ) const { return hostEntity().subEntities( codim ); }
187 
188       template< int codim >
189       typename Traits::template Codim< codim >::Entity
subEntity(int i) const190       subEntity ( int i ) const
191       {
192         typedef typename Traits::template Codim< codim >::Entity::Implementation EntityImpl;
193         return EntityImpl( *coordFunction_, hostEntity().template subEntity< codim >( i ) );
194       }
195 
hasBoundaryIntersections() const196       bool hasBoundaryIntersections () const
197       {
198         return hostEntity().hasBoundaryIntersections();
199       }
200 
equals(const GeoEntity & rhs) const201       bool equals ( const GeoEntity &rhs ) const
202       {
203         return hostEntity() == rhs.hostEntity();
204       }
205 
coordFunction() const206       const CoordFunctionType &coordFunction () const
207       {
208         assert( coordFunction_ );
209         return *coordFunction_;
210       }
211 
hostEntity() const212       const HostEntityType &hostEntity () const
213       {
214         return hostEntity_;
215       }
216 
setHostEntity(const HostEntityType & hostEntity)217       void setHostEntity ( const HostEntityType &hostEntity )
218       {
219         hostEntity_ = &hostEntity;
220       }
221 
222     private:
223       const CoordFunctionType *coordFunction_ = nullptr;
224       HostEntityType hostEntity_;
225 
226       mutable GeometryImplType geo_;
227     };
228 
229   } // namespace Fem
230 
231 } // namespace Dune
232 
233 #endif // #ifndef DUNE_FEM_GRIDPART_GEOGRIDPART_ENTITY_HH
234