dune-grid  2.2.0
scsgmapper.hh
Go to the documentation of this file.
1 // $Id: scsgmapper.hh 7472 2011-02-28 15:09:13Z mnolte $
2 
3 #ifndef DUNE_SCSGMAPPER_HH
4 #define DUNE_SCSGMAPPER_HH
5 
6 #include<iostream>
7 #include "mapper.hh"
8 
10 
17 namespace Dune
18 {
37  template <typename GV, int c>
39  public Mapper<typename GV::Grid,SingleCodimSingleGeomTypeMapper<GV,c> >
40  {
41  public:
42 
47 
52  SingleCodimSingleGeomTypeMapper (const GV& gridView);
53 
59  template<class EntityType>
60  int map (const EntityType& e) const;
61 
69  int map (const typename GV::template Codim<0>::Entity& e,
70  int i, unsigned int codim) const;
71 
80  int size () const;
81 
88  template<class EntityType>
89  bool contains (const EntityType& e, int& result) const;
90 
99  bool contains (const typename GV::template Codim<0>::Entity& e, int i, int cc, int& result) const;
100 
103  void update ()
104  { // nothing to do here
105  }
106 
107  private:
108  const typename GV::IndexSet& is;
109  };
110 
113  template <typename GV, int c>
115  : is(gridView.indexSet())
116  {
117  // check that grid has only a single geometry type
118  if (is.geomTypes(c).size() != 1)
119  DUNE_THROW(GridError, "mapper treats only a single codim and a single geometry type");
120  }
121 
122  template <typename GV, int c>
123  template<class EntityType>
124  inline int SingleCodimSingleGeomTypeMapper<GV,c>::map (const EntityType& e) const
125  {
126  enum { cc = EntityType::codimension };
127  dune_static_assert(cc == c, "Entity of wrong codim passed to SingleCodimSingleGeomTypeMapper");
128  return is.index(e);
129  }
130 
131  template <typename GV, int c>
132  inline int SingleCodimSingleGeomTypeMapper<GV,c>::map (const typename GV::template Codim<0>::Entity& e, int i, unsigned int codim) const
133  {
134  if (codim != c)
135  DUNE_THROW(GridError, "Id of wrong codim requested from SingleCodimSingleGeomTypeMapper");
136  return is.subIndex(e,i,codim);
137  }
138 
139  template <typename GV, int c>
141  {
142  return is.size(c);
143  }
144 
145  template <typename GV, int c>
146  template<class EntityType>
147  inline bool SingleCodimSingleGeomTypeMapper<GV,c>::contains (const EntityType& e, int& result) const
148  {
149  result = map(e);
150  return true;
151  }
152 
153  template <typename GV, int c>
154  inline bool SingleCodimSingleGeomTypeMapper<GV,c>::contains (const typename GV::template Codim<0>::Entity& e, int i, int cc, int& result) const
155  {
156  result = this->map(e,i,cc);
157  return true;
158  }
159 
178  template <typename G, int c>
179  class LeafSingleCodimSingleGeomTypeMapper : public SingleCodimSingleGeomTypeMapper<typename G::LeafGridView,c> {
180  public:
181  /* @brief The constructor
182  @param grid A reference to a grid.
183  */
185  : SingleCodimSingleGeomTypeMapper<typename G::LeafGridView,c>(grid.leafView())
186  {}
187  };
188 
202  template <typename G, int c>
203  class LevelSingleCodimSingleGeomTypeMapper : public SingleCodimSingleGeomTypeMapper<typename G::LevelGridView,c> {
204  public:
205  /* @brief The constructor
206  @param grid A reference to a grid.
207  @param level A valid level of the grid.
208  */
209  LevelSingleCodimSingleGeomTypeMapper (const G& grid, int level)
210  : SingleCodimSingleGeomTypeMapper<typename G::LevelGridView,c>(grid.levelView(level))
211  {}
212  };
213 
215 }
216 #endif