grapedatadisplay.hh

Go to the documentation of this file.
00001 #ifndef DUNE_GRAPE_DATA_DISPLAY_HH
00002 #define DUNE_GRAPE_DATA_DISPLAY_HH
00003 
00004 //- system includes 
00005 #include <vector>
00006 #include <limits>
00007 
00008 //- local includes 
00009 #include "grapegriddisplay.hh"
00010 
00017 namespace Dune 
00018 {
00019 
00020   // Forward Declarations
00021   // --------------------
00022  
00023   template< class ctype, int dim, int dimworld, int polOrd >
00024   class GrapeLagrangePoints;
00025 
00026 
00027 
00028   // GrapeFunction
00029   // -------------
00030 
00031   template< class GV, int dimR, int polOrd >
00032   struct GrapeFunction
00033   {
00034     typedef GV GridView;
00035 
00036     static const int dimDomain = GridView::Grid::dimension;
00037     static const int dimRange = dimR;
00038 
00039     typedef FieldVector< typename GridView::Grid::ctype, dimDomain > DomainVector;
00040     typedef FieldVector< typename GridView::Grid::ctype, dimRange > RangeVector;
00041 
00042     typedef typename GridView::template Codim< 0 >::Entity Entity;
00043 
00044     virtual ~GrapeFunction ()
00045     {}
00046 
00047     virtual void evaluate ( const Entity &entity, const DomainVector &x, RangeVector &y ) const = 0;
00048 
00049     virtual const GridView &gridView () const = 0;
00050 
00051     virtual std::string name () const = 0;
00052   };
00053 
00054 
00055 #if HAVE_GRAPE
00056 
00057   // EvalFunctionData
00058   // ----------------
00059 
00060 template <class EvalImpTraits> 
00061 struct EvalFunctionData 
00062 {
00063   typedef typename EvalImpTraits :: GridType GridType; 
00064   typedef typename EvalImpTraits :: EvalImp EvalImp;
00065   
00066   typedef typename GridType :: template Codim<0> :: Entity EntityType;
00067   enum { dim = GridType::dimension };
00068   enum { dimworld = GridType::dimensionworld };
00069 
00070   typedef typename GridType :: ctype ctype;
00071 
00072   typedef typename GrapeInterface<dim,dimworld>::DUNE_ELEM  DUNE_ELEM;
00073   typedef typename GrapeInterface<dim,dimworld>::DUNE_FDATA DUNE_FDATA;
00074 
00075   // for the data visualization, call implementations evalCoordNow
00076   inline static void evalCoordNow (EntityType &en, DUNE_FDATA *fdata, const double *coord, double * val)
00077   {
00078     EvalImp::evalCoordNow(en,fdata,coord,val); 
00079   }
00080 
00081   // for the data visualization, call implementations evalDofNow 
00082   inline static void evalDofNow (EntityType &en, int geomType, DUNE_FDATA *fdata , int localNum, double * val)
00083   {
00084     EvalImp::evalDofNow(en,geomType,fdata,localNum,val);
00085   }
00086 
00087   // evaluate at given local coord 
00088   inline static void evalCoord (DUNE_ELEM *he, DUNE_FDATA *df, 
00089                                 const double *coord, double * val);
00090 
00091   // evaluate at dof 
00092   inline static void evalDof (DUNE_ELEM *he, DUNE_FDATA *df, int localNum, double * val);
00093 
00094   // get min and max value for colorbar 
00095   inline static void getMinMaxValues(DUNE_FDATA *df, double* min, double* max );
00096 };
00097 
00098 template <class GridImp, class DiscreteFunctionType> 
00099 struct EvalDiscreteFunctions;
00100 
00101 template <class GridImp, class DiscreteFunctionType> 
00102 struct EvalDiscreteFunctionsTraits 
00103 {
00104   typedef GridImp GridType; 
00105   typedef EvalDiscreteFunctions <GridImp, DiscreteFunctionType > EvalImp;
00106 };
00107 
00108 template <class GridImp, class DiscreteFunctionType> 
00109 struct EvalDiscreteFunctions 
00110 : public EvalFunctionData< EvalDiscreteFunctionsTraits <GridImp, DiscreteFunctionType > > 
00111 {
00112   typedef GridImp GridType;
00113   typedef typename GridType :: template Codim<0> :: Entity EntityType;
00114   enum { dim = GridType::dimension };
00115   enum { dimworld = GridType::dimensionworld };
00116 
00117   typedef typename GridType :: ctype ctype;
00118 
00119   typedef typename DiscreteFunctionType :: LocalFunctionType LocalFunctionType; 
00120   typedef typename DiscreteFunctionType :: DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
00121 
00122   typedef typename DiscreteFunctionSpaceType :: RangeType RangeType;
00123   typedef typename DiscreteFunctionSpaceType :: DomainType DomainType;
00124 
00125   typedef typename GrapeInterface<dim,dimworld>::DUNE_ELEM  DUNE_ELEM;
00126   typedef typename GrapeInterface<dim,dimworld>::DUNE_FDATA DUNE_FDATA;
00127 
00128   // for the data visualization
00129   inline static void evalCoordNow (EntityType &en, DUNE_FDATA *fdata, const double *coord, double * val);
00130 
00131   // for the data visualization
00132   inline static void evalDofNow (EntityType &en, int geomType, DUNE_FDATA *fdata , int localNum, double * val);
00133 
00134   // for the data visualization
00135   inline static void evalScalar (EntityType &en, int geomType, 
00136       DiscreteFunctionType & func, LocalFunctionType &lf, 
00137                 const int * comp , int localNum, double * val);
00138   
00139   // for the data visualization
00140   inline static void evalVector (EntityType &en, int geomType, 
00141       DiscreteFunctionType & func, LocalFunctionType &lf, 
00142                 const int * comp, int vend, int localNum, double * val);
00143   
00144   // calculate min and max value of function 
00145   inline static void calcMinMax(DUNE_FDATA * df);
00146 };
00147 
00148 
00149 
00150   // EvalGrapeFunction
00151   // -----------------
00152 
00153   template< class GV, int dimR, int polOrd >
00154   struct EvalGrapeFunction;
00155 
00156   template< class GV, int dimR, int polOrd >
00157   struct EvalGrapeFunctionTraits
00158   {
00159     typedef typename GV::Grid GridType;
00160     typedef EvalGrapeFunction< GV, dimR, polOrd > EvalImp;
00161   };
00162 
00163   template< class GV, int dimR, int polOrd >
00164   struct EvalGrapeFunction
00165   : public EvalFunctionData< EvalGrapeFunctionTraits< GV, dimR, polOrd > >
00166   {
00167     typedef GV GridView;
00168 
00169     typedef Dune::GrapeFunction< GV, dimR, polOrd > GrapeFunction;
00170 
00171     static const int dimDomain = GrapeFunction::dimDomain;
00172     static const int dimRange = GrapeFunction::dimRange;
00173     static const int dimWorld = GridView::Grid::dimensionworld;
00174 
00175     typedef typename GrapeFunction::DomainVector DomainVector;
00176     typedef typename GrapeFunction::RangeVector RangeVector;
00177 
00178     typedef typename GridView::template Codim< 0 >::Entity Entity;
00179 
00180     typedef typename GrapeInterface< dimDomain, dimWorld >::DUNE_ELEM DUNE_ELEM;
00181     typedef typename GrapeInterface< dimDomain, dimWorld >::DUNE_FDATA DUNE_FDATA;
00182 
00183     // for the data visualization
00184     static void evalCoordNow ( const Entity &entity, DUNE_FDATA *fdata, const double *coord, double *val );
00185 
00186     // for the data visualization
00187     static void evalDofNow ( const Entity &entity, int geomType, DUNE_FDATA *fdata, int localNum, double *val );
00188 
00189     // calculate min and max value of function 
00190     static void calcMinMax ( DUNE_FDATA *fdata );
00191   };
00192 
00193 
00194 
00195   // EvalVectorData
00196   // --------------
00197 
00198 template <class GridImp, class VectorType, class IndexSetImp > 
00199 struct EvalVectorData;
00200 
00201 template <class GridImp, class VectorType , class IndexSetImp > 
00202 struct EvalVectorDataTraits 
00203 {
00204   typedef GridImp GridType; 
00205   typedef EvalVectorData <GridImp, VectorType, IndexSetImp > EvalImp;
00206 };
00207 
00208 template <class GridImp, class VectorType, class IndexSetImp > 
00209 struct EvalVectorData  
00210 : public EvalFunctionData< EvalVectorDataTraits <GridImp, VectorType, IndexSetImp > > 
00211 {
00212   typedef GridImp GridType;
00213   typedef typename GridType :: template Codim<0> :: Entity EntityType;
00214   enum { dim = GridType::dimension };
00215   enum { dimworld = GridType::dimensionworld };
00216 
00217   typedef typename GridType :: ctype ctype;
00218 
00219   typedef typename GrapeInterface<dim,dimworld>::DUNE_ELEM  DUNE_ELEM;
00220   typedef typename GrapeInterface<dim,dimworld>::DUNE_FDATA DUNE_FDATA;
00221 
00222   // for the data visualization
00223   inline static void evalCoordNow (EntityType &en, DUNE_FDATA *fdata, const double *coord, double * val);
00224 
00225   // for the data visualization
00226   inline static void evalDofNow (EntityType &en, int geomType, DUNE_FDATA *fdata , int localNum, double * val);
00227 
00228   // for the data visualization, evaluate linear funcs 
00229   static void evalVectorLinear ( const EntityType &entity, int geomType, 
00230                                  VectorType & func, const IndexSetImp &indexSet, 
00231                                  const int *comp, int vend, int localNum, double *val );
00232 
00233   // for the data visualization, evaluate const funcs 
00234   static void evalVectorConst ( const EntityType &entity, int geomType, 
00235                                 VectorType & func, const IndexSetImp &indexSet, 
00236                                 const int * comp, int vend, int localNum, double * val);
00237   
00238   // calculate min and max value of function 
00239   inline static void calcMinMax(DUNE_FDATA * df);
00240 };
00241 #endif 
00242 
00246 template<class GridType>
00247 class GrapeDataDisplay : public GrapeGridDisplay < GridType >
00248 {
00249   typedef GrapeDataDisplay < GridType > MyDisplayType;
00250 
00251   typedef GrapeGridDisplay < GridType > BaseType;
00252     
00253   enum { dim = GridType::dimension };
00254   enum { dimworld = GridType::dimensionworld };
00255 
00256   typedef typename GridType :: ctype ctype;
00257 
00258 #if HAVE_GRAPE
00259   typedef typename GrapeInterface<dim,dimworld>::DUNE_ELEM DUNE_ELEM;
00260   typedef typename GrapeInterface<dim,dimworld>::DUNE_FDATA DUNE_FDATA;
00261   typedef typename GrapeInterface<dim,dimworld>::DUNE_DAT DUNE_DAT;
00262   typedef typename GrapeInterface<dim,dimworld>::F_DATA F_DATA;
00263 #endif 
00264 
00265 public:
00266   typedef GridType MyGridType;
00267 
00269   inline GrapeDataDisplay(const GridType &grid, const int myrank = -1);
00270 
00272   template <class GridPartType>
00273   inline GrapeDataDisplay(const GridPartType & gridPart, const int myrank = -1);
00274 
00276   inline ~GrapeDataDisplay();
00277 
00286   template< class VectorType, class IndexSetType >
00287   inline void displayVector ( const std::string name,
00288                               const VectorType &data,
00289                               const IndexSetType &indexSet,
00290                               const int polOrd,
00291                               const unsigned int dimRange,
00292                               bool continuous = false );
00293   
00296   template <class DiscFuncType>
00297   inline void dataDisplay(const DiscFuncType &func, bool vector = false);
00298   
00300   inline void display();
00301 
00303   template <class DiscFuncType>
00304   inline void addData(const DiscFuncType &func, double time = 0.0, bool vector = false );
00305 
00307   template <class DiscFuncType>
00308   inline void addData(const DiscFuncType &func, std::string name , double time , bool vector = false );
00309 
00310   template< class GV, int dimR, int polOrd >
00311   void addData ( const GrapeFunction< GV, dimR, polOrd > &function );
00312 
00313 #if HAVE_GRAPE
00314 
00315   template <class DiscFuncType>
00316   inline void addData(const DiscFuncType &func, const DATAINFO * , double time );
00317   
00318   // retrun whether we have data or not 
00319   bool hasData () { return (vecFdata_.size() > 0); }
00320 
00321   // return vector for copying in combined display 
00322   std::vector < DUNE_FDATA * > & getFdataVec () { return vecFdata_; }
00323 
00333   template<class VectorType, class IndexSetType >
00334   inline void addVector(const std::string name, 
00335                         const VectorType & data, const IndexSetType & indexSet, 
00336                         const double time , const int polOrd , 
00337                         const int dimRange, bool continuous ); 
00338   
00349   template<class VectorType, class IndexSetType >
00350   inline void addVector(const VectorType & data, const IndexSetType & indexSet, 
00351                         const DATAINFO * dinf, double time ,
00352                         const int polOrd , const int dimRange, bool continuous ); 
00353   
00354 private:
00356   std::vector < DUNE_FDATA * > vecFdata_;
00357 
00358   enum { polynomialOrder = 1 };
00359   // store lagrange points for evaluation 
00360   GrapeLagrangePoints<ctype,dim,dimworld,polynomialOrder> lagrangePoints_;
00361 
00362   typedef typename GridType :: template Codim<0> :: Entity EntityCodim0Type;
00363   typedef void evalCoord_t(EntityCodim0Type &, DUNE_FDATA *, const double *, double * );
00364   typedef void evalDof_t  (EntityCodim0Type &,int , DUNE_FDATA * , int , double * );
00365 
00366 public:  
00367   // create object DUNE_FDATA 
00368   static DUNE_FDATA * createDuneFunc ();
00369   // delete object DUNE_FDATA 
00370   static void deleteDuneFunc (DUNE_FDATA *);
00371 #endif 
00372 };
00373 
00374 template <typename ctype, int dim, int dimworld, int polOrd> 
00375 class GrapeLagrangePoints 
00376 {
00377 #if HAVE_GRAPE
00378   enum { maxPoints = 20 };
00379   enum { numberOfTypes = (dim == 2) ? 2 : 6 };
00380   
00381   std::vector < FieldMatrix<ctype,maxPoints,dim> > points_;
00382   GrapeLagrangePoints ( const GrapeLagrangePoints& );
00383 public:
00385   GrapeLagrangePoints () : points_() 
00386   {
00387     GrapeInterface_two_two::setupReferenceElements();
00388     GrapeInterface_two_three::setupReferenceElements();
00389     GrapeInterface_three_three::setupReferenceElements();
00390 
00391     for(int type=0; type<numberOfTypes; ++type)
00392     {
00393       FieldMatrix<ctype,maxPoints,dim> coords( ctype(0) );
00394       const int nvx = numberOfVertices(type); 
00395         
00396       for(int i=0; i<nvx; ++i)
00397       {
00398         const double * p = getCoordinate(type,i);
00399         for(int j=0; j<dimworld; ++j)
00400         {
00401           assert( p );
00402           coords[i][j] = p[j]; 
00403         }
00404       }
00405       points_.push_back( coords );
00406     }
00407   }
00408    
00411   const FieldVector<ctype,dim> & 
00412   getPoint (const int geomType, const int polyOrder , const int localNum ) const 
00413   {
00414     assert( polOrd == polyOrder );
00415     assert( geomType >= 0 );
00416     assert( geomType < numberOfTypes );
00417     return points_[geomType][localNum];
00418   }
00419 
00420 private: 
00421   static int numberOfVertices( const int type )
00422   {
00423     if(type < GrapeInterface_three_three::gr_tetrahedron) 
00424       return GrapeInterface_two_two::getElementDescription(type)->number_of_vertices;
00425     else 
00426       return GrapeInterface_three_three::getElementDescription(type)->number_of_vertices;
00427   }
00428 
00429   static const double * getCoordinate( const int type, const int i )
00430   {
00431     if(type < GrapeInterface_three_three::gr_tetrahedron) 
00432     {
00433       return GrapeInterface_two_two::getElementDescription(type)->coord[i];
00434     }
00435     else 
00436       return GrapeInterface_three_three::getElementDescription(type)->coord[i];
00437   }
00438 #endif
00439 };
00440   
00441 } // end namespace Dune
00442 
00443 #include "grape/grapedatadisplay.cc"
00444 #endif

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