Dune Core Modules (2.3.1)

grapegriddisplay.hh
Go to the documentation of this file.
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_GRAPEGRIDDISPLAY_HH
4#define DUNE_GRAPEGRIDDISPLAY_HH
5
6//- system includes
7#include <list>
8#include <set>
9#include <stack>
10
11//- Dune includes
15
16#if HAVE_GRAPE
17//-local includes
18#include "grape/grapeinclude.hh"
19#endif
20
26namespace Dune
27{
28
31 {
32 g_Interior_Partition = Interior_Partition,
33 g_InteriorBorder_Partition = InteriorBorder_Partition,
34 g_Overlap_Partition = Overlap_Partition,
35 g_OverlapFront_Partition = OverlapFront_Partition,
36 g_All_Partition = All_Partition,
37 g_Ghost_Partition = Ghost_Partition
38 };
39
43 {
44 g_LeafIterator = 0,
45 g_LevelIterator = 1,
46 g_HierarchicIterator = 2,
47 g_GridPart = 3
48 };
49
53 template<class GridType>
55 {
57 typedef MyDisplayType ThisType;
58 enum { dim = GridType::dimension };
59 enum { dimworld = GridType::dimensionworld };
60
61 public:
62#if HAVE_GRAPE
63 // defined in griddisplay.hh
64 typedef typename GrapeInterface<dim,dimworld>::DUNE_ELEM DUNE_ELEM;
65 typedef typename GrapeInterface<dim,dimworld>::DUNE_DAT DUNE_DAT;
66 typedef typename GrapeInterface<dim,dimworld>::DUNE_FDATA DUNE_FDATA;
67 typedef typename GrapeInterface<dim,dimworld>::F_DATA F_DATA;
68 typedef typename GrapeInterface<dim,dimworld>::STACKENTRY STACKENTRY;
69
70 typedef typename std::stack < STACKENTRY * > StackEntryType;
71 typedef void setGridPartIterators_t (DUNE_DAT * , void * gridPart);
72#endif // #if HAVE_GRAPE
73
74 typedef typename GridType::HierarchicIterator HierarchicIteratorType;
75
76 typedef typename GridType::Traits::LocalIdSet LocalIdSetType;
77 typedef typename GridType::Traits::LeafIndexSet LeafIndexSetType;
78
79 protected:
80 typedef std::list<HierarchicIteratorType *> HierarchicIteratorList;
81 typedef typename HierarchicIteratorList::iterator ListIteratorType;
82
83 private:
86 public:
88 inline GrapeGridDisplay(const GridType &grid, const int myrank = -1);
89
91 template <class GridPartType>
92 inline GrapeGridDisplay(const GridPartType &gridPart, const int myrank = -1);
93
94 template< class VT >
95 inline GrapeGridDisplay ( const GridView< VT > &gridView, const int myrank = -1 );
96
98 inline ~GrapeGridDisplay();
99
102 inline void display();
103
105 int myRank () const { return myRank_; }
106
108 inline const GridType& getGrid() const ;
109
110#if HAVE_GRAPE
112 inline void * getHmesh();
113
115 DUNE_DAT & getDuneDat () { return dune_; }
116
118 inline void addMyMeshToTimeScene(void * timescene, double time, int proc);
119
120 bool hasData () { return false; }
121
122 protected:
123 // generate hmesh
124 inline void * setupHmesh();
125
126 inline void deleteHmesh();
127
128 typedef typename GridType::template Codim<0>::Entity EntityCodim0Type;
129
130 // type of index method
131 typedef int EntityIndexFuncType (void * iset, const EntityCodim0Type & en);
132 // type of vertex method
133 typedef int VertexIndexFuncType (void * iset, const EntityCodim0Type & en, int vx);
134
135 // return element index from given index set
136 template <class IndexSetType>
137 static int getEntityIndex(void * iset, const EntityCodim0Type & en)
138 {
139 assert( iset );
140 const IndexSetType * set = ((const IndexSetType *) iset);
141 return (en.isLeaf()) ? set->index(en) : -1;
142 }
143
144 // return vertex index from given index set
145 template< class IndexSet >
146 static int getVertexIndex ( void *iset, const EntityCodim0Type &entity, int vx )
147 {
148 assert( iset != 0 );
149 const IndexSet *indexSet = (const IndexSet *)iset;
150 //return set->template subIndex< dim >( entity, vx );
151 return indexSet->subIndex( entity, vx, dim );
152 }
153
154 public:
155 //****************************************************************
156 //
157 // --GrapeGridDisplay, Some Subroutines needed for display with GRAPE
158 //
159 //****************************************************************
160 // update element from entity
161 template <class IntersectionIteratorType>
162 inline void checkNeighbors(IntersectionIteratorType&,
163 const IntersectionIteratorType&, DUNE_ELEM *) ;
164
165 // update element from entity
166 template <class Entity>
167 inline void el_update_base (Entity& en , DUNE_ELEM *) ;
168
169 // update element from entity
170 template <class EntityPointerType, class GridView>
171 inline int el_update (EntityPointerType *, DUNE_ELEM *, const GridView& );
172
173 // update child element
174 template <class EntityPointerType>
175 inline int child_update (EntityPointerType * , DUNE_ELEM *) ;
176
177 template <class EntityPointerType>
178 inline int child_n_update (EntityPointerType *, DUNE_ELEM *) ;
179
180 // first and next macro element via LevelIterator level 0
181 template <PartitionIteratorType pitype>
182 inline int first_leaf (DUNE_ELEM * he) ;
183 template <PartitionIteratorType pitype>
184 inline int next_leaf (DUNE_ELEM * he) ;
185
186 // first and next macro element via LevelIterator level 0
187 template <class GridPartImp>
188 inline int first_item (DUNE_ELEM * he) ;
189 template <class GridPartImp>
190 inline int next_item (DUNE_ELEM * he) ;
191
192 // first and next macro element via LevelIterator level
193 template <PartitionIteratorType pitype>
194 inline int first_level (DUNE_ELEM * he, int level) ;
195
196 template <PartitionIteratorType pitype>
197 inline int next_level (DUNE_ELEM * he) ;
198
199 // methods to call for combined display
200 inline int firstMacro (DUNE_ELEM * elem) { return dune_.first_macro(elem); }
201 inline int nextMacro (DUNE_ELEM * elem) { return dune_.next_macro(elem); }
202 inline int firstChild (DUNE_ELEM * elem) { return (dune_.first_child) ? dune_.first_child(elem) : 0; }
203 inline int nextChild (DUNE_ELEM * elem) { return (dune_.next_child) ? dune_.next_child(elem) : 0; }
204
205 // first and next child via HierarchicIterator with given maxlevel in Grape
206 inline int first_child (DUNE_ELEM * he) ;
207 inline int next_child (DUNE_ELEM * he) ;
208
209 public:
210 // delete leaf iterators
211 template <PartitionIteratorType pitype>
212 inline void delete_leaf (DUNE_ELEM * he) ;
213 // delete level iterators
214 template <PartitionIteratorType pitype>
215 inline void delete_level (DUNE_ELEM * he) ;
216 // delete level and hierarchical iterators
217 template <PartitionIteratorType pitype>
218 inline void delete_hier (DUNE_ELEM * he) ;
219
220 // delete iterators
221 template <class IteratorType>
222 inline void delete_iterators(DUNE_ELEM * he) ;
223 public:
224
225 // fake function for copy iterator
226 inline static void * copy_iterator (const void * i) ;
227
228 // local to world
229 inline void local2world (DUNE_ELEM * he, const double * c, double * w);
230
231 // world to local
232 inline int world2local (DUNE_ELEM * he, const double * w, double * c);
233
234 // check inside reference element
235 inline int checkWhetherInside (DUNE_ELEM * he, const double * w);
236
237 //*********************************
238 // wrapper functions
239 //*********************************
240 // local to world
241 inline static void ctow (DUNE_ELEM * he, const double * c, double * w);
242
243 // world to local
244 inline static int wtoc (DUNE_ELEM * he, const double * w, double * c);
245
246 // check inside reference element
247 inline static int check_inside (DUNE_ELEM * he, const double * w);
248
249 // dito
250 template< class Entity >
251 int checkInside ( const Entity &entity, const double *w );
252
253 // dito
254 template< class Entity >
255 int world_to_local ( const Entity &entity, const double *w, double *c );
256
257 // dito
258 template <class EntityType>
259 inline void local_to_world(const EntityType &en, const double * c, double * w);
260
261 template <PartitionIteratorType pitype>
262 inline void selectIterators(DUNE_DAT *, void *, setGridPartIterators_t *) const;
263
264 inline void setIterationMethods(DUNE_DAT *, DUNE_FDATA * ) const;
265
266 inline void changeIterationMethods(int iterType, int partType, DUNE_FDATA *);
267
268 template <PartitionIteratorType pitype>
269 struct IterationMethods
270 {
271 // wrapper methods for first_child and next_child
272 inline static int first_mac (DUNE_ELEM * he)
273 {
274 MyDisplayType & disp = *((MyDisplayType *) he->display);
275 return disp.template first_level<pitype>(he,0);
276 }
277
278 // wrapper methods for first_child and next_child
279 inline static int first_lev (DUNE_ELEM * he)
280 {
281 MyDisplayType & disp = *((MyDisplayType *) he->display);
282 return disp.template first_level<pitype>(he,he->level_of_interest);
283 }
284
285 inline static int next_lev (DUNE_ELEM * he)
286 {
287 MyDisplayType & disp = *((MyDisplayType *) he->display);
288 return disp.template next_level<pitype>(he);
289 }
290
291 // wrapper methods for first_child and next_child
292 inline static int fst_leaf (DUNE_ELEM * he)
293 {
294 MyDisplayType & disp = *((MyDisplayType *) he->display);
295 return disp.template first_leaf<pitype>(he);
296 }
297 inline static int nxt_leaf (DUNE_ELEM * he)
298 {
299 MyDisplayType & disp = *((MyDisplayType *) he->display);
300 return disp.template next_leaf<pitype>(he);
301 }
302
303 // wrapper methods for first_child and next_child
304 inline static int fst_child (DUNE_ELEM * he)
305 {
306 MyDisplayType & disp = *((MyDisplayType *) he->display);
307 return disp.first_child(he);
308 }
309 inline static int nxt_child (DUNE_ELEM * he)
310 {
311 MyDisplayType & disp = *((MyDisplayType *) he->display);
312 return disp.next_child(he);
313 }
314
315 // wrapper methods for deleting iterators
316 inline static void del_leaf (DUNE_ELEM * he)
317 {
318 MyDisplayType & disp = *((MyDisplayType *) he->display);
319 disp.template delete_leaf<pitype>(he);
320 }
321
322 // wrapper methods for deleting iterators
323 inline static void del_level (DUNE_ELEM * he)
324 {
325 MyDisplayType & disp = *((MyDisplayType *) he->display);
326 disp.template delete_level<pitype>(he);
327 }
328
329 // wrapper methods for deleting iterators
330 inline static void del_hier (DUNE_ELEM * he)
331 {
332 MyDisplayType & disp = *((MyDisplayType *) he->display);
333 disp.template delete_hier<pitype>(he);
334 }
335
336 };
337
338 protected:
339 template <class GridPartType>
340 struct IterationMethodsGP
341 {
342 // wrapper methods for first_item and next_item
343 inline static int fst_item (DUNE_ELEM * he)
344 {
345 assert( he->display );
346 MyDisplayType & disp = *((MyDisplayType *) he->display);
347 return disp.template first_item<GridPartType>(he);
348 }
349 inline static int nxt_item (DUNE_ELEM * he)
350 {
351 assert( he->display );
352 MyDisplayType & disp = *((MyDisplayType *) he->display);
353 return disp.template next_item<GridPartType>(he);
354 }
355
356 // delete iterators
357 inline static void del_iter (DUNE_ELEM * he)
358 {
359 assert( he->display );
360 MyDisplayType & disp = *((MyDisplayType *) he->display);
361 typedef typename GridPartType :: template Codim<0> :: IteratorType IteratorType;
362 disp.template delete_iterators<IteratorType> (he);
363 }
364 };
365
366 template <class GridPartImp>
367 struct SetIter
368 {
369 static void setGPIterator (DUNE_DAT * dune ,void * gridPart)
370 {
371 assert( gridPart );
372 dune->gridPart = gridPart;
373 dune->first_macro = &IterationMethodsGP<GridPartImp>::fst_item;
374 dune->next_macro = &IterationMethodsGP<GridPartImp>::nxt_item;
375 dune->delete_iter = &IterationMethodsGP<GridPartImp>::del_iter;
376
377 dune->first_child = 0;
378 dune->next_child = 0;
379 }
380 };
381
382 template< class ViewTraits >
383 struct GridViewIterators
384 {
385 typedef Dune::GridView< ViewTraits > GridView;
386 typedef typename GridView::template Codim< 0 >::Iterator Iterator;
387
388 static int first_macro ( DUNE_ELEM *he )
389 {
390 assert( he->display != 0 );
391 MyDisplayType &display = *static_cast< MyDisplayType * >( he->display );
392
393 if( he->liter != 0 )
394 display.template delete_iterators< Iterator >( he );
395
396 assert( he->gridPart != 0 );
397 const GridView &gridView = *static_cast< const GridView * >( he->gridPart );
398
399 assert( he->liter == 0 );
400 assert( he->enditer == 0 );
401
402 Iterator *it = new Iterator( gridView.template begin< 0 >() );
403 Iterator *end = new Iterator( gridView.template end < 0 >() );
404
405 he->liter = it;
406 he->enditer = end;
407
408 if( *it == *end )
409 {
410 display.template delete_iterators< Iterator >( he );
411 return 0;
412 }
413
414 return display.el_update( it, he, gridView );
415 }
416
417 static int next_macro ( DUNE_ELEM *he )
418 {
419 assert( he->display != 0 );
420 MyDisplayType &display = *static_cast< MyDisplayType * >( he->display );
421
422 assert( he->gridPart != 0 );
423 const GridView &gridView = *static_cast< const GridView * >( he->gridPart );
424
425 Iterator *it = static_cast< Iterator * >( he->liter );
426 Iterator *end = static_cast< Iterator * >( he->enditer );
427 assert( (it != 0) && (end != 0) );
428
429 ++(*it);
430 if( *it == *end )
431 {
432 display.template delete_iterators< Iterator >( he );
433 return 0;
434 }
435
436 return display.el_update( it, he, gridView );
437 }
438
439 static void delete_iter ( DUNE_ELEM *he )
440 {
441 assert( he->display );
442 MyDisplayType &display = *static_cast< MyDisplayType * >( he->display );
443 display.template delete_iterators< Iterator >( he );
444 }
445
446 static void set ( DUNE_DAT *dune, void *gridView )
447 {
448 assert( gridView );
449 dune->gridPart = gridView;
450 dune->first_macro = &first_macro;
451 dune->next_macro = &next_macro;
452 dune->delete_iter = &delete_iter;
453
454 dune->first_child = 0;
455 dune->next_child = 0;
456 }
457 };
458
459 inline static void setIterationModus(DUNE_DAT * , DUNE_FDATA *);
460
461 public:
462 // create STACKENTRY or get from stack
463 inline static void * getStackEntry(StackEntryType & stackEntry);
464
465 // get StackEntry Wrapper
466 inline static void * getStackEn(DUNE_DAT * dune);
467
468 // free StackEntry Wrapper
469 inline static void freeStackEn(DUNE_DAT * dune, void * entry);
470
471 inline static void deleteStackEntry(StackEntryType &);
472
473 // push STACKENTRY to stack
474 inline static void freeStackEntry(StackEntryType & stackEntry, void * entry);
475
476 protected:
478 DUNE_ELEM hel_;
479 DUNE_DAT dune_;
480 setGridPartIterators_t * setGridPartIter_;
481
482 // pointer to index method
483 const EntityIndexFuncType * entityIndex;
484 // pointer to vertex method
485 const VertexIndexFuncType * vertexIndex;
486
487 StackEntryType stackEntry_;
488#endif // #if HAVE_GRAPE
489
490 // the grid we want to display
491 const GridType &grid_;
492
493 // true if we can use LevelIntersectionIterator
494 const bool hasLevelIntersections_;
495
496 void * gridPart_;
497
498 // leaf index set of the grid
499 void * indexSet_;
500
501 // leaf index set of the grid
502 const LocalIdSetType & lid_;
503
504 // my process number
505 const int myRank_;
506
507 // no better way than this canot export HMESH structure to here
508 // pointer to hmesh
509 void * hmesh_;
510
511 HierarchicIteratorList hierList_;
512 }; // end class GrapeGridDisplay
513
514#if HAVE_GRAPE
515 /**************************************************************************/
516 // element types, see dune/grid/common/grid.hh
517 // and also geldesc.hh for GR_ElementTypes
518 enum GRAPE_ElementType
519 {
520 g_vertex = GrapeInterface_three_three::gr_vertex
521 , g_line = GrapeInterface_three_three::gr_line
522 , g_triangle = GrapeInterface_three_three::gr_triangle
523 , g_quadrilateral = GrapeInterface_three_three::gr_quadrilateral
524 , g_tetrahedron = GrapeInterface_three_three::gr_tetrahedron
525 , g_pyramid = GrapeInterface_three_three::gr_pyramid
526 , g_prism = GrapeInterface_three_three::gr_prism
527 , g_hexahedron = GrapeInterface_three_three::gr_hexahedron
528 , g_iso_triangle = GrapeInterface_three_three::gr_iso_triangle
529 , g_iso_quadrilateral = GrapeInterface_three_three::gr_iso_quadrilateral
530 , g_unknown = GrapeInterface_three_three::gr_unknown
531 };
532
534 static inline GRAPE_ElementType convertToGrapeType ( GeometryType duneType , int dim )
535 {
536 static std::vector< GRAPE_ElementType > convertedType;
537 if( convertedType.size() == 0 )
538 {
539 const size_t geomSize = GlobalGeometryTypeIndex :: size( 3 ) ;
540 convertedType.resize( geomSize, g_unknown );
541
542 GeometryType type ;
544 // 2D
546 type.makeVertex();
547 convertedType[ GlobalGeometryTypeIndex :: index( type ) ] = g_vertex;
548 type.makeLine();
549 convertedType[ GlobalGeometryTypeIndex :: index( type ) ] = g_line;
550 type.makeTriangle();
551 convertedType[ GlobalGeometryTypeIndex :: index( type ) ] = g_triangle;
552 type.makeQuadrilateral();
553 convertedType[ GlobalGeometryTypeIndex :: index( type ) ] = g_quadrilateral;
554
556 // 3D
558 type.makeTetrahedron();
559 convertedType[ GlobalGeometryTypeIndex :: index( type ) ] = g_tetrahedron;
560 type.makeHexahedron();
561 convertedType[ GlobalGeometryTypeIndex :: index( type ) ] = g_hexahedron;
562 type.makePyramid();
563 convertedType[ GlobalGeometryTypeIndex :: index( type ) ] = g_pyramid;
564 type.makePrism();
565 convertedType[ GlobalGeometryTypeIndex :: index( type ) ] = g_prism;
566 }
567
568 assert( GlobalGeometryTypeIndex :: index( duneType ) < convertedType.size() );
569 assert( convertedType[ GlobalGeometryTypeIndex :: index( duneType ) ] != g_unknown );
570 return convertedType[ GlobalGeometryTypeIndex :: index( duneType ) ];
571 }
572
573 // see geldesc.hh for definition of this mapping
574 // this is the same for all namespaces (two_two , and two_three, ...)
575 static const int * const * vxMap = GrapeInterface_three_three::dune2GrapeVertex;
576 static inline int mapDune2GrapeVertex( int geomType , int vx )
577 {
578 enum { usedTypes = GrapeInterface_three_three::numberOfUsedGrapeElementTypes };
579 assert( geomType >= 0 );
580 assert( geomType < usedTypes ); // at the moment only defined from 2 to 7
581 return vxMap[geomType][vx];
582 }
583
584 // see geldesc.hh for definition of this mapping
585 // this is the same for all namespaces (two_two , and two_three, ...)
586 static const int * const * faceMap = GrapeInterface_three_three::dune2GrapeFace;
587 static inline int mapDune2GrapeFace( int geomType , int duneFace )
588 {
589 enum { usedTypes = GrapeInterface_three_three::numberOfUsedGrapeElementTypes };
590 assert( geomType >= 0 );
591 assert( geomType < usedTypes ); // at the moment only defined from 2 to 7
592 return faceMap[geomType][ duneFace ];
593 }
594#endif
595
596} // end namespace Dune
597
598#include "grape/grapegriddisplay.cc"
599
600// undefs all defines
601#include "grape/grape_undefs.hh"
602#endif
static std::size_t size(std::size_t maxdim)
Compute total number of geometry types up to and including the given dimension.
Definition: typeindex.hh:132
static std::size_t index(const GeometryType &gt)
Compute the index for the given geometry type over all dimensions.
Definition: typeindex.hh:145
Definition: grapegriddisplay.hh:55
~GrapeGridDisplay()
Destructor for GrapeGridDisplay.
Definition: grapegriddisplay.cc:101
int myRank() const
return rank of this display, for visualisation of parallel grid
Definition: grapegriddisplay.hh:105
void display()
Definition: grapegriddisplay.cc:975
const GridType & getGrid() const
return reference to Dune Grid
Definition: grapegriddisplay.cc:985
Grid view abstract base class.
Definition: gridview.hh:57
Different resources needed by all grid implementations.
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
Contains #undefs for all preprocessor macros defined by grape.
Dune namespace.
Definition: alignment.hh:14
GrapeIteratorType
the internal grape partition iterator types need to be these exact values to associate with combo but...
Definition: grapegriddisplay.hh:43
@ All_Partition
all entities
Definition: gridenums.hh:135
@ OverlapFront_Partition
interior, border, overlap and front entities
Definition: gridenums.hh:134
@ Interior_Partition
only interior entities
Definition: gridenums.hh:131
@ InteriorBorder_Partition
interior and border entities
Definition: gridenums.hh:132
@ Overlap_Partition
interior, border, and overlap entities
Definition: gridenums.hh:133
@ Ghost_Partition
only ghost entities
Definition: gridenums.hh:136
GrapePartitionIteratorType
the internal grape partition iterator types
Definition: grapegriddisplay.hh:31
Standard Dune debug streams.
Helper classes to provide indices for geometrytypes for use in a vector.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)