1#ifndef DUNE_FEM_NONBLOCKMAPPER_HH
2#define DUNE_FEM_NONBLOCKMAPPER_HH
6#include <dune/fem/gridpart/common/indexset.hh>
7#include <dune/fem/misc/functor.hh>
8#include <dune/fem/space/mapper/dofmapper.hh>
19 template<
class BlockMapper,
int blockSize >
23 namespace __NonBlockMapper
29 template<
class BlockMapper,
int bS >
32 typedef NonBlockMapper< BlockMapper, bS > DofMapperType;
34 typedef BlockMapper BlockMapperType;
35 typedef typename BlockMapper::ElementType ElementType;
36 typedef typename BlockMapper::SizeType SizeType;
37 typedef typename BlockMapper::GlobalKeyType GlobalKeyType;
39 static const int blockSize = bS;
50 typedef Base< T > BaseType;
52 template<
class,
template<
class >
class >
53 friend class DofMapper;
56 typedef typename BaseType::Traits Traits;
58 typedef typename Traits::BlockMapperType BlockMapperType;
59 static const int blockSize = Traits::blockSize;
61 typedef typename Traits::ElementType ElementType;
62 typedef typename Traits::SizeType SizeType;
63 typedef typename Traits::GlobalKeyType GlobalKeyType;
66 template<
class Functor >
69 explicit BlockFunctor ( Functor functor )
73 template<
class GlobalKey >
74 void operator() (
int localBlock,
const GlobalKey globalKey )
const
76 int localDof = blockSize*localBlock;
77 SizeType globalDof = blockSize*globalKey;
78 const int localEnd = localDof + blockSize;
79 while( localDof != localEnd )
80 functor_( localDof++, globalDof++ );
88 DofMapper ( BlockMapperType &blockMapper )
89 : blockMapper_( blockMapper )
92 SizeType
size ()
const {
return blockSize * blockMapper_.size(); }
94 bool contains (
const int codim )
const {
return blockMapper_.contains( codim ); }
96 bool fixedDataSize (
int codim )
const {
return blockMapper_.fixedDataSize( codim ); }
98 template<
class Functor >
99 void mapEach (
const ElementType &element, Functor f )
const
101 blockMapper_.mapEach( element, BlockFunctor< Functor >( std::forward< Functor >( f ) ) );
104 void map (
const ElementType &element, std::vector< GlobalKeyType > &indices )
const
106 indices.resize(
numDofs( element ) );
107 mapEach( element, [ &indices ] (
int local, GlobalKeyType global ) { indices[ local ] = global; } );
110 [[deprecated(
"Use onSubEntity method with char vector instead")]]
111 void onSubEntity (
const ElementType &element,
int i,
int c, std::vector< bool > &indices )
const
113 std::vector< char > _idx;
114 onSubEntity(element, i, c, _idx);
115 indices.resize( _idx.size() );
116 for (std::size_t i=0; i<_idx.size();++i)
117 _idx[i] = indices[i] > 0;
127 void onSubEntity (
const ElementType &element,
int i,
int c, std::vector< char > &indices )
const
129 const SizeType
numDofs = blockMapper_.numDofs( element );
130 blockMapper_.onSubEntity( element, i, c, indices );
131 indices.resize( blockSize * numDofs );
132 for( SizeType i = numDofs-1; i!=SizeType(-1) ; --i )
134 for(
int j = 0; j < blockSize; ++j )
136 assert( i < indices.size() );
137 assert( i*blockSize+j < indices.size() );
138 indices[ i*blockSize + j ] = (indices[ i ]==0)? 0 : j+1;
143 template<
class Entity,
class Functor >
144 void mapEachEntityDof (
const Entity &entity, Functor f )
const
146 blockMapper_.mapEachEntityDof( entity, BlockFunctor< Functor >( std::forward< Functor >( f ) ) );
149 template<
class Entity >
150 void mapEntityDofs (
const Entity &entity, std::vector< GlobalKeyType > &indices )
const
152 indices.resize( numEntityDofs( entity ) );
153 mapEachEntityDof( entity, [ &indices ] (
int local, GlobalKeyType global ) { indices[ local ] = global; } );
156 int maxNumDofs ()
const {
return blockSize * blockMapper_.maxNumDofs(); }
158 SizeType numDofs (
const ElementType &element )
const {
return blockSize * blockMapper_.numDofs( element ); }
160 template<
class Entity >
161 SizeType numEntityDofs (
const Entity &entity )
const {
return blockSize * blockMapper_.numEntityDofs( entity ); }
163 static constexpr bool consecutive () noexcept {
return false; }
165 SizeType numBlocks ()
const
167 DUNE_THROW( NotImplemented,
"Method numBlocks() called on non-adaptive block mapper" );
170 SizeType numberOfHoles (
int )
const
172 DUNE_THROW( NotImplemented,
"Method numberOfHoles() called on non-adaptive block mapper" );
175 GlobalKeyType oldIndex (
int hole,
int )
const
177 DUNE_THROW( NotImplemented,
"Method oldIndex() called on non-adaptive block mapper" );
180 GlobalKeyType newIndex (
int hole,
int )
const
182 DUNE_THROW( NotImplemented,
"Method newIndex() called on non-adaptive block mapper" );
185 SizeType oldOffSet (
int )
const
187 DUNE_THROW( NotImplemented,
"Method oldOffSet() called on non-adaptive block mapper" );
190 SizeType offSet (
int )
const
192 DUNE_THROW( NotImplemented,
"Method offSet() called on non-adaptive block mapper" );
195 const BlockMapperType &blockMapper ()
const {
return blockMapper_; }
197 void update () { blockMapper_.update(); }
200 BlockMapperType &blockMapper_;
208 class AdaptiveDofMapper
209 :
public DofMapper< T, Dune::Fem::AdaptiveDofMapper >
211 typedef DofMapper< T, Dune::Fem::AdaptiveDofMapper > BaseType;
214 friend class AdaptiveDofMapper;
217 typedef typename BaseType::Traits Traits;
219 typedef typename Traits::BlockMapperType BlockMapperType;
221 static const int blockSize = Traits::blockSize;
223 using BaseType::blockMapper;
225 typedef typename Traits::ElementType ElementType;
226 typedef typename Traits::SizeType SizeType;
227 typedef typename Traits::GlobalKeyType GlobalKeyType;
229 AdaptiveDofMapper ( BlockMapperType &blockMapper )
230 : BaseType( blockMapper )
233 bool consecutive ()
const {
return blockMapper().consecutive(); }
235 SizeType numBlocks ()
const {
return blockMapper().numBlocks(); }
237 SizeType numberOfHoles (
const int block )
const {
return blockSize * blockMapper().numberOfHoles( block ); }
239 GlobalKeyType oldIndex (
const int hole,
const int block )
const
241 const int i = hole % blockSize;
242 const int blockHole = hole / blockSize;
243 return blockMapper().oldIndex( blockHole, block ) * blockSize + i;
246 GlobalKeyType newIndex (
const int hole,
const int block )
const
248 const int i = hole % blockSize;
249 const int blockHole = hole / blockSize;
250 return blockMapper().newIndex( blockHole, block ) * blockSize + i;
253 SizeType oldOffSet (
const int block )
const {
return blockMapper().oldOffSet( block ) * blockSize; }
255 SizeType offSet (
const int block )
const {
return blockMapper().offSet( block ) * blockSize; }
263 template< class BlockMapper, int blockSize, bool adaptive = Capabilities::isAdaptiveDofMapper< BlockMapper >::v >
266 typedef __NonBlockMapper::Traits< BlockMapper, blockSize > Traits;
269 typedef typename std::conditional< adaptive,
270 AdaptiveDofMapper< Traits >,
271 DofMapper< Traits > >::type Type;
281 template<
class BlockMapper,
int blockSize >
283 :
public __NonBlockMapper::template Implementation< BlockMapper, blockSize >::Type
285 typedef typename __NonBlockMapper::template Implementation< BlockMapper, blockSize >::Type BaseType;
290 : BaseType( blockMapper )
298 template<
class BlockMapper,
int innerBlockSize,
int outerBlockSize >
300 :
public NonBlockMapper< BlockMapper, innerBlockSize *outerBlockSize >
307 : BaseType( blockMapper.blockMapper_ )
315 namespace Capabilities
317 template<
class BlockMapper,
int blockSize >
318 struct isAdaptiveDofMapper< NonBlockMapper< BlockMapper, blockSize > >
320 static const bool v = isAdaptiveDofMapper< BlockMapper >::v;
323 template<
class BlockMapper,
int blockSize >
324 struct isConsecutiveIndexSet< __NonBlockMapper::AdaptiveDofMapper< __NonBlockMapper::Traits< BlockMapper, blockSize > > >
326 static const bool v = isConsecutiveIndexSet< BlockMapper >::v;
Interface for calculating the size of a function space for a grid on a specified level....
Definition: dofmapper.hh:43
SizeType numDofs(const ElementType &element) const
obtain number of DoFs on an entity
Definition: dofmapper.hh:164
void mapEach(const ElementType &element, Functor f) const
map each local DoF number to a global key
Definition: dofmapper.hh:116
Definition: nonblockmapper.hh:284
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
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