dune-grid 2.9.0
skeletonfunction.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5
6#ifndef DUNE_GRID_IO_FILE_VTK_SKELETONFUNCTION_HH
7#define DUNE_GRID_IO_FILE_VTK_SKELETONFUNCTION_HH
8
9#include <memory>
10#include <string>
11#include <vector>
12
13#include <dune/common/fvector.hh>
14
18
19namespace Dune {
20
23
29 namespace VTK {
30
32 //
33 // Prototype for VTKFunktions on the skeleton
34 //
35
36 template<typename GV, typename RF>
38 typedef GV GridView;
39 typedef typename GV::Intersection Cell;
40
41 typedef typename GV::ctype DomainField;
42 static const unsigned dimDomain = GV::dimension-1;
43 typedef FieldVector<DomainField, dimDomain> Domain;
44
45 typedef RF RangeField;
46 typedef std::vector<RangeField> Range;
47 };
48
50 template <typename GV, typename RF>
52 public:
54
56 unsigned dimRange() const;
57
59
65 void evaluate(const typename Traits::Cell& c,
66 const typename Traits::Domain& xl,
67 typename Traits::Range& result) const;
68 };
69
71 //
72 // Class for writing SkeletonFunctions
73 //
74
76
80 template<typename Func>
82 : public FunctionWriterBase<typename Func::Traits::Cell>
83 {
84 typedef typename Func::Traits::RangeField RF;
85
86 std::shared_ptr<const Func> func;
87 std::string name_;
88 unsigned dimR;
89 VTK::Precision precision_;
90 std::shared_ptr<DataArrayWriter> arraywriter;
91
92 public:
93 SkeletonFunctionWriter(const std::shared_ptr<const Func>& func_,
94 const std::string& name, unsigned dimR_,
96 : func(func_), name_(name), dimR(dimR_), precision_(prec)
97 { }
98
99 SkeletonFunctionWriter(const std::shared_ptr<const Func>& func_,
100 const std::string& name,
102 : func(func_), name_(name), dimR(func->dimRange()), precision_(prec)
103 { }
104
106 virtual std::string name() const { return name_; }
107
109 virtual unsigned ncomps() const { return dimR; }
110
112 virtual void addArray(PVTUWriter& writer) {
113 writer.addArray(name(), ncomps(), precision_);
114 }
115
117 virtual bool beginWrite(VTUWriter& writer, std::size_t nitems) {
118 arraywriter.reset(writer.makeArrayWriter(name(), ncomps(),
119 nitems, precision_));
120 return !arraywriter->writeIsNoop();
121 }
122
124 virtual void write(const typename Func::Traits::Cell& cell,
125 const typename Func::Traits::Domain& xl) {
126 typename Func::Traits::Range result;
127 func->evaluate(cell, xl, result);
128 for(unsigned d = 0; d < result.size() && d < dimR; ++d)
129 arraywriter->write(result[d]);
130 for(unsigned d = result.size(); d < dimR; ++d)
131 arraywriter->write(0);
132 }
133
135 virtual void endWrite() {
136 arraywriter.reset();
137 }
138 };
139
140 } // namespace VTK
141
143
144} // namespace Dune
145
146#endif // DUNE_GRID_IO_FILE_VTK_SKELETONFUNCTION_HH
Include standard header files.
Definition: agrid.hh:60
Precision
which precision to use when writing out data to vtk files
Definition: common.hh:271
Base class for function writers.
Definition: functionwriter.hh:34
Dump a .vtu/.vtp files contents to a stream.
Definition: pvtuwriter.hh:62
void addArray(const std::string &name, unsigned ncomps, Precision prec)
Add an array to the output file.
Definition: pvtuwriter.hh:207
Definition: skeletonfunction.hh:37
RF RangeField
Definition: skeletonfunction.hh:45
FieldVector< DomainField, dimDomain > Domain
Definition: skeletonfunction.hh:43
GV GridView
Definition: skeletonfunction.hh:38
std::vector< RangeField > Range
Definition: skeletonfunction.hh:46
GV::Intersection Cell
Definition: skeletonfunction.hh:39
GV::ctype DomainField
Definition: skeletonfunction.hh:41
static const unsigned dimDomain
Definition: skeletonfunction.hh:42
A prototype for VTKFunctions on the skeleton.
Definition: skeletonfunction.hh:51
unsigned dimRange() const
get dimension of the Range
SkeletonFunctionTraits< GV, RF > Traits
Definition: skeletonfunction.hh:53
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:83
virtual std::string name() const
return name
Definition: skeletonfunction.hh:106
SkeletonFunctionWriter(const std::shared_ptr< const Func > &func_, const std::string &name, VTK::Precision prec=VTK::Precision::float32)
Definition: skeletonfunction.hh:99
virtual void addArray(PVTUWriter &writer)
add this field to the given parallel writer
Definition: skeletonfunction.hh:112
virtual void write(const typename Func::Traits::Cell &cell, const typename Func::Traits::Domain &xl)
write at the given position
Definition: skeletonfunction.hh:124
virtual bool beginWrite(VTUWriter &writer, std::size_t nitems)
start writing with the given writer
Definition: skeletonfunction.hh:117
SkeletonFunctionWriter(const std::shared_ptr< const Func > &func_, const std::string &name, unsigned dimR_, VTK::Precision prec=VTK::Precision::float32)
Definition: skeletonfunction.hh:93
virtual void endWrite()
signal end of writing
Definition: skeletonfunction.hh:135
virtual unsigned ncomps() const
return number of components of the vector
Definition: skeletonfunction.hh:109
Dump a .vtu/.vtp files contents to a stream.
Definition: vtuwriter.hh:98
DataArrayWriter * makeArrayWriter(const std::string &name, unsigned ncomps, unsigned nitems, Precision prec)
acquire a DataArrayWriter
Definition: vtuwriter.hh:380