00001 #ifndef DUNE_GRAPEGRIDDISPLAY_HH
00002 #define DUNE_GRAPEGRIDDISPLAY_HH
00003
00004
00005 #include <list>
00006 #include <set>
00007 #include <stack>
00008
00009
00010 #include <dune/common/stdstreams.hh>
00011 #include <dune/grid/common/grid.hh>
00012
00013
00014 #include "grape/grapeinclude.hh"
00015
00021 namespace Dune
00022 {
00023
00025 enum GrapePartitionIteratorType
00026 {
00027 g_Interior_Partition = Interior_Partition,
00028 g_InteriorBorder_Partition = InteriorBorder_Partition,
00029 g_Overlap_Partition = Overlap_Partition,
00030 g_OverlapFront_Partition = OverlapFront_Partition,
00031 g_All_Partition = All_Partition,
00032 g_Ghost_Partition = Ghost_Partition
00033 };
00034
00037 enum GrapeIteratorType
00038 {
00039 g_LeafIterator = 0,
00040 g_LevelIterator = 1,
00041 g_HierarchicIterator = 2,
00042 g_GridPart = 3
00043 };
00044
00048 template<class GridType>
00049 class GrapeGridDisplay
00050 {
00051 typedef GrapeGridDisplay < GridType > MyDisplayType;
00052 typedef MyDisplayType ThisType;
00053 enum { dim = GridType::dimension };
00054 enum { dimworld = GridType::dimensionworld };
00055
00056
00057 typedef typename GrapeInterface<dim,dimworld>::DUNE_ELEM DUNE_ELEM;
00058 typedef typename GrapeInterface<dim,dimworld>::DUNE_DAT DUNE_DAT;
00059 typedef typename GrapeInterface<dim,dimworld>::DUNE_FDATA DUNE_FDATA;
00060 typedef typename GrapeInterface<dim,dimworld>::F_DATA F_DATA;
00061 typedef typename GrapeInterface<dim,dimworld>::STACKENTRY STACKENTRY;
00062
00063 public:
00064 typedef typename GridType::template Codim<0>:: HierarchicIterator
00065 HierarchicIteratorType;
00066
00067 typedef typename GridType::Traits::LocalIdSet LocalIdSetType;
00068 typedef typename GridType::Traits::LeafIndexSet LeafIndexSetType;
00069
00070 typedef typename std::stack < STACKENTRY * > StackEntryType;
00071 protected:
00073 const GridType &grid_;
00074
00076 const bool hasLevelIntersections_;
00077
00078 typedef void setGridPartIterators_t(DUNE_DAT * , void * gridPart);
00079 void * gridPart_;
00080
00081 setGridPartIterators_t * setGridPartIter_;
00082
00084 void * indexSet_;
00085
00087 const LocalIdSetType & lid_;
00088
00090 const int myRank_;
00091
00093 DUNE_ELEM hel_;
00094 DUNE_DAT dune_;
00095
00096
00098 void * hmesh_;
00099
00100 typedef std::list<HierarchicIteratorType *> HierarchicIteratorList;
00101 typedef typename HierarchicIteratorList::iterator ListIteratorType;
00102 HierarchicIteratorList hierList_;
00103
00104 StackEntryType stackEntry_;
00105
00106 private:
00108 GrapeGridDisplay(const GrapeGridDisplay &);
00109 public:
00111 inline GrapeGridDisplay(const GridType &grid, const int myrank = -1);
00112
00114 template <class GridPartType>
00115 inline GrapeGridDisplay(const GridPartType &gridPart, const int myrank = -1);
00116
00118 inline ~GrapeGridDisplay();
00119
00122 inline void display();
00123
00125 int myRank () const { return myRank_; }
00126
00128 inline void * getHmesh();
00129
00131 DUNE_DAT & getDuneDat () { return dune_; }
00132
00134 inline void addMyMeshToTimeScene(void * timescene, double time, int proc);
00135
00137 inline const GridType& getGrid() const ;
00138
00139 bool hasData () { return false; }
00140
00141
00142 FieldVector<double,dimworld> globalVec_;
00143 FieldVector<double,dim> localVec_;
00144
00145
00146 protected:
00147
00148 inline void * setupHmesh();
00149
00150 inline void deleteHmesh();
00151
00152 typedef typename GridType::template Codim<0>::Entity EntityCodim0Type;
00153
00154
00155 typedef int EntityIndexFuncType(void * iset, const EntityCodim0Type & en);
00156
00157 typedef int VertexIndexFuncType(void * iset, const EntityCodim0Type & en, int vx);
00158
00159
00160 const EntityIndexFuncType * entityIndex;
00161
00162 const VertexIndexFuncType * vertexIndex;
00163
00164
00165 template <class IndexSetType>
00166 static int getEntityIndex(void * iset, const EntityCodim0Type & en)
00167 {
00168 assert( iset );
00169 const IndexSetType * set = ((const IndexSetType *) iset);
00170 return (en.isLeaf()) ? set->index(en) : -1;
00171 }
00172
00173
00174 template <class IndexSetType>
00175 static int getVertexIndex(void * iset, const EntityCodim0Type & en, int vx)
00176 {
00177 assert( iset );
00178 const IndexSetType * set = ((const IndexSetType *) iset);
00179 return set->template subIndex<dim> (en,vx);
00180 }
00181
00182 public:
00183
00184
00185
00186
00187
00188
00189 template <class IntersectionIteratorType>
00190 inline void checkNeighbors(IntersectionIteratorType&,
00191 const IntersectionIteratorType&, DUNE_ELEM *) ;
00192
00193
00194 template <class Entity>
00195 inline void el_update_base (Entity& en , DUNE_ELEM *) ;
00196
00197
00198 template <class EntityPointerType>
00199 inline int el_update (EntityPointerType *, DUNE_ELEM *) ;
00200
00201
00202 template <class EntityPointerType, class GridPartType>
00203 inline int el_update (EntityPointerType *, DUNE_ELEM *, GridPartType& );
00204
00205
00206 template <class EntityPointerType>
00207 inline int child_update (EntityPointerType * , DUNE_ELEM *) ;
00208
00209 template <class EntityPointerType>
00210 inline int child_n_update (EntityPointerType *, DUNE_ELEM *) ;
00211
00212
00213 template <PartitionIteratorType pitype>
00214 inline int first_leaf (DUNE_ELEM * he) ;
00215 template <PartitionIteratorType pitype>
00216 inline int next_leaf (DUNE_ELEM * he) ;
00217
00218
00219 template <class GridPartImp>
00220 inline int first_item (DUNE_ELEM * he) ;
00221 template <class GridPartImp>
00222 inline int next_item (DUNE_ELEM * he) ;
00223
00224
00225 template <PartitionIteratorType pitype>
00226 inline int first_level (DUNE_ELEM * he, int level) ;
00227
00228 template <PartitionIteratorType pitype>
00229 inline int next_level (DUNE_ELEM * he) ;
00230
00231
00232 inline int firstMacro (DUNE_ELEM * elem) { return dune_.first_macro(elem); }
00233 inline int nextMacro (DUNE_ELEM * elem) { return dune_.next_macro(elem); }
00234 inline int firstChild (DUNE_ELEM * elem) { return (dune_.first_child) ? dune_.first_child(elem) : 0; }
00235 inline int nextChild (DUNE_ELEM * elem) { return (dune_.next_child) ? dune_.next_child(elem) : 0; }
00236
00237
00238 inline int first_child (DUNE_ELEM * he) ;
00239 inline int next_child (DUNE_ELEM * he) ;
00240
00241 public:
00242
00243 template <PartitionIteratorType pitype>
00244 inline void delete_leaf (DUNE_ELEM * he) ;
00245
00246 template <PartitionIteratorType pitype>
00247 inline void delete_level (DUNE_ELEM * he) ;
00248
00249 template <PartitionIteratorType pitype>
00250 inline void delete_hier (DUNE_ELEM * he) ;
00251
00252
00253 template <class IteratorType>
00254 inline void delete_iterators(DUNE_ELEM * he) ;
00255 public:
00256
00257
00258 inline static void * copy_iterator (const void * i) ;
00259
00260
00261 inline void local2world (DUNE_ELEM * he, const double * c, double * w);
00262
00263
00264 inline int world2local (DUNE_ELEM * he, const double * w, double * c);
00265
00266
00267 inline int checkWhetherInside (DUNE_ELEM * he, const double * w);
00268
00269
00270
00271
00272
00273 inline static void ctow (DUNE_ELEM * he, const double * c, double * w);
00274
00275
00276 inline static int wtoc (DUNE_ELEM * he, const double * w, double * c);
00277
00278
00279 inline static int check_inside (DUNE_ELEM * he, const double * w);
00280
00281
00282 template <class EntityType>
00283 inline int checkInside(EntityType &en, const double * w);
00284
00285
00286 template <class EntityType>
00287 inline int world_to_local(EntityType &en, const double * w, double * c);
00288
00289
00290 template <class EntityType>
00291 inline void local_to_world(EntityType &en, const double * c, double * w);
00292
00293 template <PartitionIteratorType pitype>
00294 inline void selectIterators(DUNE_DAT *, void *, setGridPartIterators_t *) const;
00295
00296 inline void setIterationMethods(DUNE_DAT *, DUNE_FDATA * ) const;
00297
00298 inline void changeIterationMethods(int iterType, int partType, DUNE_FDATA *);
00299
00300 template <PartitionIteratorType pitype>
00301 struct IterationMethods
00302 {
00303
00304 inline static int first_mac (DUNE_ELEM * he)
00305 {
00306 MyDisplayType & disp = *((MyDisplayType *) he->display);
00307 return disp.template first_level<pitype>(he,0);
00308 }
00309
00310
00311 inline static int first_lev (DUNE_ELEM * he)
00312 {
00313 MyDisplayType & disp = *((MyDisplayType *) he->display);
00314 return disp.template first_level<pitype>(he,he->level_of_interest);
00315 }
00316
00317 inline static int next_lev (DUNE_ELEM * he)
00318 {
00319 MyDisplayType & disp = *((MyDisplayType *) he->display);
00320 return disp.template next_level<pitype>(he);
00321 }
00322
00323
00324 inline static int fst_leaf (DUNE_ELEM * he)
00325 {
00326 MyDisplayType & disp = *((MyDisplayType *) he->display);
00327 return disp.template first_leaf<pitype>(he);
00328 }
00329 inline static int nxt_leaf (DUNE_ELEM * he)
00330 {
00331 MyDisplayType & disp = *((MyDisplayType *) he->display);
00332 return disp.template next_leaf<pitype>(he);
00333 }
00334
00335
00336 inline static int fst_child (DUNE_ELEM * he)
00337 {
00338 MyDisplayType & disp = *((MyDisplayType *) he->display);
00339 return disp.first_child(he);
00340 }
00341 inline static int nxt_child (DUNE_ELEM * he)
00342 {
00343 MyDisplayType & disp = *((MyDisplayType *) he->display);
00344 return disp.next_child(he);
00345 }
00346
00347
00348 inline static void del_leaf (DUNE_ELEM * he)
00349 {
00350 MyDisplayType & disp = *((MyDisplayType *) he->display);
00351 disp.template delete_leaf<pitype>(he);
00352 }
00353
00354
00355 inline static void del_level (DUNE_ELEM * he)
00356 {
00357 MyDisplayType & disp = *((MyDisplayType *) he->display);
00358 disp.template delete_level<pitype>(he);
00359 }
00360
00361
00362 inline static void del_hier (DUNE_ELEM * he)
00363 {
00364 MyDisplayType & disp = *((MyDisplayType *) he->display);
00365 disp.template delete_hier<pitype>(he);
00366 }
00367
00368 };
00369
00370 protected:
00371 template <class GridPartType>
00372 struct IterationMethodsGP
00373 {
00374
00375 inline static int fst_item (DUNE_ELEM * he)
00376 {
00377 assert( he->display );
00378 MyDisplayType & disp = *((MyDisplayType *) he->display);
00379 return disp.template first_item<GridPartType>(he);
00380 }
00381 inline static int nxt_item (DUNE_ELEM * he)
00382 {
00383 assert( he->display );
00384 MyDisplayType & disp = *((MyDisplayType *) he->display);
00385 return disp.template next_item<GridPartType>(he);
00386 }
00387
00388
00389 inline static void del_iter (DUNE_ELEM * he)
00390 {
00391 assert( he->display );
00392 MyDisplayType & disp = *((MyDisplayType *) he->display);
00393 typedef typename GridPartType :: template Codim<0> :: IteratorType IteratorType;
00394 disp.template delete_iterators<IteratorType> (he);
00395 }
00396 };
00397
00398 template <class GridPartImp>
00399 struct SetIter
00400 {
00401 static void setGPIterator (DUNE_DAT * dune ,void * gridPart)
00402 {
00403 assert( gridPart );
00404 dune->gridPart = gridPart;
00405 dune->first_macro = &IterationMethodsGP<GridPartImp>::fst_item;
00406 dune->next_macro = &IterationMethodsGP<GridPartImp>::nxt_item;
00407 dune->delete_iter = &IterationMethodsGP<GridPartImp>::del_iter;
00408
00409 dune->first_child = 0;
00410 dune->next_child = 0;
00411 }
00412 };
00413
00414 inline static void setIterationModus(DUNE_DAT * , DUNE_FDATA *);
00415
00416 public:
00417
00418 inline static void * getStackEntry(StackEntryType & stackEntry);
00419
00420
00421 inline static void * getStackEn(DUNE_DAT * dune);
00422
00423
00424 inline static void freeStackEn(DUNE_DAT * dune, void * entry);
00425
00426 inline static void deleteStackEntry(StackEntryType &);
00427
00428
00429 inline static void freeStackEntry(StackEntryType & stackEntry, void * entry);
00430
00431 };
00432
00433
00434
00435
00436
00437 enum GRAPE_ElementType
00438 { g_vertex = GrapeInterface_three_three::gr_vertex
00439 , g_line = GrapeInterface_three_three::gr_line
00440 , g_triangle = GrapeInterface_three_three::gr_triangle
00441 , g_quadrilateral = GrapeInterface_three_three::gr_quadrilateral
00442 , g_tetrahedron = GrapeInterface_three_three::gr_tetrahedron
00443 , g_pyramid = GrapeInterface_three_three::gr_pyramid
00444 , g_prism = GrapeInterface_three_three::gr_prism
00445 , g_hexahedron = GrapeInterface_three_three::gr_hexahedron
00446 , g_iso_triangle = GrapeInterface_three_three::gr_iso_triangle
00447 , g_iso_quadrilateral = GrapeInterface_three_three::gr_iso_quadrilateral
00448 , g_unknown = GrapeInterface_three_three::gr_unknown
00449 };
00450
00452 static inline GRAPE_ElementType convertToGrapeType ( GeometryType type , int dim )
00453 {
00454 if(dim < 3)
00455 {
00456 if(type.isTriangle()) return g_triangle;
00457 if(type.isQuadrilateral()) return g_quadrilateral;
00458 if(type.isVertex()) return g_vertex;
00459 if(type.isLine()) return g_line;
00460 }
00461 else
00462 {
00463 if(type.isTetrahedron()) return g_tetrahedron;
00464 if(type.isHexahedron()) return g_hexahedron;
00465 if(type.isPyramid()) return g_pyramid;
00466 if(type.isPrism()) return g_prism;
00467 }
00468
00469 std::cerr << "No requested conversion for GeometryType " << type << "!\n";
00470 return g_unknown;
00471 }
00472
00473
00474
00475 static const int * const * vxMap = GrapeInterface_three_three::dune2GrapeVertex;
00476 static inline int mapDune2GrapeVertex( int geomType , int vx )
00477 {
00478 enum { usedTypes = GrapeInterface_three_three::numberOfUsedGrapeElementTypes };
00479 assert( geomType >= 0 );
00480 assert( geomType < usedTypes );
00481 return vxMap[geomType][vx];
00482 }
00483
00484 }
00485
00486 #include "grape/grapegriddisplay.cc"
00487
00488
00489 #include "grape/grape_undefs.hh"
00490 #endif