dune-grid  2.4
function.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 
4 #ifndef DUNE_GRID_IO_FILE_VTK_FUNCTION_HH
5 #define DUNE_GRID_IO_FILE_VTK_FUNCTION_HH
6 
7 #include <string>
8 
9 #include <dune/common/exceptions.hh>
10 #include <dune/common/fvector.hh>
11 
12 #include <dune/geometry/type.hh>
13 #include <dune/geometry/referenceelements.hh>
14 #include <dune/geometry/multilineargeometry.hh>
15 
17 
23 namespace Dune
24 {
27 
29  //
30  // Base VTKFunction
31  //
32 
37  template< class GridView >
39  {
40  public:
41  typedef typename GridView::ctype ctype;
43  typedef typename GridView::template Codim< 0 >::Entity Entity;
44 
47  virtual int ncomps () const = 0;
48 
50 
57  virtual double evaluate (int comp, const Entity& e,
58  const Dune::FieldVector<ctype,dim>& xi) const = 0;
59 
61  virtual std::string name () const = 0;
62 
64  virtual ~VTKFunction () {}
65  };
66 
68  //
69  // P0VTKFunction
70  //
71 
73 
87  template<typename GV, typename V>
89  : public VTKFunction< GV >
90  {
92  typedef VTKFunction< GV > Base;
95 
97  const V& v;
99  std::string s;
101  int ncomps_;
104  int mycomp_;
106  Mapper mapper;
107 
108  public:
109  typedef typename Base::Entity Entity;
110  typedef typename Base::ctype ctype;
111  using Base::dim;
112 
114  virtual int ncomps () const
115  {
116  return 1;
117  }
118 
120  virtual double evaluate (int, const Entity& e,
121  const Dune::FieldVector<ctype,dim>&) const
122  {
123  return v[mapper.index(e)*ncomps_+mycomp_];
124  }
125 
127  virtual std::string name () const
128  {
129  return s;
130  }
131 
133 
149  P0VTKFunction(const GV &gv, const V &v_, const std::string &s_,
150  int ncomps=1, int mycomp=0 )
151  : v( v_ ),
152  s( s_ ),
153  ncomps_(ncomps),
154  mycomp_(mycomp),
155  mapper( gv )
156  {
157  if (v.size()!=(unsigned int)(mapper.size()*ncomps_))
158  DUNE_THROW(IOError, "P0VTKFunction: size mismatch");
159  }
160 
162  virtual ~P0VTKFunction() {}
163  };
164 
166  //
167  // P1VTKFunction
168  //
169 
171 
185  template<typename GV, typename V>
187  : public VTKFunction< GV >
188  {
190  typedef VTKFunction< GV > Base;
193 
195  const V& v;
197  std::string s;
199  int ncomps_;
202  int mycomp_;
204  Mapper mapper;
205 
206  public:
207  typedef typename Base::Entity Entity;
208  typedef typename Base::ctype ctype;
209  using Base::dim;
210 
212  virtual int ncomps () const
213  {
214  return 1;
215  }
216 
218  virtual double evaluate (int comp, const Entity& e,
219  const Dune::FieldVector<ctype,dim>& xi) const
220  {
221  const unsigned int dim = Entity::mydimension;
222  const unsigned int nVertices = e.subEntities(dim);
223 
224  std::vector<FieldVector<ctype,1> > cornerValues(nVertices);
225  for (unsigned i=0; i<nVertices; ++i)
226  cornerValues[i] = v[mapper.subIndex(e,i,dim)*ncomps_+mycomp_];
227 
228  // (Ab)use the MultiLinearGeometry class to do multi-linear interpolation between scalars
229  const MultiLinearGeometry<ctype,dim,1> interpolation(e.type(), cornerValues);
230  return interpolation.global(xi);
231  }
232 
234  virtual std::string name () const
235  {
236  return s;
237  }
238 
240 
256  P1VTKFunction(const GV& gv, const V &v_, const std::string &s_,
257  int ncomps=1, int mycomp=0 )
258  : v( v_ ),
259  s( s_ ),
260  ncomps_(ncomps),
261  mycomp_(mycomp),
262  mapper( gv )
263  {
264  if (v.size()!=(unsigned int)(mapper.size()*ncomps_))
265  DUNE_THROW(IOError,"P1VTKFunction: size mismatch");
266  }
267 
269  virtual ~P1VTKFunction() {}
270  };
271 
273 
274 } // namespace Dune
275 
276 #endif // DUNE_GRID_IO_FILE_VTK_FUNCTION_HH
Grid::ctype ctype
type used for coordinates in grid
Definition: common/gridview.hh:127
A base class for grid functions with any return type and dimension.
Definition: function.hh:38
virtual double evaluate(int comp, const Entity &e, const Dune::FieldVector< ctype, dim > &xi) const
evaluate
Definition: function.hh:218
virtual std::string name() const
get name
Definition: function.hh:127
GridView::ctype ctype
Definition: function.hh:41
P1VTKFunction(const GV &gv, const V &v_, const std::string &s_, int ncomps=1, int mycomp=0)
construct from a vector and a name
Definition: function.hh:256
The dimension of the grid.
Definition: common/gridview.hh:130
Dimensionality of the reference element of the entity.
Definition: common/entity.hh:112
Include standard header files.
Definition: agrid.hh:59
virtual std::string name() const =0
get name
int size() const
Return total number of entities in the entity set managed by the mapper.
Definition: mcmgmapper.hh:205
virtual ~VTKFunction()
virtual destructor
Definition: function.hh:64
Mapper for multiple codim and multiple geometry types.
Take a vector and interpret it as cell data for the VTKWriter.
Definition: function.hh:88
virtual double evaluate(int comp, const Entity &e, const Dune::FieldVector< ctype, dim > &xi) const =0
evaluate single component comp in the entity e at local coordinates xi
P0VTKFunction(const GV &gv, const V &v_, const std::string &s_, int ncomps=1, int mycomp=0)
construct from a vector and a name
Definition: function.hh:149
virtual int ncomps() const
return number of components
Definition: function.hh:114
Index subIndex(const typename GV::template Codim< 0 >::Entity &e, int i, unsigned int codim) const
Map subentity of codim 0 entity to array index.
Definition: mcmgmapper.hh:190
virtual int ncomps() const =0
virtual double evaluate(int, const Entity &e, const Dune::FieldVector< ctype, dim > &) const
evaluate
Definition: function.hh:120
Base::ctype ctype
Definition: function.hh:110
Base::ctype ctype
Definition: function.hh:208
Definition: function.hh:42
virtual ~P0VTKFunction()
destructor
Definition: function.hh:162
virtual ~P1VTKFunction()
destructor
Definition: function.hh:269
virtual std::string name() const
get name
Definition: function.hh:234
Base::Entity Entity
Definition: function.hh:109
GridView::template Codim< 0 >::Entity Entity
Definition: function.hh:43
virtual int ncomps() const
return number of components
Definition: function.hh:212
Base::Entity Entity
Definition: function.hh:207
Index index(const EntityType &e) const
Map entity to array index.
Definition: mcmgmapper.hh:162
Take a vector and interpret it as point data for the VTKWriter.
Definition: function.hh:186