dune-fem  2.4.1-rc
powermapper.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_COMBINEDSPACE_POWERMAPPER_HH
2 #define DUNE_FEM_COMBINEDSPACE_POWERMAPPER_HH
3 
4 #include <dune/common/math.hh>
5 
9 
10 namespace Dune
11 {
12 
13  namespace Fem
14  {
15  // Internal Forward Declration
16  // ---------------------------
17 
18  template< class GridPart, class Mapper, int N >
19  class PowerMapper;
20 
21 #ifndef DOXYGEN
22 
23  namespace __PowerMapper
24  {
25 
26  // Traits
27  // ------
28 
29  template< class GridPart, class Mapper, int N >
30  struct Traits
31  {
32  typedef Mapper MapperType;
33 
34  typedef GridPart GridPartType;
35 
36  typedef typename MapperType::ElementType ElementType;
37  typedef typename MapperType::SizeType SizeType;
38  typedef typename MapperType::GlobalKeyType GlobalKeyType;
39 
40  typedef PowerMapper< GridPartType, MapperType, N > DofMapperType;
41 
42  static const int numComponents = N;
43  };
44 
45 
46 
47  template< class T, template< class > class Base = Dune::Fem::DofMapper >
48  class DofMapper
49  : public Base< T >
50  {
51  typedef Base< T > BaseType;
52 
53  public:
54  typedef typename BaseType::Traits Traits;
55  typedef typename BaseType::ElementType ElementType;
56  typedef typename BaseType::SizeType SizeType;
57 
58  typedef typename Traits::GridPartType GridPartType;
59  typedef typename Traits::GlobalKeyType GlobalKeyType;
60 
61  typedef typename Traits::MapperType MapperType;
62 
63  static const int numComponents = Traits::numComponents;
64 
65  protected:
66  // funtor wrapper
67  template< class Functor >
68  struct FunctorWrapper
69  {
70  FunctorWrapper ( SizeType offset, Functor functor )
71  : offset_( offset ),
72  functor_( functor )
73  {}
74 
75  template< class GlobalKey >
76  void operator() ( int localBlock, const GlobalKey &globalKey )
77  {
78  int localDof = localBlock*numComponents;
79  for( int component = 0; component < numComponents; ++component, ++localDof )
80  functor_( localDof, globalKey + component * offset_ );
81  }
82 
83  template< class GlobalKey >
84  void operator() ( const GlobalKey &globalKey )
85  {
86  for( int component = 0; component < numComponents; ++component )
87  functor_( globalKey + component * offset_ );
88  }
89 
90  private:
91  SizeType offset_;
92  Functor functor_;
93  };
94 
95  public:
96 
97  DofMapper ( GridPartType &gridPart, MapperType &mapper )
98  : gridPart_( gridPart ),
99  mapper_( mapper ),
100  offset_( mapper_.size() )
101  {}
102 
103  SizeType size () const { return mapper().size() * numComponents; }
104 
105  bool contains ( const int codim ) const { return mapper().contains( codim ); }
106 
107  bool fixedDataSize ( const int codim ) const { return mapper().fixedDataSize( codim ); }
108 
109  template< class Functor >
110  void mapEach ( const ElementType &element, Functor f ) const
111  {
112  FunctorWrapper< Functor > wrapper( offset_, f );
113  mapper().mapEach( element, wrapper );
114  }
115 
116  template< class Entity, class Functor >
117  void mapEachEntityDof ( const Entity &entity, Functor f ) const
118  {
119  FunctorWrapper< Functor > wrapper( offset_, f );
120  mapper().mapEachEntityDof( entity, wrapper );
121  }
122 
123  int maxNumDofs () const { return mapper().maxNumDofs() * numComponents; }
124 
125  SizeType numDofs ( const ElementType &element ) const { return mapper().numDofs( element ) * numComponents; }
126 
127  template< class Entity >
128  SizeType numEntityDofs ( const Entity &entity ) const { return mapper().numEntityDofs( entity ) * numComponents; }
129 
130 
131  static constexpr bool consecutive () noexcept { return false; }
132 
133  SizeType numBlocks () const
134  {
135  DUNE_THROW( NotImplemented, "Method numBlocks() called on non-adaptive block mapper" );
136  }
137 
138  SizeType numberOfHoles ( int ) const
139  {
140  DUNE_THROW( NotImplemented, "Method numberOfHoles() called on non-adaptive block mapper" );
141  }
142 
143  GlobalKeyType oldIndex ( int hole, int ) const
144  {
145  DUNE_THROW( NotImplemented, "Method oldIndex() called on non-adaptive block mapper" );
146  }
147 
148  GlobalKeyType newIndex ( int hole, int ) const
149  {
150  DUNE_THROW( NotImplemented, "Method newIndex() called on non-adaptive block mapper" );
151  }
152 
153  SizeType oldOffSet ( int ) const
154  {
155  DUNE_THROW( NotImplemented, "Method oldOffSet() called on non-adaptive block mapper" );
156  }
157 
158  SizeType offSet ( int ) const
159  {
160  DUNE_THROW( NotImplemented, "Method offSet() called on non-adaptive block mapper" );
161  }
162 
163  protected:
164  MapperType &mapper () { return mapper_; }
165  const MapperType &mapper () const { return mapper_; }
166 
167  GridPartType &gridPart_;
168  MapperType &mapper_;
169  SizeType offset_;
170  };
171 
172 
173 
174  // AdaptiveDofMapper
175  // -----------------
176 
177  template< class T >
178  class AdaptiveDofMapper
179  : public DofMapper< T, Dune::Fem::AdaptiveDofMapper >
180  {
182 
183  public:
184  typedef typename BaseType::Traits Traits;
185  typedef typename BaseType::ElementType ElementType;
186  typedef typename BaseType::SizeType SizeType;
187 
188  typedef typename Traits::GridPartType GridPartType;
189  typedef typename Traits::GlobalKeyType GlobalKeyType;
190 
191  typedef typename Traits::MapperType MapperType;
192 
193  static const int numComponents = Traits::numComponents;
194 
195  protected:
196  using BaseType::mapper;
197  using BaseType::gridPart_;
198  using BaseType::offset_;
199 
200  public:
201 
202  AdaptiveDofMapper ( GridPartType &gridPart, MapperType &mapper )
203  : BaseType( gridPart, mapper ),
204  oldOffset_( -1 )
205  {
206  DofManager< typename GridPartType::GridType >::instance( gridPart_.grid() ).addIndexSet( *this );
207  }
208 
210  {
211  DofManager< typename GridPartType::GridType >::instance( gridPart_.grid() ).removeIndexSet( *this );
212  }
213 
214  bool consecutive () const { return true; }
215 
216  SizeType numBlocks () const { return mapper().numBlocks() * numComponents; }
217 
218  SizeType numberOfHoles ( const int block ) const { return mapper().numberOfHoles( block % mapper().numBlocks() ); }
219 
220  GlobalKeyType oldIndex ( const int hole, const int block ) const
221  {
222  const int numContainedBlocks = mapper().numBlocks();
223  const int containedBlock = block % numContainedBlocks;
224  const int component = block / numContainedBlocks;
225 
226  const int containedOffset = mapper().oldIndex( hole, containedBlock );
227  return containedOffset + component * oldOffset_;
228  }
229 
230  GlobalKeyType newIndex ( const int hole, const int block ) const
231  {
232  const int numContainedBlocks = mapper().numBlocks();
233  const int containedBlock = block % numContainedBlocks;
234  const int component = block / numContainedBlocks;
235 
236  const int containedOffset = mapper().newIndex( hole, containedBlock );
237  return containedOffset + component * offset_;
238  }
239 
240  SizeType oldOffSet ( const int block ) const
241  {
242  const int numContainedBlocks = mapper().numBlocks();
243  const int containedBlock = block % numContainedBlocks;
244  const int component = block / numContainedBlocks;
245 
246  const int containedOffset = mapper().oldOffSet( containedBlock );
247  return containedOffset + component * oldOffset_;
248  }
249 
250  SizeType offSet ( const int block ) const
251  {
252  const int numContainedBlocks = mapper().numBlocks();
253  const int containedBlock = block % numContainedBlocks;
254  const int component = block / numContainedBlocks;
255 
256  const int containedOffset = mapper().offSet( containedBlock );
257  return containedOffset + component * offset_;
258  }
259 
260  template< class Entity >
261  void insertEntity ( const Entity &entity ) { update(); }
262 
263  template< class Entity >
264  void removeEntity ( const Entity &entity ) { }
265 
266  void resize () { update(); }
267 
268  bool compress () { update(); return true; }
269 
270  template< class StreamTraits >
271  void write ( OutStreamInterface< StreamTraits > &out ) const {}
272 
273  template< class StreamTraits >
274  void read ( InStreamInterface< StreamTraits > &in )
275  {
276  update();
277  }
278 
279  void backup () const {}
280  void restore () {}
281 
282  protected:
283  void update ()
284  {
285  oldOffset_ = offset_;
286  offset_ = mapper().size();
287  }
288 
289  private:
290  SizeType oldOffset_;
291  };
292 
293 
294  // Implementation
295  // --------------
296 
297  template< class GridPart, class Mapper, int N, bool adapative = Capabilities::isAdaptiveDofMapper< Mapper >::v >
298  class Implementation
299  {
300  typedef __PowerMapper::Traits< GridPart, Mapper, N > Traits;
301 
302  public:
303  typedef typename std::conditional< adapative, AdaptiveDofMapper< Traits >, DofMapper< Traits > >::type Type;
304  };
305 
306 
307 
308  } // namespace __PowerMapper
309 
310 #endif // #ifndef DOXYGEN
311 
312 
313  // PowerMapper
314  // ----------
315 
327  template< class GridPart, class Mapper, int N >
328  class PowerMapper
329  : public __PowerMapper::template Implementation< GridPart, Mapper, N >::Type
330  {
331  typedef typename __PowerMapper::template Implementation< GridPart, Mapper, N >::Type BaseType;
332 
333  public:
334  PowerMapper ( GridPart &gridPart, Mapper &mapper )
335  : BaseType( gridPart, mapper )
336  {}
337  };
338 
339 
340  // Capabilities
341  // ------------
342 
343  namespace Capabilities
344  {
345  template< class GridPart, class Mapper, int N >
346  struct isAdaptiveDofMapper< PowerMapper< GridPart, Mapper, N > >
347  {
348  static const bool v = isAdaptiveDofMapper< Mapper >::v;
349  };
350 
351  } // namespace Capabilities
354  } // namespace Fem
355 
356 } // namespace Dune
357 
358 #endif //#ifndef DUNE_FEM_COMBINEDSPACE_POWERMAPPER_HH
PowerMapper(GridPart &gridPart, Mapper &mapper)
Definition: powermapper.hh:334
Extended interface for adaptive DoF mappers.
Definition: mapper/dofmapper.hh:204
Interface for calculating the size of a function space for a grid on a specified level. Furthermore the local to global mapping of dof number is done. Also during grid adaptation this mapper knows about old and new indices of entities.
Definition: mapper/dofmapper.hh:40
Definition: coordinate.hh:4
abstract interface for an input stream
Definition: streams.hh:177
Definition: space/mapper/capabilities.hh:21
mapper allocating one DoF per subentity of a given codimension
Definition: powermapper.hh:19
static ThisType & instance(const GridType &grid)
obtain a reference to the DofManager for a given grid
Definition: dofmanager.hh:1319
abstract interface for an output stream
Definition: streams.hh:44