dune-vtk 2.12
Loading...
Searching...
No Matches
yaspdatacollector.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3#pragma once
4
5#include <array>
6#include <type_traits>
7#include <vector>
8
13#include <dune/grid/yaspgrid.hh>
14
16
17namespace Dune::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 using Super::gridView;
32
33 public:
36 , wholeExtent_(filledArray<6,int>(0))
37 , extent_(filledArray<6,int>(0))
38 , origin_(0.0)
39 , spacing_(0.0)
40 , level_(0)
41 {}
42
44 {
45 return wholeExtent_;
46 }
47
49 {
50 return extent_;
51 }
52
53 auto const& originImpl () const
54 {
55 return origin_;
56 }
57
58 auto const& spacingImpl () const
59 {
60 return spacing_;
61 }
62
63 void updateImpl ()
64 {
66
67 level_ = gridView().template begin<0,All_Partition>()->level();
68 for (int i = 0; i < dim; ++i) {
69 wholeExtent_.at(2*i) = 0;
70 wholeExtent_.at(2*i+1) = grid(gridView().grid()).levelSize(level_,i);
71 }
72
73 auto const& gl = *grid(gridView().grid()).begin(level_);
74 auto const& g = gl.interior[0];
75 auto const& gc = *g.dataBegin();
76 for (int i = 0; i < dim; ++i) {
77 extent_.at(2*i) = gc.min(i);
78 extent_.at(2*i+1) = gc.max(i)+1;
79 }
80
81 auto it = grid(gridView().grid()).begin(level_);
82 initGeometry(it->coords);
83 }
84
86 {
87 for (int i = 0; i < dim; ++i) {
88 spacing_[i] = coords.meshsize(i,0);
89 origin_[i] = 0;
90 }
91 }
92
94 {
95 for (int i = 0; i < dim; ++i) {
96 spacing_[i] = coords.meshsize(i,0);
97 origin_[i] = coords.origin(i);
98 }
99 }
100
102 {
103 for (int i = 0; i < dim; ++i) {
104 spacing_[i] = coords.meshsize(i,0); // is not constant, but also not used.
105 origin_[i] = coords.coordinate(i,0);
106 }
107 }
108
109
111 template <class T>
113 {
114 auto it = grid(gridView().grid()).begin(level_);
115 auto const& coords = it->coords;
116
118 for (int d = 0; d < dim; ++d) {
119 auto s = extent_.at(2*d+1) - extent_.at(2*d) + 1;
120 ordinates[d].resize(s);
121 for (int i = 0; i < s; ++i)
122 ordinates[d][i] = coords.coordinate(d, extent_.at(2*d) + i);
123 }
124
125 for (int d = dim; d < 3; ++d)
126 ordinates[d].resize(1, T(0));
127
128 return ordinates;
129 }
130
131
132 private:
133
134 template <class G>
135 using HostGrid = decltype(std::declval<G>().hostGrid());
136
137 template <class G,
139 auto const& grid (G const& g) const
140 {
141 return g;
142 }
143
144 template <class G,
146 auto const& grid (G const& g) const
147 {
148 return grid(g.hostGrid());
149 }
150
151 private:
152 std::array<int, 6> wholeExtent_;
153 std::array<int, 6> extent_;
154 FieldVector<ctype,3> origin_;
155 FieldVector<ctype,3> spacing_;
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 Dune::Vtk
Definition datacollector.hh:19
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 > >
@ dim
Definition datacollectorinterface.hh:29
static constexpr auto partition
The partitionset to collect data from.
Definition datacollectorinterface.hh:26
GridView const & gridView() const
Return the bound grid view.
Definition datacollectorinterface.hh:41
Implementation of DataCollector for cells, with continuous data.
Definition celltypedatacollector.hh:20
The Interface for structured data-collectors.
Definition structureddatacollector.hh:19
void updateImpl()
\copyref DefaultDataCollector::update.
Definition structureddatacollector.hh:95
Definition yaspdatacollector.hh:23
void initGeometry(TensorProductCoordinates< ctype, dim > const &coords)
Definition yaspdatacollector.hh:101
void initGeometry(EquidistantCoordinates< ctype, dim > const &coords)
Definition yaspdatacollector.hh:85
std::array< std::vector< T >, 3 > coordinatesImpl() const
Extract the ordinates from the coordinates object of the current level.
Definition yaspdatacollector.hh:112
std::array< int, 6 > const & wholeExtentImpl() const
Definition yaspdatacollector.hh:43
auto const & spacingImpl() const
Definition yaspdatacollector.hh:58
auto const & originImpl() const
Definition yaspdatacollector.hh:53
void initGeometry(EquidistantOffsetCoordinates< ctype, dim > const &coords)
Definition yaspdatacollector.hh:93
YaspDataCollector(GridView const &gridView)
Definition yaspdatacollector.hh:34
void updateImpl()
Definition yaspdatacollector.hh:63
std::array< int, 6 > const & extentImpl() const
Definition yaspdatacollector.hh:48
T at(T... args)