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 
00007 //- local includes 
00008 #include "grapegriddisplay.hh"
00009 
00016 namespace Dune 
00017 {
00018 
00019 template <typename ctype, int dim, int dimworld, int polOrd> 
00020 class GrapeLagrangePoints;
00021 
00022 template <class EvalImpTraits> 
00023 struct EvalFunctionData 
00024 {
00025   typedef typename EvalImpTraits :: GridType GridType; 
00026   typedef typename EvalImpTraits :: EvalImp EvalImp;
00027   
00028   typedef typename GridType :: template Codim<0> :: Entity EntityType;
00029   enum { dim = GridType::dimension };
00030   enum { dimworld = GridType::dimensionworld };
00031 
00032   typedef typename GridType :: ctype ctype;
00033 
00034   typedef typename GrapeInterface<dim,dimworld>::DUNE_ELEM  DUNE_ELEM;
00035   typedef typename GrapeInterface<dim,dimworld>::DUNE_FDATA DUNE_FDATA;
00036 
00037   // for the data visualization, call implementations evalCoordNow
00038   inline static void evalCoordNow (EntityType &en, DUNE_FDATA *fdata, const double *coord, double * val)
00039   {
00040     EvalImp::evalCoordNow(en,fdata,coord,val); 
00041   }
00042 
00043   // for the data visualization, call implementations evalDofNow 
00044   inline static void evalDofNow (EntityType &en, int geomType, DUNE_FDATA *fdata , int localNum, double * val)
00045   {
00046     EvalImp::evalDofNow(en,geomType,fdata,localNum,val);
00047   }
00048 
00049   // evaluate at given local coord 
00050   inline static void evalCoord (DUNE_ELEM *he, DUNE_FDATA *df, 
00051                                 const double *coord, double * val);
00052 
00053   // evaluate at dof 
00054   inline static void evalDof (DUNE_ELEM *he, DUNE_FDATA *df, int localNum, double * val);
00055 
00056   // get min and max value for colorbar 
00057   inline static void getMinMaxValues(DUNE_FDATA *df, double* min, double* max );
00058 };
00059 
00060 template <class GridImp, class DiscreteFunctionType> 
00061 struct EvalDiscreteFunctions;
00062 
00063 template <class GridImp, class DiscreteFunctionType> 
00064 struct EvalDiscreteFunctionsTraits 
00065 {
00066   typedef GridImp GridType; 
00067   typedef EvalDiscreteFunctions <GridImp, DiscreteFunctionType > EvalImp;
00068 };
00069 
00070 template <class GridImp, class DiscreteFunctionType> 
00071 struct EvalDiscreteFunctions 
00072 : public EvalFunctionData< EvalDiscreteFunctionsTraits <GridImp, DiscreteFunctionType > > 
00073 {
00074   typedef GridImp GridType;
00075   typedef typename GridType :: template Codim<0> :: Entity EntityType;
00076   enum { dim = GridType::dimension };
00077   enum { dimworld = GridType::dimensionworld };
00078 
00079   typedef typename GridType :: ctype ctype;
00080 
00081   typedef typename DiscreteFunctionType :: LocalFunctionType LocalFunctionType; 
00082   typedef typename DiscreteFunctionType :: DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
00083 
00084   typedef typename DiscreteFunctionSpaceType :: RangeType RangeType;
00085   typedef typename DiscreteFunctionSpaceType :: DomainType DomainType;
00086 
00087   typedef typename GrapeInterface<dim,dimworld>::DUNE_ELEM  DUNE_ELEM;
00088   typedef typename GrapeInterface<dim,dimworld>::DUNE_FDATA DUNE_FDATA;
00089 
00090   // for the data visualization
00091   inline static void evalCoordNow (EntityType &en, DUNE_FDATA *fdata, const double *coord, double * val);
00092 
00093   // for the data visualization
00094   inline static void evalDofNow (EntityType &en, int geomType, DUNE_FDATA *fdata , int localNum, double * val);
00095 
00096   // for the data visualization
00097   inline static void evalScalar (EntityType &en, int geomType, 
00098       DiscreteFunctionType & func, LocalFunctionType &lf, 
00099                 const int * comp , int localNum, double * val);
00100   
00101   // for the data visualization
00102   inline static void evalVector (EntityType &en, int geomType, 
00103       DiscreteFunctionType & func, LocalFunctionType &lf, 
00104                 const int * comp, int vend, int localNum, double * val);
00105   
00106   // calculate min and max value of function 
00107   inline static void calcMinMax(DUNE_FDATA * df);
00108 };
00109 
00110 template <class GridImp, class VectorType, class IndexSetImp > 
00111 struct EvalVectorData;
00112 
00113 template <class GridImp, class VectorType , class IndexSetImp > 
00114 struct EvalVectorDataTraits 
00115 {
00116   typedef GridImp GridType; 
00117   typedef EvalVectorData <GridImp, VectorType, IndexSetImp > EvalImp;
00118 };
00119 
00120 template <class GridImp, class VectorType, class IndexSetImp > 
00121 struct EvalVectorData  
00122 : public EvalFunctionData< EvalVectorDataTraits <GridImp, VectorType, IndexSetImp > > 
00123 {
00124   typedef GridImp GridType;
00125   typedef typename GridType :: template Codim<0> :: Entity EntityType;
00126   enum { dim = GridType::dimension };
00127   enum { dimworld = GridType::dimensionworld };
00128 
00129   typedef typename GridType :: ctype ctype;
00130 
00131   typedef typename GrapeInterface<dim,dimworld>::DUNE_ELEM  DUNE_ELEM;
00132   typedef typename GrapeInterface<dim,dimworld>::DUNE_FDATA DUNE_FDATA;
00133 
00134   // for the data visualization
00135   inline static void evalCoordNow (EntityType &en, DUNE_FDATA *fdata, const double *coord, double * val);
00136 
00137   // for the data visualization
00138   inline static void evalDofNow (EntityType &en, int geomType, DUNE_FDATA *fdata , int localNum, double * val);
00139 
00140   // for the data visualization, evaluate linear funcs 
00141   inline static void evalVectorLinear (EntityType &en, int geomType, 
00142                       VectorType & func, const IndexSetImp & set, 
00143                       const int * comp, int vend, int localNum, double * val);
00144 
00145   // for the data visualization, evaluate const funcs 
00146   inline static void evalVectorConst (EntityType &en, int geomType, 
00147                       VectorType & func, const IndexSetImp & set, 
00148                       const int * comp, int vend, int localNum, double * val);
00149   
00150   // calculate min and max value of function 
00151   inline static void calcMinMax(DUNE_FDATA * df);
00152 };
00153 
00154 
00158 template<class GridType>
00159 class GrapeDataDisplay : public GrapeGridDisplay < GridType >
00160 {
00161   typedef GrapeDataDisplay < GridType > MyDisplayType;
00162 
00163   typedef GrapeGridDisplay < GridType > BaseType;
00164     
00165   enum { dim = GridType::dimension };
00166   enum { dimworld = GridType::dimensionworld };
00167 
00168   typedef typename GridType :: ctype ctype;
00169 
00170   typedef typename GrapeInterface<dim,dimworld>::DUNE_ELEM DUNE_ELEM;
00171   typedef typename GrapeInterface<dim,dimworld>::DUNE_FDATA DUNE_FDATA;
00172   typedef typename GrapeInterface<dim,dimworld>::DUNE_DAT DUNE_DAT;
00173   typedef typename GrapeInterface<dim,dimworld>::F_DATA F_DATA;
00174 
00175 public:
00176   typedef GridType MyGridType;
00177 
00179   inline GrapeDataDisplay(const GridType &grid, const int myrank = -1);
00180 
00182   template <class GridPartType>
00183   inline GrapeDataDisplay(const GridPartType & gridPart, const int myrank = -1);
00184 
00186   inline ~GrapeDataDisplay();
00187 
00197   template<class VectorType, class IndexSetType >
00198   inline void displayVector(const std::string name, 
00199                             const VectorType & data, const IndexSetType & indexSet, 
00200                             const int polOrd , int dimRange, bool continuous = false); 
00201   
00204   template <class DiscFuncType>
00205   inline void dataDisplay(const DiscFuncType &func, bool vector = false);
00206   
00208   inline void display();
00209 
00211   template <class DiscFuncType>
00212   inline void addData(const DiscFuncType &func, double time = 0.0, bool vector = false );
00213   
00215   template <class DiscFuncType>
00216   inline void addData(const DiscFuncType &func, const DATAINFO * , double time );
00217   
00219   template <class DiscFuncType>
00220   inline void addData(const DiscFuncType &func, std::string name , double time , bool vector = false );
00221 
00222   // retrun whether we have data or not 
00223   bool hasData () { return (vecFdata_.size() > 0); }
00224 
00225   // return vector for copying in combined display 
00226   std::vector < DUNE_FDATA * > & getFdataVec () { return vecFdata_; }
00227 
00228 private:
00238   template<class VectorType, class IndexSetType >
00239   inline void addVector(const std::string name, 
00240                         const VectorType & data, const IndexSetType & indexSet, 
00241                         const double time , const int polOrd , 
00242                         const int dimRange, bool continuous ); 
00243   
00253   template<class VectorType, class IndexSetType >
00254   inline void addVector(const VectorType & data, const IndexSetType & indexSet, 
00255                         const DATAINFO * dinf, double time ,
00256                         const int polOrd , const int dimRange, bool continuous ); 
00257   
00259   std::vector < DUNE_FDATA * > vecFdata_;
00260 
00261   enum { polynomialOrder = 1 };
00262   // store lagrange points for evaluation 
00263   GrapeLagrangePoints<ctype,dim,dimworld,polynomialOrder> lagrangePoints_;
00264 
00265   typedef typename GridType :: template Codim<0> :: Entity EntityCodim0Type;
00266   typedef void evalCoord_t(EntityCodim0Type &, DUNE_FDATA *, const double *, double * );
00267   typedef void evalDof_t  (EntityCodim0Type &,int , DUNE_FDATA * , int , double * );
00268 
00269 public:  
00270   // create object DUNE_FDATA 
00271   static DUNE_FDATA * createDuneFunc ();
00272   // delete object DUNE_FDATA 
00273   static void deleteDuneFunc (DUNE_FDATA *);
00274 };
00275 
00276 template <typename ctype, int dim, int dimworld, int polOrd> 
00277 class GrapeLagrangePoints 
00278 {
00279   enum { maxPoints = 20 };
00280   enum { numberOfTypes = (dim == 2) ? 2 : 6 };
00281   
00282   std::vector < FieldMatrix<ctype,maxPoints,dim> > points_;
00283 public:
00285   GrapeLagrangePoints ()  
00286   {
00287     for(int type=0; type<numberOfTypes; type++)
00288     {
00289       FieldMatrix<ctype,maxPoints,dim> coords(0.0);
00290       int nvx = numberOfVertices(type); 
00291         
00292       for(int i=0; i<nvx; i++)
00293       {
00294         const double * p = getCoordinate(type,i);
00295         for(int j=0; j<dimworld; j++)
00296         {
00297           assert( p );
00298           coords[i][j] = p[j]; 
00299         }
00300       }
00301       points_.push_back( coords );
00302     }
00303   }
00304    
00307   const FieldVector<ctype,dim> & 
00308   getPoint (int geomType, int polyOrder , int localNum ) const 
00309   {
00310     assert( polOrd == polyOrder );
00311     assert( geomType >= 0 );
00312     assert( geomType < numberOfTypes );
00313     return points_[geomType][localNum];
00314   }
00315 
00316 private: 
00317   int numberOfVertices( int type )
00318   {
00319     if(type < 2) 
00320       return GrapeInterface_two_two::getElementDescription(type)->number_of_vertices;
00321     else 
00322       return GrapeInterface_three_three::getElementDescription(type)->number_of_vertices;
00323   }
00324 
00325   const double * getCoordinate( int type, int i )
00326   {
00327     if(type < 2) 
00328       return GrapeInterface_two_two::getElementDescription(type)->coord[i];
00329     else 
00330       return GrapeInterface_three_three::getElementDescription(type)->coord[i];
00331   }
00332 };
00333   
00334 } // end namespace Dune
00335 
00336 #include "grape/grapedatadisplay.cc"
00337 #endif

Generated on 9 Apr 2008 with Doxygen (ver 1.5.2) [logfile].