dune-grid 2.8.0
Loading...
Searching...
No Matches
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
16
17namespace 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 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_,
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,
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
Include standard header files.
Definition: agrid.hh:58
Precision
which precision to use when writing out data to vtk files
Definition: common.hh:269
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
Definition: skeletonfunction.hh:35
RF RangeField
Definition: skeletonfunction.hh:43
FieldVector< DomainField, dimDomain > Domain
Definition: skeletonfunction.hh:41
GV GridView
Definition: skeletonfunction.hh:36
std::vector< RangeField > Range
Definition: skeletonfunction.hh:44
GV::Intersection Cell
Definition: skeletonfunction.hh:37
GV::ctype DomainField
Definition: skeletonfunction.hh:39
static const unsigned dimDomain
Definition: skeletonfunction.hh:40
A prototype for VTKFunctions on the skeleton.
Definition: skeletonfunction.hh:49
unsigned dimRange() const
get dimension of the Range
SkeletonFunctionTraits< GV, RF > Traits
Definition: skeletonfunction.hh:51
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
SkeletonFunctionWriter(const std::shared_ptr< const Func > &func_, const std::string &name, VTK::Precision prec=VTK::Precision::float32)
Definition: skeletonfunction.hh:97
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
SkeletonFunctionWriter(const std::shared_ptr< const Func > &func_, const std::string &name, unsigned dimR_, VTK::Precision prec=VTK::Precision::float32)
Definition: skeletonfunction.hh:91
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