Dune Core Modules (unstable)

skeletonfunction.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © 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
14
15#include <dune/grid/io/file/vtk/functionwriter.hh>
16#include <dune/grid/io/file/vtk/pvtuwriter.hh>
17#include <dune/grid/io/file/vtk/vtuwriter.hh>
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>
37 struct SkeletonFunctionTraits {
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:
53 typedef SkeletonFunctionTraits<GV, RF> Traits;
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_,
95 VTK::Precision prec = VTK::Precision::float32)
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,
101 VTK::Precision prec = VTK::Precision::float32)
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
vector space out of a tensor product of fields.
Definition: fvector.hh:95
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
A prototype for VTKFunctions on the skeleton.
Definition: skeletonfunction.hh:51
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:83
virtual std::string name() const
return name
Definition: skeletonfunction.hh:106
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
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
Precision
which precision to use when writing out data to vtk files
Definition: common.hh:271
Implements a vector constructed from a given type representing a field and a compile-time given size.
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)