Dune Core Modules (2.6.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
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
17namespace 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 std::shared_ptr<DataArrayWriter<RF> > arraywriter;
88
89 public:
90 SkeletonFunctionWriter(const std::shared_ptr<const Func>& func_,
91 const std::string& name, unsigned dimR_)
92 : func(func_), name_(name), dimR(dimR_)
93 { }
94
95 SkeletonFunctionWriter(const std::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
vector space out of a tensor product of fields.
Definition: fvector.hh:93
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)
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:101
virtual void addArray(PVTUWriter &writer)
add this field to the given parallel writer
Definition: skeletonfunction.hh:107
virtual void write(const typename Func::Traits::Cell &cell, const typename Func::Traits::Domain &xl)
write at the given position
Definition: skeletonfunction.hh:119
virtual bool beginWrite(VTUWriter &writer, std::size_t nitems)
start writing with the given writer
Definition: skeletonfunction.hh:112
virtual void endWrite()
signal end of writing
Definition: skeletonfunction.hh:130
virtual unsigned ncomps() const
return number of components of the vector
Definition: skeletonfunction.hh:104
Dump a .vtu/.vtp files contents to a stream.
Definition: vtuwriter.hh:96
DataArrayWriter< T > * makeArrayWriter(const std::string &name, unsigned ncomps, unsigned nitems)
acquire a DataArrayWriter
Definition: vtuwriter.hh:379
Implements a vector constructed from a given type representing a field and a compile-time given size.
Dune namespace.
Definition: alignedallocator.hh:10
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 27, 23:30, 2024)