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