Dune Core Modules (2.9.1)

indexidset.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 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
98 static const int dimension = std::remove_const< GridImp >::type::dimension;
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
223 auto size (GeometryType type) const
224 {
225 CHECK_INTERFACE_IMPLEMENTATION((asImp().size(type)));
226 return asImp().size(type);
227 }
228
236 auto size (int codim) const
237 {
238 CHECK_INTERFACE_IMPLEMENTATION((asImp().size(codim)));
239 return asImp().size(codim);
240 }
241
247 template<class Entity>
248 bool contains (const Entity& e) const
249 {
250 CHECK_INTERFACE_IMPLEMENTATION((asImp().contains(e)));
251 return asImp().contains(e);
252 }
253
254 protected:
255 // Must be explicitly defined although this class should get a default constructor.
256 IndexSet() = default;
257
258 public:
260 IndexSet(const IndexSet&) = delete;
262 IndexSet& operator=(const IndexSet&) = delete;
263
264 private:
266 IndexSetImp& asImp () {return static_cast<IndexSetImp &> (*this);}
268 const IndexSetImp& asImp () const {return static_cast<const IndexSetImp &>(*this);}
269 };
270
271#undef CHECK_INTERFACE_IMPLEMENTATION
272#undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
273
274
275
279 template<class GridImp, class IndexSetImp>
281 : public IndexSet< GridImp, IndexSetImp >
282 {
284 typedef typename std::remove_const< GridImp >::type::Traits Traits;
285
286 public:
288 typedef typename Base::IndexType IndexType;
289
290 typedef typename Base::Types Types;
291
293 static const int dimension = Base::dimension;
294
295 using Base::index;
296 using Base::subIndex;
297
298 //===========================================================
302 //===========================================================
303
304 Types types ( int codim ) const { return asImp().geomTypes( codim ); }
305
313 auto size ( const int codim ) const
314 {
315 using SizeType = std::decay_t<decltype( Base::size( Dune::GeometryType() ) )>;
316
317 const std::vector< GeometryType > &geomTs = asImp().geomTypes( codim );
318 typedef typename std::vector< GeometryType >::const_iterator Iterator;
319
320 const Iterator end = geomTs.end();
321
322 SizeType s ( 0 );
323 for( Iterator it = geomTs.begin() ; it != end; ++it )
324 s += Base::size( *it );
325
326 return s;
327 }
329
330 private:
331 IndexSetImp &asImp () { return static_cast< IndexSetImp & >( *this );}
332 const IndexSetImp &asImp () const { return static_cast< const IndexSetImp & >( *this ); }
333 };
334
335
450 template<class GridImp, class IdSetImp, class IdTypeImp>
451 class IdSet
452 {
453 /* We use the remove_const to extract the Type from the mutable class,
454 because the const class is not instantiated yet. */
455 using Traits = typename std::remove_const< GridImp >::type::Traits;
456 public:
458 typedef IdTypeImp IdType;
459
461 template <int cc>
462 struct Codim {
463 using Entity = typename Traits::template Codim<cc>::Entity;
464 };
465
467 static constexpr auto dimension = std::remove_const< GridImp >::type::dimension;
468
470 template<class Entity>
471 IdType id (const Entity& e) const
472 {
473 constexpr static int cc = Entity::codimension;
474 return asImp().template id<cc>(e);
475 }
476
478 template<int cc>
479 IdType id (const typename Codim<cc>::Entity& e) const
480 {
481 return asImp().template id<cc>(e);
482 }
483
486 IdType subId (const typename Codim<0>::Entity& e, int i, unsigned int codim) const
487 {
488 return asImp().subId(e,i,codim);
489 }
490
491 protected:
492 // Default constructor (is not provided automatically because copy constructor is private)
493 IdSet() = default;
494
495 public:
497 IdSet(const IdSet&) = delete;
499 IdSet& operator=(const IdSet&) = delete;
500
501 private:
503 IdSetImp& asImp () {return static_cast<IdSetImp &> (*this);}
505 const IdSetImp& asImp () const {return static_cast<const IdSetImp &>(*this);}
506 };
507
508}
509
510#endif // DUNE_GRID_COMMON_INDEXIDSET_HH
Provides check for implementation of interface methods when using static polymorphism,...
Wrapper class for entities.
Definition: entity.hh:66
static constexpr int codimension
Know your own codimension.
Definition: entity.hh:106
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:126
Id Set Interface.
Definition: indexidset.hh:452
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:486
static constexpr auto dimension
dimension of the grid (maximum allowed codimension)
Definition: indexidset.hh:467
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:479
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:458
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:471
Provide default implementation of method if IndexSet.
Definition: indexidset.hh:282
Base::IndexType IndexType
The type used for the indices.
Definition: indexidset.hh:288
static const int dimension
dimension of the grid (maximum allowed codimension)
Definition: indexidset.hh:293
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:313
Index Set Interface base class.
Definition: 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: indexidset.hh:236
auto size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:223
IndexType subIndex(const Entity &e, int i, unsigned int codim) const
Map a subentity to an index.
Definition: indexidset.hh:182
static const int dimension
dimension of the grid (maximum allowed codimension)
Definition: indexidset.hh:98
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:153
TypesImp Types
iterator range for geometry types in domain
Definition: indexidset.hh:95
Types types(int codim) const
obtain all geometry types of entities in domain
Definition: 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: indexidset.hh:113
IndexSet & operator=(const IndexSet &)=delete
Forbid the assignment operator.
IndexTypeImp IndexType
The type used for the indices.
Definition: 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: indexidset.hh:129
bool contains(const Entity &e) const
Return true if the given entity is contained in .
Definition: indexidset.hh:248
Different resources needed by all grid implementations.
A few common exception classes.
Dune namespace.
Definition: alignedallocator.hh:13
Export the type of the entity used as parameter in the id(...) method.
Definition: indexidset.hh:462
Export the type of the entity used as parameter in the index(...) method.
Definition: indexidset.hh:87
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)