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