dune-fem  2.4.1-rc
nonblockmapper.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_NONBLOCKMAPPER_HH
2 #define DUNE_FEM_NONBLOCKMAPPER_HH
3 
4 #include <vector>
5 
8 
9 namespace Dune
10 {
11 
12  namespace Fem
13  {
14 
15  // Internal Forward Declarations
16  // -----------------------------
17 
18  template< class BlockMapper, int blockSize >
20 
21 
22  namespace __NonBlockMapper
23  {
24 
25  // Traits
26  // ------
27 
28  template< class BlockMapper, int bS >
29  struct Traits
30  {
32 
33  typedef BlockMapper BlockMapperType;
34  typedef typename BlockMapper::ElementType ElementType;
35  typedef typename BlockMapper::SizeType SizeType;
36  typedef typename BlockMapper::GlobalKeyType GlobalKeyType;
37 
38  static const int blockSize = bS;
39  };
40 
41 
42  // DofMapper
43  // ---------
44 
45  template< class T, template< class > class Base = Dune::Fem::DofMapper >
46  class DofMapper
47  : public Base< T >
48  {
49  typedef Base< T > BaseType;
50 
51  template< class, template< class > class >
52  friend class DofMapper;
53 
54 
55  public:
56  typedef typename BaseType::Traits Traits;
57  protected:
58 
60  static const int blockSize = Traits::blockSize;
61 
62  public:
63  typedef typename Traits::ElementType ElementType;
64  typedef typename Traits::SizeType SizeType;
66 
67  private:
68  template< class Functor >
69  struct BlockFunctor
70  {
71  explicit BlockFunctor ( Functor functor )
72  : functor_( functor )
73  {}
74 
75  template< class GlobalKey >
76  void operator() ( int localBlock, const GlobalKey globalKey )
77  {
78  int localDof = blockSize*localBlock;
79  SizeType globalDof = blockSize*globalKey;
80  const int localEnd = localDof + blockSize;
81  while( localDof != localEnd )
82  functor_( localDof++, globalDof++ );
83  }
84 
85  private:
86  Functor functor_;
87  };
88 
89  public:
90 
91  DofMapper ( BlockMapperType &blockMapper )
92  : blockMapper_( blockMapper )
93  {}
94 
95  SizeType size () const { return blockSize * blockMapper_.size(); }
96 
97  bool contains ( const int codim ) const { return blockMapper_.contains( codim ); }
98 
99  bool fixedDataSize ( int codim ) const { return blockMapper_.fixedDataSize( codim ); }
100 
101  template< class Functor >
102  void mapEach ( const ElementType &element, Functor f ) const
103  {
104  blockMapper_.mapEach( element, BlockFunctor< Functor >( f ) );
105  }
106 
107  void map ( const ElementType &element, std::vector< std::size_t > &indices ) const
108  DUNE_DEPRECATED_MSG( "This function is out dated and will be deleted in version 1.5" )
109  {
110  indices.resize( numDofs( element ) );
111  mapEach( element, AssignFunctor< std::vector< std::size_t > >( indices ) );
112  }
113 
114  template< class Entity, class Functor >
115  void mapEachEntityDof ( const Entity &entity, Functor f ) const
116  {
117  blockMapper_.mapEachEntityDof( entity, BlockFunctor< Functor >( f ) );
118  }
119 
120  int maxNumDofs () const { return blockSize * blockMapper_.maxNumDofs(); }
121 
122  SizeType numDofs ( const ElementType &element ) const { return blockSize * blockMapper_.numDofs( element ); }
123 
124  template< class Entity >
125  SizeType numEntityDofs ( const Entity &entity ) const { return blockSize * blockMapper_.numEntityDofs( entity ); }
126 
127  static constexpr bool consecutive () noexcept { return false; }
128 
129  SizeType numBlocks () const
130  {
131  DUNE_THROW( NotImplemented, "Method numBlocks() called on non-adaptive block mapper" );
132  }
133 
134  SizeType numberOfHoles ( int ) const
135  {
136  DUNE_THROW( NotImplemented, "Method numberOfHoles() called on non-adaptive block mapper" );
137  }
138 
139  GlobalKeyType oldIndex ( int hole, int ) const
140  {
141  DUNE_THROW( NotImplemented, "Method oldIndex() called on non-adaptive block mapper" );
142  }
143 
144  GlobalKeyType newIndex ( int hole, int ) const
145  {
146  DUNE_THROW( NotImplemented, "Method newIndex() called on non-adaptive block mapper" );
147  }
148 
149  SizeType oldOffSet ( int ) const
150  {
151  DUNE_THROW( NotImplemented, "Method oldOffSet() called on non-adaptive block mapper" );
152  }
153 
154  SizeType offSet ( int ) const
155  {
156  DUNE_THROW( NotImplemented, "Method offSet() called on non-adaptive block mapper" );
157  }
158 
159  protected:
160  const BlockMapperType &blockMapper () const { return blockMapper_; }
161 
162  private:
163  BlockMapperType &blockMapper_;
164  };
165 
166 
167  // AdaptiveDofMapper
168  // -----------------
169 
170  template< class T >
172  : public DofMapper< T, Dune::Fem::AdaptiveDofMapper >
173  {
175 
176  template< class >
177  friend class AdaptiveDofMapper;
178 
179  public:
180  typedef typename BaseType::Traits Traits;
181  protected:
182 
184  static const int blockSize = Traits::blockSize;
185 
186  using BaseType::blockMapper;
187 
188  public:
190  typedef typename Traits::SizeType SizeType;
192 
193  AdaptiveDofMapper ( BlockMapperType &blockMapper )
194  : BaseType( blockMapper )
195  {}
196 
197  bool consecutive () const { return blockMapper().consecutive(); }
198 
199  SizeType numBlocks () const { return blockMapper().numBlocks(); }
200 
201  SizeType numberOfHoles ( const int block ) const { return blockSize * blockMapper().numberOfHoles( block ); }
202 
203  GlobalKeyType oldIndex ( const int hole, const int block ) const
204  {
205  const int i = hole % blockSize;
206  const int blockHole = hole / blockSize;
207  return blockMapper().oldIndex( blockHole, block ) * blockSize + i;
208  }
209 
210  GlobalKeyType newIndex ( const int hole, const int block ) const
211  {
212  const int i = hole % blockSize;
213  const int blockHole = hole / blockSize;
214  return blockMapper().newIndex( blockHole, block ) * blockSize + i;
215  }
216 
217  SizeType oldOffSet ( const int block ) const { return blockMapper().oldOffSet( block ) * blockSize; }
218 
219  SizeType offSet ( const int block ) const { return blockMapper().offSet( block ) * blockSize; }
220  };
221 
222 
223  // Implementation
224  // --------------
225 
226  template< class BlockMapper, int blockSize, bool adaptive = Capabilities::isAdaptiveDofMapper< BlockMapper >::v >
228  {
230 
231  public:
232  typedef typename std::conditional< adaptive,
235  };
236 
237  } // namespace __NonBlockMapper
238 
239 
240  // NonBlockMapper
241  // --------------
242 
244  template< class BlockMapper, int blockSize >
245  class NonBlockMapper
246  : public __NonBlockMapper::template Implementation< BlockMapper, blockSize >::Type
247  {
248  typedef typename __NonBlockMapper::template Implementation< BlockMapper, blockSize >::Type BaseType;
249 
250  public:
251 
252  NonBlockMapper ( BlockMapper &blockMapper )
253  : BaseType( blockMapper )
254  {}
255  };
256 
257 
258  // NonBlockMapper for NonBlockMapper
259  // ---------------------------------
260 
261  template< class BlockMapper, int innerBlockSize, int outerBlockSize >
262  class NonBlockMapper< NonBlockMapper< BlockMapper, innerBlockSize >, outerBlockSize >
263  : public NonBlockMapper< BlockMapper, innerBlockSize *outerBlockSize >
264  {
267 
268  public:
270  : BaseType( blockMapper.blockMapper_ )
271  {}
272  };
273 
274 
275  // Capabilities
276  // ------------
277 
278  namespace Capabilities
279  {
280  template< class BlockMapper, int blockSize >
281  struct isAdaptiveDofMapper< NonBlockMapper< BlockMapper, blockSize > >
282  {
284  };
285 
286  } // namespace Capabilities
287 
288  } // namespace Fem
289 
290 } // namespace Dune
291 
292 #endif // #ifndef DUNE_FEM_NONBLOCKMAPPER_HH
Traits::SizeType SizeType
Definition: nonblockmapper.hh:190
SizeType size() const
Definition: nonblockmapper.hh:95
AdaptiveDofMapper(BlockMapperType &blockMapper)
Definition: nonblockmapper.hh:193
Traits::ElementType ElementType
Definition: nonblockmapper.hh:189
SizeType numDofs(const ElementType &element) const
Definition: nonblockmapper.hh:122
NonBlockMapper(BlockMapper &blockMapper)
Definition: nonblockmapper.hh:252
GlobalKeyType newIndex(const int hole, const int block) const
Definition: nonblockmapper.hh:210
NonBlockMapper(const NonBlockMapper< BlockMapper, innerBlockSize > &blockMapper)
Definition: nonblockmapper.hh:269
Definition: nonblockmapper.hh:46
GlobalKeyType oldIndex(const int hole, const int block) const
Definition: nonblockmapper.hh:203
NonBlockMapper< BlockMapper, bS > DofMapperType
Definition: nonblockmapper.hh:31
SizeType offSet(const int block) const
Definition: nonblockmapper.hh:219
Definition: nonblockmapper.hh:171
Definition: nonblockmapper.hh:227
Traits::GlobalKeyType GlobalKeyType
Definition: nonblockmapper.hh:191
static constexpr bool consecutive() noexcept
Definition: nonblockmapper.hh:127
Traits::GlobalKeyType GlobalKeyType
Definition: nonblockmapper.hh:65
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
BlockMapper::GlobalKeyType GlobalKeyType
Definition: nonblockmapper.hh:36
Definition: misc/functor.hh:30
Definition: nonblockmapper.hh:19
std::conditional< adaptive, AdaptiveDofMapper< Traits >, DofMapper< Traits > >::type Type
Definition: nonblockmapper.hh:234
BlockMapper::SizeType SizeType
Definition: nonblockmapper.hh:35
SizeType numBlocks() const
Definition: nonblockmapper.hh:129
void map(const ElementType &element, std::vector< std::size_t > &indices) const
Definition: nonblockmapper.hh:107
const BlockMapperType & blockMapper() const
Definition: nonblockmapper.hh:160
Definition: coordinate.hh:4
void mapEach(const ElementType &element, Functor f) const
Definition: nonblockmapper.hh:102
bool consecutive() const
Definition: nonblockmapper.hh:197
SizeType numberOfHoles(const int block) const
Definition: nonblockmapper.hh:201
DofMapper(BlockMapperType &blockMapper)
Definition: nonblockmapper.hh:91
Traits::BlockMapperType BlockMapperType
Definition: nonblockmapper.hh:183
SizeType numBlocks() const
Definition: nonblockmapper.hh:199
int maxNumDofs() const
Definition: nonblockmapper.hh:120
Traits::SizeType SizeType
Definition: nonblockmapper.hh:64
SizeType oldOffSet(int) const
Definition: nonblockmapper.hh:149
SizeType oldOffSet(const int block) const
Definition: nonblockmapper.hh:217
bool contains(const int codim) const
Definition: nonblockmapper.hh:97
SizeType numberOfHoles(int) const
Definition: nonblockmapper.hh:134
static const int blockSize
Definition: nonblockmapper.hh:38
Definition: space/mapper/capabilities.hh:21
bool fixedDataSize(int codim) const
Definition: nonblockmapper.hh:99
GlobalKeyType newIndex(int hole, int) const
Definition: nonblockmapper.hh:144
GlobalKeyType oldIndex(int hole, int) const
Definition: nonblockmapper.hh:139
Traits::BlockMapperType BlockMapperType
Definition: nonblockmapper.hh:59
SizeType numEntityDofs(const Entity &entity) const
Definition: nonblockmapper.hh:125
BlockMapper::ElementType ElementType
Definition: nonblockmapper.hh:34
BlockMapper BlockMapperType
Definition: nonblockmapper.hh:33
Traits::ElementType ElementType
Definition: nonblockmapper.hh:63
BaseType::Traits Traits
Definition: nonblockmapper.hh:180
void mapEachEntityDof(const Entity &entity, Functor f) const
Definition: nonblockmapper.hh:115
Definition: nonblockmapper.hh:29
BaseType::Traits Traits
Definition: nonblockmapper.hh:56
SizeType offSet(int) const
Definition: nonblockmapper.hh:154