dune-vtk 2.12
Loading...
Searching...
No Matches
datacollectorinterface.hh
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <vector>
5
7
8namespace Dune::Vtk
9{
11
16 template <class GV, class Derived, class Partition = Partitions::InteriorBorder>
18 {
19 public:
21 using GridView = GV;
22
24 static constexpr auto partition = Partition{};
25
27 enum { dim = GridView::dimension };
28
30 enum { dow = GridView::dimensionworld };
32 public:
35 : gridView_(gridView)
36 {}
37
39 GridView const& gridView () const
40 {
41 return gridView_;
42 }
43
45 void update ()
46 {
47 asDerived().updateImpl();
48 }
49
51 int ghostLevel () const
52 {
53 return asDerived().ghostLevelImpl();
54 }
55
58 {
59 return asDerived().numCellsImpl();
60 }
61
64 {
65 return asDerived().numPointsImpl();
66 }
67
69
75 template <class T>
77 {
78 return asDerived().template pointsImpl<T>();
79 }
80
82
90 template <class T, class VtkFunction>
91 std::vector<T> pointData (VtkFunction const& fct) const
92 {
93 return asDerived().template pointDataImpl<T>(fct);
94 }
95
97
103 template <class T, class VtkFunction>
104 std::vector<T> cellData (VtkFunction const& fct) const
105 {
106 return asDerived().template cellDataImpl<T>(fct);
107 }
108
109 // Return the collective communication object from the grid.
110 auto comm () const
111 {
112 return gridView_.comm();
113 }
114
115 protected: // cast to derived type
116
117 Derived& asDerived ()
118 {
119 return static_cast<Derived&>(*this);
120 }
121
122 const Derived& asDerived () const
123 {
124 return static_cast<const Derived&>(*this);
125 }
126
127 public: // default implementations
128
130 {
131 /* do nothing */
132 }
133
134 int ghostLevelImpl () const
135 {
136 return gridView_.overlapSize(0);
137 }
138
139 // Evaluate `fct` in center of cell.
140 template <class T, class VtkFunction>
141 std::vector<T> cellDataImpl (VtkFunction const& fct) const;
142
143 private:
144 GridView gridView_;
145 };
146
147} // end namespace Dune::Vtk
148
Definition writer.hh:16
Base class for data collectors in a CRTP style.
Definition datacollectorinterface.hh:18
@ dow
Definition datacollectorinterface.hh:30
void update()
Update the DataCollector on the current GridView.
Definition datacollectorinterface.hh:45
std::uint64_t numCells() const
Return the number of cells in (this partition of the) grid.
Definition datacollectorinterface.hh:57
auto comm() const
Definition datacollectorinterface.hh:110
std::vector< T > pointData(VtkFunction const &fct) const
Return a flat vector of function values evaluated at the points.
Definition datacollectorinterface.hh:91
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:104
int ghostLevel() const
Return the number of ghost elements.
Definition datacollectorinterface.hh:51
const Derived & asDerived() const
Definition datacollectorinterface.hh:122
std::vector< T > points() const
Return a flat vector of point coordinates.
Definition datacollectorinterface.hh:76
std::uint64_t numPoints() const
Return the number of points in (this partition of the) grid.
Definition datacollectorinterface.hh:63
@ dim
Definition datacollectorinterface.hh:27
std::vector< T > cellDataImpl(VtkFunction const &fct) const
Definition datacollectorinterface.impl.hh:10
static constexpr auto partition
The partitionset to collect data from.
Definition datacollectorinterface.hh:24
GV GridView
Type of the bound grid view.
Definition datacollectorinterface.hh:21
Derived & asDerived()
Definition datacollectorinterface.hh:117
GridView const & gridView() const
Return the bound grid view.
Definition datacollectorinterface.hh:39
int ghostLevelImpl() const
Definition datacollectorinterface.hh:134
void updateImpl()
Definition datacollectorinterface.hh:129
DataCollectorInterface(GridView const &gridView)
Store a copy of the GridView.
Definition datacollectorinterface.hh:34