grapegriddisplay.hh

Go to the documentation of this file.
00001 #ifndef DUNE_GRAPEGRIDDISPLAY_HH
00002 #define DUNE_GRAPEGRIDDISPLAY_HH
00003 
00004 //- system includes 
00005 #include <list>
00006 #include <set>
00007 #include <stack>
00008 
00009 //- Dune includes 
00010 #include <dune/common/stdstreams.hh>
00011 #include <dune/grid/common/grid.hh>
00012 
00013 #if HAVE_GRAPE
00014 //-local includes 
00015 #include "grape/grapeinclude.hh"
00016 #endif
00017 
00023 namespace Dune 
00024 {
00025 
00027 enum GrapePartitionIteratorType 
00028 {
00029   g_Interior_Partition       = Interior_Partition,
00030   g_InteriorBorder_Partition = InteriorBorder_Partition,
00031   g_Overlap_Partition        = Overlap_Partition,
00032   g_OverlapFront_Partition   = OverlapFront_Partition,
00033   g_All_Partition            = All_Partition,
00034   g_Ghost_Partition          = Ghost_Partition
00035 };
00036   
00039 enum GrapeIteratorType 
00040 {
00041   g_LeafIterator       = 0,
00042   g_LevelIterator      = 1,
00043   g_HierarchicIterator = 2,
00044   g_GridPart           = 3 
00045 };
00046   
00050 template<class GridType>
00051 class GrapeGridDisplay 
00052 {
00053   typedef GrapeGridDisplay < GridType > MyDisplayType;
00054   typedef  MyDisplayType ThisType;
00055   enum { dim = GridType::dimension };
00056   enum { dimworld = GridType::dimensionworld };
00057 
00058 public:
00059 #if HAVE_GRAPE
00060   // defined in griddisplay.hh 
00061   typedef typename GrapeInterface<dim,dimworld>::DUNE_ELEM  DUNE_ELEM;
00062   typedef typename GrapeInterface<dim,dimworld>::DUNE_DAT   DUNE_DAT;
00063   typedef typename GrapeInterface<dim,dimworld>::DUNE_FDATA DUNE_FDATA;
00064   typedef typename GrapeInterface<dim,dimworld>::F_DATA     F_DATA;
00065   typedef typename GrapeInterface<dim,dimworld>::STACKENTRY STACKENTRY;
00066   
00067   typedef typename std::stack < STACKENTRY * > StackEntryType; 
00068   typedef void setGridPartIterators_t(DUNE_DAT * , void * gridPart);
00069 #endif // #if HAVE_GRAPE
00070 
00071   typedef typename GridType::HierarchicIterator HierarchicIteratorType; 
00072 
00073   typedef typename GridType::Traits::LocalIdSet LocalIdSetType; 
00074   typedef typename GridType::Traits::LeafIndexSet LeafIndexSetType; 
00075     
00076 protected:
00077   typedef std::list<HierarchicIteratorType *> HierarchicIteratorList;
00078   typedef typename HierarchicIteratorList::iterator ListIteratorType;
00079 
00080 private:  
00082   GrapeGridDisplay(const GrapeGridDisplay &); 
00083 public:
00085   inline GrapeGridDisplay(const GridType &grid, const int myrank = -1);
00086 
00088   template <class GridPartType>
00089   inline GrapeGridDisplay(const GridPartType &gridPart, const int myrank = -1);
00090 
00091   template< class VT >
00092   inline GrapeGridDisplay ( const GridView< VT > &gridView, const int myrank = -1 );
00093 
00095   inline ~GrapeGridDisplay();
00096 
00099   inline void display();
00100 
00102   int myRank () const { return myRank_; }
00103 
00105   inline const GridType& getGrid() const ;
00106 
00107 #if HAVE_GRAPE
00108 
00109   inline void * getHmesh();
00110 
00112   DUNE_DAT & getDuneDat () { return dune_; } 
00113 
00115   inline void addMyMeshToTimeScene(void * timescene, double time, int proc);
00116  
00117   bool hasData () { return false; }
00118 
00119 protected:  
00120   // generate hmesh 
00121   inline void * setupHmesh();
00122 
00123   inline void deleteHmesh();
00124 
00125   typedef typename GridType::template Codim<0>::Entity EntityCodim0Type;
00126 
00127   // type of index method 
00128   typedef int EntityIndexFuncType(void * iset, const EntityCodim0Type & en);
00129   // type of vertex method 
00130   typedef int VertexIndexFuncType(void * iset, const EntityCodim0Type & en, int vx);
00131   
00132   // return element index from given index set
00133   template <class IndexSetType>
00134   static int getEntityIndex(void * iset, const EntityCodim0Type & en)
00135   {
00136     assert( iset );
00137     const IndexSetType * set = ((const IndexSetType *) iset);
00138     return (en.isLeaf()) ? set->index(en) : -1;
00139   }
00140   
00141   // return vertex index from given index set
00142   template< class IndexSet >
00143   static int getVertexIndex ( void *iset, const EntityCodim0Type &entity, int vx )
00144   {
00145     assert( iset != 0 );
00146     const IndexSet *indexSet = (const IndexSet *)iset;
00147     //return set->template subIndex< dim >( entity, vx );
00148     return indexSet->subIndex( entity, vx, dim );
00149   }
00150   
00151 public:
00152 //****************************************************************  
00153 //
00154 // --GrapeGridDisplay, Some Subroutines needed for display with GRAPE
00155 // 
00156 //****************************************************************  
00157   // update element from entity
00158   template <class IntersectionIteratorType>
00159   inline void checkNeighbors(IntersectionIteratorType&, 
00160             const IntersectionIteratorType&, DUNE_ELEM *) ;
00161   
00162   // update element from entity
00163   template <class Entity>
00164   inline void el_update_base (Entity& en , DUNE_ELEM *) ;
00165 
00166   // update element from entity
00167   template <class EntityPointerType>
00168   inline int el_update (EntityPointerType *, DUNE_ELEM *) ;
00169 
00170   // update element from entity
00171   template <class EntityPointerType, class GridPartType>
00172   inline int el_update (EntityPointerType *, DUNE_ELEM *, GridPartType& );
00173 
00174   template< class EntityPointer, class VT >
00175   int el_update ( EntityPointer *, DUNE_ELEM *, const GridView< VT > & );
00176 
00177   // update child element 
00178   template <class EntityPointerType>
00179   inline int child_update (EntityPointerType * , DUNE_ELEM *) ;
00180 
00181   template <class EntityPointerType>
00182   inline int child_n_update (EntityPointerType *, DUNE_ELEM *) ;
00183 
00184   // first and next macro element via LevelIterator level 0 
00185   template <PartitionIteratorType pitype> 
00186   inline int first_leaf (DUNE_ELEM * he) ;
00187   template <PartitionIteratorType pitype> 
00188   inline int next_leaf (DUNE_ELEM * he) ;
00189   
00190   // first and next macro element via LevelIterator level 0 
00191   template <class GridPartImp> 
00192   inline int first_item (DUNE_ELEM * he) ;
00193   template <class GridPartImp> 
00194   inline int next_item (DUNE_ELEM * he) ;
00195   
00196   // first and next macro element via LevelIterator level  
00197   template <PartitionIteratorType pitype> 
00198   inline int first_level (DUNE_ELEM * he, int level) ;
00199   
00200   template <PartitionIteratorType pitype> 
00201   inline int next_level (DUNE_ELEM * he) ;
00202 
00203   // methods to call for combined display 
00204   inline int firstMacro (DUNE_ELEM * elem) { return dune_.first_macro(elem); }
00205   inline int nextMacro  (DUNE_ELEM * elem) { return dune_.next_macro(elem);  }
00206   inline int firstChild (DUNE_ELEM * elem) { return (dune_.first_child) ? dune_.first_child(elem) : 0; }
00207   inline int nextChild  (DUNE_ELEM * elem) { return (dune_.next_child) ? dune_.next_child(elem) : 0; }
00208   
00209   // first and next child via HierarchicIterator with given maxlevel in Grape
00210   inline int first_child (DUNE_ELEM * he) ;
00211   inline int next_child (DUNE_ELEM * he) ;
00212 
00213 public:   
00214   // delete leaf iterators 
00215   template <PartitionIteratorType pitype> 
00216   inline void delete_leaf (DUNE_ELEM * he) ;
00217   // delete level iterators 
00218   template <PartitionIteratorType pitype> 
00219   inline void delete_level (DUNE_ELEM * he) ;
00220   // delete level and hierarchical iterators 
00221   template <PartitionIteratorType pitype> 
00222   inline void delete_hier (DUNE_ELEM * he) ;
00223 
00224   // delete iterators 
00225   template <class IteratorType> 
00226   inline void delete_iterators(DUNE_ELEM * he) ;
00227 public:  
00228   
00229   // fake function for copy iterator 
00230   inline static void * copy_iterator (const void * i) ;
00231 
00232   // local to world 
00233   inline void local2world (DUNE_ELEM * he, const double * c, double * w);
00234 
00235   // world to local 
00236   inline int world2local (DUNE_ELEM * he, const double * w, double * c);
00237  
00238   // check inside reference element 
00239   inline int checkWhetherInside (DUNE_ELEM * he, const double * w);
00240 
00241   //*********************************
00242   //  wrapper functions 
00243   //*********************************
00244   // local to world 
00245   inline static void ctow (DUNE_ELEM * he, const double * c, double * w);
00246 
00247   // world to local 
00248   inline static int wtoc (DUNE_ELEM * he, const double * w, double * c);
00249  
00250   // check inside reference element 
00251   inline static int check_inside (DUNE_ELEM * he, const double * w);
00252 
00253   // dito 
00254   template< class Entity >
00255   int checkInside ( const Entity &entity, const double *w );
00256  
00257   // dito 
00258   template< class Entity >
00259   int world_to_local ( const Entity &entity, const double *w, double *c );
00260   
00261   // dito
00262   template <class EntityType>
00263   inline void local_to_world(EntityType &en, const double * c, double * w);  
00264 
00265   template <PartitionIteratorType pitype>
00266   inline void selectIterators(DUNE_DAT *, void *, setGridPartIterators_t *) const;
00267   
00268   inline void setIterationMethods(DUNE_DAT *, DUNE_FDATA * ) const;
00269   
00270   inline void changeIterationMethods(int iterType, int partType, DUNE_FDATA *);
00271 
00272   template <PartitionIteratorType pitype>
00273   struct IterationMethods 
00274   {
00275     // wrapper methods for first_child and next_child
00276     inline static int first_mac (DUNE_ELEM * he)
00277     {
00278       MyDisplayType & disp = *((MyDisplayType *) he->display);
00279       return disp.template first_level<pitype>(he,0);
00280     }
00281 
00282     // wrapper methods for first_child and next_child
00283     inline static int first_lev (DUNE_ELEM * he)
00284     {
00285       MyDisplayType & disp = *((MyDisplayType *) he->display);
00286       return disp.template first_level<pitype>(he,he->level_of_interest);
00287     }
00288 
00289     inline static int next_lev  (DUNE_ELEM * he)
00290     {
00291       MyDisplayType & disp = *((MyDisplayType *) he->display);
00292       return disp.template next_level<pitype>(he);
00293     }
00294   
00295     // wrapper methods for first_child and next_child
00296     inline static int fst_leaf (DUNE_ELEM * he)
00297     {
00298       MyDisplayType & disp = *((MyDisplayType *) he->display);
00299       return disp.template first_leaf<pitype>(he);
00300     }
00301     inline static int nxt_leaf (DUNE_ELEM * he)
00302     {
00303       MyDisplayType & disp = *((MyDisplayType *) he->display);
00304       return disp.template next_leaf<pitype>(he);
00305     }
00306   
00307     // wrapper methods for first_child and next_child
00308     inline static int fst_child (DUNE_ELEM * he)
00309     {
00310       MyDisplayType & disp = *((MyDisplayType *) he->display);
00311       return disp.first_child(he);
00312     }
00313     inline static int nxt_child (DUNE_ELEM * he)
00314     {
00315       MyDisplayType & disp = *((MyDisplayType *) he->display);
00316       return disp.next_child(he);
00317     }
00318 
00319     // wrapper methods for deleting iterators 
00320     inline static void del_leaf (DUNE_ELEM * he)
00321     {
00322       MyDisplayType & disp = *((MyDisplayType *) he->display);
00323       disp.template delete_leaf<pitype>(he);
00324     }
00325 
00326     // wrapper methods for deleting iterators 
00327     inline static void del_level (DUNE_ELEM * he)
00328     {
00329       MyDisplayType & disp = *((MyDisplayType *) he->display);
00330       disp.template delete_level<pitype>(he);
00331     }
00332 
00333     // wrapper methods for deleting iterators 
00334     inline static void del_hier (DUNE_ELEM * he)
00335     {
00336       MyDisplayType & disp = *((MyDisplayType *) he->display);
00337       disp.template delete_hier<pitype>(he);
00338     }
00339 
00340   };
00341 
00342 protected:
00343   template <class GridPartType>
00344   struct IterationMethodsGP
00345   {
00346     // wrapper methods for first_item and next_item
00347     inline static int fst_item (DUNE_ELEM * he)
00348     {
00349       assert( he->display );
00350       MyDisplayType & disp = *((MyDisplayType *) he->display);
00351       return disp.template first_item<GridPartType>(he);
00352     }
00353     inline static int nxt_item (DUNE_ELEM * he)
00354     {
00355       assert( he->display );
00356       MyDisplayType & disp = *((MyDisplayType *) he->display);
00357       return disp.template next_item<GridPartType>(he);
00358     }
00359     
00360     // delete iterators 
00361     inline static void del_iter (DUNE_ELEM * he)
00362     {
00363       assert( he->display );
00364       MyDisplayType & disp = *((MyDisplayType *) he->display);
00365       typedef typename GridPartType :: template Codim<0> :: IteratorType IteratorType;
00366       disp.template delete_iterators<IteratorType> (he);
00367     }
00368   };
00369 
00370   template <class GridPartImp> 
00371   struct SetIter
00372   {
00373     static void setGPIterator (DUNE_DAT * dune ,void * gridPart)
00374     {
00375       assert( gridPart );
00376       dune->gridPart = gridPart;
00377       dune->first_macro = &IterationMethodsGP<GridPartImp>::fst_item;
00378       dune->next_macro  = &IterationMethodsGP<GridPartImp>::nxt_item;
00379       dune->delete_iter = &IterationMethodsGP<GridPartImp>::del_iter;
00380 
00381       dune->first_child = 0;
00382       dune->next_child = 0;
00383     }
00384   };
00385 
00386   template< class ViewTraits >
00387   struct GridViewIterators
00388   {
00389     typedef Dune::GridView< ViewTraits > GridView;
00390     typedef typename GridView::template Codim< 0 >::Iterator Iterator;
00391 
00392     static int first_macro ( DUNE_ELEM *he )
00393     {
00394       assert( he->display != 0 );
00395       MyDisplayType &display = *static_cast< MyDisplayType * >( he->display );
00396 
00397       if( he->liter != 0 )
00398         display.template delete_iterators< Iterator >( he );
00399   
00400       assert( he->gridPart != 0 );
00401       const GridView &gridView = *static_cast< const GridView * >( he->gridPart );
00402 
00403       assert( he->liter   == 0 );
00404       assert( he->enditer == 0 );
00405       
00406       Iterator *it  = new Iterator( gridView.template begin< 0 >() );
00407       Iterator *end = new Iterator( gridView.template end  < 0 >() );
00408 
00409       he->liter   = it;
00410       he->enditer = end;
00411 
00412       if( *it == *end )
00413       {
00414         display.template delete_iterators< Iterator >( he );
00415         return 0;
00416       }
00417 
00418       return display.el_update( it, he, gridView );
00419     }
00420 
00421     static int next_macro ( DUNE_ELEM *he )
00422     {
00423       assert( he->display != 0 );
00424       MyDisplayType &display = *static_cast< MyDisplayType * >( he->display );
00425 
00426       assert( he->gridPart != 0 );
00427       const GridView &gridView = *static_cast< const GridView * >( he->gridPart );
00428 
00429       Iterator *it  = static_cast< Iterator * >( he->liter );
00430       Iterator *end = static_cast< Iterator * >( he->enditer );
00431       assert( (it != 0) && (end != 0) );
00432      
00433       ++(*it);
00434       if( *it == *end )
00435       {
00436         display.template delete_iterators< Iterator >( he );
00437         return 0;
00438       }
00439 
00440       return display.el_update( it, he, gridView );
00441     }
00442     
00443     static void delete_iter ( DUNE_ELEM *he )
00444     {
00445       assert( he->display );
00446       MyDisplayType &display = *static_cast< MyDisplayType * >( he->display );
00447       display.template delete_iterators< Iterator >( he );
00448     }
00449 
00450     static void set ( DUNE_DAT *dune, void *gridView )
00451     {
00452       assert( gridView );
00453       dune->gridPart = gridView;
00454       dune->first_macro = &first_macro;
00455       dune->next_macro = &next_macro;
00456       dune->delete_iter = &delete_iter;
00457 
00458       dune->first_child = 0;
00459       dune->next_child = 0;
00460     }
00461   };
00462 
00463   inline static void setIterationModus(DUNE_DAT * , DUNE_FDATA *);
00464 
00465 public:  
00466   // create STACKENTRY or get from stack 
00467   inline static void * getStackEntry(StackEntryType & stackEntry); 
00468  
00469   // get StackEntry Wrapper 
00470   inline static void * getStackEn(DUNE_DAT * dune);
00471 
00472   // free StackEntry Wrapper 
00473   inline static void freeStackEn(DUNE_DAT * dune, void * entry);
00474 
00475   inline static void deleteStackEntry(StackEntryType &);
00476 
00477   // push STACKENTRY to stack 
00478   inline static void freeStackEntry(StackEntryType & stackEntry, void * entry);
00479 
00480 protected:  
00482   DUNE_ELEM hel_;
00483   DUNE_DAT dune_;
00484   setGridPartIterators_t * setGridPartIter_;
00485 
00486   // pointer to index method 
00487   const EntityIndexFuncType * entityIndex;
00488   // pointer to vertex method   
00489   const VertexIndexFuncType * vertexIndex;
00490 
00491   StackEntryType stackEntry_;
00492 #endif // #if HAVE_GRAPE
00493 
00494   // the grid we want to display 
00495   const GridType &grid_;
00496   
00497   // true if we can use LevelIntersectionIterator 
00498   const bool hasLevelIntersections_;
00499 
00500   void * gridPart_;
00501 
00502   // leaf index set of the grid 
00503   void * indexSet_;
00504 
00505   // leaf index set of the grid 
00506   const LocalIdSetType & lid_; 
00507 
00508   // my process number 
00509   const int myRank_;
00510 
00511   // no better way than this canot export HMESH structure to here
00512   // pointer to hmesh 
00513   void * hmesh_;
00514 
00515   HierarchicIteratorList hierList_;
00516 }; // end class GrapeGridDisplay
00517 
00518 #if HAVE_GRAPE
00519 /**************************************************************************/
00520 //  element types, see dune/grid/common/grid.hh 
00521 // and also geldesc.hh for GR_ElementTypes 
00522 enum GRAPE_ElementType
00523     {  g_vertex         = GrapeInterface_three_three::gr_vertex
00524     ,  g_line           = GrapeInterface_three_three::gr_line
00525     ,  g_triangle       = GrapeInterface_three_three::gr_triangle
00526     ,  g_quadrilateral  = GrapeInterface_three_three::gr_quadrilateral
00527     ,  g_tetrahedron    = GrapeInterface_three_three::gr_tetrahedron
00528     ,  g_pyramid        = GrapeInterface_three_three::gr_pyramid
00529     ,  g_prism          = GrapeInterface_three_three::gr_prism 
00530     ,  g_hexahedron     = GrapeInterface_three_three::gr_hexahedron
00531     ,  g_iso_triangle   = GrapeInterface_three_three::gr_iso_triangle
00532     ,  g_iso_quadrilateral  = GrapeInterface_three_three::gr_iso_quadrilateral
00533     ,  g_unknown            = GrapeInterface_three_three::gr_unknown
00534     };
00535 
00537 static inline GRAPE_ElementType convertToGrapeType ( GeometryType type , int dim )
00538 {
00539   if(dim < 3) 
00540   {
00541     if(type.isTriangle())       return g_triangle;
00542     if(type.isQuadrilateral())  return g_quadrilateral;
00543     if(type.isVertex())         return g_vertex;
00544     if(type.isLine())           return g_line;
00545   }
00546   else 
00547   {
00548     if(type.isTetrahedron())    return g_tetrahedron;
00549     if(type.isHexahedron())     return g_hexahedron;
00550     if(type.isPyramid())        return g_pyramid;
00551     if(type.isPrism())          return g_prism;
00552   }
00553   
00554   std::cerr << "No requested conversion for GeometryType " << type << "!\n";
00555   return g_unknown;
00556 }
00557 
00558 // see geldesc.hh for definition of this mapping 
00559 // this is the same for all namespaces (two_two , and two_three, ...)
00560 static const int * const * vxMap = GrapeInterface_three_three::dune2GrapeVertex;
00561 static inline int mapDune2GrapeVertex( int geomType , int vx )
00562 {
00563   enum { usedTypes = GrapeInterface_three_three::numberOfUsedGrapeElementTypes };
00564   assert( geomType >= 0 );
00565   assert( geomType <  usedTypes ); // at the moment only defined from 2 to 7 
00566   return vxMap[geomType][vx];
00567 }
00568 
00569 // see geldesc.hh for definition of this mapping 
00570 // this is the same for all namespaces (two_two , and two_three, ...)
00571 static const int * const * faceMap = GrapeInterface_three_three::dune2GrapeFace;
00572 static inline int mapDune2GrapeFace( int geomType , int duneFace )
00573 {
00574   enum { usedTypes = GrapeInterface_three_three::numberOfUsedGrapeElementTypes };
00575   assert( geomType >= 0 );
00576   assert( geomType <  usedTypes ); // at the moment only defined from 2 to 7 
00577   return faceMap[geomType][ duneFace ];
00578 }
00579 #endif
00580 
00581 } // end namespace Dune
00582 
00583 #include "grape/grapegriddisplay.cc"
00584 
00585 // undefs all defines 
00586 #include "grape/grape_undefs.hh"
00587 #endif

Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].