dune-pdelab  2.0.0
dofindex.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 #ifndef DUNE_PDELAB_COMMON_DOFINDEX_HH
4 #define DUNE_PDELAB_COMMON_DOFINDEX_HH
5 
7 #include <dune/common/array.hh>
8 
9 namespace Dune {
10 
11  namespace PDELab {
12 
13  template<typename T, std::size_t tree_n, std::size_t entity_n = 1>
14  class DOFIndex
15  {
16 
17  public:
18 
20  static const std::size_t max_depth = tree_n;
21  static const std::size_t entity_capacity = entity_n;
22 
23  typedef array<T,entity_capacity> EntityIndex;
25 
26  typedef typename TreeIndex::size_type size_type;
27  typedef T value_type;
28 
29  class View
30  {
31 
32  friend class DOFIndex;
33 
34  public:
35 
36  static const std::size_t max_depth = tree_n;
37  static const std::size_t entity_capacity = entity_n;
38 
39  typedef const array<T,entity_n>& EntityIndex;
41 
42  const EntityIndex& entityIndex() const
43  {
44  return _entity_index_view;
45  }
46 
47  const TreeIndex& treeIndex() const
48  {
49  return _tree_index_view;
50  }
51 
52  View back_popped() const
53  {
54  return View(_entity_index_view,_tree_index_view.back_popped());
55  }
56 
57  friend std::ostream& operator<< (std::ostream& s, const View& di)
58  {
59  s << "(";
60 
61  for (typename std::remove_reference<EntityIndex>::type::const_iterator it = di._entity_index_view.begin(); it != di._entity_index_view.end(); ++it)
62  s << std::setw(4) << *it;
63 
64  s << " | "
65  << di._tree_index_view
66  << ")";
67  return s;
68  }
69 
70  std::size_t size() const
71  {
72  return _tree_index_view.size();
73  };
74 
75  private:
76 
77  explicit View(const DOFIndex& dof_index)
78  : _entity_index_view(dof_index._entity_index)
79  , _tree_index_view(dof_index._tree_index.view())
80  {}
81 
82  View(const DOFIndex& dof_index, std::size_t size)
83  : _entity_index_view(dof_index._entity_index)
84  , _tree_index_view(dof_index._tree_index.view(size))
85  {}
86 
87  View(const EntityIndex& entity_index, const TreeIndex& tree_index)
88  : _entity_index_view(entity_index)
89  , _tree_index_view(tree_index)
90  {}
91 
92  EntityIndex _entity_index_view;
93  TreeIndex _tree_index_view;
94 
95  };
96 
99  {}
100 
101  explicit DOFIndex(const View& view)
102  : _entity_index(view._entity_index_view)
103  , _tree_index(view._tree_index_view)
104  {}
105 
106  View view() const
107  {
108  return View(*this);
109  }
110 
111  View view(std::size_t size) const
112  {
113  return View(*this,size);
114  }
115 
116  void clear()
117  {
118  std::fill(_entity_index.begin(),_entity_index.end(),0);
119  _tree_index.clear();
120  }
121 
124  {
125  return _entity_index;
126  }
127 
128  const EntityIndex& entityIndex() const
129  {
130  return _entity_index;
131  }
132 
134  {
135  return _tree_index;
136  }
137 
138  const TreeIndex& treeIndex() const
139  {
140  return _tree_index;
141  }
142 
144  friend std::ostream& operator<< (std::ostream& s, const DOFIndex& di)
145  {
146  s << "(";
147 
148  for (typename EntityIndex::const_iterator it = di._entity_index.begin(); it != di._entity_index.end(); ++it)
149  s << std::setw(4) << *it;
150 
151  s << " | "
152  << di._tree_index
153  << ")";
154  return s;
155  }
156 
158 
161  bool operator== (const DOFIndex& r) const
162  {
163  return
164  std::equal(_entity_index.begin(),_entity_index.end(),r._entity_index.begin()) &&
165  _tree_index == r._tree_index;
166  }
167 
169  bool operator!= (const DOFIndex& r) const
170  {
171  return !(*this == r);
172  }
173 
174 #if 0
175  bool operator< (const DOFIndex& r) const
176  {
177  // FIXME: think about natural ordering
178  return _c.size() < _r.size();
179  return std::lexicographical_compare(_c.begin(),_c.end(),r._c.begin(),r._c.end());
180  }
181 #endif
182 
183  std::size_t size() const
184  {
185  return _tree_index.size();
186  }
187 
188  private:
189 
191  TreeIndex _tree_index;
192 
193  };
194 
195  template<typename T, std::size_t n1, std::size_t n2>
196  inline std::size_t hash_value(const DOFIndex<T,n1,n2>& di)
197  {
198  std::size_t seed = 0;
199  hash_range(seed,di.entityIndex().begin(),di.entityIndex().end());
200  hash_range(seed,di.treeIndex().begin(),di.treeIndex().end());
201  return seed;
202  }
203 
204 
205 
206  } // namespace PDELab
207 } // namespace Dune
208 
209 DUNE_DEFINE_HASH(DUNE_HASH_TEMPLATE_ARGS(typename T, std::size_t n1, std::size_t n2),DUNE_HASH_TYPE(Dune::PDELab::DOFIndex<T,n1,n2>))
210 
211 #endif // DUNE_PDELAB_COMMON_DOFINDEX_HH
T value_type
Definition: dofindex.hh:27
Definition: dofindex.hh:14
TreeIndex & treeIndex()
Definition: dofindex.hh:133
const array< T, entity_n > & EntityIndex
Definition: dofindex.hh:39
std::size_t size() const
Definition: dofindex.hh:183
bool operator==(const DOFIndex &r) const
Tests whether two MultiIndices are equal.
Definition: dofindex.hh:161
static const std::size_t max_depth
The maximum possible depth of the MultiIndex.
Definition: dofindex.hh:20
View back_popped() const
Definition: dofindex.hh:52
friend std::ostream & operator<<(std::ostream &s, const DOFIndex &di)
Writes a pretty representation of the MultiIndex to the given std::ostream.
Definition: dofindex.hh:144
const EntityIndex & _entity_index
Definition: datahandleprovider.hh:47
static const std::size_t entity_capacity
Definition: dofindex.hh:21
const EntityIndex & entityIndex() const
Definition: dofindex.hh:42
Definition: dofindex.hh:29
friend std::ostream & operator<<(std::ostream &s, const View &di)
Definition: dofindex.hh:57
static const std::size_t max_depth
Definition: dofindex.hh:36
array< T, entity_capacity > EntityIndex
Definition: dofindex.hh:23
const TreeIndex & treeIndex() const
Definition: dofindex.hh:47
DOFIndex()
Default constructor.
Definition: dofindex.hh:98
const TreeIndex & treeIndex() const
Definition: dofindex.hh:138
bool operator!=(const DOFIndex &r) const
Tests whether two MultiIndices are not equal.
Definition: dofindex.hh:169
const EntityIndex & entityIndex() const
Definition: dofindex.hh:128
EntityIndex & entityIndex()
Returns the index of the grid entity associated with the DOF.
Definition: dofindex.hh:123
TreeIndex::size_type size_type
Definition: dofindex.hh:26
static const std::size_t entity_capacity
Definition: dofindex.hh:37
void clear()
Definition: dofindex.hh:116
DOFIndex(const View &view)
Definition: dofindex.hh:101
View view(std::size_t size) const
Definition: dofindex.hh:111
std::size_t hash_value(const DOFIndex< T, n1, n2 > &di)
Definition: dofindex.hh:196
std::size_t size() const
Definition: dofindex.hh:70
MultiIndex< T, max_depth > TreeIndex
Definition: dofindex.hh:24
const std::string s
Definition: function.hh:1103
MultiIndex< T, tree_n >::View TreeIndex
Definition: dofindex.hh:40
View view() const
Definition: dofindex.hh:106