dune-grid  2.2.1
grapedatadisplay.hh
Go to the documentation of this file.
1 #ifndef DUNE_GRAPE_DATA_DISPLAY_HH
2 #define DUNE_GRAPE_DATA_DISPLAY_HH
3 
4 //- system includes
5 #include <vector>
6 #include <limits>
7 
8 //- local includes
9 #include "grapegriddisplay.hh"
10 
17 namespace Dune
18 {
19 
20  // Forward Declarations
21  // --------------------
22 
23  template< class ctype, int dim, int dimworld, int polOrd >
24  class GrapeLagrangePoints;
25 
26 
27 
28  // GrapeFunction
29  // -------------
30 
31  template< class GV, int dimR, int polOrd >
33  {
34  typedef GV GridView;
35 
36  static const int dimDomain = GridView::Grid::dimension;
37  static const int dimRange = dimR;
38 
39  typedef FieldVector< typename GridView::Grid::ctype, dimDomain > DomainVector;
40  typedef FieldVector< typename GridView::Grid::ctype, dimRange > RangeVector;
41 
42  typedef typename GridView::template Codim< 0 >::Entity Entity;
43 
44  virtual ~GrapeFunction ()
45  {}
46 
47  virtual void evaluate ( const Entity &entity, const DomainVector &x, RangeVector &y ) const = 0;
48 
49  virtual const GridView &gridView () const = 0;
50 
51  virtual std::string name () const = 0;
52  };
53 
54 
55 #if HAVE_GRAPE
56 
57  // EvalFunctionData
58  // ----------------
59 
60 template <class EvalImpTraits>
61 struct EvalFunctionData
62 {
63  typedef typename EvalImpTraits :: GridType GridType;
64  typedef typename EvalImpTraits :: EvalImp EvalImp;
65 
66  typedef typename GridType :: template Codim<0> :: Entity EntityType;
67  enum { dim = GridType::dimension };
68  enum { dimworld = GridType::dimensionworld };
69 
70  typedef typename GridType :: ctype ctype;
71 
72  typedef typename GrapeInterface<dim,dimworld>::DUNE_ELEM DUNE_ELEM;
73  typedef typename GrapeInterface<dim,dimworld>::DUNE_FDATA DUNE_FDATA;
74 
75  // for the data visualization, call implementations evalCoordNow
76  inline static void evalCoordNow (const EntityType &en, DUNE_FDATA *fdata, const double *coord, double * val)
77  {
78  EvalImp::evalCoordNow(en,fdata,coord,val);
79  }
80 
81  // for the data visualization, call implementations evalDofNow
82  inline static void evalDofNow (const EntityType &en, int geomType, DUNE_FDATA *fdata , int localNum, double * val)
83  {
84  EvalImp::evalDofNow(en,geomType,fdata,localNum,val);
85  }
86 
87  // evaluate at given local coord
88  inline static void evalCoord (DUNE_ELEM *he, DUNE_FDATA *df,
89  const double *coord, double * val);
90 
91  // evaluate at dof
92  inline static void evalDof (DUNE_ELEM *he, DUNE_FDATA *df, int localNum, double * val);
93 
94  // get min and max value for colorbar
95  inline static void getMinMaxValues(DUNE_FDATA *df, double* min, double* max );
96 };
97 
98 template <class GridImp, class DiscreteFunctionType>
99 struct EvalDiscreteFunctions;
100 
101 template <class GridImp, class DiscreteFunctionType>
102 struct EvalDiscreteFunctionsTraits
103 {
104  typedef GridImp GridType;
105  typedef EvalDiscreteFunctions <GridImp, DiscreteFunctionType > EvalImp;
106 };
107 
108 template <class GridImp, class DiscreteFunctionType>
109 struct EvalDiscreteFunctions
110 : public EvalFunctionData< EvalDiscreteFunctionsTraits <GridImp, DiscreteFunctionType > >
111 {
112  typedef GridImp GridType;
113  typedef typename GridType :: template Codim<0> :: Entity EntityType;
114  enum { dim = GridType::dimension };
115  enum { dimworld = GridType::dimensionworld };
116 
117  typedef typename GridType :: ctype ctype;
118 
119  typedef typename DiscreteFunctionType :: LocalFunctionType LocalFunctionType;
120  typedef typename DiscreteFunctionType :: DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
121 
122  typedef typename DiscreteFunctionSpaceType :: RangeType RangeType;
123  typedef typename DiscreteFunctionSpaceType :: DomainType DomainType;
124 
125  typedef typename GrapeInterface<dim,dimworld>::DUNE_ELEM DUNE_ELEM;
126  typedef typename GrapeInterface<dim,dimworld>::DUNE_FDATA DUNE_FDATA;
127 
128  // for the data visualization
129  inline static void evalCoordNow (const EntityType &en, DUNE_FDATA *fdata, const double *coord, double * val);
130 
131  // for the data visualization
132  inline static void evalDofNow (const EntityType &en, int geomType, DUNE_FDATA *fdata , int localNum, double * val);
133 
134  // for the data visualization
135  inline static void evalScalar (const EntityType &en, int geomType,
136  DiscreteFunctionType & func, LocalFunctionType &lf,
137  const int * comp , int localNum, double * val);
138 
139  // for the data visualization
140  inline static void evalVector (const EntityType &en, int geomType,
141  DiscreteFunctionType & func, LocalFunctionType &lf,
142  const int * comp, int vend, int localNum, double * val);
143 
144  // calculate min and max value of function
145  inline static void calcMinMax(DUNE_FDATA * df);
146 };
147 
148 
149 
150  // EvalGrapeFunction
151  // -----------------
152 
153  template< class GV, int dimR, int polOrd >
154  struct EvalGrapeFunction;
155 
156  template< class GV, int dimR, int polOrd >
157  struct EvalGrapeFunctionTraits
158  {
159  typedef typename GV::Grid GridType;
160  typedef EvalGrapeFunction< GV, dimR, polOrd > EvalImp;
161  };
162 
163  template< class GV, int dimR, int polOrd >
164  struct EvalGrapeFunction
165  : public EvalFunctionData< EvalGrapeFunctionTraits< GV, dimR, polOrd > >
166  {
167  typedef GV GridView;
168 
169  typedef Dune::GrapeFunction< GV, dimR, polOrd > GrapeFunction;
170 
171  static const int dimDomain = GrapeFunction::dimDomain;
172  static const int dimRange = GrapeFunction::dimRange;
173  static const int dimWorld = GridView::Grid::dimensionworld;
174 
175  typedef typename GrapeFunction::DomainVector DomainVector;
176  typedef typename GrapeFunction::RangeVector RangeVector;
177 
178  typedef typename GridView::template Codim< 0 >::Entity Entity;
179 
180  typedef typename GrapeInterface< dimDomain, dimWorld >::DUNE_ELEM DUNE_ELEM;
181  typedef typename GrapeInterface< dimDomain, dimWorld >::DUNE_FDATA DUNE_FDATA;
182 
183  // for the data visualization
184  static void evalCoordNow ( const Entity &entity, DUNE_FDATA *fdata, const double *coord, double *val );
185 
186  // for the data visualization
187  static void evalDofNow ( const Entity &entity, int geomType, DUNE_FDATA *fdata, int localNum, double *val );
188 
189  // calculate min and max value of function
190  static void calcMinMax ( DUNE_FDATA *fdata );
191  };
192 
193 
194 
195  // EvalVectorData
196  // --------------
197 
198 template <class GridImp, class VectorType, class IndexSetImp >
199 struct EvalVectorData;
200 
201 template <class GridImp, class VectorType , class IndexSetImp >
202 struct EvalVectorDataTraits
203 {
204  typedef GridImp GridType;
205  typedef EvalVectorData <GridImp, VectorType, IndexSetImp > EvalImp;
206 };
207 
208 template <class GridImp, class VectorType, class IndexSetImp >
209 struct EvalVectorData
210 : public EvalFunctionData< EvalVectorDataTraits <GridImp, VectorType, IndexSetImp > >
211 {
212  typedef GridImp GridType;
213  typedef typename GridType :: template Codim<0> :: Entity EntityType;
214  enum { dim = GridType::dimension };
215  enum { dimworld = GridType::dimensionworld };
216 
217  typedef typename GridType :: ctype ctype;
218 
219  typedef typename GrapeInterface<dim,dimworld>::DUNE_ELEM DUNE_ELEM;
220  typedef typename GrapeInterface<dim,dimworld>::DUNE_FDATA DUNE_FDATA;
221 
222  // for the data visualization
223  inline static void evalCoordNow (const EntityType &en, DUNE_FDATA *fdata, const double *coord, double * val);
224 
225  // for the data visualization
226  inline static void evalDofNow (const EntityType &en, int geomType, DUNE_FDATA *fdata , int localNum, double * val);
227 
228  // for the data visualization, evaluate linear funcs
229  static void evalVectorLinear ( const EntityType &entity, int geomType,
230  VectorType & func, const IndexSetImp &indexSet,
231  const int *comp, int vend, int localNum, double *val );
232 
233  // for the data visualization, evaluate const funcs
234  static void evalVectorConst ( const EntityType &entity, int geomType,
235  VectorType & func, const IndexSetImp &indexSet,
236  const int * comp, int vend, int localNum, double * val);
237 
238  // calculate min and max value of function
239  inline static void calcMinMax(DUNE_FDATA * df);
240 };
241 #endif
242 
246 template<class GridType>
247 class GrapeDataDisplay : public GrapeGridDisplay < GridType >
248 {
250 
252 
253  enum { dim = GridType::dimension };
254  enum { dimworld = GridType::dimensionworld };
255 
256  typedef typename GridType :: ctype ctype;
257 
258 #if HAVE_GRAPE
259  typedef typename GrapeInterface<dim,dimworld>::DUNE_ELEM DUNE_ELEM;
260  typedef typename GrapeInterface<dim,dimworld>::DUNE_FDATA DUNE_FDATA;
261  typedef typename GrapeInterface<dim,dimworld>::DUNE_DAT DUNE_DAT;
262  typedef typename GrapeInterface<dim,dimworld>::F_DATA F_DATA;
263 #endif
264 
265 public:
266  typedef GridType MyGridType;
267 
269  inline GrapeDataDisplay(const GridType &grid, const int myrank = -1);
270 
272  template <class GridPartType>
273  inline GrapeDataDisplay(const GridPartType & gridPart, const int myrank = -1);
274 
276  inline ~GrapeDataDisplay();
277 
287  template< class VectorType, class IndexSetType >
288  inline void displayVector ( const std::string name,
289  const VectorType &data,
290  const IndexSetType &indexSet,
291  const int polOrd,
292  const unsigned int dimRange,
293  bool continuous = false );
294 
297  template <class DiscFuncType>
298  inline void dataDisplay(const DiscFuncType &func, bool vector = false);
299 
301  inline void display();
302 
304  template <class DiscFuncType>
305  inline void addData(const DiscFuncType &func, double time = 0.0, bool vector = false );
306 
308  template <class DiscFuncType>
309  inline void addData(const DiscFuncType &func, std::string name , double time , bool vector = false );
310 
311  template< class GV, int dimR, int polOrd >
312  void addData ( const GrapeFunction< GV, dimR, polOrd > &function );
313 
314 #if HAVE_GRAPE
315 
316  template <class DiscFuncType>
317  inline void addData(const DiscFuncType &func, const DATAINFO * , double time );
318 
319  // retrun whether we have data or not
320  bool hasData () { return (vecFdata_.size() > 0); }
321 
322  // return vector for copying in combined display
323  std::vector < DUNE_FDATA * > & getFdataVec () { return vecFdata_; }
324 
334  template<class VectorType, class IndexSetType >
335  inline void addVector(const std::string name,
336  const VectorType & data, const IndexSetType & indexSet,
337  const double time , const int polOrd ,
338  const int dimRange, bool continuous );
339 
350  template<class VectorType, class IndexSetType >
351  inline void addVector(const VectorType & data, const IndexSetType & indexSet,
352  const DATAINFO * dinf, double time ,
353  const int polOrd , const int dimRange, bool continuous );
354 
355 private:
357  std::vector < DUNE_FDATA * > vecFdata_;
358 
359  enum { polynomialOrder = 1 };
360  // store lagrange points for evaluation
361  GrapeLagrangePoints<ctype,dim,dimworld,polynomialOrder> lagrangePoints_;
362 
363  typedef typename GridType :: template Codim<0> :: Entity EntityCodim0Type;
364  typedef void evalCoord_t(EntityCodim0Type &, DUNE_FDATA *, const double *, double * );
365  typedef void evalDof_t (EntityCodim0Type &,int , DUNE_FDATA * , int , double * );
366 
367 public:
368  // create object DUNE_FDATA
369  static DUNE_FDATA * createDuneFunc ();
370  // delete object DUNE_FDATA
371  static void deleteDuneFunc (DUNE_FDATA *);
372 #endif
373 };
374 
375 template <typename ctype, int dim, int dimworld, int polOrd>
377 {
378 #if HAVE_GRAPE
379  enum { maxPoints = 20 };
380  enum { numberOfTypes = (dim == 2) ? 2 : 6 };
381 
382  std::vector < FieldMatrix<ctype,maxPoints,dim> > points_;
384 public:
386  GrapeLagrangePoints () : points_()
387  {
388  GrapeInterface_two_two::setupReferenceElements();
389  GrapeInterface_two_three::setupReferenceElements();
390  GrapeInterface_three_three::setupReferenceElements();
391 
392  for(int type=0; type<numberOfTypes; ++type)
393  {
394  FieldMatrix<ctype,maxPoints,dim> coords( ctype(0) );
395  const int nvx = numberOfVertices(type);
396 
397  for(int i=0; i<nvx; ++i)
398  {
399  const double * p = getCoordinate(type,i);
400  for(int j=0; j<dimworld; ++j)
401  {
402  assert( p );
403  coords[i][j] = p[j];
404  }
405  }
406  points_.push_back( coords );
407  }
408  }
409 
412  const FieldVector<ctype,dim> &
413  getPoint (const int geomType, const int polyOrder , const int localNum ) const
414  {
415  assert( polOrd == polyOrder );
416  assert( geomType >= 0 );
417  assert( geomType < numberOfTypes );
418  return points_[geomType][localNum];
419  }
420 
421 private:
422  static int numberOfVertices( const int type )
423  {
424  if(type < GrapeInterface_three_three::gr_tetrahedron)
425  return GrapeInterface_two_two::getElementDescription(type)->number_of_vertices;
426  else
427  return GrapeInterface_three_three::getElementDescription(type)->number_of_vertices;
428  }
429 
430  static const double * getCoordinate( const int type, const int i )
431  {
432  if(type < GrapeInterface_three_three::gr_tetrahedron)
433  {
434  return GrapeInterface_two_two::getElementDescription(type)->coord[i];
435  }
436  else
437  return GrapeInterface_three_three::getElementDescription(type)->coord[i];
438  }
439 #endif
440 };
441 
442 } // end namespace Dune
443 
444 #include "grape/grapedatadisplay.cc"
445 #endif