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 EntityPointerType>
00195 inline int el_update (EntityPointerType *, DUNE_ELEM *) ;
00196
00197
00198 template <class EntityPointerType>
00199 inline int child_update (EntityPointerType * , DUNE_ELEM *) ;
00200
00201 template <class EntityPointerType>
00202 inline int child_n_update (EntityPointerType *, DUNE_ELEM *) ;
00203
00204
00205 template <PartitionIteratorType pitype>
00206 inline int first_leaf (DUNE_ELEM * he) ;
00207 template <PartitionIteratorType pitype>
00208 inline int next_leaf (DUNE_ELEM * he) ;
00209
00210
00211 template <class GridPartImp>
00212 inline int first_item (DUNE_ELEM * he) ;
00213 template <class GridPartImp>
00214 inline int next_item (DUNE_ELEM * he) ;
00215
00216
00217 template <PartitionIteratorType pitype>
00218 inline int first_level (DUNE_ELEM * he, int level) ;
00219
00220 template <PartitionIteratorType pitype>
00221 inline int next_level (DUNE_ELEM * he) ;
00222
00223
00224 inline int firstMacro (DUNE_ELEM * elem) { return dune_.first_macro(elem); }
00225 inline int nextMacro (DUNE_ELEM * elem) { return dune_.next_macro(elem); }
00226 inline int firstChild (DUNE_ELEM * elem) { return (dune_.first_child) ? dune_.first_child(elem) : 0; }
00227 inline int nextChild (DUNE_ELEM * elem) { return (dune_.next_child) ? dune_.next_child(elem) : 0; }
00228
00229
00230 inline int first_child (DUNE_ELEM * he) ;
00231 inline int next_child (DUNE_ELEM * he) ;
00232
00233 public:
00234
00235 template <PartitionIteratorType pitype>
00236 inline void delete_leaf (DUNE_ELEM * he) ;
00237
00238 template <PartitionIteratorType pitype>
00239 inline void delete_level (DUNE_ELEM * he) ;
00240
00241 template <PartitionIteratorType pitype>
00242 inline void delete_hier (DUNE_ELEM * he) ;
00243
00244
00245 template <class IteratorType>
00246 inline void delete_iterators(DUNE_ELEM * he) ;
00247 public:
00248
00249
00250 inline static void * copy_iterator (const void * i) ;
00251
00252
00253 inline void local2world (DUNE_ELEM * he, const double * c, double * w);
00254
00255
00256 inline int world2local (DUNE_ELEM * he, const double * w, double * c);
00257
00258
00259 inline int checkWhetherInside (DUNE_ELEM * he, const double * w);
00260
00261
00262
00263
00264
00265 inline static void ctow (DUNE_ELEM * he, const double * c, double * w);
00266
00267
00268 inline static int wtoc (DUNE_ELEM * he, const double * w, double * c);
00269
00270
00271 inline static int check_inside (DUNE_ELEM * he, const double * w);
00272
00273
00274 template <class EntityType>
00275 inline int checkInside(EntityType &en, const double * w);
00276
00277
00278 template <class EntityType>
00279 inline int world_to_local(EntityType &en, const double * w, double * c);
00280
00281
00282 template <class EntityType>
00283 inline void local_to_world(EntityType &en, const double * c, double * w);
00284
00285 template <PartitionIteratorType pitype>
00286 inline void selectIterators(DUNE_DAT *, void *, setGridPartIterators_t *) const;
00287
00288 inline void setIterationMethods(DUNE_DAT *, DUNE_FDATA * ) const;
00289
00290 inline void changeIterationMethods(int iterType, int partType, DUNE_FDATA *);
00291
00292 template <PartitionIteratorType pitype>
00293 struct IterationMethods
00294 {
00295
00296 inline static int first_mac (DUNE_ELEM * he)
00297 {
00298 MyDisplayType & disp = *((MyDisplayType *) he->display);
00299 return disp.template first_level<pitype>(he,0);
00300 }
00301
00302
00303 inline static int first_lev (DUNE_ELEM * he)
00304 {
00305 MyDisplayType & disp = *((MyDisplayType *) he->display);
00306 return disp.template first_level<pitype>(he,he->level_of_interest);
00307 }
00308
00309 inline static int next_lev (DUNE_ELEM * he)
00310 {
00311 MyDisplayType & disp = *((MyDisplayType *) he->display);
00312 return disp.template next_level<pitype>(he);
00313 }
00314
00315
00316 inline static int fst_leaf (DUNE_ELEM * he)
00317 {
00318 MyDisplayType & disp = *((MyDisplayType *) he->display);
00319 return disp.template first_leaf<pitype>(he);
00320 }
00321 inline static int nxt_leaf (DUNE_ELEM * he)
00322 {
00323 MyDisplayType & disp = *((MyDisplayType *) he->display);
00324 return disp.template next_leaf<pitype>(he);
00325 }
00326
00327
00328 inline static int fst_child (DUNE_ELEM * he)
00329 {
00330 MyDisplayType & disp = *((MyDisplayType *) he->display);
00331 return disp.first_child(he);
00332 }
00333 inline static int nxt_child (DUNE_ELEM * he)
00334 {
00335 MyDisplayType & disp = *((MyDisplayType *) he->display);
00336 return disp.next_child(he);
00337 }
00338
00339
00340 inline static void del_leaf (DUNE_ELEM * he)
00341 {
00342 MyDisplayType & disp = *((MyDisplayType *) he->display);
00343 disp.template delete_leaf<pitype>(he);
00344 }
00345
00346
00347 inline static void del_level (DUNE_ELEM * he)
00348 {
00349 MyDisplayType & disp = *((MyDisplayType *) he->display);
00350 disp.template delete_level<pitype>(he);
00351 }
00352
00353
00354 inline static void del_hier (DUNE_ELEM * he)
00355 {
00356 MyDisplayType & disp = *((MyDisplayType *) he->display);
00357 disp.template delete_hier<pitype>(he);
00358 }
00359
00360 };
00361
00362 protected:
00363 template <class GridPartType>
00364 struct IterationMethodsGP
00365 {
00366
00367 inline static int fst_item (DUNE_ELEM * he)
00368 {
00369 assert( he->display );
00370 MyDisplayType & disp = *((MyDisplayType *) he->display);
00371 return disp.template first_item<GridPartType>(he);
00372 }
00373 inline static int nxt_item (DUNE_ELEM * he)
00374 {
00375 assert( he->display );
00376 MyDisplayType & disp = *((MyDisplayType *) he->display);
00377 return disp.template next_item<GridPartType>(he);
00378 }
00379
00380
00381 inline static void del_iter (DUNE_ELEM * he)
00382 {
00383 assert( he->display );
00384 MyDisplayType & disp = *((MyDisplayType *) he->display);
00385 typedef typename GridPartType :: template Codim<0> :: IteratorType IteratorType;
00386 disp.template delete_iterators<IteratorType> (he);
00387 }
00388 };
00389
00390 template <class GridPartImp>
00391 struct SetIter
00392 {
00393 static void setGPIterator (DUNE_DAT * dune ,void * gridPart)
00394 {
00395 assert( gridPart );
00396 dune->gridPart = gridPart;
00397 dune->first_macro = &IterationMethodsGP<GridPartImp>::fst_item;
00398 dune->next_macro = &IterationMethodsGP<GridPartImp>::nxt_item;
00399 dune->delete_iter = &IterationMethodsGP<GridPartImp>::del_iter;
00400
00401 dune->first_child = 0;
00402 dune->next_child = 0;
00403 }
00404 };
00405
00406 inline static void setIterationModus(DUNE_DAT * , DUNE_FDATA *);
00407
00408 public:
00409
00410 inline static void * getStackEntry(StackEntryType & stackEntry);
00411
00412
00413 inline static void * getStackEn(DUNE_DAT * dune);
00414
00415
00416 inline static void freeStackEn(DUNE_DAT * dune, void * entry);
00417
00418 inline static void deleteStackEntry(StackEntryType &);
00419
00420
00421 inline static void freeStackEntry(StackEntryType & stackEntry, void * entry);
00422
00423 };
00424
00425
00426
00427
00428
00429 enum GRAPE_ElementType
00430 { g_vertex = GrapeInterface_three_three::gr_vertex
00431 , g_line = GrapeInterface_three_three::gr_line
00432 , g_triangle = GrapeInterface_three_three::gr_triangle
00433 , g_quadrilateral = GrapeInterface_three_three::gr_quadrilateral
00434 , g_tetrahedron = GrapeInterface_three_three::gr_tetrahedron
00435 , g_pyramid = GrapeInterface_three_three::gr_pyramid
00436 , g_prism = GrapeInterface_three_three::gr_prism
00437 , g_hexahedron = GrapeInterface_three_three::gr_hexahedron
00438 , g_iso_triangle = GrapeInterface_three_three::gr_iso_triangle
00439 , g_iso_quadrilateral = GrapeInterface_three_three::gr_iso_quadrilateral
00440 , g_unknown = GrapeInterface_three_three::gr_unknown
00441 };
00442
00444 static inline GRAPE_ElementType convertToGrapeType ( GeometryType type , int dim )
00445 {
00446 if(dim < 3)
00447 {
00448 if(type.isTriangle()) return g_triangle;
00449 if(type.isQuadrilateral()) return g_quadrilateral;
00450 if(type.isVertex()) return g_vertex;
00451 if(type.isLine()) return g_line;
00452 }
00453 else
00454 {
00455 if(type.isTetrahedron()) return g_tetrahedron;
00456 if(type.isHexahedron()) return g_hexahedron;
00457 if(type.isPyramid()) return g_pyramid;
00458 if(type.isPrism()) return g_prism;
00459 }
00460
00461 std::cerr << "No requested conversion for GeometryType " << type << "!\n";
00462 return g_unknown;
00463 }
00464
00465
00466
00467 static const int * const * vxMap = GrapeInterface_three_three::dune2GrapeVertex;
00468 static inline int mapDune2GrapeVertex( int geomType , int vx )
00469 {
00470 enum { usedTypes = GrapeInterface_three_three::numberOfUsedGrapeElementTypes };
00471 assert( geomType >= 0 );
00472 assert( geomType < usedTypes );
00473 return vxMap[geomType][vx];
00474 }
00475
00476 }
00477
00478 #include "grape/grapegriddisplay.cc"
00479
00480
00481 #include "grape/grape_undefs.hh"
00482 #endif