Dune Core Modules (2.7.0)

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 <memory>
8 #include <string>
9 #include <vector>
10 
11 #include <dune/common/fvector.hh>
12 
13 #include <dune/grid/io/file/vtk/functionwriter.hh>
14 #include <dune/grid/io/file/vtk/pvtuwriter.hh>
15 #include <dune/grid/io/file/vtk/vtuwriter.hh>
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>
35  struct SkeletonFunctionTraits {
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:
51  typedef SkeletonFunctionTraits<GV, RF> Traits;
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  std::shared_ptr<const Func> func;
85  std::string name_;
86  unsigned dimR;
87  VTK::Precision precision_;
88  std::shared_ptr<DataArrayWriter> arraywriter;
89 
90  public:
91  SkeletonFunctionWriter(const std::shared_ptr<const Func>& func_,
92  const std::string& name, unsigned dimR_,
93  VTK::Precision prec = VTK::Precision::float32)
94  : func(func_), name_(name), dimR(dimR_), precision_(prec)
95  { }
96 
97  SkeletonFunctionWriter(const std::shared_ptr<const Func>& func_,
98  const std::string& name,
99  VTK::Precision prec = VTK::Precision::float32)
100  : func(func_), name_(name), dimR(func->dimRange()), precision_(prec)
101  { }
102 
104  virtual std::string name() const { return name_; }
105 
107  virtual unsigned ncomps() const { return dimR; }
108 
110  virtual void addArray(PVTUWriter& writer) {
111  writer.addArray(name(), ncomps(), precision_);
112  }
113 
115  virtual bool beginWrite(VTUWriter& writer, std::size_t nitems) {
116  arraywriter.reset(writer.makeArrayWriter(name(), ncomps(),
117  nitems, precision_));
118  return !arraywriter->writeIsNoop();
119  }
120 
122  virtual void write(const typename Func::Traits::Cell& cell,
123  const typename Func::Traits::Domain& xl) {
124  typename Func::Traits::Range result;
125  func->evaluate(cell, xl, result);
126  for(unsigned d = 0; d < result.size() && d < dimR; ++d)
127  arraywriter->write(result[d]);
128  for(unsigned d = result.size(); d < dimR; ++d)
129  arraywriter->write(0);
130  }
131 
133  virtual void endWrite() {
134  arraywriter.reset();
135  }
136  };
137 
138  } // namespace VTK
139 
141 
142 } // namespace Dune
143 
144 #endif // DUNE_GRID_IO_FILE_VTK_SKELETONFUNCTION_HH
vector space out of a tensor product of fields.
Definition: fvector.hh:96
Base class for function writers.
Definition: functionwriter.hh:32
Dump a .vtu/.vtp files contents to a stream.
Definition: pvtuwriter.hh:60
void addArray(const std::string &name, unsigned ncomps, Precision prec)
Add an array to the output file.
Definition: pvtuwriter.hh:205
A prototype for VTKFunctions on the skeleton.
Definition: skeletonfunction.hh:49
unsigned dimRange() const
get dimension of the Range
void evaluate(const typename Traits::Cell &c, const typename Traits::Domain &xl, typename Traits::Range &result) const
evaluate at local point xl in Cell c, store in result
function writer for skeleton functions
Definition: skeletonfunction.hh:81
virtual std::string name() const
return name
Definition: skeletonfunction.hh:104
virtual void addArray(PVTUWriter &writer)
add this field to the given parallel writer
Definition: skeletonfunction.hh:110
virtual void write(const typename Func::Traits::Cell &cell, const typename Func::Traits::Domain &xl)
write at the given position
Definition: skeletonfunction.hh:122
virtual bool beginWrite(VTUWriter &writer, std::size_t nitems)
start writing with the given writer
Definition: skeletonfunction.hh:115
virtual void endWrite()
signal end of writing
Definition: skeletonfunction.hh:133
virtual unsigned ncomps() const
return number of components of the vector
Definition: skeletonfunction.hh:107
Dump a .vtu/.vtp files contents to a stream.
Definition: vtuwriter.hh:96
DataArrayWriter * makeArrayWriter(const std::string &name, unsigned ncomps, unsigned nitems, Precision prec)
acquire a DataArrayWriter
Definition: vtuwriter.hh:378
Precision
which precision to use when writing out data to vtk files
Definition: common.hh:319
Implements a vector constructed from a given type representing a field and a compile-time given size.
Dune namespace.
Definition: alignedallocator.hh:14
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 15, 22:30, 2024)