Dune Core Modules (2.5.0)

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
11
12#include <dune/geometry/type.hh>
13#include <dune/geometry/referenceelements.hh>
14#include <dune/geometry/multilineargeometry.hh>
15
17
23namespace Dune
24{
27
29 //
30 // Base VTKFunction
31 //
32
37 template< class GridView >
39 {
40 public:
41 typedef typename GridView::ctype ctype;
42 enum { dim = GridView::dimension };
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
@ mydimension
Dimensionality of the reference element of the entity.
Definition: entity.hh:115
Default exception class for I/O errors.
Definition: exceptions.hh:229
generic geometry implementation based on corner coordinates
Definition: multilineargeometry.hh:190
GlobalCoordinate global(const LocalCoordinate &local) const
evaluate the mapping
Definition: multilineargeometry.hh:287
Index index(const EntityType &e) const
Map entity to array index.
Definition: mcmgmapper.hh:146
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:160
int size() const
Return total number of entities in the entity set managed by the mapper.
Definition: mcmgmapper.hh:179
Take a vector and interpret it as cell data for the VTKWriter.
Definition: function.hh:90
virtual int ncomps() const
return number of components
Definition: function.hh:114
virtual ~P0VTKFunction()
destructor
Definition: function.hh:162
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 double evaluate(int, const Entity &e, const Dune::FieldVector< ctype, dim > &) const
evaluate
Definition: function.hh:120
virtual std::string name() const
get name
Definition: function.hh:127
Take a vector and interpret it as point data for the VTKWriter.
Definition: function.hh:188
virtual std::string name() const
get name
Definition: function.hh:234
virtual ~P1VTKFunction()
destructor
Definition: function.hh:269
virtual double evaluate(int comp, const Entity &e, const Dune::FieldVector< ctype, dim > &xi) const
evaluate
Definition: function.hh:218
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
virtual int ncomps() const
return number of components
Definition: function.hh:212
A base class for grid functions with any return type and dimension.
Definition: function.hh:39
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
virtual std::string name() const =0
get name
virtual int ncomps() const =0
virtual ~VTKFunction()
virtual destructor
Definition: function.hh:64
A few common exception classes.
Implements a vector constructed from a given type representing a field and a compile-time given size.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Grid::ctype ctype
type used for coordinates in grid
Definition: gridview.hh:125
@ dimension
The dimension of the grid.
Definition: gridview.hh:128
Mapper for multiple codim and multiple geometry types.
Dune namespace.
Definition: alignment.hh:11
Static tag representing a codimension.
Definition: dimension.hh:22
A unique label for each type of element that can occur in a grid.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)