Dune Core Modules (2.3.1)

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// $Id$
4
5#ifndef DUNE_INDEXIDSET_HH
6#define DUNE_INDEXIDSET_HH
7
8#include <iostream>
9#include <vector>
13
14
20namespace Dune
21{
22
24
76 template<class GridImp, class IndexSetImp, class IndexTypeImp>
78 {
79 /* We use the remove_const to extract the Type from the mutable class,
80 because the const class is not instantiated yet. */
81 typedef typename remove_const< GridImp >::type::Traits Traits;
82
83 public:
85 typedef IndexTypeImp IndexType;
86
89
90 //===========================================================
94 //===========================================================
95
102 /*
103 We use the remove_const to extract the Type from the mutable class,
104 because the const class is not instantiated yet.
105 */
106 template<int cc>
107 IndexType index (const typename remove_const<GridImp>::type::
108 Traits::template Codim<cc>::Entity& e) const
109 {
110 CHECK_INTERFACE_IMPLEMENTATION((asImp().template index<cc>(e)));
111 return asImp().template index<cc>(e);
112 }
113
123 template<class EntityType>
124 IndexType index (const EntityType& e) const
125 {
126 enum { cc = EntityType::codimension };
127 CHECK_INTERFACE_IMPLEMENTATION((asImp().template index<cc>(e)));
128 return asImp().template index<cc>(e);
129 }
130
145 template< int cc >
146 IndexType subIndex ( const typename Traits::template Codim< cc >::Entity &e,
147 int i, unsigned int codim ) const
148 {
149 CHECK_INTERFACE_IMPLEMENTATION((asImp().template subIndex< cc >(e,i,codim)));
150 return asImp().template subIndex< cc >(e,i,codim);
151 }
152
171 template< class Entity >
172 IndexType subIndex ( const Entity &e, int i, unsigned int codim ) const
173 {
174 static const int cc = Entity::codimension;
175 return asImp().template subIndex< cc >( e, i, codim );
176 }
178
179
180 //===========================================================
184 //===========================================================
185
193 const std::vector<GeometryType>& geomTypes (int codim) const
194 {
195 CHECK_INTERFACE_IMPLEMENTATION((asImp().geomTypes(codim)));
196 return asImp().geomTypes(codim);
197 }
198
205 {
206 CHECK_INTERFACE_IMPLEMENTATION((asImp().size(type)));
207 return asImp().size(type);
208 }
209
216 IndexType size (int codim) const
217 {
218 CHECK_INTERFACE_IMPLEMENTATION((asImp().size(codim)));
219 return asImp().size(codim);
220 }
221
227 template<class EntityType>
228 bool contains (const EntityType& e) const
229 {
230 CHECK_INTERFACE_IMPLEMENTATION((asImp().contains(e)));
231 return asImp().contains(e);
232 }
233
234 // Must be explicitely defined although this class should get a default constructor.
235 IndexSet() {}
236
237 private:
239 IndexSet(const IndexSet&);
241 IndexSet& operator=(const IndexSet&);
242
244 IndexSetImp& asImp () {return static_cast<IndexSetImp &> (*this);}
246 const IndexSetImp& asImp () const {return static_cast<const IndexSetImp &>(*this);}
247 };
248
249#undef CHECK_INTERFACE_IMPLEMENTATION
250#undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
251
252
253
257 template<class GridImp, class IndexSetImp>
259 : public IndexSet< GridImp, IndexSetImp >
260 {
262 typedef typename remove_const< GridImp >::type::Traits Traits;
263
264 public:
266 typedef typename Base::IndexType IndexType;
267
269 static const int dimension = Base::dimension;
270
271 using Base::index;
272 using Base::subIndex;
273
274 //===========================================================
278 //===========================================================
279
288 template< int cc >
289 IndexType subIndex ( const typename Traits::template Codim< cc >::Entity &e, int i, unsigned int codim ) const
290 {
291 // this does not work, since subEntity is a template method requiring codim to be
292 // a template parameter
293 // return index( *(e.subEntity( i, codim )) );
294 DUNE_THROW(NotImplemented,"subIndex for entities is not is not implemented");
295 return -1;
296 }
298
299 //===========================================================
303 //===========================================================
304
311 IndexType size ( const int codim ) const
312 {
313 IndexType s( 0 );
314 const std::vector< GeometryType > &geomTs = Base::geomTypes( codim );
315 typedef typename std::vector< GeometryType >::const_iterator Iterator;
316 const Iterator end = geomTs.end();
317 for( Iterator it = geomTs.begin(); it != end; ++it )
318 s += Base::size( *it );
319 return s;
320 }
322 };
323
324
401 template<class GridImp, class IdSetImp, class IdTypeImp>
402 class IdSet
403 {
404 public:
406 typedef IdTypeImp IdType;
407
409 template<class EntityType>
410 IdType id (const EntityType& e) const
411 {
412 enum { cc = EntityType::codimension };
413 return asImp().template id<cc>(e);
414 }
415
417 /*
418 We use the remove_const to extract the Type from the mutable class,
419 because the const class is not instantiated yet.
420 */
421 template<int cc>
422 IdType id (const typename remove_const<GridImp>::type::
423 Traits::template Codim<cc>::Entity& e) const
424 {
425 return asImp().template id<cc>(e);
426 }
427
430 IdType subId (const typename remove_const<GridImp>::type::
431 Traits::template Codim<0>::Entity& e, int i, unsigned int codim) const
432 {
433 return asImp().subId(e,i,codim);
434 }
435
436 // Default constructor (is not provided automatically because copy constructor is private)
437 IdSet() {}
438
439 private:
441 IdSet(const IdSet&);
443 IdSet& operator=(const IdSet&);
444
446 IdSetImp& asImp () {return static_cast<IdSetImp &> (*this);}
448 const IdSetImp& asImp () const {return static_cast<const IdSetImp &>(*this);}
449 };
450
451}
452
453#endif
Provides check for implementation of interface methods when using static polymorphism,...
Wrapper class for entities.
Definition: entity.hh:57
@ codimension
Know your own codimension.
Definition: entity.hh:99
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
Id Set Interface.
Definition: indexidset.hh:403
IdType id(const typename 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:422
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:406
IdType subId(const typename 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:430
IdType id(const EntityType &e) const
Get id of an entity. This method is simpler to use than the one below.
Definition: indexidset.hh:410
Provide default implementation of method if IndexSet.
Definition: indexidset.hh:260
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:311
Base::IndexType IndexType
The type used for the indices.
Definition: indexidset.hh:266
static const int dimension
dimension of the grid (maximum allowed codimension)
Definition: indexidset.hh:269
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:289
Index Set Interface base class.
Definition: indexidset.hh:78
static const int dimension
dimension of the grid (maximum allowed codimension)
Definition: indexidset.hh:88
IndexType index(const typename remove_const< GridImp >::type::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:107
IndexType size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:204
IndexType subIndex(const Entity &e, int i, unsigned int codim) const
Map a subentity to an index.
Definition: indexidset.hh:172
IndexTypeImp IndexType
The type used for the indices.
Definition: indexidset.hh:85
IndexType index(const EntityType &e) const
Map entity to index. Easier to use than the above because codimension template parameter need not be ...
Definition: indexidset.hh:124
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:146
const std::vector< GeometryType > & geomTypes(int codim) const
Return vector with all geometry types of entities in domain of index map. Return a vector with all ge...
Definition: indexidset.hh:193
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:216
bool contains(const EntityType &e) const
Return true if the given entity is contained in .
Definition: indexidset.hh:228
Default exception for dummy implementations.
Definition: exceptions.hh:289
Different resources needed by all grid implementations.
A few common exception classes.
A static for loop for template meta-programming.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
Dune namespace.
Definition: alignment.hh:14
Removes a const qualifier while preserving others.
Definition: typetraits.hh:176
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)