dune-pdelab  2.7-git
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 #include<memory>
11 
12 #include<dune/common/shared_ptr.hh>
13 
14 #include<dune/grid/io/file/vtk/vtkwriter.hh>
15 
17 
18 namespace Dune {
19  namespace PDELab {
20 
22  template<typename T> // T is a grid function
24  : public Dune::VTKFunction<typename T::Traits::GridViewType>
25  {
26  typedef typename T::Traits::GridViewType::Grid::ctype DF;
27  enum {n=T::Traits::GridViewType::dimension};
28  typedef typename T::Traits::GridViewType::Grid::template Codim<0>::Entity Entity;
29 
30  public:
32 
48  VTKGridFunctionAdapter(const T& t_, std::string s_,
49  const std::vector<std::size_t> &remap_ =
50  rangeVector(std::size_t(T::Traits::dimRange)))
51  : t(stackobject_to_shared_ptr(t_)), s(s_), remap(remap_)
52  {}
53 
55 
68  VTKGridFunctionAdapter(const std::shared_ptr<const T>& t_, std::string s_,
69  const std::vector<std::size_t> &remap_ =
70  rangeVector(std::size_t(T::Traits::dimRange)))
71  : t(t_), s(s_), remap(remap_)
72  { }
73 
74  virtual int ncomps () const override
75  {
76  return remap.size();;
77  }
78 
79  virtual double evaluate (int comp, const Entity& e, const Dune::FieldVector<DF,n>& xi) const override
80  {
81  typename T::Traits::DomainType x;
82  typename T::Traits::RangeType y;
83 
84  for (int i=0; i<n; i++)
85  x[i] = xi[i];
86  t->evaluate(e,x,y);
87  return y[remap[comp]];
88  }
89 
90  virtual std::string name () const override
91  {
92  return s;
93  }
94 
95  private:
96  std::shared_ptr<const T> t;
97  std::string s;
98  std::vector<std::size_t> remap;
99  };
100 
102 
118  template<class GF>
119  std::shared_ptr<VTKGridFunctionAdapter<GF> > makeVTKGridFunctionAdapter
120  ( const std::shared_ptr<GF> &gf, const std::string &name,
121  const std::vector<std::size_t> &remap =
122  rangeVector(std::size_t(GF::Traits::dimRange)))
123  { return std::make_shared<VTKGridFunctionAdapter<GF> >(gf, name, remap); }
124 
126 
142  template<class GF>
143  std::shared_ptr<VTKGridFunctionAdapter<GF> > makeVTKGridFunctionAdapter
144  ( const GF &gf, const std::string &name,
145  const std::vector<std::size_t> &remap =
146  rangeVector(std::size_t(GF::Traits::dimRange)))
147  { return std::make_shared<VTKGridFunctionAdapter<GF> >(stackobject_to_shared_ptr(gf), name, remap); }
148 
150 
164  template<class GF>
165  std::shared_ptr<VTKGridFunctionAdapter<GF> > makeVTKGridFunctionAdapter
166  ( const std::shared_ptr<const GF> &gf, const std::string &name,
167  const std::vector<std::size_t> &remap =
168  rangeVector(std::size_t(GF::Traits::dimRange)))
169  { return std::make_shared<VTKGridFunctionAdapter<GF> >(gf, name, remap); }
170 
175  template<typename G, typename FEM>
177  : public Dune::VTKFunction<G>
178  {
179  typedef typename G::ctype DF;
180  enum {n=G::dimension};
181  typedef typename G::template Codim<0>::Entity Entity;
182 
183  public:
184  VTKFiniteElementMapAdapter (const FEM& fem_, std::string s_)
185  : fem(fem_), s(s_)
186  {}
187 
188  virtual int ncomps () const override
189  {
190  return 1;
191  }
192 
193  virtual double evaluate (int comp, const Entity& e, const Dune::FieldVector<DF,n>& xi) const override
194  {
195  return fem.getOrder(e);
196  }
197 
198  virtual std::string name () const override
199  {
200  return s;
201  }
202 
203  private:
204  const FEM& fem;
205  std::string s;
206  };
207 
208  }
209 }
210 
211 #endif // DUNE_PDELAB_COMMON_VTKEXPORT_HH
const Entity & e
Definition: localfunctionspace.hh:123
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
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
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:120
wrap a GridFunction so it can be used with the VTKWriter from dune-grid.
Definition: vtkexport.hh:25
virtual double evaluate(int comp, const Entity &e, const Dune::FieldVector< DF, n > &xi) const override
Definition: vtkexport.hh:79
virtual std::string name() const override
Definition: vtkexport.hh:90
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:48
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:68
virtual int ncomps() const override
Definition: vtkexport.hh:74
Definition: vtkexport.hh:178
virtual std::string name() const override
Definition: vtkexport.hh:198
virtual double evaluate(int comp, const Entity &e, const Dune::FieldVector< DF, n > &xi) const override
Definition: vtkexport.hh:193
virtual int ncomps() const override
Definition: vtkexport.hh:188
VTKFiniteElementMapAdapter(const FEM &fem_, std::string s_)
Definition: vtkexport.hh:184