indexset.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=2 sw=2 sts=2:
3#ifndef DUNE_POLYHEDRALGRID_INDEXSET_HH
4#define DUNE_POLYHEDRALGRID_INDEXSET_HH
5
6#include <vector>
7
8#include <dune/common/typetraits.hh>
9
10#include <dune/grid/common/gridenums.hh>
11#include <dune/grid/common/indexidset.hh>
12
14
15namespace Dune
16{
17
18 // PolyhedralGridIndexSet
19 // --------------
20
21 template< int dim, int dimworld, typename coord_t >
23 : public IndexSet< PolyhedralGrid< dim, dimworld, coord_t >, PolyhedralGridIndexSet< dim, dimworld, coord_t >, int >
24 {
26
27 protected:
29 typedef IndexSet< GridType, This, int > Base;
30
31 typedef typename std::remove_const< GridType >::type::Traits Traits;
32
33 public:
34 static const int dimension = Traits::dimension;
35
36 typedef typename Base::IndexType IndexType;
37
39 : grid_(&grid)
40 {
41 }
42
43 template< class Entity >
44 IndexType index ( const Entity &entity ) const
45 {
46 return index< Entity::codimension >( entity );
47 }
48
49 template< int cd >
50 IndexType index ( const typename Traits::template Codim< cd >::Entity &entity ) const
51 {
52 return entity.impl().index();
53 }
54
55 template< int cd >
56 IndexType subIndex ( const typename Traits::template Codim< cd >::Entity &entity, int i, unsigned int codim ) const
57 {
58 return subIndex( entity, i, codim );
59 }
60
61 template< class Entity >
62 IndexType subIndex ( const Entity &entity, int i, unsigned int codim ) const
63 {
64 if( codim == 0 )
65 return index( entity );
66 else if ( codim == 1 )
67 return index( entity.impl().template subEntity< 1 > ( i ) );
68 else if ( codim == dimension )
69 {
70 return index( entity.impl().template subEntity< dimension > ( i ) );
71 }
72 else
73 {
74 DUNE_THROW(NotImplemented,"codimension not available");
75 return IndexType( -1 );
76 }
77 }
78
79 IndexType size ( GeometryType type ) const
80 {
81 return grid().size( type );
82 }
83
84 int size ( int codim ) const
85 {
86 return grid().size( codim );
87 }
88
89 template< class Entity >
90 bool contains ( const Entity &entity ) const
91 {
92 return index(entity) >= 0 && index(entity) < size(Entity::codimension);
93 }
94
95 const std::vector< GeometryType > &geomTypes ( int codim ) const
96 {
97 return grid().geomTypes(codim);
98 }
99
100 const std::vector< GeometryType >& types(int codim) const
101 {
102 return grid().geomTypes(codim);
103 }
104
105 const GridType& grid() const { assert( grid_ ); return *grid_; }
106
107 protected:
109 };
110
111} // namespace Dune
112
113#endif // #ifndef DUNE_POLYHEDRALGRID_INDEXSET_HH
Definition: indexset.hh:24
IndexType subIndex(const Entity &entity, int i, unsigned int codim) const
Definition: indexset.hh:62
Base::IndexType IndexType
Definition: indexset.hh:36
IndexType subIndex(const typename Traits::template Codim< cd >::Entity &entity, int i, unsigned int codim) const
Definition: indexset.hh:56
IndexType index(const typename Traits::template Codim< cd >::Entity &entity) const
Definition: indexset.hh:50
IndexType size(GeometryType type) const
Definition: indexset.hh:79
const std::vector< GeometryType > & types(int codim) const
Definition: indexset.hh:100
int size(int codim) const
Definition: indexset.hh:84
bool contains(const Entity &entity) const
Definition: indexset.hh:90
const GridType & grid() const
Definition: indexset.hh:105
PolyhedralGridIndexSet< dim, dimworld, coord_t > This
Definition: indexset.hh:28
IndexSet< GridType, This, int > Base
Definition: indexset.hh:29
IndexType index(const Entity &entity) const
Definition: indexset.hh:44
std::remove_const< GridType >::type::Traits Traits
Definition: indexset.hh:31
PolyhedralGridIndexSet(const GridType &grid)
Definition: indexset.hh:38
static const int dimension
Definition: indexset.hh:34
const std::vector< GeometryType > & geomTypes(int codim) const
Definition: indexset.hh:95
const GridType * grid_
Definition: indexset.hh:108
identical grid wrapper
Definition: grid.hh:159
int size(int, int codim) const
obtain number of entites on a level
Definition: grid.hh:427
const std::vector< GeometryType > & geomTypes(const unsigned int codim) const
Definition: grid.hh:1131
The namespace Dune is the main namespace for all Dune code.
Definition: common/CartesianIndexMapper.hpp:10