dune-vtk 2.8
Loading...
Searching...
No Matches
datacollectorinterface.hh
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <vector>
5
6#include <dune/grid/common/partitionset.hh>
7
8namespace Dune
9{
10 namespace Vtk
11 {
13
18 template <class GridViewType, class Derived, class Partition = Partitions::InteriorBorder>
20 {
21 public:
23 static constexpr auto partition = Partition{};
24
25 using GridView = GridViewType;
26
28 enum { dim = GridView::dimension };
29
31 enum { dow = GridView::dimensionworld };
32
33 public:
36 : gridView_(gridView)
37 {}
38
40 void update ()
41 {
42 asDerived().updateImpl();
43 }
44
46 int ghostLevel () const
47 {
48 return asDerived().ghostLevelImpl();
49 }
50
52 std::uint64_t numCells () const
53 {
54 return asDerived().numCellsImpl();
55 }
56
58 std::uint64_t numPoints () const
59 {
60 return asDerived().numPointsImpl();
61 }
62
64
70 template <class T>
71 std::vector<T> points () const
72 {
73 return asDerived().template pointsImpl<T>();
74 }
75
77
85 template <class T, class VtkFunction>
86 std::vector<T> pointData (VtkFunction const& fct) const
87 {
88 return asDerived().template pointDataImpl<T>(fct);
89 }
90
92
98 template <class T, class VtkFunction>
99 std::vector<T> cellData (VtkFunction const& fct) const
100 {
101 return asDerived().template cellDataImpl<T>(fct);
102 }
103
104 protected: // cast to derived type
105
106 Derived& asDerived ()
107 {
108 return static_cast<Derived&>(*this);
109 }
110
111 const Derived& asDerived () const
112 {
113 return static_cast<const Derived&>(*this);
114 }
115
116 public: // default implementations
117
119 {
120 /* do nothing */
121 }
122
123 int ghostLevelImpl () const
124 {
125 return gridView_.overlapSize(0);
126 }
127
128 // Evaluate `fct` in center of cell.
129 template <class T, class VtkFunction>
130 std::vector<T> cellDataImpl (VtkFunction const& fct) const;
131
132 protected:
134 };
135
136 } // end namespace Vtk
137} // end namespace Dune
138
Definition: writer.hh:13
Base class for data collectors in a CRTP style.
Definition: datacollectorinterface.hh:20
std::vector< T > pointData(VtkFunction const &fct) const
Return a flat vector of function values evaluated at the points.
Definition: datacollectorinterface.hh:86
@ dow
Definition: datacollectorinterface.hh:31
std::uint64_t numPoints() const
Return the number of points in (this partition of the) grid.
Definition: datacollectorinterface.hh:58
static constexpr auto partition
The partitionset to collect data from.
Definition: datacollectorinterface.hh:23
int ghostLevelImpl() const
Definition: datacollectorinterface.hh:123
std::vector< T > points() const
Return a flat vector of point coordinates.
Definition: datacollectorinterface.hh:71
Derived & asDerived()
Definition: datacollectorinterface.hh:106
std::vector< T > cellData(VtkFunction const &fct) const
Return a flat vector of function values evaluated at the cells in the order of traversal.
Definition: datacollectorinterface.hh:99
GridViewType GridView
Definition: datacollectorinterface.hh:25
const Derived & asDerived() const
Definition: datacollectorinterface.hh:111
@ dim
Definition: datacollectorinterface.hh:28
std::vector< T > cellDataImpl(VtkFunction const &fct) const
Definition: datacollectorinterface.impl.hh:11
GridView gridView_
Definition: datacollectorinterface.hh:133
void update()
Update the DataCollector on the current GridView.
Definition: datacollectorinterface.hh:40
DataCollectorInterface(GridView const &gridView)
Store a copy of the GridView.
Definition: datacollectorinterface.hh:35
std::uint64_t numCells() const
Return the number of cells in (this partition of the) grid.
Definition: datacollectorinterface.hh:52
void updateImpl()
Definition: datacollectorinterface.hh:118
int ghostLevel() const
Return the number of ghost elements.
Definition: datacollectorinterface.hh:46