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