dune-grid  2.3beta2
skeletonfunction.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_SKELETONFUNCTION_HH
5 #define DUNE_GRID_IO_FILE_VTK_SKELETONFUNCTION_HH
6 
7 #include <string>
8 #include <vector>
9 
10 #include <dune/common/fvector.hh>
11 #include <dune/common/shared_ptr.hh>
12 
16 
17 namespace Dune {
18 
21 
27  namespace VTK {
28 
30  //
31  // Prototype for VTKFunktions on the skeleton
32  //
33 
34  template<typename GV, typename RF>
36  typedef GV GridView;
37  typedef typename GV::Intersection Cell;
38 
39  typedef typename GV::ctype DomainField;
40  static const unsigned dimDomain = GV::dimension-1;
41  typedef FieldVector<DomainField, dimDomain> Domain;
42 
43  typedef RF RangeField;
44  typedef std::vector<RangeField> Range;
45  };
46 
48  template <typename GV, typename RF>
50  public:
52 
54  unsigned dimRange() const;
55 
57 
63  void evaluate(const typename Traits::Cell& c,
64  const typename Traits::Domain& xl,
65  typename Traits::Range& result) const;
66  };
67 
69  //
70  // Class for writing SkeletonFunctions
71  //
72 
74 
78  template<typename Func>
80  : public FunctionWriterBase<typename Func::Traits::Cell>
81  {
82  typedef typename Func::Traits::RangeField RF;
83 
84  shared_ptr<const Func> func;
85  std::string name_;
86  unsigned dimR;
87  shared_ptr<DataArrayWriter<RF> > arraywriter;
88 
89  public:
90  SkeletonFunctionWriter(const shared_ptr<const Func>& func_,
91  const std::string& name, unsigned dimR_)
92  : func(func_), name_(name), dimR(dimR_)
93  { }
94 
95  SkeletonFunctionWriter(const shared_ptr<const Func>& func_,
96  const std::string& name)
97  : func(func_), name_(name), dimR(func->dimRange())
98  { }
99 
101  virtual std::string name() const { return name_; }
102 
104  virtual unsigned ncomps() const { return dimR; }
105 
107  virtual void addArray(PVTUWriter& writer) {
108  writer.addArray<RF>(name(), ncomps());
109  }
110 
112  virtual bool beginWrite(VTUWriter& writer, std::size_t nitems) {
113  arraywriter.reset(writer.makeArrayWriter<RF>(name(), ncomps(),
114  nitems));
115  return !arraywriter->writeIsNoop();
116  }
117 
119  virtual void write(const typename Func::Traits::Cell& cell,
120  const typename Func::Traits::Domain& xl) {
121  typename Func::Traits::Range result;
122  func->evaluate(cell, xl, result);
123  for(unsigned d = 0; d < result.size() && d < dimR; ++d)
124  arraywriter->write(result[d]);
125  for(unsigned d = result.size(); d < dimR; ++d)
126  arraywriter->write(0);
127  }
128 
130  virtual void endWrite() {
131  arraywriter.reset();
132  }
133  };
134 
135  } // namespace VTK
136 
138 
139 } // namespace Dune
140 
141 #endif // DUNE_GRID_IO_FILE_VTK_SKELETONFUNCTION_HH