dune-fem 2.8.0
Loading...
Searching...
No Matches
padaptivespace/generic.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_SPACE_PADAPTIVE_GENERIC_HH
2#define DUNE_FEM_SPACE_PADAPTIVE_GENERIC_HH
3
4#include <cassert>
5#include <list>
6#include <vector>
7
8#include <dune/common/math.hh>
9
21
24
25namespace Dune
26{
27
28 namespace Fem
29 {
30
31 // GenericDiscreteFunctionSpace
32 // ----------------------------
33
40 template< class Traits >
42 : public DiscreteFunctionSpaceDefault< Traits >
43 {
46
47 public:
50
52
54 typedef typename BaseType::GridType GridType;
57 typedef typename IteratorType::Entity EntityType;
59
60 typedef typename Traits::ShapeFunctionSetType ShapeFunctionSetType;
62
64
66 static const int polynomialOrder = Traits::polynomialOrder;
67
68 protected:
69 // single type for shape function sets of all polynomial orders
70 typedef typename Traits::ScalarShapeFunctionSetType ScalarShapeFunctionSetType;
71 // storage for scalar shape function set per polynomial order
73 // factory for shape function set of static order
74 template< int pOrd >
76 {
77 typedef typename Traits::template ScalarShapeFunctionSetFactory< pOrd >::Type Type;
78 };
79
80 protected:
81 template< int pOrd >
82 struct Initialize;
83
84 // DoF manager
86
87 public:
88 typedef typename Traits::CompiledLocalKeyType CompiledLocalKeyType;
90
91 // key that identifies the basis function set, here the polynomial order
92 typedef int KeyType;
93
95 typedef int IdentifierType;
97 static const IdentifierType id = 665;
98
109 const int order,
110 const InterfaceType commInterface,
111 const CommunicationDirection commDirection )
112 : BaseType( gridPart, commInterface, commDirection ),
113 order_( order ),
117 {
119 }
120
121 protected:
122 // copy constructor needed for p-adaptation
124 : BaseType( other.gridPart_, other.commInterface_, other.commDirection_ ),
125 order_( other.order_ ),
128 blockMapper_( initialize( &other.blockMapper() ) )
129 {}
130
131 public:
132
134 // Interface methods //
136
138 inline DFSpaceIdentifier type () const { return GenericSpace_id; }
142 {
143 return BasisFunctionSetType( entity, shapeFunctionSet( entity ) );
145
147 inline bool continuous () const { return Traits::continuousSpace; }
148
150 inline int order () const { return order_; }
151
153 inline int order (const typename BaseType::EntityType &entity) const
154 {
155 return blockMapper().polynomOrder( entity );
156 }
157
159 inline bool multipleBaseFunctionSets () const { return (polynomialOrder > 1); }
160
163 {
164 assert( blockMapper_ );
165 return *blockMapper_;
166 }
167
168
170 // Non-interface methods //
172
181 {
182 return shapeFunctionSet( entity.type(), order( entity ) );
183 }
184
193 ShapeFunctionSetType shapeFunctionSet ( const GeometryType &type, const int order = polynomialOrder ) const
194 {
196 }
197
207 template< class EntityType >
208 inline const CompiledLocalKeyType &compiledLocalKey ( const EntityType &entity ) const
209 {
210 return compiledLocalKey( entity.type(), order( entity ) );
211 }
212
223 inline const CompiledLocalKeyType &compiledLocalKey ( const GeometryType type, const int order = polynomialOrder ) const
224 {
225 return compiledLocalKeys_[ order ][ type ];
226 }
227
228
230 // Adaptive interface methods //
232
242 KeyType key ( const EntityType &entity ) const
243 {
244 return blockMapper().order( entity );
245 }
246
252 void mark ( const KeyType &key, const EntityType &entity )
253 {
254 return blockMapper().suggestPolynomOrder( entity, key );
255 }
256
263 KeyType getMark ( const EntityType &entity ) const
264 {
265 return blockMapper().suggestPolynomOrder( entity );
266 }
267
274 void adapt ()
275 {
276 // adjust mapper by using previously set new polynomial orders
277 blockMapper().adapt();
278
279 // resize discrete functions (only functions belonging
280 // to this space will be affected ), for convenience
283 }
284
285 template< class DiscreteFunctionSpace, class Implementation >
287 {
288 // create a copy of this space (to be improved, avoid DofManager involvement)
289 DiscreteFunctionSpaceType oldSpace( asImp() );
290
291 // adjust mapper by using previously set new polynomial orders
292 blockMapper().adapt();
293
294 // possibly enlarge memory attached to this space
296
297 // create temporary storage for projection of discrete functions
298 typedef std::vector< typename BaseType::RangeFieldType > TmpDofVectorType;
299 TmpDofVectorType tmpVector( oldSpace.size() );
300
301 // type of intermediate storage
302 typedef VectorDiscreteFunction< DiscreteFunctionSpaceType, TmpDofVectorType > IntermediateStorageFunctionType;
303
304 // Adapt space and then discrete functions
305 IntermediateStorageFunctionType tmp( "padapt-temp", oldSpace, tmpVector );
306
307 // go through list and adjust discrete functions
308 // see DefaultDataProjectionTuple and DefaultDataProjection for possible implementation
309 projection( tmp );
310
311 // resize discrete functions (only functions belonging
312 // to this space will be affected ), for convenience
315 }
316
319 protected:
320 // initialize space and create block mapper
321 BlockMapperType *initialize ( const BlockMapperType *otherMapper = 0 )
322 {
323 const IndexSetType &indexSet = gridPart().indexSet();
324
326 const std::vector< GeometryType > &geometryTypes
327 = allGeometryTypes.geomTypes( 0 );
328
329 for( unsigned int i = 0; i < geometryTypes.size(); ++i )
330 {
333 }
334
335 if( otherMapper )
336 {
337 // make a copy of the other block mapper
338 return new BlockMapperType( *otherMapper, order_, compiledLocalKeys_ );
339 }
340 else
341 {
342 // create new block mapper, this mapper is unique for each space since
343 // the polynomial degrees might be different for each element
345 }
346 }
347
348 protected:
349 // dynamically set maximal polynomial order
350 const int order_;
351
352 // storage for base function sets
353 std::vector< ScalarShapeFunctionSetStorageType > scalarShapeFunctionSets_;
354 // storage for compiled local keys
355 std::vector< LocalKeyStorageType > compiledLocalKeys_;
356
357 // corresponding mapper
358 std::unique_ptr< BlockMapperType > blockMapper_;
359 };
360
361
362
363 // Implementation of GenericDiscreteFunctionSpace::Initialize
364 // ----------------------------------------------------------
365
366 template< class Traits >
367 template <int pOrd>
369 {
371 {
372 static CompiledLocalKeyType *createObject ( const GeometryType &type )
373 {
374 return new CompiledLocalKeyType( type, pOrd );
375 }
377 {
378 delete obj;
379 }
380 };
381
382 static void apply ( const int maxOrder,
383 std::vector< ScalarShapeFunctionSetStorageType > &scalarShapeFunctionSets,
384 std::vector< LocalKeyStorageType > &compiledLocalKeys,
385 const GeometryType &type )
386 {
387 // avoid creating shape function sets for polynomial orders that are not used
388 if( pOrd > maxOrder ) return ;
389
390 typedef typename ScalarShapeFunctionSetFactory< pOrd >::Type ScalarShapeFunctionSetFactoryType;
392 scalarShapeFunctionSets[ pOrd ].template insert< SingletonProviderType >( type );
393
394 typedef SingletonList< GeometryType, CompiledLocalKeyType, CompiledLocalKeyFactory > CompiledLocalKeySingletonProviderType;
395 compiledLocalKeys[ pOrd ].template insert< CompiledLocalKeySingletonProviderType >( type );
396 }
397 };
398
399 } // namespace Fem
400
401} // Dune namespace
402
403#endif // #ifndef DUNE_FEM_SPACE_PADAPTIVE_GENERIC_HH
Provides a proxy class for pointers to a shape function set.
DFSpaceIdentifier
enumerator for identification of spaces
Definition: discretefunctionspace.hh:94
@ GenericSpace_id
id for Generic Space
Definition: discretefunctionspace.hh:100
void enlargeMemory()
resize the MemObject if necessary
Definition: dofmanager.hh:1015
void resize()
Resize index sets and memory due to what the mapper has as new size.
Definition: dofmanager.hh:983
void compress()
Compress all data that is hold by this dofmanager.
Definition: dofmanager.hh:1038
Definition: bindguard.hh:11
static DUNE_PRIVATE void apply(Args &&... args)
Definition: forloop.hh:23
Definition: vectorfunction/vectorfunction.hh:42
default implementation uses method geomTypes of given index set. Used in DiscreteFunctionSpaces.
Definition: allgeomtypes.hh:99
const std ::vector< GeometryType > & geomTypes(unsigned int codim) const
returns vector with geometry tpyes this index set has indices for
Definition: allgeomtypes.hh:171
Abstract definition of the local restriction and prolongation of discrete functions.
Definition: dataprojection/dataprojection.hh:29
const DiscreteFunctionSpaceType & asImp() const
Definition: discretefunctionspace.hh:576
Traits::FunctionSpaceType FunctionSpaceType
type of function space
Definition: discretefunctionspace.hh:193
Traits::BasisFunctionSetType BasisFunctionSetType
type of basis function set of this space
Definition: discretefunctionspace.hh:200
GridPartType::IntersectionType IntersectionType
type of the intersections
Definition: discretefunctionspace.hh:225
This is the class with default implementations for discrete function. The methods not marked with hav...
Definition: discretefunctionspace.hh:628
const InterfaceType commInterface_
Definition: discretefunctionspace.hh:698
BaseType::EntityType EntityType
Definition: discretefunctionspace.hh:644
BaseType::BlockMapperType BlockMapperType
Definition: discretefunctionspace.hh:660
BaseType::GridPartType GridPartType
Definition: discretefunctionspace.hh:640
BaseType::IndexSetType IndexSetType
Definition: discretefunctionspace.hh:642
Traits::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: discretefunctionspace.hh:638
GridPartType & gridPart_
Definition: discretefunctionspace.hh:679
const IndexSetType & indexSet() const
Get a reference to the associated index set.
Definition: discretefunctionspace.hh:751
DofManagerType & dofManager_
Definition: discretefunctionspace.hh:695
BaseType::IteratorType IteratorType
Definition: discretefunctionspace.hh:643
GridPartType & gridPart() const
Definition: discretefunctionspace.hh:745
BaseType::GridType GridType
Definition: discretefunctionspace.hh:641
const CommunicationDirection commDirection_
Definition: discretefunctionspace.hh:699
Traits Traits
Definition: discretefunctionspace.hh:630
Definition: space/mapper/capabilities.hh:22
Please doc me.
Definition: padaptivespace/generic.hh:43
KeyType getMark(const EntityType &entity) const
get key to be assigned to an entity after next call to adapt()
Definition: padaptivespace/generic.hh:263
BlockMapperType & blockMapper() const
get a reference to the block mapper
Definition: padaptivespace/generic.hh:162
static const int polynomialOrder
maximal available polynomial order
Definition: padaptivespace/generic.hh:66
std::vector< LocalKeyStorageType > compiledLocalKeys_
Definition: padaptivespace/generic.hh:355
const int order_
Definition: padaptivespace/generic.hh:350
BasisFunctionSetType basisFunctionSet(const EntityType &entity) const
get basis function set for given entity
Definition: padaptivespace/generic.hh:141
ShapeFunctionSetType shapeFunctionSet(const GeometryType &type, const int order=polynomialOrder) const
return shape unique function set for geometry type
Definition: padaptivespace/generic.hh:193
BaseType::IndexSetType IndexSetType
Definition: padaptivespace/generic.hh:55
void adapt(DataProjection< DiscreteFunctionSpace, Implementation > &projection)
Definition: padaptivespace/generic.hh:286
bool continuous() const
returns true if the space contains only globally continuous functions
Definition: padaptivespace/generic.hh:147
std::vector< ScalarShapeFunctionSetStorageType > scalarShapeFunctionSets_
Definition: padaptivespace/generic.hh:353
const CompiledLocalKeyType & compiledLocalKey(const GeometryType type, const int order=polynomialOrder) const
provide access to the compiled local keys for a geometry type and polynomial order
Definition: padaptivespace/generic.hh:223
Traits::ShapeFunctionSetType ShapeFunctionSetType
Definition: padaptivespace/generic.hh:60
BaseType::GridPartType GridPartType
Definition: padaptivespace/generic.hh:53
BaseType::GridType GridType
Definition: padaptivespace/generic.hh:54
GenericDiscreteFunctionSpace(const GenericDiscreteFunctionSpace &other)
Definition: padaptivespace/generic.hh:123
BaseType::FunctionSpaceType FunctionSpaceType
Definition: padaptivespace/generic.hh:51
ShapeFunctionSetType shapeFunctionSet(const EntityType &entity) const
return shape function set for given entity
Definition: padaptivespace/generic.hh:180
BaseType::IntersectionType IntersectionType
Definition: padaptivespace/generic.hh:58
int KeyType
Definition: padaptivespace/generic.hh:92
KeyType key(const EntityType &entity) const
get identifiying basis function set key assigned to given entity
Definition: padaptivespace/generic.hh:242
bool multipleBaseFunctionSets() const
this space has more than one base function set
Definition: padaptivespace/generic.hh:159
BaseType::BasisFunctionSetType BasisFunctionSetType
Definition: padaptivespace/generic.hh:61
BaseType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: padaptivespace/generic.hh:49
void adapt()
p adaptation
Definition: padaptivespace/generic.hh:274
void mark(const KeyType &key, const EntityType &entity)
assign new key to given entity
Definition: padaptivespace/generic.hh:252
BaseType::IteratorType IteratorType
Definition: padaptivespace/generic.hh:56
std::unique_ptr< BlockMapperType > blockMapper_
Definition: padaptivespace/generic.hh:358
GenericDiscreteFunctionSpace(GridPartType &gridPart, const int order, const InterfaceType commInterface, const CommunicationDirection commDirection)
constructor
Definition: padaptivespace/generic.hh:108
BaseType::BlockMapperType BlockMapperType
Definition: padaptivespace/generic.hh:63
DFSpaceIdentifier type() const
return type identifier of discrete function space
Definition: padaptivespace/generic.hh:138
int IdentifierType
type of identifier for this discrete function space
Definition: padaptivespace/generic.hh:95
int order(const typename BaseType::EntityType &entity) const
get global order of space
Definition: padaptivespace/generic.hh:153
Traits::CompiledLocalKeyType CompiledLocalKeyType
Definition: padaptivespace/generic.hh:88
const CompiledLocalKeyType & compiledLocalKey(const EntityType &entity) const
provide access to the compiled local keys for an entity
Definition: padaptivespace/generic.hh:208
BlockMapperType * initialize(const BlockMapperType *otherMapper=0)
Definition: padaptivespace/generic.hh:321
Traits::ScalarShapeFunctionSetType ScalarShapeFunctionSetType
Definition: padaptivespace/generic.hh:70
ThisType GenericDiscreteFunctionSpaceType
Definition: padaptivespace/generic.hh:48
BaseSetLocalKeyStorage< ScalarShapeFunctionSetType > ScalarShapeFunctionSetStorageType
Definition: padaptivespace/generic.hh:72
BaseSetLocalKeyStorage< CompiledLocalKeyType > LocalKeyStorageType
Definition: padaptivespace/generic.hh:89
IteratorType::Entity EntityType
Definition: padaptivespace/generic.hh:57
int order() const
get global order of space
Definition: padaptivespace/generic.hh:150
Traits::template ScalarShapeFunctionSetFactory< pOrd >::Type Type
Definition: padaptivespace/generic.hh:77
Definition: padaptivespace/generic.hh:369
static void apply(const int maxOrder, std::vector< ScalarShapeFunctionSetStorageType > &scalarShapeFunctionSets, std::vector< LocalKeyStorageType > &compiledLocalKeys, const GeometryType &type)
Definition: padaptivespace/generic.hh:382
static CompiledLocalKeyType * createObject(const GeometryType &type)
Definition: padaptivespace/generic.hh:372
static void deleteObject(CompiledLocalKeyType *obj)
Definition: padaptivespace/generic.hh:376
Singleton list for key/object pairs.
Definition: singletonlist.hh:53