Dune Core Modules (unstable)

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>
11 #include <dune/grid/common/grid.hh>
12 
13 
19 namespace Dune
20 {
21 
23 
76  template< class GridImp, class IndexSetImp, class IndexTypeImp, class TypesImp >
77  class IndexSet
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  SizeType s ( 0 );
318  for(GeometryType gt : types(codim))
319  s += Base::size(gt);
320 
321  return s;
322  }
324 
325  private:
326  IndexSetImp &asImp () { return static_cast< IndexSetImp & >( *this );}
327  const IndexSetImp &asImp () const { return static_cast< const IndexSetImp & >( *this ); }
328  };
329 
330 
445  template<class GridImp, class IdSetImp, class IdTypeImp>
446  class IdSet
447  {
448  /* We use the remove_const to extract the Type from the mutable class,
449  because the const class is not instantiated yet. */
450  using Traits = typename std::remove_const< GridImp >::type::Traits;
451  public:
453  typedef IdTypeImp IdType;
454 
456  template <int cc>
457  struct Codim {
458  using Entity = typename Traits::template Codim<cc>::Entity;
459  };
460 
462  static constexpr auto dimension = std::remove_const< GridImp >::type::dimension;
463 
465  template<class Entity>
466  IdType id (const Entity& e) const
467  {
468  constexpr static int cc = Entity::codimension;
469  return asImp().template id<cc>(e);
470  }
471 
473  template<int cc>
474  IdType id (const typename Codim<cc>::Entity& e) const
475  {
476  return asImp().template id<cc>(e);
477  }
478 
481  IdType subId (const typename Codim<0>::Entity& e, int i, unsigned int codim) const
482  {
483  return asImp().subId(e,i,codim);
484  }
485 
486  protected:
487  // Default constructor (is not provided automatically because copy constructor is private)
488  IdSet() = default;
489 
490  public:
492  IdSet(const IdSet&) = delete;
494  IdSet& operator=(const IdSet&) = delete;
495 
496  private:
498  IdSetImp& asImp () {return static_cast<IdSetImp &> (*this);}
500  const IdSetImp& asImp () const {return static_cast<const IdSetImp &>(*this);}
501  };
502 
503 }
504 
505 #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
constexpr static 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:114
Id Set Interface.
Definition: indexidset.hh:447
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:481
static constexpr auto dimension
dimension of the grid (maximum allowed codimension)
Definition: indexidset.hh:462
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:474
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:453
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:466
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
IndexTypeImp IndexType
The type used for the indices.
Definition: indexidset.hh:92
IndexSet & operator=(const IndexSet &)=delete
Forbid the assignment operator.
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.
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:158
Dune namespace.
Definition: alignedallocator.hh:13
Export the type of the entity used as parameter in the id(...) method.
Definition: indexidset.hh:457
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.80.0 (Apr 27, 22:29, 2024)