dune-vtk  0.2
yaspdatacollector.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <array>
4 #include <type_traits>
5 #include <vector>
6 
7 #include <dune/common/filledarray.hh>
8 #include <dune/common/fvector.hh>
9 #include <dune/common/std/type_traits.hh>
10 #include <dune/grid/common/gridenums.hh>
11 #include <dune/grid/yaspgrid.hh>
12 
14 
15 namespace Dune
16 {
17  namespace Vtk
18  {
19  // Specialization for YaspGrid
20  template <class GridView>
22  : public StructuredDataCollectorInterface<GridView, YaspDataCollector<GridView>>
23  {
24  using Self = YaspDataCollector;
26  using ctype = typename GridView::ctype;
27 
28  public:
29  using Super::dim;
30  using Super::partition;
31 
32  public:
33  YaspDataCollector (GridView const& gridView)
34  : Super(gridView)
35  , wholeExtent_(filledArray<6,int>(0))
36  , extent_(filledArray<6,int>(0))
37  , origin_(0.0)
38  , spacing_(0.0)
39  , level_(0)
40  {}
41 
42  std::array<int, 6> const& wholeExtentImpl () const
43  {
44  return wholeExtent_;
45  }
46 
47  std::array<int, 6> const& extentImpl () const
48  {
49  return extent_;
50  }
51 
52  auto const& originImpl () const
53  {
54  return origin_;
55  }
56 
57  auto const& spacingImpl () const
58  {
59  return spacing_;
60  }
61 
62  void updateImpl ()
63  {
65 
66  level_ = gridView_.template begin<0,All_Partition>()->level();
67  for (int i = 0; i < dim; ++i) {
68  wholeExtent_[2*i] = 0;
69  wholeExtent_[2*i+1] = grid(gridView_.grid()).levelSize(level_,i);
70  }
71 
72  auto const& gl = *grid(gridView_.grid()).begin(level_);
73  auto const& g = gl.interior[0];
74  auto const& gc = *g.dataBegin();
75  for (int i = 0; i < dim; ++i) {
76  extent_[2*i] = gc.min(i);
77  extent_[2*i+1] = gc.max(i)+1;
78  }
79 
80  auto it = grid(gridView_.grid()).begin(level_);
81  initGeometry(it->coords);
82  }
83 
84  void initGeometry (EquidistantCoordinates<ctype,dim> const& coords)
85  {
86  for (int i = 0; i < dim; ++i) {
87  spacing_[i] = coords.meshsize(i,0);
88  origin_[i] = 0;
89  }
90  }
91 
92  void initGeometry (EquidistantOffsetCoordinates<ctype,dim> const& coords)
93  {
94  for (int i = 0; i < dim; ++i) {
95  spacing_[i] = coords.meshsize(i,0);
96  origin_[i] = coords.origin(i);
97  }
98  }
99 
100  void initGeometry (TensorProductCoordinates<ctype,dim> const& coords)
101  {
102  for (int i = 0; i < dim; ++i) {
103  spacing_[i] = coords.meshsize(i,0); // is not constant, but also not used.
104  origin_[i] = coords.coordinate(i,0);
105  }
106  }
107 
108 
110  template <class T>
111  std::array<std::vector<T>, 3> coordinatesImpl () const
112  {
113  auto it = grid(gridView_.grid()).begin(level_);
114  auto const& coords = it->coords;
115 
116  std::array<std::vector<T>, 3> ordinates{};
117  for (int d = 0; d < dim; ++d) {
118  auto s = extent_[2*d+1] - extent_[2*d] + 1;
119  ordinates[d].resize(s);
120  for (int i = 0; i < s; ++i)
121  ordinates[d][i] = coords.coordinate(d, extent_[2*d] + i);
122  }
123 
124  for (int d = dim; d < 3; ++d)
125  ordinates[d].resize(1, T(0));
126 
127  return ordinates;
128  }
129 
130 
131  private:
132 
133  template <class G>
134  using HostGrid = decltype(std::declval<G>().hostGrid());
135 
136  template <class G,
137  std::enable_if_t<not Std::is_detected<HostGrid, G>::value, int> = 0>
138  auto const& grid (G const& g) const
139  {
140  return g;
141  }
142 
143  template <class G,
144  std::enable_if_t<Std::is_detected<HostGrid, G>::value, int> = 0>
145  auto const& grid (G const& g) const
146  {
147  return grid(g.hostGrid());
148  }
149 
150  protected:
151  using Super::gridView_;
152  std::array<int, 6> wholeExtent_;
153  std::array<int, 6> extent_;
156  int level_;
157  };
158 
159  namespace Impl
160  {
161  template <class GridView, int dim, class Coordinates>
162  struct StructuredDataCollectorImpl<GridView, YaspGrid<dim,Coordinates>>
163  {
164  using type = YaspDataCollector<GridView>;
165  };
166  }
167 
168  } // end namespace Vtk
169 } // end namespace Dune
Definition: writer.hh:13
static constexpr auto partition
The partitionset to collect data from.
Definition: datacollectorinterface.hh:23
GridViewType GridView
Definition: datacollectorinterface.hh:25
@ dim
Definition: datacollectorinterface.hh:28
GridView gridView_
Definition: datacollectorinterface.hh:133
The Interface for structured data-collectors.
Definition: structureddatacollector.hh:19
void updateImpl()
\copyref DefaultDataCollector::update.
Definition: structureddatacollector.hh:94
Definition: yaspdatacollector.hh:23
std::array< int, 6 > extent_
Definition: yaspdatacollector.hh:153
void initGeometry(TensorProductCoordinates< ctype, dim > const &coords)
Definition: yaspdatacollector.hh:100
void initGeometry(EquidistantCoordinates< ctype, dim > const &coords)
Definition: yaspdatacollector.hh:84
std::array< int, 6 > wholeExtent_
Definition: yaspdatacollector.hh:152
FieldVector< ctype, 3 > spacing_
Definition: yaspdatacollector.hh:155
FieldVector< ctype, 3 > origin_
Definition: yaspdatacollector.hh:154
auto const & originImpl() const
Definition: yaspdatacollector.hh:52
std::array< std::vector< T >, 3 > coordinatesImpl() const
Extract the ordinates from the coordinates object of the current level.
Definition: yaspdatacollector.hh:111
void initGeometry(EquidistantOffsetCoordinates< ctype, dim > const &coords)
Definition: yaspdatacollector.hh:92
int level_
Definition: yaspdatacollector.hh:156
std::array< int, 6 > const & wholeExtentImpl() const
Definition: yaspdatacollector.hh:42
YaspDataCollector(GridView const &gridView)
Definition: yaspdatacollector.hh:33
void updateImpl()
Definition: yaspdatacollector.hh:62
auto const & spacingImpl() const
Definition: yaspdatacollector.hh:57
std::array< int, 6 > const & extentImpl() const
Definition: yaspdatacollector.hh:47