DUNE PDELab (2.8)

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 auto size (GeometryType type) const
222 {
223 CHECK_INTERFACE_IMPLEMENTATION((asImp().size(type)));
224 return asImp().size(type);
225 }
226
234 auto size (int codim) const
235 {
236 CHECK_INTERFACE_IMPLEMENTATION((asImp().size(codim)));
237 return asImp().size(codim);
238 }
239
245 template<class Entity>
246 bool contains (const Entity& e) const
247 {
248 CHECK_INTERFACE_IMPLEMENTATION((asImp().contains(e)));
249 return asImp().contains(e);
250 }
251
252 protected:
253 // Must be explicitly defined although this class should get a default constructor.
254 IndexSet() = default;
255
256 public:
258 IndexSet(const IndexSet&) = delete;
260 IndexSet& operator=(const IndexSet&) = delete;
261
262 private:
264 IndexSetImp& asImp () {return static_cast<IndexSetImp &> (*this);}
266 const IndexSetImp& asImp () const {return static_cast<const IndexSetImp &>(*this);}
267 };
268
269#undef CHECK_INTERFACE_IMPLEMENTATION
270#undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
271
272
273
277 template<class GridImp, class IndexSetImp>
279 : public IndexSet< GridImp, IndexSetImp >
280 {
282 typedef typename std::remove_const< GridImp >::type::Traits Traits;
283
284 public:
286 typedef typename Base::IndexType IndexType;
287
288 typedef typename Base::Types Types;
289
291 static const int dimension = Base::dimension;
292
293 using Base::index;
294 using Base::subIndex;
295
296 //===========================================================
300 //===========================================================
301
302 Types types ( int codim ) const { return asImp().geomTypes( codim ); }
303
311 auto size ( const int codim ) const
312 {
313 using SizeType = std::decay_t<decltype( Base::size( Dune::GeometryType() ) )>;
314
315 const std::vector< GeometryType > &geomTs = asImp().geomTypes( codim );
316 typedef typename std::vector< GeometryType >::const_iterator Iterator;
317
318 const Iterator end = geomTs.end();
319
320 SizeType s ( 0 );
321 for( Iterator it = geomTs.begin() ; it != end; ++it )
322 s += Base::size( *it );
323
324 return s;
325 }
327
328 private:
329 IndexSetImp &asImp () { return static_cast< IndexSetImp & >( *this );}
330 const IndexSetImp &asImp () const { return static_cast< const IndexSetImp & >( *this ); }
331 };
332
333
448 template<class GridImp, class IdSetImp, class IdTypeImp>
449 class IdSet
450 {
451 /* We use the remove_const to extract the Type from the mutable class,
452 because the const class is not instantiated yet. */
453 using Traits = typename std::remove_const< GridImp >::type::Traits;
454 public:
456 typedef IdTypeImp IdType;
457
459 template <int cc>
460 struct Codim {
461 using Entity = typename Traits::template Codim<cc>::Entity;
462 };
463
465 static constexpr auto dimension = std::remove_const< GridImp >::type::dimension;
466
468 template<class Entity>
469 IdType id (const Entity& e) const
470 {
471 enum { cc = Entity::codimension };
472 return asImp().template id<cc>(e);
473 }
474
476 /*
477 We use the remove_const to extract the Type from the mutable class,
478 because the const class is not instantiated yet.
479 */
480 template<int cc>
481 IdType id (const typename Codim<cc>::Entity& e) const
482 {
483 return asImp().template id<cc>(e);
484 }
485
488 IdType subId (const typename Codim<0>::Entity& e, int i, unsigned int codim) const
489 {
490 return asImp().subId(e,i,codim);
491 }
492
493 protected:
494 // Default constructor (is not provided automatically because copy constructor is private)
495 IdSet() = default;
496
497 public:
499 IdSet(const IdSet&) = delete;
501 IdSet& operator=(const IdSet&) = delete;
502
503 private:
505 IdSetImp& asImp () {return static_cast<IdSetImp &> (*this);}
507 const IdSetImp& asImp () const {return static_cast<const IdSetImp &>(*this);}
508 };
509
510}
511
512#endif // DUNE_GRID_COMMON_INDEXIDSET_HH
Provides check for implementation of interface methods when using static polymorphism,...
Wrapper class for entities.
Definition: entity.hh:64
@ codimension
Know your own codimension.
Definition: entity.hh:105
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:123
Id Set Interface.
Definition: indexidset.hh:450
IdType subId(const typename 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:488
static constexpr auto dimension
dimension of the grid (maximum allowed codimension)
Definition: indexidset.hh:465
IdSet(const IdSet &)=delete
Forbid the copy constructor.
IdType id(const typename Codim< cc >::Entity &e) const
Get id of an entity of codim cc. Unhandy because template parameter must be supplied explicitly.
Definition: indexidset.hh:481
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:456
IdSet & operator=(const IdSet &)=delete
Forbid the assignment operator.
IdType id(const Entity &e) const
Get id of an entity. This method is simpler to use than the one below.
Definition: indexidset.hh:469
Provide default implementation of method if IndexSet.
Definition: indexidset.hh:280
Base::IndexType IndexType
The type used for the indices.
Definition: indexidset.hh:286
static const int dimension
dimension of the grid (maximum allowed codimension)
Definition: indexidset.hh:291
auto 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
Index Set Interface base class.
Definition: indexidset.hh:76
auto 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:234
auto size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:221
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 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
IndexSet(const IndexSet &)=delete
Forbid the copy constructor.
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
IndexSet & operator=(const IndexSet &)=delete
Forbid the assignment operator.
IndexTypeImp IndexType
The type used for the indices.
Definition: indexidset.hh:90
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:246
Different resources needed by all grid implementations.
A few common exception classes.
Dune namespace.
Definition: alignedallocator.hh:11
Export the type of the entity used as parameter in the id(...) method.
Definition: indexidset.hh:460
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 (Aug 31, 22:30, 2024)