dune-grid  2.9.0
geometrygrid/indexsets.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 #ifndef DUNE_GEOGRID_INDEXSETS_HH
6 #define DUNE_GEOGRID_INDEXSETS_HH
7 
8 #include <vector>
9 
10 #include <dune/common/typetraits.hh>
11 
14 
16 
17 namespace Dune
18 {
19 
20  namespace GeoGrid
21  {
22 
23  // IndexSet
24  // --------
25 
26  template< class Grid, class HostIndexSet >
27  class IndexSet
28  : public Dune::IndexSet< Grid, IndexSet< Grid, HostIndexSet >, typename HostIndexSet::IndexType, typename HostIndexSet::Types >
29  {
32 
33  typedef typename std::remove_const< Grid >::type::Traits Traits;
34 
35  typedef typename Traits::HostGrid HostGrid;
36 
37  public:
38  static const int dimension = Traits::dimension;
39 
40  typedef typename Base::IndexType IndexType;
41 
42  typedef typename Base::Types Types;
43 
44  IndexSet () = default;
45 
46  explicit IndexSet ( const HostIndexSet &hostIndexSet )
47  : hostIndexSet_( &hostIndexSet )
48  {}
49 
50  // The index set contains a pointer to the host index set, so copying or assigning this can be dangerous.
51  IndexSet ( const This & ) = delete;
52  IndexSet ( This && ) = delete;
53 
54  IndexSet &operator= ( const This & ) = delete;
55  IndexSet &operator= ( This && ) = delete;
56 
57  using Base::index;
58  using Base::subIndex;
59 
60  template< int cc >
61  IndexType index ( const typename Traits::template Codim< cc >::Entity &entity ) const
62  {
63  return entity.impl().index( hostIndexSet() );
64  }
65 
66  template< int cc >
67  IndexType subIndex ( const typename Traits::template Codim< cc >::Entity &entity, int i, unsigned int codim ) const
68  {
69  return entity.impl().subIndex( hostIndexSet(), i, codim );
70  }
71 
72  std::size_t size ( GeometryType type ) const
73  {
74  return hostIndexSet().size( type );
75  }
76 
77  std::size_t size ( int codim ) const
78  {
79  return hostIndexSet().size( codim );
80  }
81 
82  template< class Entity >
83  bool contains ( const Entity &entity ) const
84  {
85  return entity.impl().isContained( hostIndexSet() );
86  }
87 
88  Types types ( int codim ) const { return hostIndexSet().types( codim ); }
89 
90  const std::vector< GeometryType > &geomTypes ( int codim ) const
91  {
92  return hostIndexSet().geomTypes( codim );
93  }
94 
95  explicit operator bool () const { return bool( hostIndexSet_ ); }
96 
97  void reset () { hostIndexSet_ = nullptr; }
98  void reset ( const HostIndexSet &hostIndexSet ) { hostIndexSet_ = &hostIndexSet; }
99 
100  private:
101  const HostIndexSet &hostIndexSet () const
102  {
103  assert( *this );
104  return *hostIndexSet_;
105  }
106 
107  const HostIndexSet *hostIndexSet_ = nullptr;
108  };
109 
110  } // namespace GeoGrid
111 
112 } // namespace Dune
113 
114 #endif // #ifndef DUNE_GEOGRID_INDEXSETS_HH
Provides base classes for index and id sets.
Include standard header files.
Definition: agrid.hh:60
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
Index Set Interface base class.
Definition: indexidset.hh:78
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
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
DUNE-conform implementation of the entity.
Definition: geometrygrid/entity.hh:34
Definition: geometrygrid/indexsets.hh:29
std::size_t size(GeometryType type) const
Definition: geometrygrid/indexsets.hh:72
Types types(int codim) const
Definition: geometrygrid/indexsets.hh:88
IndexSet(const This &)=delete
void reset(const HostIndexSet &hostIndexSet)
Definition: geometrygrid/indexsets.hh:98
void reset()
Definition: geometrygrid/indexsets.hh:97
static const int dimension
Definition: geometrygrid/indexsets.hh:38
IndexType subIndex(const typename Traits::template Codim< cc >::Entity &entity, int i, unsigned int codim) const
Definition: geometrygrid/indexsets.hh:67
IndexSet(This &&)=delete
bool contains(const Entity &entity) const
Definition: geometrygrid/indexsets.hh:83
IndexSet(const HostIndexSet &hostIndexSet)
Definition: geometrygrid/indexsets.hh:46
Base::Types Types
Definition: geometrygrid/indexsets.hh:42
IndexSet & operator=(const This &)=delete
std::size_t size(int codim) const
Definition: geometrygrid/indexsets.hh:77
const std::vector< GeometryType > & geomTypes(int codim) const
Definition: geometrygrid/indexsets.hh:90
Base::IndexType IndexType
Definition: geometrygrid/indexsets.hh:40
IndexType index(const typename Traits::template Codim< cc >::Entity &entity) const
Definition: geometrygrid/indexsets.hh:61