dune-grid 2.12-git
Loading...
Searching...
No Matches
common/indexidset.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5
6#ifndef DUNE_GRID_COMMON_INDEXIDSET_HH
7#define DUNE_GRID_COMMON_INDEXIDSET_HH
8
9#include <vector>
12
13
19namespace Dune
20{
21
23
76 template< class GridImp, class IndexSetImp, class IndexTypeImp, class TypesImp >
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 std::remove_const< GridImp >::type::Traits Traits;
82
83 public:
85 template <int cc>
86 struct Codim
87 {
88 typedef typename Traits :: template Codim<cc> :: Entity Entity;
89 };
90
92 typedef IndexTypeImp IndexType;
93
95 typedef TypesImp Types;
96
99
100 //===========================================================
104 //===========================================================
105
112 template<int cc>
113 IndexType index (const typename Traits::template Codim<cc>::Entity& e) const
114 {
115 CHECK_INTERFACE_IMPLEMENTATION((asImp().template index<cc>(e)));
116 return asImp().template index<cc>(e);
117 }
118
128 template<class Entity>
129 IndexType index (const Entity& e) const
130 {
131 constexpr static int cc = Entity::codimension;
132 CHECK_INTERFACE_IMPLEMENTATION((asImp().template index<cc>(e)));
133 return asImp().template index<cc>(e);
134 }
135
152 template< int cc >
153 IndexType subIndex ( const typename Traits::template Codim< cc >::Entity &e,
154 int i, unsigned int codim ) const
155 {
156 CHECK_INTERFACE_IMPLEMENTATION((asImp().template subIndex< cc >(e,i,codim)));
157 return asImp().template subIndex< cc >(e,i,codim);
158 }
159
181 template< class Entity >
182 IndexType subIndex ( const Entity &e, int i, unsigned int codim ) const
183 {
184 static const int cc = Entity::codimension;
185 return asImp().template subIndex< cc >( e, i, codim );
186 }
188
189
190 //===========================================================
194 //===========================================================
195
211 Types types ( int codim ) const
212 {
213 CHECK_INTERFACE_IMPLEMENTATION( (asImp().types( codim )) );
214 return asImp().types( codim );
215 }
216
226 auto size (GeometryType type) const
227 {
228 CHECK_INTERFACE_IMPLEMENTATION((asImp().size(type)));
229 return asImp().size(type);
230 }
231
239 auto size (int codim) const
240 {
241 CHECK_INTERFACE_IMPLEMENTATION((asImp().size(codim)));
242 return asImp().size(codim);
243 }
244
250 template<class Entity>
251 bool contains (const Entity& e) const
252 {
254 return asImp().contains(e);
255 }
256
257 protected:
258 // Must be explicitly defined although this class should get a default constructor.
259 IndexSet() = default;
260
261 public:
263 IndexSet(const IndexSet&) = delete;
265 IndexSet& operator=(const IndexSet&) = delete;
266
267 private:
269 IndexSetImp& asImp () {return static_cast<IndexSetImp &> (*this);}
271 const IndexSetImp& asImp () const {return static_cast<const IndexSetImp &>(*this);}
272 };
273
274#undef CHECK_INTERFACE_IMPLEMENTATION
275#undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
276
277
278
282 template<class GridImp, class IndexSetImp>
284 : public IndexSet< GridImp, IndexSetImp >
285 {
287 typedef typename std::remove_const< GridImp >::type::Traits Traits;
288
289 public:
291 typedef typename Base::IndexType IndexType;
292
293 typedef typename Base::Types Types;
294
296 static const int dimension = Base::dimension;
297
298 using Base::index;
299 using Base::subIndex;
300
301 //===========================================================
305 //===========================================================
306
307 Types types ( int codim ) const { return asImp().geomTypes( codim ); }
308
316 auto size ( const int codim ) const
317 {
318 using SizeType = std::decay_t<decltype( Base::size( Dune::GeometryType() ) )>;
319
320 SizeType s ( 0 );
321 for(GeometryType gt : types(codim))
322 s += Base::size(gt);
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
466
468 template<class Entity>
469 IdType id (const Entity& e) const
470 {
471 constexpr static int cc = Entity::codimension;
472 return asImp().template id<cc>(e);
473 }
474
476 template<int cc>
477 IdType id (const typename Codim<cc>::Entity& e) const
478 {
479 return asImp().template id<cc>(e);
480 }
481
484 IdType subId (const typename Codim<0>::Entity& e, int i, unsigned int codim) const
485 {
486 return asImp().subId(e,i,codim);
487 }
488
489 protected:
490 // Default constructor (is not provided automatically because copy constructor is private)
491 IdSet() = default;
492
493 public:
495 IdSet(const IdSet&) = delete;
497 IdSet& operator=(const IdSet&) = delete;
498
499 private:
501 IdSetImp& asImp () {return static_cast<IdSetImp &> (*this);}
503 const IdSetImp& asImp () const {return static_cast<const IdSetImp &>(*this);}
504 };
505
506}
507
508#endif // DUNE_GRID_COMMON_INDEXIDSET_HH
#define CHECK_INTERFACE_IMPLEMENTATION(dummy)
int size() const
Include standard header files.
Wrapper class for entities.
Definition common/entity.hh:66
static constexpr int codimension
Know your own codimension.
Definition common/entity.hh:106
Index Set Interface base class.
Definition common/indexidset.hh:78
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 common/indexidset.hh:239
auto size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition common/indexidset.hh:226
IndexType subIndex(const Entity &e, int i, unsigned int codim) const
Map a subentity to an index.
Definition common/indexidset.hh:182
static const int dimension
dimension of the grid (maximum allowed codimension)
Definition common/indexidset.hh:98
IndexSet()=default
IndexType subIndex(const typename Traits::template Codim< cc >::Entity &e, int i, unsigned int codim) const
Map a subentity to an index.
Definition common/indexidset.hh:153
TypesImp Types
iterator range for geometry types in domain
Definition common/indexidset.hh:95
Types types(int codim) const
obtain all geometry types of entities in domain
Definition common/indexidset.hh:211
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 common/indexidset.hh:113
IndexSet & operator=(const IndexSet &)=delete
Forbid the assignment operator.
IndexTypeImp IndexType
The type used for the indices.
Definition common/indexidset.hh:92
IndexType index(const Entity &e) const
Map entity to index. Easier to use than the above because codimension template parameter need not be ...
Definition common/indexidset.hh:129
bool contains(const Entity &e) const
Return true if the given entity is contained in .
Definition common/indexidset.hh:251
Id Set Interface.
Definition common/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 common/indexidset.hh:484
static constexpr auto dimension
dimension of the grid (maximum allowed codimension)
Definition common/indexidset.hh:465
IdSet(const IdSet &)=delete
Forbid the copy constructor.
IdSet()=default
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 common/indexidset.hh:477
IdTypeImp IdType
Type used to represent an id.
Definition common/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 common/indexidset.hh:469
Export the type of the entity used as parameter in the index(...) method.
Definition common/indexidset.hh:87
Traits::template Codim< cc >::Entity Entity
Definition common/indexidset.hh:88
Provide default implementation of method if IndexSet.
Definition common/indexidset.hh:285
Base::IndexType IndexType
The type used for the indices.
Definition common/indexidset.hh:291
Base::Types Types
Definition common/indexidset.hh:293
static const int dimension
dimension of the grid (maximum allowed codimension)
Definition common/indexidset.hh:296
Types types(int codim) const
Definition common/indexidset.hh:307
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 common/indexidset.hh:316
Export the type of the entity used as parameter in the id(...) method.
Definition common/indexidset.hh:460
typename Traits::template Codim< cc >::Entity Entity
Definition common/indexidset.hh:461
Different resources needed by all grid implementations.