datacollectorinterface.hh 3.13 KB
Newer Older
1
2
#pragma once

3
4
#include <cstdint>
#include <vector>
5

6
namespace Dune {
7

8
template <class GridView, class Derived, class Partition>
9
10
11
class DataCollectorInterface
{
public:
12
13
14
15
16
17
18
19
20
21
22
  /// The partitionset to collect data from
  static constexpr auto partition = Partition{};

  /// The dimension of the grid
  enum { dim = GridView::dimension };

  /// The dimension of the world
  enum { dow = GridView::dimensionworld };

public:
  /// Store a copy of the GridView
Praetorius, Simon's avatar
Praetorius, Simon committed
23
24
25
26
  DataCollectorInterface (GridView const& gridView)
    : gridView_(gridView)
  {}

27
  /// Update the DataCollector on the current GridView
Praetorius, Simon's avatar
Praetorius, Simon committed
28
29
30
31
  void update ()
  {
    asDerived().updateImpl();
  }
32

33
  /// Return the number of ghost elements
34
35
36
37
38
  int ghostLevel () const
  {
    return asDerived().ghostLevelImpl();
  }

39
40
41
42
43
44
45
  /// \brief Return the number of cells in (this partition of the) grid
  std::uint64_t numCells () const
  {
    return asDerived().numCellsImpl();
  }

  /// Return the number of points in (this partition of the) grid
46
47
48
49
50
  std::uint64_t numPoints () const
  {
    return asDerived().numPointsImpl();
  }

51
  /// Return a flat vector of point coordinates
52
53
54
55
56
57
58
  /**
   * All coordinates are extended to 3 components and concatenated.
   * [p0_x, p0_y, p0_z, p1_x, p1_y, p1_z, ...]
   * If the GridView::dimensionworld < 3, the remaining components are
   * set to 0
   **/
  template <class T>
Praetorius, Simon's avatar
Praetorius, Simon committed
59
60
61
62
  std::vector<T> points () const
  {
    return asDerived().template pointsImpl<T>();
  }
63

64
  /// Return a flat vector of function values evaluated at the points.
65
66
67
68
69
70
71
72
  /**
   * In case of a vector valued function, flat the vector entries:
   * [fct(p0)_0, fct(p0)_1, fct(p0)_2, fct(p1)_0, ...]
   * where the vector dimension must be 3 (possible extended by 0s)
   * In case of tensor valued function, flat the tensor row-wise:
   * [fct(p0)_00, fct(p0)_01, fct(p0)_02, fct(p0)_10, fct(p0)_11, fct(p0)_12, fct(p0)_20...]
   * where the tensor dimension must be 3x3 (possible extended by 0s)
   **/
73
74
  template <class T, class VtkFunction>
  std::vector<T> pointData (VtkFunction const& fct) const
Praetorius, Simon's avatar
Praetorius, Simon committed
75
76
77
  {
    return asDerived().template pointDataImpl<T>(fct);
  }
78

79
  /// Return a flat vector of function values evaluated at the cells in the order of traversal.
80
  /**
81
   * \see pointData.
82
83
84
85
   * Note: Cells might be descibred explicitly by connectivity, offsets, and types, e.g. in
   * an UnstructuredGrid, or might be described implicitly by the grid type, e.g. in
   * StructuredGrid.
   */
86
87
  template <class T, class VtkFunction>
  std::vector<T> cellData (VtkFunction const& fct) const
Praetorius, Simon's avatar
Praetorius, Simon committed
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
  {
    return asDerived().template cellDataImpl<T>(fct);
  }

protected: // cast to derived type

  Derived& asDerived ()
  {
    return static_cast<Derived&>(*this);
  }

  const Derived& asDerived () const
  {
    return static_cast<const Derived&>(*this);
  }

104
public: // default implementations
Praetorius, Simon's avatar
Praetorius, Simon committed
105

106
107
108
109
110
111
112
113
114
  void updateImpl ()
  {
    /* do nothing */
  }

  int ghostLevelImpl () const
  {
    return gridView_.overlapSize(0);
  }
Praetorius, Simon's avatar
Praetorius, Simon committed
115

116
  // Evaluate `fct` in center of cell.
117
  template <class T, class VtkFunction>
118
  std::vector<T> cellDataImpl (VtkFunction const& fct) const;
Praetorius, Simon's avatar
Praetorius, Simon committed
119
120
121

protected:
  GridView gridView_;
122
123
};

124
} // end namespace Dune
125
126

#include "datacollectorinterface.impl.hh"