dune-grid
2.2.0
|
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 (const 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 (const 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 (const EntityType &en, DUNE_FDATA *fdata, const double *coord, double * val); 00130 00131 // for the data visualization 00132 inline static void evalDofNow (const EntityType &en, int geomType, DUNE_FDATA *fdata , int localNum, double * val); 00133 00134 // for the data visualization 00135 inline static void evalScalar (const 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 (const 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 (const EntityType &en, DUNE_FDATA *fdata, const double *coord, double * val); 00224 00225 // for the data visualization 00226 inline static void evalDofNow (const 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 00287 template< class VectorType, class IndexSetType > 00288 inline void displayVector ( const std::string name, 00289 const VectorType &data, 00290 const IndexSetType &indexSet, 00291 const int polOrd, 00292 const unsigned int dimRange, 00293 bool continuous = false ); 00294 00297 template <class DiscFuncType> 00298 inline void dataDisplay(const DiscFuncType &func, bool vector = false); 00299 00301 inline void display(); 00302 00304 template <class DiscFuncType> 00305 inline void addData(const DiscFuncType &func, double time = 0.0, bool vector = false ); 00306 00308 template <class DiscFuncType> 00309 inline void addData(const DiscFuncType &func, std::string name , double time , bool vector = false ); 00310 00311 template< class GV, int dimR, int polOrd > 00312 void addData ( const GrapeFunction< GV, dimR, polOrd > &function ); 00313 00314 #if HAVE_GRAPE 00315 00316 template <class DiscFuncType> 00317 inline void addData(const DiscFuncType &func, const DATAINFO * , double time ); 00318 00319 // retrun whether we have data or not 00320 bool hasData () { return (vecFdata_.size() > 0); } 00321 00322 // return vector for copying in combined display 00323 std::vector < DUNE_FDATA * > & getFdataVec () { return vecFdata_; } 00324 00334 template<class VectorType, class IndexSetType > 00335 inline void addVector(const std::string name, 00336 const VectorType & data, const IndexSetType & indexSet, 00337 const double time , const int polOrd , 00338 const int dimRange, bool continuous ); 00339 00350 template<class VectorType, class IndexSetType > 00351 inline void addVector(const VectorType & data, const IndexSetType & indexSet, 00352 const DATAINFO * dinf, double time , 00353 const int polOrd , const int dimRange, bool continuous ); 00354 00355 private: 00357 std::vector < DUNE_FDATA * > vecFdata_; 00358 00359 enum { polynomialOrder = 1 }; 00360 // store lagrange points for evaluation 00361 GrapeLagrangePoints<ctype,dim,dimworld,polynomialOrder> lagrangePoints_; 00362 00363 typedef typename GridType :: template Codim<0> :: Entity EntityCodim0Type; 00364 typedef void evalCoord_t(EntityCodim0Type &, DUNE_FDATA *, const double *, double * ); 00365 typedef void evalDof_t (EntityCodim0Type &,int , DUNE_FDATA * , int , double * ); 00366 00367 public: 00368 // create object DUNE_FDATA 00369 static DUNE_FDATA * createDuneFunc (); 00370 // delete object DUNE_FDATA 00371 static void deleteDuneFunc (DUNE_FDATA *); 00372 #endif 00373 }; 00374 00375 template <typename ctype, int dim, int dimworld, int polOrd> 00376 class GrapeLagrangePoints 00377 { 00378 #if HAVE_GRAPE 00379 enum { maxPoints = 20 }; 00380 enum { numberOfTypes = (dim == 2) ? 2 : 6 }; 00381 00382 std::vector < FieldMatrix<ctype,maxPoints,dim> > points_; 00383 GrapeLagrangePoints ( const GrapeLagrangePoints& ); 00384 public: 00386 GrapeLagrangePoints () : points_() 00387 { 00388 GrapeInterface_two_two::setupReferenceElements(); 00389 GrapeInterface_two_three::setupReferenceElements(); 00390 GrapeInterface_three_three::setupReferenceElements(); 00391 00392 for(int type=0; type<numberOfTypes; ++type) 00393 { 00394 FieldMatrix<ctype,maxPoints,dim> coords( ctype(0) ); 00395 const int nvx = numberOfVertices(type); 00396 00397 for(int i=0; i<nvx; ++i) 00398 { 00399 const double * p = getCoordinate(type,i); 00400 for(int j=0; j<dimworld; ++j) 00401 { 00402 assert( p ); 00403 coords[i][j] = p[j]; 00404 } 00405 } 00406 points_.push_back( coords ); 00407 } 00408 } 00409 00412 const FieldVector<ctype,dim> & 00413 getPoint (const int geomType, const int polyOrder , const int localNum ) const 00414 { 00415 assert( polOrd == polyOrder ); 00416 assert( geomType >= 0 ); 00417 assert( geomType < numberOfTypes ); 00418 return points_[geomType][localNum]; 00419 } 00420 00421 private: 00422 static int numberOfVertices( const int type ) 00423 { 00424 if(type < GrapeInterface_three_three::gr_tetrahedron) 00425 return GrapeInterface_two_two::getElementDescription(type)->number_of_vertices; 00426 else 00427 return GrapeInterface_three_three::getElementDescription(type)->number_of_vertices; 00428 } 00429 00430 static const double * getCoordinate( const int type, const int i ) 00431 { 00432 if(type < GrapeInterface_three_three::gr_tetrahedron) 00433 { 00434 return GrapeInterface_two_two::getElementDescription(type)->coord[i]; 00435 } 00436 else 00437 return GrapeInterface_three_three::getElementDescription(type)->coord[i]; 00438 } 00439 #endif 00440 }; 00441 00442 } // end namespace Dune 00443 00444 #include "grape/grapedatadisplay.cc" 00445 #endif