DUNE-FEM (unstable)

generic.hh
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
10#include <dune/fem/common/forloop.hh>
11#include <dune/fem/function/vectorfunction.hh>
12#include <dune/fem/space/basisfunctionset/default.hh>
13#include <dune/fem/space/common/basesetlocalkeystorage.hh>
14#include <dune/fem/space/common/discretefunctionspace.hh>
15#include <dune/fem/space/common/dofmanager.hh>
16#include <dune/fem/space/common/interpolate.hh>
18#include <dune/fem/space/shapefunctionset/selectcaching.hh>
19#include <dune/fem/space/shapefunctionset/simple.hh>
20#include <dune/fem/space/shapefunctionset/vectorial.hh>
21
22#include <dune/fem/space/common/dataprojection/dataprojection.hh>
23#include <dune/fem/space/common/dataprojection/tuple.hh>
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:
49 typedef typename BaseType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
50
51 typedef typename BaseType::FunctionSpaceType FunctionSpaceType;
52
53 typedef typename BaseType::GridPartType GridPartType;
54 typedef typename BaseType::GridType GridType;
55 typedef typename BaseType::IndexSetType IndexSetType;
56 typedef typename BaseType::IteratorType IteratorType;
57 typedef typename IteratorType::Entity EntityType;
58 typedef typename BaseType::IntersectionType IntersectionType;
59
60 typedef typename Traits::ShapeFunctionSetType ShapeFunctionSetType;
61 typedef typename BaseType::BasisFunctionSetType BasisFunctionSetType;
62
63 typedef typename BaseType::BlockMapperType BlockMapperType;
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 >
75 struct ScalarShapeFunctionSetFactory
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
85 using BaseType :: dofManager_;
86
87 public:
88 typedef typename Traits::CompiledLocalKeyType CompiledLocalKeyType;
89 typedef BaseSetLocalKeyStorage< CompiledLocalKeyType > LocalKeyStorageType;
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
99 using BaseType::asImp;
109 const int order,
110 const InterfaceType commInterface,
111 const CommunicationDirection commDirection )
112 : BaseType( gridPart, commInterface, commDirection ),
113 order_( order ),
114 scalarShapeFunctionSets_( order_+1 ),
115 compiledLocalKeys_( order_+1 ),
116 blockMapper_( initialize() )
117 {
118 assert( Capabilities::isAdaptiveDofMapper< BlockMapperType>::v );
119 }
120
121 protected:
122 // copy constructor needed for p-adaptation
124 : BaseType( other.gridPart_, other.commInterface_, other.commDirection_ ),
125 order_( other.order_ ),
126 scalarShapeFunctionSets_( order_+1 ),
127 compiledLocalKeys_( order_+1 ),
128 blockMapper_( initialize( &other.blockMapper() ) )
129 {}
130
131 public:
132
134 // Interface methods //
136
138 inline DFSpaceIdentifier type () const { return GenericSpace_id; }
141 BasisFunctionSetType basisFunctionSet ( const EntityType &entity ) const
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
162 BlockMapperType &blockMapper () const
163 {
164 assert( blockMapper_ );
165 return *blockMapper_;
166 }
167
168
170 // Non-interface methods //
172
180 ShapeFunctionSetType shapeFunctionSet ( const EntityType &entity ) const
181 {
182 return shapeFunctionSet( entity.type(), order( entity ) );
183 }
184
193 ShapeFunctionSetType shapeFunctionSet ( const GeometryType &type, const int order = polynomialOrder ) const
194 {
195 return ShapeFunctionSetType( &scalarShapeFunctionSets_[ order ][ type ] );
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
281 dofManager_.resize();
282 dofManager_.compress();
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
295 dofManager_.enlargeMemory();
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
313 dofManager_.resize();
314 dofManager_.compress();
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
325 AllGeomTypes< IndexSetType, GridType > allGeometryTypes( indexSet );
326 const std::vector< GeometryType > &geometryTypes
327 = allGeometryTypes.geomTypes( 0 );
328
329 for( unsigned int i = 0; i < geometryTypes.size(); ++i )
330 {
331 Fem::ForLoop< Initialize, 1, polynomialOrder >::
332 apply( order_, scalarShapeFunctionSets_, compiledLocalKeys_, geometryTypes[ i ] );
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
344 return new BlockMapperType( gridPart(), order_, compiledLocalKeys_ );
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>
368 struct GenericDiscreteFunctionSpace< Traits >::Initialize
369 {
370 struct CompiledLocalKeyFactory
371 {
372 static CompiledLocalKeyType *createObject ( const GeometryType &type )
373 {
374 return new CompiledLocalKeyType( type, pOrd );
375 }
376 static void deleteObject ( CompiledLocalKeyType *obj )
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;
391 typedef SingletonList< const GeometryType, ScalarShapeFunctionSetType, ScalarShapeFunctionSetFactoryType > SingletonProviderType;
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
Definition: default.hh:124
This is the class with default implementations for discrete function. The methods not marked with hav...
Definition: discretefunctionspace.hh:649
const IndexSetType & indexSet() const
Get a reference to the associated index set.
Definition: discretefunctionspace.hh:772
GridPartType & gridPart() const
Definition: discretefunctionspace.hh:766
Traits::FunctionSpaceType FunctionSpaceType
type of function space
Definition: discretefunctionspace.hh:194
Traits::BasisFunctionSetType BasisFunctionSetType
type of basis function set of this space
Definition: discretefunctionspace.hh:201
GridPartType::IntersectionType IntersectionType
type of the intersections
Definition: discretefunctionspace.hh:226
Please doc me.
Definition: generic.hh:43
KeyType getMark(const EntityType &entity) const
get key to be assigned to an entity after next call to adapt()
Definition: generic.hh:263
BlockMapperType & blockMapper() const
get a reference to the block mapper
Definition: generic.hh:162
static const int polynomialOrder
maximal available polynomial order
Definition: generic.hh:66
BasisFunctionSetType basisFunctionSet(const EntityType &entity) const
get basis function set for given entity
Definition: generic.hh:141
ShapeFunctionSetType shapeFunctionSet(const GeometryType &type, const int order=polynomialOrder) const
return shape unique function set for geometry type
Definition: generic.hh:193
bool continuous() const
returns true if the space contains only globally continuous functions
Definition: generic.hh:147
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: generic.hh:223
ShapeFunctionSetType shapeFunctionSet(const EntityType &entity) const
return shape function set for given entity
Definition: generic.hh:180
KeyType key(const EntityType &entity) const
get identifiying basis function set key assigned to given entity
Definition: generic.hh:242
bool multipleBaseFunctionSets() const
this space has more than one base function set
Definition: generic.hh:159
void adapt()
p adaptation
Definition: generic.hh:274
void mark(const KeyType &key, const EntityType &entity)
assign new key to given entity
Definition: generic.hh:252
GenericDiscreteFunctionSpace(GridPartType &gridPart, const int order, const InterfaceType commInterface, const CommunicationDirection commDirection)
constructor
Definition: generic.hh:108
DFSpaceIdentifier type() const
return type identifier of discrete function space
Definition: generic.hh:138
int IdentifierType
type of identifier for this discrete function space
Definition: generic.hh:95
int order(const typename BaseType::EntityType &entity) const
get global order of space
Definition: generic.hh:153
const CompiledLocalKeyType & compiledLocalKey(const EntityType &entity) const
provide access to the compiled local keys for an entity
Definition: generic.hh:208
int order() const
get global order of space
Definition: generic.hh:150
Abstract definition of the local restriction and prolongation of discrete functions.
Definition: dataprojection.hh:29
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:114
DFSpaceIdentifier
enumerator for identification of spaces
Definition: discretefunctionspace.hh:95
@ GenericSpace_id
id for Generic Space
Definition: discretefunctionspace.hh:101
void enlargeMemory()
resize the MemObject if necessary
Definition: dofmanager.hh:1045
void resize()
Resize index sets and memory due to what the mapper has as new size.
Definition: dofmanager.hh:1012
void compress()
Compress all data that is hold by this dofmanager.
Definition: dofmanager.hh:1068
CommunicationDirection
Define a type for communication direction parameter.
Definition: gridenums.hh:170
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:86
Some useful basic math stuff.
Dune namespace.
Definition: alignedallocator.hh:13
Provides a proxy class for pointers to a shape function set.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)