Dune Core Modules (2.3.1)

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
16
22namespace Dune
23{
26
28 //
29 // Base VTKFunction
30 //
31
36 template< class GridView >
38 {
39 public:
40 typedef typename GridView::ctype ctype;
41 enum { dim = GridView::dimension };
42 typedef typename GridView::template Codim< 0 >::Entity Entity;
43
46 virtual int ncomps () const = 0;
47
49
56 virtual double evaluate (int comp, const Entity& e,
57 const Dune::FieldVector<ctype,dim>& xi) const = 0;
58
60 virtual std::string name () const = 0;
61
63 virtual ~VTKFunction () {}
64 };
65
67 //
68 // P0VTKFunction
69 //
70
72
86 template<typename GV, typename V>
88 : public VTKFunction< GV >
89 {
91 typedef VTKFunction< GV > Base;
94
96 const V& v;
98 std::string s;
100 int ncomps_;
103 int mycomp_;
105 Mapper mapper;
106
107 public:
108 typedef typename Base::Entity Entity;
109 typedef typename Base::ctype ctype;
110 using Base::dim;
111
113 virtual int ncomps () const
114 {
115 return 1;
116 }
117
119 virtual double evaluate (int comp, const Entity& e,
120 const Dune::FieldVector<ctype,dim>& xi) const
121 {
122 return v[mapper.map(e)*ncomps_+mycomp_];
123 }
124
126 virtual std::string name () const
127 {
128 return s;
129 }
130
132
148 P0VTKFunction(const GV &gv, const V &v_, const std::string &s_,
149 int ncomps=1, int mycomp=0 )
150 : v( v_ ),
151 s( s_ ),
152 ncomps_(ncomps),
153 mycomp_(mycomp),
154 mapper( gv )
155 {
156 if (v.size()!=(unsigned int)(mapper.size()*ncomps_))
157 DUNE_THROW(IOError, "P0VTKFunction: size mismatch");
158 }
159
161 virtual ~P0VTKFunction() {}
162 };
163
165 //
166 // P1VTKFunction
167 //
168
170
189 template<typename GV, typename V>
191 : public VTKFunction< GV >
192 {
194 typedef VTKFunction< GV > Base;
197
199 const V& v;
201 std::string s;
203 int ncomps_;
206 int mycomp_;
208 Mapper mapper;
209
210 public:
211 typedef typename Base::Entity Entity;
212 typedef typename Base::ctype ctype;
213 using Base::dim;
214
216 virtual int ncomps () const
217 {
218 return 1;
219 }
220
222 virtual double evaluate (int comp, const Entity& e,
223 const Dune::FieldVector<ctype,dim>& xi) const
224 {
225 double min=1E100;
226 int imin=-1;
227 Dune::GeometryType gt = e.type();
228 for (int i=0; i<e.template count<dim>(); ++i)
229 {
232 .position(i,dim);
233 local -= xi;
234 if (local.infinity_norm()<min)
235 {
236 min = local.infinity_norm();
237 imin = i;
238 }
239 }
240 return v[mapper.map(e,imin,dim)*ncomps_+mycomp_];
241 }
242
244 virtual std::string name () const
245 {
246 return s;
247 }
248
250
266 P1VTKFunction(const GV& gv, const V &v_, const std::string &s_,
267 int ncomps=1, int mycomp=0 )
268 : v( v_ ),
269 s( s_ ),
270 ncomps_(ncomps),
271 mycomp_(mycomp),
272 mapper( gv )
273 {
274 if (v.size()!=(unsigned int)(mapper.size()*ncomps_))
275 DUNE_THROW(IOError,"P1VTKFunction: size mismatch");
276 }
277
279 virtual ~P1VTKFunction() {}
280 };
281
283
284} // namespace Dune
285
286#endif // DUNE_GRID_IO_FILE_VTK_FUNCTION_HH
FieldTraits< value_type >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: densevector.hh:539
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
Grid::ctype ctype
type used for coordinates in grid
Definition: gridview.hh:117
@ dimension
The dimension of the grid.
Definition: gridview.hh:120
Default exception class for I/O errors.
Definition: exceptions.hh:257
int map(const EntityType &e) const
Map entity to array index.
Definition: mcmgmapper.hh:153
int size() const
Return total number of entities in the entity set managed by the mapper.
Definition: mcmgmapper.hh:181
Take a vector and interpret it as cell data for the VTKWriter.
Definition: function.hh:89
virtual int ncomps() const
return number of components
Definition: function.hh:113
virtual double evaluate(int comp, const Entity &e, const Dune::FieldVector< ctype, dim > &xi) const
evaluate
Definition: function.hh:119
virtual ~P0VTKFunction()
destructor
Definition: function.hh:161
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:148
virtual std::string name() const
get name
Definition: function.hh:126
Take a vector and interpret it as point data for the VTKWriter.
Definition: function.hh:192
virtual std::string name() const
get name
Definition: function.hh:244
virtual ~P1VTKFunction()
destructor
Definition: function.hh:279
virtual double evaluate(int comp, const Entity &e, const Dune::FieldVector< ctype, dim > &xi) const
evaluate
Definition: function.hh:222
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:266
virtual int ncomps() const
return number of components
Definition: function.hh:216
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 =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:63
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:244
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:132
Mapper for multiple codim and multiple geometry types.
Dune namespace.
Definition: alignment.hh:14
static const ReferenceElement< ctype, dim > & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:568
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)