dune-grid  2.3.1
scsgmapper.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 // $Id$
4 
5 #ifndef DUNE_SCSGMAPPER_HH
6 #define DUNE_SCSGMAPPER_HH
7 
8 #include <iostream>
9 #include "mapper.hh"
10 
11 #include <dune/grid/common/grid.hh>
12 
19 namespace Dune
20 {
39  template <typename GV, int c>
41  public Mapper<typename GV::Grid,SingleCodimSingleGeomTypeMapper<GV,c> >
42  {
43  public:
44 
49 
54  SingleCodimSingleGeomTypeMapper (const GV& gridView);
55 
61  template<class EntityType>
62  int map (const EntityType& e) const;
63 
71  int map (const typename GV::template Codim<0>::Entity& e,
72  int i, unsigned int codim) const;
73 
82  int size () const;
83 
90  template<class EntityType>
91  bool contains (const EntityType& e, int& result) const;
92 
101  bool contains (const typename GV::template Codim<0>::Entity& e, int i, int cc, int& result) const;
102 
105  void update ()
106  { // nothing to do here
107  }
108 
109  private:
110  const typename GV::IndexSet& is;
111  };
112 
115  template <typename GV, int c>
117  : is(gridView.indexSet())
118  {
119  // check that grid has only a single geometry type
120  if (is.geomTypes(c).size() != 1)
121  DUNE_THROW(GridError, "mapper treats only a single codim and a single geometry type");
122  }
123 
124  template <typename GV, int c>
125  template<class EntityType>
126  inline int SingleCodimSingleGeomTypeMapper<GV,c>::map (const EntityType& e) const
127  {
128  enum { cc = EntityType::codimension };
129  dune_static_assert(cc == c, "Entity of wrong codim passed to SingleCodimSingleGeomTypeMapper");
130  return is.index(e);
131  }
132 
133  template <typename GV, int c>
134  inline int SingleCodimSingleGeomTypeMapper<GV,c>::map (const typename GV::template Codim<0>::Entity& e, int i, unsigned int codim) const
135  {
136  if (codim != c)
137  DUNE_THROW(GridError, "Id of wrong codim requested from SingleCodimSingleGeomTypeMapper");
138  return is.subIndex(e,i,codim);
139  }
140 
141  template <typename GV, int c>
143  {
144  return is.size(c);
145  }
146 
147  template <typename GV, int c>
148  template<class EntityType>
149  inline bool SingleCodimSingleGeomTypeMapper<GV,c>::contains (const EntityType& e, int& result) const
150  {
151  result = map(e);
152  return true;
153  }
154 
155  template <typename GV, int c>
156  inline bool SingleCodimSingleGeomTypeMapper<GV,c>::contains (const typename GV::template Codim<0>::Entity& e, int i, int cc, int& result) const
157  {
158  result = this->map(e,i,cc);
159  return true;
160  }
161 
180  template <typename G, int c>
181  class LeafSingleCodimSingleGeomTypeMapper : public SingleCodimSingleGeomTypeMapper<typename G::LeafGridView,c> {
182  public:
183  /* @brief The constructor
184  @param grid A reference to a grid.
185  */
187  : SingleCodimSingleGeomTypeMapper<typename G::LeafGridView,c>(grid.leafView())
188  {}
189  };
190 
204  template <typename G, int c>
205  class LevelSingleCodimSingleGeomTypeMapper : public SingleCodimSingleGeomTypeMapper<typename G::LevelGridView,c> {
206  public:
207  /* @brief The constructor
208  @param grid A reference to a grid.
209  @param level A valid level of the grid.
210  */
211  LevelSingleCodimSingleGeomTypeMapper (const G& grid, int level)
212  : SingleCodimSingleGeomTypeMapper<typename G::LevelGridView,c>(grid.levelGridView(level))
213  {}
214  };
215 
217 }
218 #endif