dune-vtk 2.12
Loading...
Searching...
No Matches
spdatacollector.hh
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <vector>
5
8
10
11#if HAVE_DUNE_SPGRID
12#include <dune/grid/spgrid.hh>
13
14namespace Dune::Vtk
15{
16 // Specialization for SPGrid
17 template <class GridView>
18 class SPDataCollector
19 : public StructuredDataCollectorInterface<GridView, SPDataCollector<GridView>>
20 {
21 using Self = SPDataCollector;
22 using Super = StructuredDataCollectorInterface<GridView, Self>;
23 using ctype = typename GridView::ctype;
24
25 public:
26 using Super::dim;
27 using Super::partition;
28 using Super::gridView;
29
30 public:
31 SPDataCollector (GridView const& gridView)
32 : Super(gridView)
33 , wholeExtent_(filledArray<6,int>(0))
34 , extent_(filledArray<6,int>(0))
35 , origin_(0.0)
36 , spacing_(0.0)
37 {}
38
39 std::array<int, 6> const& wholeExtentImpl () const
40 {
41 return wholeExtent_;
42 }
43
44 std::array<int, 6> const& extentImpl () const
45 {
46 return extent_;
47 }
48
49 auto const& originImpl () const
50 {
51 return origin_;
52 }
53
54 auto const& spacingImpl () const
55 {
56 return spacing_;
57 }
58
59 void updateImpl ()
60 {
61 Super::updateImpl();
62
63 auto const& localMesh = gridView().impl().gridLevel().localMesh();
64 auto const& begin = gridView().impl().gridLevel().globalMesh().begin();
65 auto const& end = gridView().impl().gridLevel().globalMesh().end();
66 auto const& cube = gridView().grid().domain().cube();
67
68 for (int i = 0; i < dim; ++i) {
69 wholeExtent_[2*i] = begin[i];
70 wholeExtent_[2*i+1] = end[i];
71 extent_[2*i] = localMesh.begin()[i];
72 extent_[2*i+1] = localMesh.end()[i];
73 spacing_[i] = cube.width()[i] / (end[i] - begin[i]);
74 origin_[i] = cube.origin()[i];
75 }
76 }
77
78 private:
79 std::array<int, 6> wholeExtent_;
80 std::array<int, 6> extent_;
81 FieldVector<ctype,3> origin_;
82 FieldVector<ctype,3> spacing_;
84 };
85
86 namespace Impl
87 {
88 template <class GridView, class ct, int dim, template< int > class Ref, class Comm>
89 struct StructuredDataCollectorImpl<GridView, SPGrid<ct,dim,Ref,Comm>>
90 {
91 using type = SPDataCollector<GridView>;
92 };
93 }
94
95} // end namespace Dune::Vtk
96
97#endif // HAVE_DUNE_SPGRID
Definition writer.hh:16
constexpr std::array< T, n > filledArray(const T &t)
iterator end()
iterator begin()
size_type dim() const
GridView(const Implementation &imp)