dune-fem 2.8.0
Loading...
Searching...
No Matches
codimensionmapper.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_SPACE_MAPPER_CODIMENSIONMAPPER_HH
2#define DUNE_FEM_SPACE_MAPPER_CODIMENSIONMAPPER_HH
3
4#include <cassert>
5
6#include <algorithm>
7#include <type_traits>
8
9#include <dune/common/exceptions.hh>
10
11#include <dune/geometry/referenceelements.hh>
12#include <dune/geometry/type.hh>
13
18
19namespace Dune
20{
21
22 namespace Fem
23 {
24
25 // Internal forward declaration
26 // ----------------------------
27
28 template< class GridPart, int codim >
29 class CodimensionMapper;
30
31
32
33#ifndef DOXYGEN
34
35 namespace __CodimensionMapper
36 {
37
38 // Traits
39 // ------
40
41 template< class GridPart, int codim >
42 struct Traits
43 {
44 typedef CodimensionMapper< GridPart, codim > DofMapperType;
45
46 static const int codimension = codim;
47
48 typedef GridPart GridPartType;
49 typedef typename GridPartType::IndexSetType IndexSetType;
50
51 typedef typename GridPartType::template Codim< 0 >::EntityType ElementType;
52 //typedef typename IndexSetType::IndexType SizeType;
53 typedef std::size_t SizeType;
54 typedef SizeType GlobalKeyType;
55 };
56
57
58
59 // DofMapper
60 // ---------
61
62 template< class T, template< class > class Base = Dune::Fem::DofMapper >
63 class DofMapper
64 : public Base< T >
65 {
66 typedef Base< T > BaseType;
67
68 public:
69 typedef typename BaseType::Traits Traits;
70
71 static const int codimension = Traits::codimension;
72
73 typedef typename Traits::GridPartType GridPartType;
74 typedef typename Traits::IndexSetType IndexSetType;
75
76 typedef typename BaseType::ElementType ElementType;
77 typedef typename BaseType::SizeType SizeType;
78 typedef typename Traits::GlobalKeyType GlobalKeyType;
79
80 explicit DofMapper ( const GridPartType &gridPart )
81 : DofMapper( gridPart.indexSet() )
82 {}
83
84 explicit DofMapper ( const IndexSetType &indexSet )
85 : indexSet_( indexSet ),
86 extension_( 0 ),
87 maxNumDofs_( 0 )
88 {
89 AllGeomTypes< IndexSetType, typename GridPartType::GridType > types( indexSet );
90 for( GeometryType type : types.geomTypes( 0 ) )
91 maxNumDofs_ = std::max( maxNumDofs_, referenceElement( type ).size( codimension ) );
92
93 // submit codimension request to index set to enable support
94 std::vector< int > codimensions( 1, int(Traits::codimension) );
95 indexSet_.requestCodimensions( codimensions );
96 }
97
98 /* \name DofMapper interface methods
99 * \{
100 */
101
102 SizeType size () const
103 {
104 return indexSet().size( codimension ) + extension_;
105 }
106
107 static constexpr bool contains ( int codim ) noexcept
108 {
109 return codim == codimension;
110 }
111
112 static constexpr bool fixedDataSize ( int codim ) noexcept
113 {
114 return true;
115 }
116
117 template< class Function >
118 void mapEach ( const ElementType &element, Function function ) const
119 {
120 if( codimension == 0 )
121 function( 0, indexSet().index( element ) );
122 else
123 {
124 const SizeType numDofs = this->numDofs( element );
125 for( SizeType i = 0; i < numDofs; ++i )
126 function( i, indexSet().subIndex( element, i, codimension ) );
127 }
128 }
129
130 void map ( const ElementType &element, std::vector< GlobalKeyType > &indices ) const
131 {
132 indices.resize( numDofs( element ) );
133 mapEach( element, [ &indices ] ( int local, GlobalKeyType global ) { indices[ local ] = global; } );
134 }
135
136 template< class Entity >
137 void mapEntityDofs ( const Entity &entity, std::vector< GlobalKeyType > &indices ) const
138 {
139 indices.resize( numEntityDofs( entity ) );
140 mapEachEntityDof( entity, AssignFunctor< std::vector< GlobalKeyType > >( indices ) );
141 }
142
143 template< class Entity, class Function >
144 void mapEachEntityDof ( const Entity &entity, Function function ) const
145 {
146 assert( Entity::codimension == codimension );
147 function( 0, indexSet().index( entity ) );
148 }
149
150 int maxNumDofs () const { return maxNumDofs_; }
151
152 SizeType numDofs ( const ElementType &element ) const
153 {
154 return element.subEntities( codimension );
155 }
156
157 template< class Entity >
158 static constexpr SizeType numEntityDofs ( const Entity &entity ) noexcept
159 {
160 return contains( Entity::codimension ) ? 1 : 0;
161 }
162
163 void update () {}
164
165 void extendSize( const SizeType extension )
166 {
167 extension_ = extension;
168 }
169
170 void onSubEntity ( const ElementType &element, int i, int c, std::vector< bool > &indices ) const
171 {
172 indices.resize( numDofs(element) );
173 std::fill(indices.begin(),indices.end(),false);
174 indices[i] = true;
175 }
176
177 /* \} */
178
179 /* \name AdaptiveDofMapper interface methods
180 * \{
181 */
182
183 /* Compatibility methods; users expect an AdaptiveDiscreteFunction to
184 * compile over spaces built on top of a LeafGridPart or LevelGridPart.
185 *
186 * The AdaptiveDiscreteFunction requires the block mapper (i.e. this
187 * type) to be adaptive. The CodimensionMapper however is truly
188 * adaptive if and only if the underlying index set is adaptive. We
189 * don't want to wrap the index set as 1) it hides the actual problem
190 * (don't use the AdaptiveDiscreteFunction with non-adaptive index
191 * sets), and 2) other dune-fem classes may make correct use of the
192 * index set's capabilities.
193 */
194
195 static constexpr bool consecutive () noexcept { return false; }
196
197 SizeType numBlocks () const
198 {
199 DUNE_THROW( NotImplemented, "Method numBlocks() called on non-adaptive block mapper" );
200 }
201
202 SizeType numberOfHoles ( int ) const
203 {
204 DUNE_THROW( NotImplemented, "Method numberOfHoles() called on non-adaptive block mapper" );
205 }
206
207 GlobalKeyType oldIndex ( int hole, int ) const
208 {
209 DUNE_THROW( NotImplemented, "Method oldIndex() called on non-adaptive block mapper" );
210 }
211
212 GlobalKeyType newIndex ( int hole, int ) const
213 {
214 DUNE_THROW( NotImplemented, "Method newIndex() called on non-adaptive block mapper" );
215 }
216
217 SizeType oldOffSet ( int ) const
218 {
219 DUNE_THROW( NotImplemented, "Method oldOffSet() called on non-adaptive block mapper" );
220 }
221
222 SizeType offSet ( int ) const
223 {
224 DUNE_THROW( NotImplemented, "Method offSet() called on non-adaptive block mapper" );
225 }
226
227 /* \} */
228
229 protected:
230 const IndexSetType &indexSet () const { return indexSet_; }
231
232 private:
233 static auto referenceElement ( GeometryType type )
234 -> decltype( ReferenceElements< typename GridPartType::ctype, GridPartType::dimension >::general( type ) )
235 {
236 return ReferenceElements< typename GridPartType::ctype, GridPartType::dimension >::general( type );
237 }
238
239 const IndexSetType &indexSet_;
240 SizeType extension_;
241 int maxNumDofs_;
242 };
243
244
245
246 // AdaptiveDofMapper
247 // -----------------
248
249 template< class Traits >
250 class AdaptiveDofMapper
251 : public DofMapper< Traits, Dune::Fem::AdaptiveDofMapper >
252 {
253 typedef DofMapper< Traits, Dune::Fem::AdaptiveDofMapper > BaseType;
254
255 public:
256 static const int codimension = BaseType::codimension;
257
258 typedef typename BaseType::SizeType SizeType;
259 typedef typename BaseType::GlobalKeyType GlobalKeyType;
260
261 protected:
262 using BaseType::indexSet;
263
264 public:
265 explicit AdaptiveDofMapper ( const typename BaseType::GridPartType &gridPart )
266 : BaseType( gridPart )
267 {}
268
269 explicit AdaptiveDofMapper ( const typename BaseType::IndexSetType &indexSet )
270 : BaseType( indexSet )
271 {}
272
273 static constexpr bool consecutive () noexcept { return true; }
274
275 static constexpr SizeType numBlocks () noexcept
276 {
277 return 1;
278 }
279
280 SizeType numberOfHoles ( int ) const
281 {
282 return indexSet().numberOfHoles( codimension );
283 }
284
285 GlobalKeyType oldIndex ( int hole, int ) const
286 {
287 return indexSet().oldIndex( hole, codimension );
288 }
289
290 GlobalKeyType newIndex ( int hole, int ) const
291 {
292 return indexSet().newIndex( hole, codimension );
293 }
294
295 static constexpr SizeType oldOffSet ( int ) noexcept
296 {
297 return 0;
298 }
299
300 static constexpr SizeType offSet ( int ) noexcept
301 {
302 return 0;
303 }
304 };
305
306
307
308 // Implementation
309 // --------------
310
311 template< class GridPart, int codim,
312 bool adaptive = Capabilities::isAdaptiveIndexSet< typename GridPart::IndexSetType >::v >
313 class Implementation
314 {
315 typedef __CodimensionMapper::Traits< GridPart, codim > Traits;
316
317 public:
318 typedef typename std::conditional< adaptive,
319 AdaptiveDofMapper< Traits >,
320 DofMapper< Traits >
321 >::type Type;
322 };
323
324 } // namespace __CodimensionMapper
325
326#endif // #ifndef DOXYGEN
327
328
329
330 // CodimensionMapper
331 // -----------------
332
342 template< class GridPart, int codim >
344 : public __CodimensionMapper::template Implementation< GridPart, codim >::Type
345 {
346 typedef typename __CodimensionMapper::template Implementation< GridPart, codim >::Type BaseType;
347
348 public:
349 explicit CodimensionMapper ( const typename BaseType::GridPartType &gridPart )
350 : BaseType( gridPart )
351 {}
352
353 explicit CodimensionMapper ( const typename BaseType::IndexSetType *indexSet )
354 : BaseType( *indexSet )
355 {}
356
357 explicit CodimensionMapper ( const typename BaseType::IndexSetType &indexSet )
358 : BaseType( indexSet )
359 {}
360 };
361
362
363 // Capabilities
364 // ------------
365
366 namespace Capabilities
367 {
368 // isAdaptiveDofMapper
369 // -------------------
370
371 template< class GridPart, int codim >
372 struct isAdaptiveDofMapper< CodimensionMapper< GridPart, codim > >
373 {
375 };
376
377
378 // isConsecutiveIndexSet
379 // ---------------------
380
381 template< class GridPart, int codim >
382 struct isConsecutiveIndexSet< __CodimensionMapper::AdaptiveDofMapper< __CodimensionMapper::Traits< GridPart, codim > > >
383 {
384 static const bool v = true;
385 };
386
387 } // namespace Capabilities
388
389 } // namespace Fem
390
391} // namespace Dune
392
393#endif // #ifndef DUNE_FEM_SPACE_MAPPER_CODIMENSIONMAPPER_HH
double max(const Dune::Fem::Double &v, const double p)
Definition: double.hh:965
Definition: bindguard.hh:11
specialize with true if index set implements the interface for consecutive index sets
Definition: common/indexset.hh:42
static const bool v
Definition: common/indexset.hh:49
specialize with true if index set implements the interface for adaptive index sets
Definition: common/indexset.hh:64
Definition: space/mapper/capabilities.hh:22
static const bool v
Definition: space/mapper/capabilities.hh:23
mapper allocating one DoF per subentity of a given codimension
Definition: codimensionmapper.hh:345
CodimensionMapper(const typename BaseType::IndexSetType &indexSet)
Definition: codimensionmapper.hh:357
CodimensionMapper(const typename BaseType::IndexSetType *indexSet)
Definition: codimensionmapper.hh:353
CodimensionMapper(const typename BaseType::GridPartType &gridPart)
Definition: codimensionmapper.hh:349
Interface for calculating the size of a function space for a grid on a specified level....
Definition: mapper/dofmapper.hh:43
Extended interface for adaptive DoF mappers.
Definition: mapper/dofmapper.hh:219