Dune Core Modules (2.3.1)

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