Dune Core Modules (2.3.1)

indexsets.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_ALBERTAGRIDINDEXSETS_HH
4#define DUNE_ALBERTAGRIDINDEXSETS_HH
5
7
10
12#include <dune/grid/albertagrid/misc.hh>
13#include <dune/grid/albertagrid/dofadmin.hh>
14#include <dune/grid/albertagrid/dofvector.hh>
17
18#if HAVE_ALBERTA
19
20namespace Dune
21{
22
23 namespace Alberta
24 {
25 typedef Dune::IndexStack< int, 100000 > IndexStack;
26
27 extern IndexStack *currentIndexStack;
28 }
29
30
31
32 // AlbertaGridHierarchicIndexSet
33 // -----------------------------
34
35 template< int dim, int dimworld >
36 class AlbertaGridHierarchicIndexSet
37 : public IndexSet< AlbertaGridFamily< dim, dimworld >, AlbertaGridHierarchicIndexSet< dim,dimworld >, int >
38 {
39 typedef AlbertaGridHierarchicIndexSet< dim, dimworld > This;
40 typedef IndexSet< AlbertaGridFamily< dim, dimworld >, This, int > Base;
41
42 friend class AlbertaGrid< dim, dimworld >;
43
44 public:
46 typedef AlbertaGridFamily< dim, dimworld > GridFamily;
47
48 typedef typename Base::IndexType IndexType;
49
50 static const int dimension = GridFamily::dimension;
51
52 typedef Alberta::ElementInfo< dimension > ElementInfo;
53 typedef Alberta::HierarchyDofNumbering< dimension > DofNumbering;
54
55 private:
56 typedef typename GridFamily::Traits Traits;
57
58 typedef Alberta::DofVectorPointer< IndexType > IndexVectorPointer;
59
60 class InitEntityNumber;
61
62 template< int codim >
63 struct CreateEntityNumbers;
64
65 template< int codim >
66 struct RefineNumbering;
67
68 template< int codim >
69 struct CoarsenNumbering;
70
71 explicit AlbertaGridHierarchicIndexSet ( const DofNumbering &dofNumbering );
72
73 public:
74 typedef Alberta::IndexStack IndexStack;
75
77 template< class Entity >
78 bool contains ( const Entity & ) const
79 {
80 return true;
81 }
82
83 using Base::index;
84 using Base::subIndex;
85
87 template< int cc >
88 IndexType index ( const typename Traits::template Codim< cc >::Entity &entity ) const
89 {
90 typedef AlbertaGridEntity< cc, dim, const Grid > EntityImp;
91 const EntityImp &entityImp = Grid::getRealImplementation( entity );
92 return subIndex( entityImp.elementInfo(), entityImp.subEntity(), cc );
93 }
94
96 template< int cc >
97 IndexType subIndex ( const typename Traits::template Codim< cc >::Entity &entity, int i, unsigned int codim ) const
98 {
99 typedef AlbertaGridEntity< cc, dim, const Grid > EntityImp;
100 const EntityImp &entityImp = Grid::getRealImplementation( entity );
101
102 int k = i;
103 if( cc > 0 )
104 {
105 const ReferenceElement< Alberta::Real, dimension > &refElement
107 k = refElement.subEntity( entityImp.subEntity(), cc, i, codim );
108 }
109
110 const int j = entityImp.grid().generic2alberta( codim, k );
111 return subIndex( entityImp.elementInfo(), j, codim );
112 }
113
115 IndexType size ( const GeometryType &type ) const
116 {
117 return (type.isSimplex() ? size( dimension - type.dim() ) : 0);
118 }
119
121 IndexType size ( int codim ) const
122 {
123 assert( (codim >= 0) && (codim <= dimension) );
124 return indexStack_[ codim ].size();
125 }
126
128 const std::vector< GeometryType > &geomTypes( int codim ) const
129 {
130 assert( (codim >= 0) && (codim <= dimension) );
131 return geomTypes_[ codim ];
132 }
133
134 IndexType subIndex ( const ElementInfo &elementInfo, int i, unsigned int codim ) const
135 {
136 assert( !elementInfo == false );
137 return subIndex( elementInfo.element(), i, codim );
138 }
139
146 IndexType subIndex ( const Alberta::Element *element, int i, unsigned int codim ) const
147 {
148 IndexType *array = (IndexType *)entityNumbers_[ codim ];
149 const IndexType subIndex = array[ dofNumbering_( element, codim, i ) ];
150 assert( (subIndex >= 0) && (subIndex < size( codim )) );
151 return subIndex;
152 }
153
154 void preAdapt ()
155 {
156 // set global pointer to index stack
157 if( !IndexVectorPointer::supportsAdaptationData )
158 {
159 assert( Alberta::currentIndexStack == 0 );
160 Alberta::currentIndexStack = indexStack_;
161 }
162 }
163
164 void postAdapt ()
165 {
166 // remove global pointer to index stack
167 if( !IndexVectorPointer::supportsAdaptationData )
168 Alberta::currentIndexStack = 0;
169 }
170
171 void create ();
172 void read ( const std::string &filename );
173 bool write ( const std::string &filename ) const;
174
175 void release ()
176 {
177 for( int i = 0; i <= dimension; ++i )
178 entityNumbers_[ i ].release();
179 }
180
181 private:
182 template< int codim >
183 static IndexStack &getIndexStack ( const IndexVectorPointer &dofVector )
184 {
185 IndexStack *indexStack;
186 if( IndexVectorPointer::supportsAdaptationData )
187 indexStack = dofVector.template getAdaptationData< IndexStack >();
188 else
189 indexStack = &Alberta::currentIndexStack[ codim ];
190 assert( indexStack != 0 );
191 return *indexStack;
192 }
193
194 // access to the dof vectors
195 const DofNumbering &dofNumbering_;
196
197 // index stacks providing new numbers during adaptation
198 IndexStack indexStack_[ dimension+1 ];
199
200 // dof vectors storing the (persistent) numbering
201 IndexVectorPointer entityNumbers_[ dimension+1 ];
202
203 // all geometry types contained in the grid
204 std::vector< GeometryType > geomTypes_[ dimension+1 ];
205 };
206
207
208
209 // AlbertaGridHierarchicIndexSet::InitEntityNumber
210 // -----------------------------------------------
211
212 template< int dim, int dimworld >
213 class AlbertaGridHierarchicIndexSet< dim, dimworld >::InitEntityNumber
214 {
215 IndexStack &indexStack_;
216
217 public:
218 InitEntityNumber ( IndexStack &indexStack )
219 : indexStack_( indexStack )
220 {}
221
222 void operator() ( int &dof )
223 {
224 dof = indexStack_.getIndex();
225 }
226 };
227
228
229
230 // AlbertaGridHierarchicIndexSet::CreateEntityNumbers
231 // --------------------------------------------------
232
233 template< int dim, int dimworld >
234 template< int codim >
235 struct AlbertaGridHierarchicIndexSet< dim, dimworld >::CreateEntityNumbers
236 {
237 static void setup ( AlbertaGridHierarchicIndexSet< dim, dimworld > &indexSet );
238
239 static void apply ( const Alberta::HierarchyDofNumbering< dimension > &dofNumbering,
240 AlbertaGridHierarchicIndexSet< dim, dimworld > &indexSet );
241
242 static void apply ( const std::string &filename,
243 const Alberta::MeshPointer< dimension > &mesh,
244 AlbertaGridHierarchicIndexSet< dim, dimworld > &indexSet );
245 };
246
247
248
249 // AlbertaGridHierarchicIndexSet::RefineNumbering
250 // ----------------------------------------------
251
252 template< int dim, int dimworld >
253 template< int codim >
254 struct AlbertaGridHierarchicIndexSet< dim, dimworld >::RefineNumbering
255 {
256 static const int dimension = dim;
257 static const int codimension = codim;
258
259 private:
260 typedef Alberta::DofAccess< dimension, codimension > DofAccess;
261
262 explicit RefineNumbering ( const IndexVectorPointer &dofVector )
263 : indexStack_( getIndexStack< codimension >( dofVector ) ),
264 dofVector_( dofVector ),
265 dofAccess_( dofVector.dofSpace() )
266 {}
267
268 public:
269 void operator() ( const Alberta::Element *child, int subEntity );
270
271 typedef Alberta::Patch< dimension > Patch;
272 static void interpolateVector ( const IndexVectorPointer &dofVector,
273 const Patch &patch );
274
275 private:
276 IndexStack &indexStack_;
277 IndexVectorPointer dofVector_;
278 DofAccess dofAccess_;
279 };
280
281
282
283 // AlbertaGridHierarchicIndexSet::CoarsenNumbering
284 // -----------------------------------------------
285
286 template< int dim, int dimworld >
287 template< int codim >
288 struct AlbertaGridHierarchicIndexSet< dim, dimworld >::CoarsenNumbering
289 {
290 static const int dimension = dim;
291 static const int codimension = codim;
292
293 private:
294 typedef Alberta::DofAccess< dimension, codimension > DofAccess;
295
296 explicit CoarsenNumbering ( const IndexVectorPointer &dofVector )
297 : indexStack_( getIndexStack< codimension >( dofVector ) ),
298 dofVector_( dofVector ),
299 dofAccess_( dofVector.dofSpace() )
300 {}
301
302 public:
303 void operator() ( const Alberta::Element *child, int subEntity );
304
305 typedef Alberta::Patch< dimension > Patch;
306 static void restrictVector ( const IndexVectorPointer &dofVector,
307 const Patch &patch );
308 private:
309 IndexStack &indexStack_;
310 IndexVectorPointer dofVector_;
311 DofAccess dofAccess_;
312 };
313
314
315
316 // AlbertaGridIndexSet
317 // -------------------
318
319 template< int dim, int dimworld >
320 class AlbertaGridIndexSet
321 : public IndexSet< AlbertaGrid< dim, dimworld >, AlbertaGridIndexSet< dim, dimworld >, int >
322 {
323 typedef AlbertaGridIndexSet< dim, dimworld > This;
324 typedef IndexSet< AlbertaGrid< dim, dimworld >, This, int > Base;
325
326 public:
327 typedef AlbertaGrid< dim, dimworld > Grid;
328
329 typedef typename Base::IndexType IndexType;
330
331 static const int dimension = Grid::dimension;
332
333 typedef Alberta::ElementInfo< dimension > ElementInfo;
334 typedef Alberta::HierarchyDofNumbering< dimension > DofNumbering;
335
336 private:
337 typedef typename Grid::Traits Traits;
338
339 template< int codim >
340 struct Insert;
341
342 public:
343 explicit AlbertaGridIndexSet ( const DofNumbering &dofNumbering )
344 : dofNumbering_( dofNumbering )
345 {
346 for( int codim = 0; codim <= dimension; ++codim )
347 {
348 indices_[ codim ] = 0;
349
350 const GeometryType type( GeometryType::simplex, dimension - codim );
351 geomTypes_[ codim ].push_back( type );
352 }
353 }
354
355 ~AlbertaGridIndexSet ()
356 {
357 for( int codim = 0; codim <= dimension; ++codim )
358 delete[] indices_[ codim ];
359 }
360
361 template< class Entity >
362 bool contains ( const Entity &entity ) const
363 {
364 const int codim = Entity::codimension;
365
366 const AlbertaGridEntity< codim, dim, const Grid > &entityImp
367 = Grid::getRealImplementation( entity );
368 const Alberta::Element *element = entityImp.elementInfo().el();
369
370 const IndexType *const array = indices_[ codim ];
371 const IndexType subIndex = array[ dofNumbering_( element, codim, entityImp.subEntity() ) ];
372
373 return (subIndex >= 0);
374 }
375
376 using Base::index;
377 using Base::subIndex;
378
380 template< int cc >
381 IndexType index ( const typename Traits::template Codim< cc >::Entity &entity ) const
382 {
383 typedef AlbertaGridEntity< cc, dim, const Grid > EntityImp;
384 const EntityImp &entityImp = Grid::getRealImplementation( entity );
385 return subIndex( entityImp.elementInfo(), entityImp.subEntity(), cc );
386 }
387
389 template< int cc >
390 IndexType subIndex ( const typename Traits::template Codim< cc >::Entity &entity, int i, unsigned int codim ) const
391 {
392 typedef AlbertaGridEntity< cc, dim, const Grid > EntityImp;
393 const EntityImp &entityImp = Grid::getRealImplementation( entity );
394
395 int k = i;
396 if( cc > 0 )
397 {
398 const ReferenceElement< Alberta::Real, dimension > &refElement
400 k = refElement.subEntity( entityImp.subEntity(), cc, i, codim );
401 }
402
403 const int j = entityImp.grid().generic2alberta( codim, k );
404 return subIndex( entityImp.elementInfo(), j, codim );
405 }
406
407 IndexType size ( const GeometryType &type ) const
408 {
409 return (type.isSimplex() ? size( dimension - type.dim() ) : 0);
410 }
411
412 IndexType size ( int codim ) const
413 {
414 assert( (codim >= 0) && (codim <= dimension) );
415 return size_[ codim ];
416 }
417
418 const std::vector< GeometryType > &geomTypes( int codim ) const
419 {
420 assert( (codim >= 0) && (codim <= dimension) );
421 return geomTypes_[ codim ];
422 }
423
424 template< class Iterator >
425 void update ( const Iterator &begin, const Iterator &end )
426 {
427 for( int codim = 0; codim <= dimension; ++codim )
428 {
429 delete[] indices_[ codim ];
430
431 const unsigned int dofSize = dofNumbering_.size( codim );
432 indices_[ codim ] = new IndexType[ dofSize ];
433 for( unsigned int i = 0; i < dofSize; ++i )
434 indices_[ codim ][ i ] = -1;
435
436 size_[ codim ] = 0;
437 }
438
439 for( Iterator it = begin; it != end; ++it )
440 {
441 const AlbertaGridEntity< 0, dim, const Grid > &entityImp
443 const Alberta::Element *element = entityImp.elementInfo().el();
444 ForLoop< Insert, 0, dimension >::apply( element, *this );
445 }
446 }
447
448 private:
449 IndexType subIndex ( const ElementInfo &elementInfo, int i, unsigned int codim ) const
450 {
451 assert( !elementInfo == false );
452 return subIndex( elementInfo.element(), i, codim );
453 }
454
461 IndexType subIndex ( const Alberta::Element *element, int i, unsigned int codim ) const
462 {
463 const IndexType *const array = indices_[ codim ];
464 const IndexType subIndex = array[ dofNumbering_( element, codim, i ) ];
465 assert( (subIndex >= 0) && (subIndex < size( codim )) );
466 return subIndex;
467 }
468
469 // access to the dof vectors
470 const DofNumbering &dofNumbering_;
471
472 // an array of indices for each codimension
473 IndexType *indices_[ dimension+1 ];
474
475 // the size of each codimension
476 IndexType size_[ dimension+1 ];
477
478 // all geometry types contained in the grid
479 std::vector< GeometryType > geomTypes_[ dimension+1 ];
480 };
481
482
483
484 // AlbertaGridIndexSet::Insert
485 // ---------------------------
486
487 template< int dim, int dimworld >
488 template< int codim >
489 struct AlbertaGridIndexSet< dim, dimworld >::Insert
490 {
491 static void apply ( const Alberta::Element *const element,
492 AlbertaGridIndexSet< dim, dimworld > &indexSet )
493 {
494 int *const array = indexSet.indices_[ codim ];
495 IndexType &size = indexSet.size_[ codim ];
496
497 for( int i = 0; i < Alberta::NumSubEntities< dim, codim >::value; ++i )
498 {
499 int &index = array[ indexSet.dofNumbering_( element, codim, i ) ];
500 if( index < 0 )
501 index = size++;
502 }
503 }
504 };
505
506
507
508 // AlbertaGridIdSet
509 // ----------------
510
512 template< int dim, int dimworld >
514 : public IdSet< AlbertaGrid< dim, dimworld >, AlbertaGridIdSet< dim, dimworld >, unsigned int >
515 {
517 typedef IdSet< AlbertaGrid< dim, dimworld >, This, unsigned int > Base;
518
519 friend class AlbertaGrid< dim, dimworld >;
520
521 public:
523 typedef typename Base::IdType IdType;
524
525 private:
527
528 static const int dimension = Grid::dimension;
529
530 typedef typename Grid::HierarchicIndexSet HierarchicIndexSet;
531
532 // create id set, only allowed for AlbertaGrid
533 AlbertaGridIdSet ( const HierarchicIndexSet &hIndexSet )
534 : hIndexSet_( hIndexSet )
535 {}
536
537 public:
539 template< class Entity >
540 IdType id ( const Entity &e ) const
541 {
542 const int codim = Entity::codimension;
543 return id< codim >( e );
544 }
545
547 template< int codim >
548 IdType id ( const typename Grid::template Codim< codim >::Entity &e ) const
549 {
550 assert( (codim >= 0) && (codim <= dimension) );
551 const IdType index = hIndexSet_.index( e );
552 return (index << 2) | IdType( codim );
553 }
554
556 IdType subId ( const typename Grid::template Codim< 0 >::Entity &e, int i, unsigned int subcodim ) const
557 {
558 assert( int( subcodim ) <= dimension );
559 const IdType index = hIndexSet_.subIndex( e, i, subcodim );
560 return (index << 2) | IdType( subcodim );
561 }
562
563 template< int codim >
564 IdType subId ( const typename Grid::template Codim< codim >::Entity &e, int i, unsigned int subcodim ) const
565 {
566 assert( (codim >= 0) && (codim <= dimension) && (int( codim + subcodim ) <= dimension) );
567 const IdType index = hIndexSet_.subIndex( e, i, subcodim );
568 return (index << 2) | IdType( codim + subcodim );
569 }
570
571 template< class Entity >
572 IdType subId ( const Entity &e, int i, unsigned int subcodim ) const
573 {
574 return subId< Entity::codimension >( e, i, subcodim );
575 }
576
577 private:
578 // prohibit copying
579 AlbertaGridIdSet ( const This & );
580
581 const HierarchicIndexSet &hIndexSet_;
582 };
583
584} // namespace Dune
585
586#endif // #if HAVE_ALBERTA
587
588#endif // #ifndef DUNE_ALBERTAGRIDINDEXSETS_HH
provides the GridFamily for AlbertaGrid
hierarchic index set of AlbertaGrid
Definition: indexsets.hh:515
IdType id(const typename Grid::template Codim< codim >::Entity &e) const
Get id of an entity of codim cc. Unhandy because template parameter must be supplied explicitely.
Definition: indexsets.hh:548
IdType id(const Entity &e) const
Get id of an entity. This method is simpler to use than the one below.
Definition: indexsets.hh:540
Base::IdType IdType
export type of id
Definition: indexsets.hh:523
IdType subId(const typename Grid::template Codim< 0 >::Entity &e, int i, unsigned int subcodim) const
Get id of subentity i of co-dimension codim of a co-dimension 0 entity.
Definition: indexsets.hh:556
Traits::HierarchicIndexSet HierarchicIndexSet
type of hierarchic index set
Definition: agrid.hh:189
Wrapper class for entities.
Definition: entity.hh:57
@ codimension
Know your own codimension.
Definition: entity.hh:99
@ simplex
Simplicial element in any nonnegative dimension.
Definition: type.hh:30
static ReturnImplementationType< InterfaceType >::ImplementationType & getRealImplementation(InterfaceType &i)
return real implementation of interface class
Definition: grid.hh:1223
Id Set Interface.
Definition: indexidset.hh:403
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:406
IndexType index(const typename remove_const< GridImp >::type::Traits::template Codim< cc >::Entity &e) const
Map entity to index. The result of calling this method with an entity that is not in the index set is...
Definition: indexidset.hh:107
IndexType size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:204
IndexTypeImp IndexType
The type used for the indices.
Definition: indexidset.hh:85
IndexType subIndex(const typename Traits::template Codim< cc >::Entity &e, int i, unsigned int codim) const
Map a subentity to an index.
Definition: indexidset.hh:146
bool contains(const EntityType &e) const
Return true if the given entity is contained in .
Definition: indexidset.hh:228
Definition: indexstack.hh:24
Different resources needed by all grid implementations.
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
provides a wrapper for ALBERTA's el_info structure
Provides base classes for index and id sets.
Provides an index stack that supplies indices for element numbering for a grid (i....
Dune namespace.
Definition: alignment.hh:14
Standard Dune debug streams.
static const ReferenceElement< ctype, dim > & simplex()
get simplex reference elements
Definition: referenceelements.hh:574
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)