DUNE PDELab (git)

vtkexport.hh
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
13
15
16#include<dune/pdelab/common/range.hh>
17
18namespace 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
Wrapper class for entities.
Definition: entity.hh:66
vector space out of a tensor product of fields.
Definition: fvector.hh:91
Definition: vtkexport.hh:178
virtual std::string name() const override
get name
Definition: vtkexport.hh:198
virtual int ncomps() const override
Definition: vtkexport.hh:188
wrap a GridFunction so it can be used with the VTKWriter from dune-grid.
Definition: vtkexport.hh:25
virtual std::string name() const override
get name
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
A base class for grid functions with any return type and dimension.
Definition: function.hh:42
Dune namespace.
Definition: alignedallocator.hh:13
std::shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:72
This file implements several utilities related to std::shared_ptr.
Static tag representing a codimension.
Definition: dimension.hh:24
Provides file i/o for the visualization toolkit.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 23, 23:29, 2024)