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