dune-pdelab  2.5-dev
vtkexport.hh
Go to the documentation of this file.
1 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=8 sw=2 sts=2:
3 
4 #ifndef DUNE_PDELAB_COMMON_VTKEXPORT_HH
5 #define DUNE_PDELAB_COMMON_VTKEXPORT_HH
6 
7 #include<cstddef>
8 #include<string>
9 #include<vector>
10 
11 #include <dune/common/shared_ptr.hh>
12 
13 #include<dune/grid/io/file/vtk/vtkwriter.hh>
14 
16 
17 namespace Dune {
18  namespace PDELab {
19 
21  template<typename T> // T is a grid function
23  : public Dune::VTKFunction<typename T::Traits::GridViewType>
24  {
25  typedef typename T::Traits::GridViewType::Grid::ctype DF;
26  enum {n=T::Traits::GridViewType::dimension};
27  typedef typename T::Traits::GridViewType::Grid::template Codim<0>::Entity Entity;
28 
29  public:
31 
47  VTKGridFunctionAdapter(const T& t_, std::string s_,
48  const std::vector<std::size_t> &remap_ =
49  rangeVector(std::size_t(T::Traits::dimRange)))
50  : t(stackobject_to_shared_ptr(t_)), s(s_), remap(remap_)
51  {}
52 
54 
67  VTKGridFunctionAdapter(const std::shared_ptr<const T>& t_, std::string s_,
68  const std::vector<std::size_t> &remap_ =
69  rangeVector(std::size_t(T::Traits::dimRange)))
70  : t(t_), s(s_), remap(remap_)
71  { }
72 
73  virtual int ncomps () const
74  {
75  return remap.size();;
76  }
77 
78  virtual double evaluate (int comp, const Entity& e, const Dune::FieldVector<DF,n>& xi) const
79  {
80  typename T::Traits::DomainType x;
81  typename T::Traits::RangeType y;
82 
83  for (int i=0; i<n; i++)
84  x[i] = xi[i];
85  t->evaluate(e,x,y);
86  return y[remap[comp]];
87  }
88 
89  virtual std::string name () const
90  {
91  return s;
92  }
93 
94  private:
95  std::shared_ptr<const T> t;
96  std::string s;
97  std::vector<std::size_t> remap;
98  };
99 
101 
117  template<class GF>
118  std::shared_ptr<VTKGridFunctionAdapter<GF> > makeVTKGridFunctionAdapter
119  ( const std::shared_ptr<GF> &gf, const std::string &name,
120  const std::vector<std::size_t> &remap =
121  rangeVector(std::size_t(GF::Traits::dimRange)))
122  { return std::make_shared<VTKGridFunctionAdapter<GF> >(gf, name, remap); }
123 
125 
141  template<class GF>
142  std::shared_ptr<VTKGridFunctionAdapter<GF> > makeVTKGridFunctionAdapter
143  ( const GF &gf, const std::string &name,
144  const std::vector<std::size_t> &remap =
145  rangeVector(std::size_t(GF::Traits::dimRange)))
146  { return std::make_shared<VTKGridFunctionAdapter<GF> >(stackobject_to_shared_ptr(gf), name, remap); }
147 
149 
163  template<class GF>
164  std::shared_ptr<VTKGridFunctionAdapter<GF> > makeVTKGridFunctionAdapter
165  ( const std::shared_ptr<const GF> &gf, const std::string &name,
166  const std::vector<std::size_t> &remap =
167  rangeVector(std::size_t(GF::Traits::dimRange)))
168  { return std::make_shared<VTKGridFunctionAdapter<GF> >(gf, name, remap); }
169 
174  template<typename G, typename FEM>
176  : public Dune::VTKFunction<G>
177  {
178  typedef typename G::ctype DF;
179  enum {n=G::dimension};
180  typedef typename G::template Codim<0>::Entity Entity;
181 
182  public:
183  VTKFiniteElementMapAdapter (const FEM& fem_, std::string s_)
184  : fem(fem_), s(s_)
185  {}
186 
187  virtual int ncomps () const
188  {
189  return 1;
190  }
191 
192  virtual double evaluate (int comp, const Entity& e, const Dune::FieldVector<DF,n>& xi) const
193  {
194  return fem.getOrder(e);
195  }
196 
197  virtual std::string name () const
198  {
199  return s;
200  }
201 
202  private:
203  const FEM& fem;
204  std::string s;
205  };
206 
207  }
208 }
209 
210 #endif // DUNE_PDELAB_COMMON_VTKEXPORT_HH
VTKFiniteElementMapAdapter(const FEM &fem_, std::string s_)
Definition: vtkexport.hh:183
virtual std::string name() const
Definition: vtkexport.hh:89
virtual int ncomps() const
Definition: vtkexport.hh:187
virtual double evaluate(int comp, const Entity &e, const Dune::FieldVector< DF, n > &xi) const
Definition: vtkexport.hh:78
const std::string s
Definition: function.hh:1101
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
std::vector< T > rangeVector(T begin, T passed_the_end, T increment=1)
Generate a vector with a range of numbers.
Definition: range.hh:22
wrap a GridFunction so it can be used with the VTKWriter from dune-grid.
Definition: vtkexport.hh:22
virtual std::string name() const
Definition: vtkexport.hh:197
const Entity & e
Definition: localfunctionspace.hh:111
std::shared_ptr< VTKGridFunctionAdapter< GF > > makeVTKGridFunctionAdapter(const std::shared_ptr< GF > &gf, const std::string &name, const std::vector< std::size_t > &remap=rangeVector(std::size_t(GF::Traits::dimRange)))
construct a VTKGridFunctionAdapter
Definition: vtkexport.hh:119
VTKGridFunctionAdapter(const T &t_, std::string s_, const std::vector< std::size_t > &remap_=rangeVector(std::size_t(T::Traits::dimRange)))
construct a VTKGridFunctionAdapter
Definition: vtkexport.hh:47
VTKGridFunctionAdapter(const std::shared_ptr< const T > &t_, std::string s_, const std::vector< std::size_t > &remap_=rangeVector(std::size_t(T::Traits::dimRange)))
construct a VTKGridFunctionAdapter
Definition: vtkexport.hh:67
virtual double evaluate(int comp, const Entity &e, const Dune::FieldVector< DF, n > &xi) const
Definition: vtkexport.hh:192
virtual int ncomps() const
Definition: vtkexport.hh:73
Definition: vtkexport.hh:175