Dune Core Modules (2.5.2)

indexidset.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_GRID_COMMON_INDEXIDSET_HH
5#define DUNE_GRID_COMMON_INDEXIDSET_HH
6
7#include <vector>
10
11
17namespace Dune
18{
19
21
74 template< class GridImp, class IndexSetImp, class IndexTypeImp, class TypesImp >
76 {
77 /* We use the remove_const to extract the Type from the mutable class,
78 because the const class is not instantiated yet. */
79 typedef typename std::remove_const< GridImp >::type::Traits Traits;
80
81 public:
83 template <int cc>
84 struct Codim
85 {
86 typedef typename Traits :: template Codim<cc> :: Entity Entity;
87 };
88
90 typedef IndexTypeImp IndexType;
91
93 typedef TypesImp Types;
94
96 static const int dimension = std::remove_const< GridImp >::type::dimension;
97
98 //===========================================================
102 //===========================================================
103
110 template<int cc>
111 IndexType index (const typename Traits::template Codim<cc>::Entity& e) const
112 {
113 CHECK_INTERFACE_IMPLEMENTATION((asImp().template index<cc>(e)));
114 return asImp().template index<cc>(e);
115 }
116
126 template<class Entity>
127 IndexType index (const Entity& e) const
128 {
129 enum { cc = Entity::codimension };
130 CHECK_INTERFACE_IMPLEMENTATION((asImp().template index<cc>(e)));
131 return asImp().template index<cc>(e);
132 }
133
150 template< int cc >
151 IndexType subIndex ( const typename Traits::template Codim< cc >::Entity &e,
152 int i, unsigned int codim ) const
153 {
154 CHECK_INTERFACE_IMPLEMENTATION((asImp().template subIndex< cc >(e,i,codim)));
155 return asImp().template subIndex< cc >(e,i,codim);
156 }
157
179 template< class Entity >
180 IndexType subIndex ( const Entity &e, int i, unsigned int codim ) const
181 {
182 static const int cc = Entity::codimension;
183 return asImp().template subIndex< cc >( e, i, codim );
184 }
186
187
188 //===========================================================
192 //===========================================================
193
209 Types types ( int codim ) const
210 {
211 CHECK_INTERFACE_IMPLEMENTATION( (asImp().types( codim )) );
212 return asImp().types( codim );
213 }
214
221 {
222 CHECK_INTERFACE_IMPLEMENTATION((asImp().size(type)));
223 return asImp().size(type);
224 }
225
232 IndexType size (int codim) const
233 {
234 CHECK_INTERFACE_IMPLEMENTATION((asImp().size(codim)));
235 return asImp().size(codim);
236 }
237
243 template<class Entity>
244 bool contains (const Entity& e) const
245 {
246 CHECK_INTERFACE_IMPLEMENTATION((asImp().contains(e)));
247 return asImp().contains(e);
248 }
249
250 // Must be explicitly defined although this class should get a default constructor.
251 IndexSet() {}
252
253 private:
255 IndexSet(const IndexSet&);
257 IndexSet& operator=(const IndexSet&);
258
260 IndexSetImp& asImp () {return static_cast<IndexSetImp &> (*this);}
262 const IndexSetImp& asImp () const {return static_cast<const IndexSetImp &>(*this);}
263 };
264
265#undef CHECK_INTERFACE_IMPLEMENTATION
266#undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
267
268
269
273 template<class GridImp, class IndexSetImp>
275 : public IndexSet< GridImp, IndexSetImp >
276 {
278 typedef typename std::remove_const< GridImp >::type::Traits Traits;
279
280 public:
282 typedef typename Base::IndexType IndexType;
283
284 typedef typename Base::Types Types;
285
287 static const int dimension = Base::dimension;
288
289 using Base::index;
290 using Base::subIndex;
291
292 //===========================================================
296 //===========================================================
297
298 Types types ( int codim ) const { return asImp().geomTypes( codim ); }
299
306 IndexType size ( const int codim ) const
307 {
308 IndexType s( 0 );
309 const std::vector< GeometryType > &geomTs = asImp().geomTypes( codim );
310 typedef typename std::vector< GeometryType >::const_iterator Iterator;
311 const Iterator end = geomTs.end();
312 for( Iterator it = geomTs.begin(); it != end; ++it )
313 s += Base::size( *it );
314 return s;
315 }
317
318 private:
319 IndexSetImp &asImp () { return static_cast< IndexSetImp & >( *this );}
320 const IndexSetImp &asImp () const { return static_cast< const IndexSetImp & >( *this ); }
321 };
322
323
400 template<class GridImp, class IdSetImp, class IdTypeImp>
401 class IdSet
402 {
403 public:
405 typedef IdTypeImp IdType;
406
408 template<class Entity>
409 IdType id (const Entity& e) const
410 {
411 enum { cc = Entity::codimension };
412 return asImp().template id<cc>(e);
413 }
414
416 /*
417 We use the remove_const to extract the Type from the mutable class,
418 because the const class is not instantiated yet.
419 */
420 template<int cc>
421 IdType id (const typename std::remove_const<GridImp>::type::
422 Traits::template Codim<cc>::Entity& e) const
423 {
424 return asImp().template id<cc>(e);
425 }
426
429 IdType subId (const typename std::remove_const<GridImp>::type::
430 Traits::template Codim<0>::Entity& e, int i, unsigned int codim) const
431 {
432 return asImp().subId(e,i,codim);
433 }
434
435 // Default constructor (is not provided automatically because copy constructor is private)
436 IdSet() {}
437
438 private:
440 IdSet(const IdSet&);
442 IdSet& operator=(const IdSet&);
443
445 IdSetImp& asImp () {return static_cast<IdSetImp &> (*this);}
447 const IdSetImp& asImp () const {return static_cast<const IdSetImp &>(*this);}
448 };
449
450}
451
452#endif // DUNE_GRID_COMMON_INDEXIDSET_HH
Provides check for implementation of interface methods when using static polymorphism,...
Wrapper class for entities.
Definition: entity.hh:65
@ codimension
Know your own codimension.
Definition: entity.hh:107
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:268
Id Set Interface.
Definition: indexidset.hh:402
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:405
IdType subId(const typename std::remove_const< GridImp >::type::Traits::template Codim< 0 >::Entity &e, int i, unsigned int codim) const
Get id of subentity i of co-dimension codim of a co-dimension 0 entity.
Definition: indexidset.hh:429
IdType id(const typename std::remove_const< GridImp >::type::Traits::template Codim< cc >::Entity &e) const
Get id of an entity of codim cc. Unhandy because template parameter must be supplied explicitely.
Definition: indexidset.hh:421
IdType id(const Entity &e) const
Get id of an entity. This method is simpler to use than the one below.
Definition: indexidset.hh:409
Provide default implementation of method if IndexSet.
Definition: indexidset.hh:276
IndexType size(const int codim) const
Return total number of entities of given codim in the entity set . This is simply a sum over all geom...
Definition: indexidset.hh:306
Base::IndexType IndexType
The type used for the indices.
Definition: indexidset.hh:282
static const int dimension
dimension of the grid (maximum allowed codimension)
Definition: indexidset.hh:287
Index Set Interface base class.
Definition: indexidset.hh:76
IndexType subIndex(const Entity &e, int i, unsigned int codim) const
Map a subentity to an index.
Definition: indexidset.hh:180
static const int dimension
dimension of the grid (maximum allowed codimension)
Definition: indexidset.hh:96
IndexType size(int codim) const
Return total number of entities of given codim in the entity set . This is simply a sum over all geom...
Definition: indexidset.hh:232
IndexType subIndex(const typename Traits::template Codim< cc >::Entity &e, int i, unsigned int codim) const
Map a subentity to an index.
Definition: indexidset.hh:151
TypesImp Types
iterator range for geometry types in domain
Definition: indexidset.hh:93
Types types(int codim) const
obtain all geometry types of entities in domain
Definition: indexidset.hh:209
IndexType index(const typename Traits::template Codim< cc >::Entity &e) const
Map entity to index. The result of calling this method with an entity that is not in the index set is...
Definition: indexidset.hh:111
IndexTypeImp IndexType
The type used for the indices.
Definition: indexidset.hh:90
IndexType size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:220
IndexType index(const Entity &e) const
Map entity to index. Easier to use than the above because codimension template parameter need not be ...
Definition: indexidset.hh:127
bool contains(const Entity &e) const
Return true if the given entity is contained in .
Definition: indexidset.hh:244
Different resources needed by all grid implementations.
A few common exception classes.
Dune namespace.
Definition: alignment.hh:11
Static tag representing a codimension.
Definition: dimension.hh:22
Export the type of the entity used as parameter in the index(...) method.
Definition: indexidset.hh:85
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)