1#ifndef DUNE_FEM_SPACE_MAPPER_CODIMENSIONMAPPER_HH
2#define DUNE_FEM_SPACE_MAPPER_CODIMENSIONMAPPER_HH
9#include <dune/common/exceptions.hh>
11#include <dune/geometry/referenceelements.hh>
12#include <dune/geometry/type.hh>
28 template<
class Gr
idPart,
int codim >
29 class CodimensionMapper;
35 namespace __CodimensionMapper
41 template<
class Gr
idPart,
int codim >
44 typedef CodimensionMapper< GridPart, codim > DofMapperType;
46 static const int codimension = codim;
48 typedef GridPart GridPartType;
49 typedef typename GridPartType::IndexSetType IndexSetType;
51 typedef typename GridPartType::template Codim< 0 >::EntityType ElementType;
53 typedef std::size_t SizeType;
54 typedef SizeType GlobalKeyType;
66 typedef Base< T > BaseType;
69 typedef typename BaseType::Traits Traits;
71 static const int codimension = Traits::codimension;
73 typedef typename Traits::GridPartType GridPartType;
74 typedef typename Traits::IndexSetType IndexSetType;
76 typedef typename BaseType::ElementType ElementType;
77 typedef typename BaseType::SizeType SizeType;
78 typedef typename Traits::GlobalKeyType GlobalKeyType;
80 explicit DofMapper (
const GridPartType &gridPart )
81 : DofMapper( gridPart.indexSet() )
84 explicit DofMapper (
const IndexSetType &indexSet )
85 : indexSet_( indexSet ),
89 AllGeomTypes< IndexSetType, typename GridPartType::GridType > types( indexSet );
90 for( GeometryType type : types.geomTypes( 0 ) )
91 maxNumDofs_ =
std::max( maxNumDofs_, referenceElement( type ).size( codimension ) );
94 std::vector< int > codimensions( 1,
int(Traits::codimension) );
95 indexSet_.requestCodimensions( codimensions );
102 SizeType size ()
const
104 return indexSet().size( codimension ) + extension_;
107 static constexpr bool contains (
int codim )
noexcept
109 return codim == codimension;
112 static constexpr bool fixedDataSize (
int codim )
noexcept
117 template<
class Function >
118 void mapEach (
const ElementType &element, Function function )
const
120 if( codimension == 0 )
121 function( 0, indexSet().index( element ) );
124 const SizeType numDofs = this->numDofs( element );
125 for( SizeType i = 0; i < numDofs; ++i )
126 function( i, indexSet().subIndex( element, i, codimension ) );
130 void map (
const ElementType &element, std::vector< GlobalKeyType > &indices )
const
132 indices.resize( numDofs( element ) );
133 mapEach( element, [ &indices ] (
int local, GlobalKeyType global ) { indices[ local ] = global; } );
136 template<
class Entity >
137 void mapEntityDofs (
const Entity &entity, std::vector< GlobalKeyType > &indices )
const
139 indices.resize( numEntityDofs( entity ) );
140 mapEachEntityDof( entity, AssignFunctor< std::vector< GlobalKeyType > >( indices ) );
143 template<
class Entity,
class Function >
144 void mapEachEntityDof (
const Entity &entity, Function function )
const
146 assert( Entity::codimension == codimension );
147 function( 0, indexSet().index( entity ) );
150 int maxNumDofs ()
const {
return maxNumDofs_; }
152 SizeType numDofs (
const ElementType &element )
const
154 return element.subEntities( codimension );
157 template<
class Entity >
158 static constexpr SizeType numEntityDofs (
const Entity &entity )
noexcept
160 return contains( Entity::codimension ) ? 1 : 0;
165 void extendSize(
const SizeType extension )
167 extension_ = extension;
170 void onSubEntity (
const ElementType &element,
int i,
int c, std::vector< bool > &indices )
const
172 indices.resize( numDofs(element) );
173 std::fill(indices.begin(),indices.end(),
false);
195 static constexpr bool consecutive () noexcept {
return false; }
197 SizeType numBlocks ()
const
199 DUNE_THROW( NotImplemented,
"Method numBlocks() called on non-adaptive block mapper" );
202 SizeType numberOfHoles (
int )
const
204 DUNE_THROW( NotImplemented,
"Method numberOfHoles() called on non-adaptive block mapper" );
207 GlobalKeyType oldIndex (
int hole,
int )
const
209 DUNE_THROW( NotImplemented,
"Method oldIndex() called on non-adaptive block mapper" );
212 GlobalKeyType newIndex (
int hole,
int )
const
214 DUNE_THROW( NotImplemented,
"Method newIndex() called on non-adaptive block mapper" );
217 SizeType oldOffSet (
int )
const
219 DUNE_THROW( NotImplemented,
"Method oldOffSet() called on non-adaptive block mapper" );
222 SizeType offSet (
int )
const
224 DUNE_THROW( NotImplemented,
"Method offSet() called on non-adaptive block mapper" );
230 const IndexSetType &indexSet ()
const {
return indexSet_; }
233 static auto referenceElement ( GeometryType type )
234 ->
decltype( ReferenceElements< typename GridPartType::ctype, GridPartType::dimension >::general( type ) )
236 return ReferenceElements< typename GridPartType::ctype, GridPartType::dimension >::general( type );
239 const IndexSetType &indexSet_;
249 template<
class Traits >
250 class AdaptiveDofMapper
251 :
public DofMapper< Traits, Dune::Fem::AdaptiveDofMapper >
253 typedef DofMapper< Traits, Dune::Fem::AdaptiveDofMapper > BaseType;
256 static const int codimension = BaseType::codimension;
258 typedef typename BaseType::SizeType SizeType;
259 typedef typename BaseType::GlobalKeyType GlobalKeyType;
262 using BaseType::indexSet;
265 explicit AdaptiveDofMapper (
const typename BaseType::GridPartType &gridPart )
266 : BaseType( gridPart )
269 explicit AdaptiveDofMapper (
const typename BaseType::IndexSetType &indexSet )
270 : BaseType( indexSet )
273 static constexpr bool consecutive () noexcept {
return true; }
275 static constexpr SizeType numBlocks () noexcept
280 SizeType numberOfHoles (
int )
const
282 return indexSet().numberOfHoles( codimension );
285 GlobalKeyType oldIndex (
int hole,
int )
const
287 return indexSet().oldIndex( hole, codimension );
290 GlobalKeyType newIndex (
int hole,
int )
const
292 return indexSet().newIndex( hole, codimension );
295 static constexpr SizeType oldOffSet (
int )
noexcept
300 static constexpr SizeType offSet (
int )
noexcept
311 template<
class GridPart,
int codim,
312 bool adaptive = Capabilities::isAdaptiveIndexSet< typename GridPart::IndexSetType >::v >
315 typedef __CodimensionMapper::Traits< GridPart, codim > Traits;
318 typedef typename std::conditional< adaptive,
319 AdaptiveDofMapper< Traits >,
342 template<
class Gr
idPart,
int codim >
344 :
public __CodimensionMapper::template Implementation< GridPart, codim >::Type
346 typedef typename __CodimensionMapper::template Implementation< GridPart, codim >::Type BaseType;
350 : BaseType( gridPart )
354 : BaseType( *indexSet )
358 : BaseType( indexSet )
366 namespace Capabilities
371 template<
class Gr
idPart,
int codim >
381 template<
class Gr
idPart,
int codim >
384 static const bool v =
true;
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