DUNE-FEM (unstable)

indexsetdofmapper.hh
1#ifndef DUNE_FEM_DOFMAPPER_INDEXSETDOFMAPPER_HH
2#define DUNE_FEM_DOFMAPPER_INDEXSETDOFMAPPER_HH
3
4#include <cassert>
5
6#include <type_traits>
7#include <utility>
8
9#include <dune/geometry/referenceelements.hh>
10#include <dune/geometry/type.hh>
12
13#include <dune/fem/gridpart/common/gridpart.hh>
14#include <dune/fem/gridpart/common/indexset.hh>
15#include <dune/fem/misc/functor.hh>
16#include <dune/fem/space/common/dofmanager.hh>
17#include <dune/fem/space/mapper/code.hh>
18#include <dune/fem/space/mapper/exceptions.hh>
19#include <dune/fem/space/mapper/dofmapper.hh>
20
21// save diagnostic state
22#pragma GCC diagnostic push
23// turn off the specific warning, caused by code in line 419.
24#pragma GCC diagnostic ignored "-Wattributes"
25
26namespace Dune
27{
28
29 namespace Fem
30 {
31
32 // DefaultLocalDofMapping
33 // ----------------------
34
35 template< class GridPart >
36 class DefaultLocalDofMapping
37 {
38 struct Mapping
39 {
40 template< class Iterator, class Functor >
41 void operator() ( std::size_t index, unsigned int numDofs, Iterator begin, Iterator end, Functor functor ) const
42 {
43 while( begin != end )
44 functor( *(begin++), index++ );
45 }
46 };
47
48 public:
49 DefaultLocalDofMapping () {}
50 DefaultLocalDofMapping ( const GridPart & ) {}
51
52 Mapping operator() ( const typename GridPart::template Codim< 0 >::EntityType &element, unsigned int subEntity, unsigned int codim ) const { return {}; }
53 };
54
55
56
57 namespace __IndexSetDofMapper
58 {
59
60 // DofMapperBase
61 // -------------
62
63 template< class GridPart, class LocalDofMapping >
64 class DofMapperBase
65 {
66 typedef DofMapperBase< GridPart, LocalDofMapping > ThisType;
67
68 public:
69 typedef std::size_t SizeType;
70
71 protected:
72 struct SubEntityInfo
73 {
74 SubEntityInfo ()
75 : numDofs( 0 )
76 {}
77
78 unsigned int codim;
79 unsigned int numDofs;
80 SizeType offset, oldOffset;
81 };
82
83 enum CodimType { CodimEmpty, CodimFixedSize, CodimVariableSize };
84 static const int dimension = GridPart::dimension;
86 typedef typename RefElementsType::ReferenceElement RefElementType;
87
88 struct BuildFunctor;
89
90 struct SubEntityFilter
91 {
92 SubEntityFilter(const RefElementType &refElement, int subEntity, int codim)
93 : active_(dimension+1), size_(0)
94 {
95 for (int c=0;c<=dimension;++c)
96 {
97 std::vector<bool> &a = active_[c];
98 a.resize( refElement.size( c ), false );
99 if (c<codim) continue;
100 if (c==codim) { a[subEntity]=true; ++size_; continue; }
101 for (int i=0;i<refElement.size(subEntity, codim, c);++i)
102 {
103 a[refElement.subEntity(subEntity, codim, i, c)] = true;
104 ++size_;
105 }
106 }
107 }
108 bool operator()(int i,int c) const { return active_[c][i]; }
109 private:
110 std::vector< std::vector< bool > > active_;
111 int size_;
112 };
113
114 template< class Functor >
115 struct MapFunctor;
116
117 public:
118 typedef SizeType GlobalKeyType;
119
120 typedef GridPart GridPartType;
121 typedef LocalDofMapping LocalDofMappingType;
122 typedef typename GridPart::GridType GridType;
123
124 typedef typename GridPartType::template Codim< 0 >::EntityType ElementType;
125
126 template< class CodeFactory >
127 DofMapperBase ( const GridPartType &gridPart, LocalDofMappingType localDofMapping, const CodeFactory &codeFactory );
128
129 // mapping for DoFs
150 template< class Functor >
151 void mapEach ( const ElementType &element, Functor f ) const;
152
153 void map ( const ElementType &element, std::vector< GlobalKeyType > &indices ) const;
154
155 [[deprecated("Use onSubEntity method with char vector instead")]]
156 void onSubEntity ( const ElementType &element, int i, int c, std::vector< bool > &indices ) const
157 {
158 std::vector< char > _idx;
159 onSubEntity(element, i, c, _idx);
160 indices.resize( _idx.size() );
161 for (std::size_t i=0; i<_idx.size();++i)
162 _idx[i] = indices[i] > 0;
163 }
180 void onSubEntity( const ElementType &element, int i, int c, std::vector< char > &indices ) const;
181
182 unsigned int maxNumDofs () const { return maxNumDofs_; }
183 unsigned int numDofs ( const ElementType &element ) const { return code( element ).numDofs(); }
184
185 // assignment of DoFs to entities
186 template< class Entity, class Functor >
187 void mapEachEntityDof ( const Entity &entity, Functor f ) const;
188
189 template< class Entity >
190 void mapEntityDofs ( const Entity &entity, std::vector< GlobalKeyType > &indices ) const;
191
192 template< class Entity >
193 unsigned int numEntityDofs ( const Entity &entity ) const;
194
195 // global information
196
197 bool contains ( int codim ) const { return (codimType_[ codim ] != CodimEmpty); }
198
199 bool fixedDataSize ( int codim ) const { return (codimType_[ codim ] == CodimFixedSize); }
200
201 SizeType size () const { return size_; }
202
204 void update ();
205
206 /* \name AdaptiveDofMapper interface methods
207 * \{
208 */
209
210 /* Compatibility methods; users expect an AdaptiveDiscreteFunction to
211 * compile over spaces built on top of a LeafGridPart or LevelGridPart.
212 *
213 * The AdaptiveDiscreteFunction requires the block mapper (i.e. this
214 * type) to be adaptive. The CodimensionMapper however is truly
215 * adaptive if and only if the underlying index set is adaptive. We
216 * don't want to wrap the index set as 1) it hides the actual problem
217 * (don't use the AdaptiveDiscreteFunction with non-adaptive index
218 * sets), and 2) other dune-fem classes may make correct use of the
219 * index set's capabilities.
220 */
221
222 static constexpr bool consecutive () noexcept { return false; }
223
224 SizeType numBlocks () const
225 {
226 DUNE_THROW( NotImplemented, "Method numBlocks() called on non-adaptive block mapper" );
227 }
228
229 SizeType numberOfHoles ( int ) const
230 {
231 DUNE_THROW( NotImplemented, "Method numberOfHoles() called on non-adaptive block mapper" );
232 }
233
234 GlobalKeyType oldIndex ( int hole, int ) const
235 {
236 DUNE_THROW( NotImplemented, "Method oldIndex() called on non-adaptive block mapper" );
237 }
238
239 GlobalKeyType newIndex ( int hole, int ) const
240 {
241 DUNE_THROW( NotImplemented, "Method newIndex() called on non-adaptive block mapper" );
242 }
243
244 SizeType oldOffSet ( int ) const
245 {
246 DUNE_THROW( NotImplemented, "Method oldOffSet() called on non-adaptive block mapper" );
247 }
248
249 SizeType offSet ( int ) const
250 {
251 DUNE_THROW( NotImplemented, "Method offSet() called on non-adaptive block mapper" );
252 }
253
254 template< class Entity >
255 void insertEntity ( const Entity &entity )
256 {
257 DUNE_THROW( NotImplemented, "Method insertEntity(entity) called on non-adaptive block mapper" );
258 }
259 template< class Entity >
260 void removeEntity ( const Entity &entity )
261 {
262 DUNE_THROW( NotImplemented, "Method removeEntity(entity) called on non-adaptive block mapper" );
263 }
264
265 void resize () { update(); }
266 bool compress () { update(); return true;}
267 void backup () const {}
268 void restore () {}
269 template <class StreamTraits>
270 void write( OutStreamInterface< StreamTraits >& out ) const {}
271 template <class StreamTraits>
272 void read( InStreamInterface< StreamTraits >& in ) { update(); }
273
274 /* \} */
275
276 protected:
278 void requestCodimensions ();
279
280 typedef typename GridPartType::IndexSetType IndexSetType;
281 typedef std::vector< GeometryType > BlockMapType;
282
283 const DofMapperCode &code ( const GeometryType &gt ) const;
284 const DofMapperCode &code ( const ElementType &element ) const { return code( element.type() ); }
285
286 template< class Entity >
287 const SubEntityInfo &subEntityInfo ( const Entity &entity ) const;
288
289 const IndexSetType &indexSet () const { return indexSet_; }
290
291 const IndexSetType &indexSet_;
292 LocalDofMapping localDofMapping_;
293 std::vector< DofMapperCode > code_;
294 unsigned int maxNumDofs_;
295 SizeType size_;
296 std::vector< SubEntityInfo > subEntityInfo_;
297 BlockMapType blockMap_;
298 CodimType codimType_[ dimension+1 ];
299 };
300
301
302
303 // DofMapper::BuildFunctor
304 // -----------------------
305
306 template< class GridPart, class LocalDofMapping >
307 struct DofMapperBase< GridPart, LocalDofMapping >::BuildFunctor
308 {
309 explicit BuildFunctor ( std::vector< SubEntityInfo > &subEntityInfo )
310 : subEntityInfo_( subEntityInfo )
311 {}
312
313 template< class Iterator >
314 void operator() ( unsigned int gtIndex, unsigned int subEntity, Iterator it, Iterator end )
315 {
316 SubEntityInfo &info = subEntityInfo_[ gtIndex ];
317 const unsigned int numDofs = end - it;
318 if( info.numDofs == 0 )
319 info.numDofs = numDofs;
320 else if( info.numDofs != numDofs )
321 DUNE_THROW( DofMapperError, "Inconsistent number of DoFs on subEntity (codim = " << info.codim << ")." );
322 }
323
324 private:
325 std::vector< SubEntityInfo > &subEntityInfo_;
326 };
327
328
329
330
331 // Implementation of DofMapper
332 // ---------------------------
333
334 template< class GridPart, class LocalDofMapping >
335 const int DofMapperBase< GridPart, LocalDofMapping >::dimension;
336
337 template< class GridPart, class LocalDofMapping >
338 template< class CodeFactory >
339 inline DofMapperBase< GridPart, LocalDofMapping >
340 ::DofMapperBase ( const GridPartType &gridPart, LocalDofMappingType localDofMapping, const CodeFactory &codeFactory )
341 // NOTE: Don't store gridPart in this class since the lifetime of gridPart
342 // might be shorter than the lifetime of this class. The lifetime of
343 // indexSet is guaranteed to be longer, so storage of that class is fine
344 : indexSet_( gridPart.indexSet() ),
345 localDofMapping_( std::move( localDofMapping ) ),
346 code_( LocalGeometryTypeIndex::size( dimension ) ),
347 maxNumDofs_( 0 ),
348 subEntityInfo_( GlobalGeometryTypeIndex::size( dimension ) )
349 {
350 std::vector< GeometryType > gt( GlobalGeometryTypeIndex::size( dimension ) );
351
352 const typename RefElementsType::Iterator end = RefElementsType::end();
353 for( typename RefElementsType::Iterator it = RefElementsType::begin(); it != end; ++it )
354 {
355 const RefElementType refElement = *it;
356
357 for( int codim = 0; codim <= dimension; ++codim )
358 {
359 for( int i = 0; i < refElement.size( codim ); ++i )
360 {
361 const unsigned int gtIdx = GlobalGeometryTypeIndex::index( refElement.type( i, codim ) );
362 gt[ gtIdx ] = refElement.type( i, codim );
363 subEntityInfo_[ gtIdx ].codim = codim;
364 }
365 }
366
367 DofMapperCode &code = code_[ LocalGeometryTypeIndex::index( refElement.type() ) ];
368 code = codeFactory( refElement );
369 maxNumDofs_ = std::max( code.numDofs(), maxNumDofs_ );
370 code( BuildFunctor( subEntityInfo_ ) );
371 }
372
373 for( int codim = 0; codim <= dimension; ++codim )
374 codimType_[ codim ] = CodimEmpty;
375
376 unsigned int codimDofs[ dimension+1 ];
377 for( unsigned int i = 0; i < subEntityInfo_.size(); ++i )
378 {
379 const SubEntityInfo &info = subEntityInfo_[ i ];
380 if( info.numDofs == 0 )
381 {
382 continue;
383 }
384
385 // see commit message f86ab6e96a27fdecfa82de43fe9099f01e240e1b
386 // Note: hasSingleGeometryType does not exist on all IndexSets
387 static const bool hasSingleGeometryType = Dune::Capabilities::hasSingleGeometryType< typename GridPartType::GridType > :: v ;
388 const auto & geomTypes = indexSet().types(info.codim);
389
390 if (hasSingleGeometryType && geomTypes[0] != gt[i])
391 {
392 continue;
393 }
394
395 if( codimType_[ info.codim ] == CodimEmpty )
396 codimType_[ info.codim ] = CodimFixedSize;
397 else if( codimDofs[ info.codim ] != info.numDofs )
398 codimType_[ info.codim ] = CodimVariableSize;
399
400 codimDofs[ info.codim ] = info.numDofs;
401 blockMap_.push_back( gt[ i ] );
402 }
403
404 // submit request for codimensions to index set
405 requestCodimensions ();
406
407 // update offsets
408 update();
409 }
410
411
412 template< class GridPart, class LocalDofMapping >
413 template< class Functor >
414 inline void DofMapperBase< GridPart, LocalDofMapping >
415 ::mapEach ( const ElementType &element, Functor f ) const
416 {
417 const auto &idxSet = indexSet();
418
419 code( element )( [ this, &idxSet, &element, f ] ( unsigned int gtIndex, unsigned int subEntity, auto begin, auto end ) {
420 const SubEntityInfo &info = subEntityInfo_[ gtIndex ];
421 const SizeType subIndex = idxSet.subIndex( element, subEntity, info.codim );
422 SizeType index = info.offset + SizeType( info.numDofs ) * subIndex;
423 localDofMapping_( element, subEntity, info.codim )( index, info.numDofs, begin, end, f );
424 } );
425 }
426
427
428 template< class GridPart, class LocalDofMapping >
429 inline void DofMapperBase< GridPart, LocalDofMapping >
430 ::map ( const ElementType &element, std::vector< SizeType > &indices ) const
431 {
432 indices.resize( numDofs( element ) );
433 mapEach( element, AssignFunctor< std::vector< SizeType > >( indices ) );
434 }
435
436 template< class GridPart, class LocalDofMapping >
437 template< class Entity, class Functor >
438 inline void DofMapperBase< GridPart, LocalDofMapping >
439 ::mapEachEntityDof ( const Entity &entity, Functor f ) const
440 {
441 const SubEntityInfo &info = subEntityInfo( entity );
442 const unsigned int numDofs = info.numDofs;
443 SizeType index = info.offset + numDofs * SizeType( indexSet().index( entity ) );
444 for( unsigned int i = 0; i < info.numDofs; ++i )
445 f( i, index++ );
446 }
447
448
449 template< class GridPart, class LocalDofMapping >
450 template< class Entity >
451 inline void DofMapperBase< GridPart, LocalDofMapping >
452 ::mapEntityDofs ( const Entity &entity, std::vector< SizeType > &indices ) const
453 {
454 indices.resize( numEntityDofs( entity ) );
455 mapEachEntityDof( entity, AssignFunctor< std::vector< SizeType > >( indices ) );
456 }
457
458 template< class GridPart, class LocalDofMapping >
459 inline void DofMapperBase< GridPart, LocalDofMapping >
460 ::onSubEntity( const ElementType &element, int i, int c, std::vector< char > &indices ) const
461 {
462 const SubEntityFilter filter( RefElementsType::general( element.type() ), i, c );
463 indices.resize( numDofs( element ) );
464 code( element )( [ this, &indices, &filter ] ( unsigned int gtIndex, unsigned int subEntity, auto begin, auto end ) {
465 const bool active = filter( subEntity, subEntityInfo_[ gtIndex ].codim );
466 while( begin != end )
467 indices[ *(begin++) ] = active? 1:0;
468 } );
469 }
470
471 template< class GridPart, class LocalDofMapping >
472 template< class Entity >
473 inline unsigned int
474 DofMapperBase< GridPart, LocalDofMapping >
475 ::numEntityDofs ( const Entity &entity ) const
476 {
477 return subEntityInfo( entity ).numDofs;
478 }
479
480
481 template< class GridPart, class LocalDofMapping >
482 inline void DofMapperBase< GridPart, LocalDofMapping >::requestCodimensions ()
483 {
484 // this is only possible for index sets derived from Dune::Fem::IndexSet
485 if constexpr ( Capabilities::isDuneFemIndexSet< IndexSetType >::v )
486 {
487 // collect all available codimensions
488 std::vector< int > codimensions;
489 codimensions.reserve( dimension+1 );
490
491 for( typename BlockMapType::const_iterator it = blockMap_.begin(); it != blockMap_.end(); ++it )
492 {
493 SubEntityInfo &info = subEntityInfo_[ GlobalGeometryTypeIndex::index( *it ) ];
494 codimensions.push_back( info.codim );
495 }
496
497 // submit request for codimension to indexSet
498 indexSet().requestCodimensions( codimensions );
499 }
500 }
501
502 template< class GridPart, class LocalDofMapping >
503 inline void DofMapperBase< GridPart, LocalDofMapping >::update ()
504 {
505 size_ = 0;
506 for( const auto& geomType : blockMap_ )
507 {
508 SubEntityInfo &info = subEntityInfo_[ GlobalGeometryTypeIndex::index( geomType ) ];
509 info.oldOffset = info.offset;
510 info.offset = size_;
511 size_ += SizeType( info.numDofs ) * SizeType( indexSet().size( geomType ) );
512 }
513 }
514
515
516 template< class GridPart, class LocalDofMapping >
517 inline const DofMapperCode &DofMapperBase< GridPart, LocalDofMapping >
518 ::code ( const GeometryType &gt ) const
519 {
520 return code_[ LocalGeometryTypeIndex::index( gt ) ];
521 }
522
523
524 template< class GridPart, class LocalDofMapping >
525 template< class Entity >
526 inline const typename DofMapperBase< GridPart, LocalDofMapping >::SubEntityInfo &
527 DofMapperBase< GridPart, LocalDofMapping >::subEntityInfo ( const Entity &entity ) const
528 {
529 return subEntityInfo_[ GlobalGeometryTypeIndex::index( entity.type() ) ];
530 }
531
532
533
534 // DofMapper
535 // ---------
536
537 template< class GridPart, class LocalDofMapping >
538 class DofMapper
539 : public DofMapperBase< GridPart, LocalDofMapping >
540 {
541 typedef DofMapper< GridPart, LocalDofMapping > ThisType;
542 typedef DofMapperBase< GridPart, LocalDofMapping > BaseType;
543
544 protected:
545 typedef typename BaseType::SubEntityInfo SubEntityInfo;
546 typedef typename BaseType::GridPartType::GridType GridType;
547 typedef DofManager< GridType > DofManagerType;
548
549 public:
550 typedef typename BaseType::GridPartType GridPartType;
551 typedef typename BaseType::LocalDofMappingType LocalDofMappingType;
552 typedef typename BaseType::SizeType SizeType;
553
554 template< class CodeFactory >
555 DofMapper ( const GridPartType &gridPart, LocalDofMappingType localDofMapping, const CodeFactory &codeFactory )
556 : BaseType( gridPart, std::move( localDofMapping ), codeFactory ),
557 dofManager_( DofManagerType::instance( gridPart.grid() ) )
558 {
559 dofManager_.addIndexSet( *this );
560 }
561
562 DofMapper ( const ThisType & ) = delete;
563
564 ~DofMapper ()
565 {
566 dofManager_.removeIndexSet( *this );
567 }
568
569 ThisType &operator= ( const ThisType & ) = delete;
570
571 protected:
572 DofManagerType& dofManager_;
573 };
574
575
576 // AdaptiveDofMapper
577 // -----------------
578
579 template< class GridPart, class LocalDofMapping >
580 class AdaptiveDofMapper
581 : public DofMapperBase< GridPart, LocalDofMapping >
582 {
583 typedef AdaptiveDofMapper< GridPart, LocalDofMapping > ThisType;
584 typedef DofMapperBase< GridPart, LocalDofMapping > BaseType;
585
586 protected:
587 typedef typename BaseType::SubEntityInfo SubEntityInfo;
588 typedef typename BaseType::GridPartType::GridType GridType;
589 typedef DofManager< GridType > DofManagerType;
590
591 public:
592 typedef typename BaseType::GridPartType GridPartType;
593 typedef typename BaseType::LocalDofMappingType LocalDofMappingType;
594 typedef typename BaseType::SizeType SizeType;
595
596 template< class CodeFactory >
597 AdaptiveDofMapper ( const GridPartType &gridPart, LocalDofMappingType localDofMapping, const CodeFactory &codeFactory )
598 : BaseType( gridPart, std::move( localDofMapping ), codeFactory ),
599 dofManager_( DofManagerType::instance( gridPart.grid() ) )
600 {
601 dofManager_.addIndexSet( *this );
602 }
603
604 AdaptiveDofMapper ( const ThisType & ) = delete;
605
606 ~AdaptiveDofMapper ()
607 {
608 dofManager_.removeIndexSet( *this );
609 }
610
611 ThisType &operator= ( const ThisType & ) = delete;
612
613 // Adaptive DoF mappers are always up to date, so this method does nothing.
614 // update is done several times during insertEntity
615 void update () {}
616
617 // adaptation interface
618
619 int numBlocks () const { return blockMap_.size(); }
620 SizeType offSet ( int blk ) const;
621 SizeType oldOffSet ( int blk ) const;
622
623 SizeType numberOfHoles ( int blk ) const;
624
625 SizeType oldIndex ( SizeType hole, int blk ) const;
626 SizeType newIndex ( SizeType hole, int blk ) const;
627
628 // adaptation methods (as for index sets)
629
630 bool consecutive () const { return true; }
631
632 template< class Entity >
633 void insertEntity ( const Entity &entity ) { BaseType::update(); }
634
635 template< class Entity >
636 void removeEntity ( const Entity &entity ) {}
637
638 void resize () { BaseType::update(); }
639
640 bool compress () { BaseType::update(); return true; }
641
642 template <class StreamTraits>
643 void write( OutStreamInterface< StreamTraits >& out ) const {}
644
645 template <class StreamTraits>
646 void read( InStreamInterface< StreamTraits >& in )
647 {
648 BaseType::update();
649 }
650
651 void backup () const {}
652 void restore () {}
653
654 protected:
655 using BaseType::indexSet;
656
657 using BaseType::blockMap_;
658 using BaseType::subEntityInfo_;
659
660 DofManagerType& dofManager_;
661 };
662
663
664
665 // Implementation of AdaptiveDofMapper
666 // -----------------------------------
667
668 template< class GridPart, class LocalDofMapping >
669 inline typename AdaptiveDofMapper< GridPart, LocalDofMapping >::SizeType
670 AdaptiveDofMapper< GridPart, LocalDofMapping >::offSet ( int blk ) const
671 {
672 assert( (blk >= 0) && (blk < numBlocks()) );
673 const unsigned int gtIdx = GlobalGeometryTypeIndex::index( blockMap_[ blk ] );
674 return subEntityInfo_[ gtIdx ].offset;
675 }
676
677
678 template< class GridPart, class LocalDofMapping >
679 inline typename AdaptiveDofMapper< GridPart, LocalDofMapping >::SizeType
680 AdaptiveDofMapper< GridPart, LocalDofMapping >::oldOffSet ( int blk ) const
681 {
682 assert( (blk >= 0) && (blk < numBlocks()) );
683 const unsigned int gtIdx = GlobalGeometryTypeIndex::index( blockMap_[ blk ] );
684 return subEntityInfo_[ gtIdx ].oldOffset;
685 }
686
687
688 template< class GridPart, class LocalDofMapping >
689 inline typename AdaptiveDofMapper< GridPart, LocalDofMapping >::SizeType
690 AdaptiveDofMapper< GridPart, LocalDofMapping >::numberOfHoles ( int blk ) const
691 {
692 assert( (blk >= 0) && (blk < numBlocks()) );
693 const unsigned int gtIdx = GlobalGeometryTypeIndex::index( blockMap_[ blk ] );
694 const SubEntityInfo &info = subEntityInfo_[ gtIdx ];
695 return SizeType( info.numDofs ) * SizeType( indexSet().numberOfHoles( blockMap_[ blk ] ) );
696 }
697
698
699 template< class GridPart, class LocalDofMapping >
700 inline typename AdaptiveDofMapper< GridPart, LocalDofMapping >::SizeType
701 AdaptiveDofMapper< GridPart, LocalDofMapping >::oldIndex ( SizeType hole, int blk ) const
702 {
703 assert( (hole >= 0) && (hole < numberOfHoles( blk )) );
704 const unsigned int gtIdx = GlobalGeometryTypeIndex::index( blockMap_[ blk ] );
705 const SubEntityInfo &info = subEntityInfo_[ gtIdx ];
706 const unsigned int numDofs = info.numDofs;
707 const SizeType index = indexSet().oldIndex( hole / numDofs, blockMap_[ blk ] );
708 return info.offset + numDofs * index + (hole % numDofs);
709 }
710
711
712 template< class GridPart, class LocalDofMapping >
713 inline typename AdaptiveDofMapper< GridPart, LocalDofMapping >::SizeType
714 AdaptiveDofMapper< GridPart, LocalDofMapping >::newIndex ( SizeType hole, int blk ) const
715 {
716 assert( (hole >= 0) && (hole < numberOfHoles( blk )) );
717 const unsigned int gtIdx = GlobalGeometryTypeIndex::index( blockMap_[ blk ] );
718 const SubEntityInfo &info = subEntityInfo_[ gtIdx ];
719 const unsigned int numDofs = info.numDofs;
720 const SizeType index = indexSet().newIndex( hole / numDofs, blockMap_[ blk ] );
721 return info.offset + numDofs * index + (hole % numDofs);
722 }
723
724
725
726 // Implementation
727 // --------------
728
729 template< class GridPart, class LocalDofMapping, bool adaptive = Capabilities::isAdaptiveIndexSet< typename GridPart::IndexSetType >::v >
730 struct Implementation
731 {
732 typedef typename std::conditional< adaptive, AdaptiveDofMapper< GridPart, LocalDofMapping >, DofMapper< GridPart, LocalDofMapping > >::type Type;
733 };
734
735 } // namespace __IndexSetDofMapper
736
737
738
739 // IndexSetDofMapper
740 // -----------------
741
742 template< class GridPart, class LocalDofMapping = DefaultLocalDofMapping< GridPart > >
743 class IndexSetDofMapper
744 : public __IndexSetDofMapper::template Implementation< GridPart, LocalDofMapping >::Type
745 {
746 typedef typename __IndexSetDofMapper::template Implementation< GridPart, LocalDofMapping >::Type BaseType;
747
748 public:
749 typedef typename BaseType::GridPartType GridPartType;
750 typedef typename BaseType::LocalDofMappingType LocalDofMappingType;
751
752 template< class CodeFactory >
753 IndexSetDofMapper ( const GridPartType &gridPart, LocalDofMappingType localDofMapping, const CodeFactory &codeFactory )
754 : BaseType( gridPart, std::move( localDofMapping ), codeFactory )
755 {}
756
757 template< class CodeFactory >
758 IndexSetDofMapper ( const GridPartType &gridPart, const CodeFactory &codeFactory )
759 : BaseType( gridPart, LocalDofMappingType( gridPart ), codeFactory )
760 {}
761 };
762
763
764 // Capabilities
765 // ------------
766
767 namespace Capabilities
768 {
769 // isAdaptiveDofMapper
770 // -------------------
771
772 template< class GridPart, class LocalDofMapping >
773 struct isAdaptiveDofMapper< IndexSetDofMapper< GridPart, LocalDofMapping > >
774 {
775 static const bool v = Capabilities::isAdaptiveIndexSet< typename GridPart::IndexSetType >::v;
776 };
777
778
779 // isConsecutiveIndexSet
780 // ---------------------
781
782 template< class GridPart, class LocalDofMapping >
783 struct isConsecutiveIndexSet< __IndexSetDofMapper::AdaptiveDofMapper< GridPart, LocalDofMapping > >
784 {
785 static const bool v = true;
786 };
787
788 } // namespace Capabilities
789
790 } // namespace Fem
791
792} // namespace Dune
793
794// turn the warnings back on
795#pragma GCC diagnostic pop
796
797#endif //#ifndef DUNE_FEM_DOFMAPPER_INDEXSETDOFMAPPER_HH
consecutive, persistent index set for the leaf level based on the grid's hierarchy index set
Definition: adaptiveleafindexset.hh:1351
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:158
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
constexpr std::bool_constant<((II==value)||...)> contains(std::integer_sequence< T, II... >, std::integral_constant< T, value >)
Checks whether or not a given sequence contains a value.
Definition: integersequence.hh:137
STL namespace.
Specialize with 'true' for if the codimension 0 entity of the grid has only one possible geometry typ...
Definition: capabilities.hh:27
Class providing access to the singletons of the reference elements.
Definition: referenceelements.hh:128
typename Container::ReferenceElement ReferenceElement
The reference element type.
Definition: referenceelements.hh:146
A unique label for each type of element that can occur in a grid.
Helper classes to provide indices for geometrytypes for use in a vector.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)