Dune Core Modules (2.4.1)

universalmapper.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_GRID_COMMON_UNIVERSALMAPPER_HH
4#define DUNE_GRID_COMMON_UNIVERSALMAPPER_HH
5
6#include <iostream>
7#include <map>
8#include "mapper.hh"
9
16namespace Dune
17{
35 template <typename G, typename IDS, typename IndexType=int>
37 public Mapper<G,UniversalMapper<G,IDS> >
38 {
39 typedef typename IDS::IdType IdType;
40 public:
41
43 typedef IndexType Index;
44
51 UniversalMapper (const G& grid, const IDS& idset)
52 : g(grid), ids(idset), index_()
53 {
54 n=0; // zero data elements
55 }
56
64 template<class EntityType>
65 Index DUNE_DEPRECATED_MSG("Will be removed after dune-grid-2.4. Use method 'index' instead!") map (const EntityType& e) const
66 {
67 IdType id = ids.id(e); // get id
68 typename std::map<IdType,Index>::iterator it = index_.find(id); // look up in map
69 if (it!=index_.end()) return it->second; // return index if found
70 index_[id] = n++; // put next index in map
71 return n-1; // and return it
72 }
73
81 template<class EntityType>
82 Index index (const EntityType& e) const
83 {
84 IdType id = ids.id(e); // get id
85 typename std::map<IdType,Index>::iterator it = index_.find(id); // look up in map
86 if (it!=index_.end()) return it->second; // return index if found
87 index_[id] = n++; // put next index in map
88 return n-1; // and return it
89 }
90
91
101 Index DUNE_DEPRECATED_MSG("Will be removed after dune-grid-2.4. Use method 'subIndex' instead!") map (const typename G::Traits::template Codim<0>::Entity& e, int i, int cc) const
102 {
103 IdType id = ids.subId(e,i,cc); // get id
104 typename std::map<IdType,Index>::iterator it = index_.find(id); // look up in map
105 if (it!=index_.end()) return it->second; // return index if found
106 index_[id] = n++; // put next index in map
107 return n-1; // and return it
108 }
109
119 Index subIndex (const typename G::Traits::template Codim<0>::Entity& e, int i, int cc) const
120 {
121 IdType id = ids.subId(e,i,cc); // get id
122 typename std::map<IdType,Index>::iterator it = index_.find(id); // look up in map
123 if (it!=index_.end()) return it->second; // return index if found
124 index_[id] = n++; // put next index in map
125 return n-1; // and return it
126 }
127
136 int size () const
137 {
138 return n;
139 }
140
149 template<class EntityType>
150 bool contains (const EntityType& e, Index& result) const
151 {
152 IdType id = ids.id(e); // get id
153 typename std::map<IdType,Index>::iterator it = index_.find(id); // look up in map
154 if (it!=index_.end())
155 {
156 result = it->second;
157 return true;
158 }
159 else
160 return false;
161 }
162
171 bool contains (const typename G::Traits::template Codim<0>::Entity& e, int i, int cc, Index& result) const
172 {
173 IdType id = ids.subId(e,i,cc); // get id
174 typename std::map<IdType,Index>::iterator it = index_.find(id); // look up in map
175 if (it!=index_.end())
176 {
177 result = it->second;
178 return true;
179 }
180 else
181 return false;
182 }
183
186 void update ()
187 { // nothing to do here
188 }
189
190 // clear the mapper
191 void clear ()
192 {
193 index_.clear();
194 n = 0;
195 }
196
197 private:
198 mutable int n; // number of data elements required
199 const G& g;
200 const IDS& ids;
201 mutable std::map<IdType,Index> index_;
202 };
203
204
205
206
213 template <typename G>
214 class GlobalUniversalMapper : public UniversalMapper<G,typename G::Traits::GlobalIdSet>
215 {
216 public:
217 /* @brief The constructor
218 @param grid A reference to a grid.
219 */
220 GlobalUniversalMapper (const G& grid)
222 {}
223 };
224
231 template <typename G>
232 class LocalUniversalMapper : public UniversalMapper<G,typename G::Traits::LocalIdSet>
233 {
234 public:
239 LocalUniversalMapper (const G& grid)
240 : UniversalMapper<G,typename G::Traits::LocalIdSet>(grid,grid.localIdSet())
241 {}
242 };
243
244
246}
247#endif
Wrapper class for entities.
Definition: entity.hh:62
Universal mapper based on global ids.
Definition: universalmapper.hh:215
Universal mapper based on local ids.
Definition: universalmapper.hh:233
LocalUniversalMapper(const G &grid)
The constructor.
Definition: universalmapper.hh:239
Mapper interface.
Definition: mapper.hh:108
Implements a mapper for an arbitrary subset of entities.
Definition: universalmapper.hh:38
UniversalMapper(const G &grid, const IDS &idset)
Construct mapper from grid and one of its id sets.
Definition: universalmapper.hh:51
IndexType Index
Number type used for indices.
Definition: universalmapper.hh:43
Index index(const EntityType &e) const
Map entity to array index.
Definition: universalmapper.hh:82
Index DUNE_DEPRECATED_MSG("Will be removed after dune-grid-2.4. Use method 'subIndex' instead!") map(const typename G
Map subentity of codim 0 entity to array index.
Definition: universalmapper.hh:101
Index DUNE_DEPRECATED_MSG("Will be removed after dune-grid-2.4. Use method 'index' instead!") map(const EntityType &e) const
Map entity to array index.
Definition: universalmapper.hh:65
Provides classes with basic mappers which are used to attach data to a grid.
Dune namespace.
Definition: alignment.hh:10
Static tag representing a codimension.
Definition: dimension.hh:22
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)