Dune Core Modules (2.5.0)

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 index (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
83 Index subIndex (const typename G::Traits::template Codim<0>::Entity& e, int i, int cc) const
84 {
85 IdType id = ids.subId(e,i,cc); // get id
86 typename std::map<IdType,Index>::iterator it = index_.find(id); // look up in map
87 if (it!=index_.end()) return it->second; // return index if found
88 index_[id] = n++; // put next index in map
89 return n-1; // and return it
90 }
91
100 int size () const
101 {
102 return n;
103 }
104
113 template<class EntityType>
114 bool contains (const EntityType& e, Index& result) const
115 {
116 IdType id = ids.id(e); // get id
117 typename std::map<IdType,Index>::iterator it = index_.find(id); // look up in map
118 if (it!=index_.end())
119 {
120 result = it->second;
121 return true;
122 }
123 else
124 return false;
125 }
126
135 bool contains (const typename G::Traits::template Codim<0>::Entity& e, int i, int cc, Index& result) const
136 {
137 IdType id = ids.subId(e,i,cc); // get id
138 typename std::map<IdType,Index>::iterator it = index_.find(id); // look up in map
139 if (it!=index_.end())
140 {
141 result = it->second;
142 return true;
143 }
144 else
145 return false;
146 }
147
150 void update ()
151 { // nothing to do here
152 }
153
154 // clear the mapper
155 void clear ()
156 {
157 index_.clear();
158 n = 0;
159 }
160
161 private:
162 mutable int n; // number of data elements required
163 const G& g;
164 const IDS& ids;
165 mutable std::map<IdType,Index> index_;
166 };
167
168
169
170
177 template <typename G>
178 class GlobalUniversalMapper : public UniversalMapper<G,typename G::Traits::GlobalIdSet>
179 {
180 public:
181 /* @brief The constructor
182 @param grid A reference to a grid.
183 */
184 GlobalUniversalMapper (const G& grid)
186 {}
187 };
188
195 template <typename G>
196 class LocalUniversalMapper : public UniversalMapper<G,typename G::Traits::LocalIdSet>
197 {
198 public:
203 LocalUniversalMapper (const G& grid)
204 : UniversalMapper<G,typename G::Traits::LocalIdSet>(grid,grid.localIdSet())
205 {}
206 };
207
208
210}
211#endif
Universal mapper based on global ids.
Definition: universalmapper.hh:179
Universal mapper based on local ids.
Definition: universalmapper.hh:197
LocalUniversalMapper(const G &grid)
The constructor.
Definition: universalmapper.hh:203
Mapper interface.
Definition: mapper.hh:107
Implements a mapper for an arbitrary subset of entities.
Definition: universalmapper.hh:38
bool contains(const EntityType &e, Index &result) const
Returns true if the entity is contained in the index set.
Definition: universalmapper.hh:114
Index subIndex(const typename G::Traits::template Codim< 0 >::Entity &e, int i, int cc) const
Map subentity of codim 0 entity to array index.
Definition: universalmapper.hh:83
bool contains(const typename G::Traits::template Codim< 0 >::Entity &e, int i, int cc, Index &result) const
Returns true if the entity is contained in the index set.
Definition: universalmapper.hh:135
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:65
int size() const
Return total number of entities in the entity set managed by the mapper.
Definition: universalmapper.hh:100
void update()
Recalculates map after mesh adaptation.
Definition: universalmapper.hh:150
Provides classes with basic mappers which are used to attach data to a grid.
Dune namespace.
Definition: alignment.hh:11
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 13, 23:29, 2024)