~ubuntu-branches/ubuntu/utopic/dune-grid/utopic-proposed

« back to all changes in this revision

Viewing changes to dune/grid/yaspgrid/yaspgridindexsets.hh

  • Committer: Package Import Robot
  • Author(s): Ansgar Burchardt
  • Date: 2014-02-14 10:49:16 UTC
  • mfrom: (1.3.1) (5.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20140214104916-2clchnny3eu7ks4w
Tags: 2.3.0-2
InstallĀ /usr/share/dune-grid.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 
2
// vi: set et ts=4 sw=2 sts=2:
 
3
#ifndef DUNE_GRID_YASPGRIDINDEXSET_HH
 
4
#define DUNE_GRID_YASPGRIDINDEXSET_HH
 
5
 
 
6
/** \file
 
7
 *
 
8
   \brief level-wise, non-persistent, consecutive indices for YaspGrid
 
9
 
 
10
 */
 
11
 
 
12
namespace Dune {
 
13
 
 
14
  /** \brief Implementation of Level- and LeafIndexSets for YaspGrid
 
15
   *
 
16
   * \tparam GridImp The YaspGrid class we are an index set for
 
17
   * \tparam isLeafIndexSet false: class functions as level index set,
 
18
   *         true: class functions as leaf index set
 
19
   */
 
20
  template<class GridImp, bool isLeafIndexSet>
 
21
  class YaspIndexSet
 
22
    : public IndexSet< GridImp, YaspIndexSet< GridImp, isLeafIndexSet >, unsigned int >
 
23
  {
 
24
    typedef YaspIndexSet< GridImp, isLeafIndexSet > This;
 
25
    typedef IndexSet< GridImp, This, unsigned int > Base;
 
26
 
 
27
  public:
 
28
    typedef typename Base::IndexType IndexType;
 
29
 
 
30
    using Base::subIndex;
 
31
 
 
32
    /** \brief Level grid view constructor stores reference to a grid and level */
 
33
    YaspIndexSet ( const GridImp &g, int l )
 
34
      : grid( g ),
 
35
        level( l )
 
36
    {
 
37
      assert(not isLeafIndexSet);
 
38
 
 
39
      // contains a single element type;
 
40
      for (int codim=0; codim<=GridImp::dimension; codim++)
 
41
        mytypes[codim].push_back(GeometryType(GeometryType::cube,GridImp::dimension-codim));
 
42
    }
 
43
 
 
44
    /** \brief Level grid view constructor stores reference to a grid and level */
 
45
    YaspIndexSet ( const GridImp &g )
 
46
      : grid( g )
 
47
    {
 
48
      assert(isLeafIndexSet);
 
49
 
 
50
      // contains a single element type;
 
51
      for (int codim=0; codim<=GridImp::dimension; codim++)
 
52
        mytypes[codim].push_back(GeometryType(GeometryType::cube,GridImp::dimension-codim));
 
53
    }
 
54
 
 
55
    //! get index of an entity
 
56
    template<int cc>
 
57
    IndexType index (const typename remove_const<GridImp>::type::Traits::template Codim<cc>::Entity& e) const
 
58
    {
 
59
      assert( cc == 0 || cc == GridImp::dimension );
 
60
      return grid.getRealImplementation(e).compressedIndex();
 
61
    }
 
62
 
 
63
    //! get index of subentity of an entity
 
64
    template< int cc >
 
65
    IndexType subIndex ( const typename remove_const< GridImp >::type::Traits::template Codim< cc >::Entity &e,
 
66
                         int i, unsigned int codim ) const
 
67
    {
 
68
      assert( cc == 0 || cc == GridImp::dimension );
 
69
      if( cc == GridImp::dimension )
 
70
        return grid.getRealImplementation(e).compressedIndex();
 
71
      else
 
72
        return grid.getRealImplementation(e).subCompressedIndex(i,codim);
 
73
    }
 
74
 
 
75
    //! get number of entities of given type and level (the level is known to the object)
 
76
    int size (GeometryType type) const
 
77
    {
 
78
      return (isLeafIndexSet)
 
79
        ? grid.size( type )
 
80
        : grid.size( level, type );
 
81
    }
 
82
 
 
83
    //! return size of set for a given codim
 
84
    int size (int codim) const
 
85
    {
 
86
      return (isLeafIndexSet)
 
87
        ? grid.size( codim )
 
88
        : grid.size( level, codim );
 
89
    }
 
90
 
 
91
    //! return true if the given entity is contained in \f$E\f$.
 
92
    template<class EntityType>
 
93
    bool contains (const EntityType& e) const
 
94
    {
 
95
      return (isLeafIndexSet)
 
96
        ? e.level() == grid.maxLevel()
 
97
        : e.level() == level;
 
98
    }
 
99
 
 
100
    //! deliver all geometry types used in this grid
 
101
    const std::vector<GeometryType>& geomTypes (int codim) const
 
102
    {
 
103
      return mytypes[codim];
 
104
    }
 
105
 
 
106
  private:
 
107
    const GridImp& grid;
 
108
    int level;
 
109
    std::vector<GeometryType> mytypes[remove_const<GridImp>::type::dimension+1];
 
110
  };
 
111
 
 
112
}   // namespace Dune
 
113
 
 
114
#endif  // DUNE_GRID_YASPGRIDINDEXSET_HH