dune-vtk 2.12
Loading...
Searching...
No Matches
codimdatacollector.hh
Go to the documentation of this file.
1#pragma once
2
3#include <numeric>
4#include <vector>
5
9#include <dune/vtk/types.hh>
10
12
13namespace Dune::Vtk
14{
16 template <class GridView, class Partition = Partitions::InteriorBorder>
18 : public UnstructuredDataCollectorInterface<GridView, CodimDataCollector<GridView,Partition>, Partition>
19 {
22
23 public:
24 using Super::dim;
25 using Super::partition;
26 using Super::gridView;
27
28 public:
29 explicit CodimDataCollector (GridView const& gridView, int codim = 1)
31 , codim_(codim)
32 {}
33
35 void updateImpl ()
36 {
37 numPoints_ = gridView().size(dim);
38 numCells_ = gridView().size(codim_);
39 }
40
43 {
44 return numPoints_;
45 }
46
48 template <class T>
50 {
51 std::vector<T> data(numPoints_ * 3);
52 auto const& indexSet = gridView().indexSet();
53 for (auto const& vertex : vertices(gridView(), partition)) {
54 auto v = vertex.geometry().center();
55 std::size_t idx = 3*indexSet.index(vertex);
56 for (std::size_t j = 0; j < v.size(); ++j)
57 data[idx+j] = v[j];
58 for (std::size_t j = v.size(); j < 3u; ++j)
59 data[idx+j] = T(0);
60 }
61 return data;
62 }
63
66 {
67 std::vector<std::uint64_t> data(numPoints_);
68 auto const& indexSet = gridView().indexSet();
70 for (auto const& vertex : vertices(gridView(), partition)) {
71 data[indexSet.index(vertex)] = globalIndexSet.index(vertex);
72 }
73 return data;
74 }
75
78 {
79 return numCells_;
80 }
81
85 {
86 auto const& indexSet = gridView().indexSet();
87 auto types = indexSet.types(codim_);
88 int maxVertices = std::accumulate(types.begin(), types.end(), 1, [codim=codim_](int m, GeometryType t) {
89 switch (codim) {
90 case 0:
91 return std::max(m, referenceElement<double,dim>(t).size(dim));
92 case 1: if constexpr (dim >= 1) {
93 return std::max(m, referenceElement<double,dim-1>(t).size(dim-1)); } break;
94 case 2: if constexpr (dim >= 2) {
95 return std::max(m, referenceElement<double,dim-2>(t).size(dim-2)); } break;
96 case 3: if constexpr (dim >= 3) {
97 return std::max(m, referenceElement<double,dim-3>(t).size(dim-3)); } break;
98 default:
99 return std::max(m, referenceElement<double,0>(t).size(0));
100 }
101 return m;
102 });
103
104 Cells cells;
106 cells.offsets.reserve(numCells_);
107 cells.types.reserve(numCells_);
108
109 std::vector<bool> visited(gridView().size(codim_), false);
111 for (auto const& c : elements(gridView(), partition)) {
112 auto refElem = referenceElement(c);
113 for (int i = 0; i < refElem.size(codim_); ++i) {
114 Vtk::CellType cellType(refElem.type(i,codim_));
115 std::size_t idx = indexSet.subIndex(c,i,codim_);
116 if (!visited[idx]) {
117 visited[idx] = true;
118 for (int j = 0; j < refElem.size(i,codim_,dim); ++j)
120 refElem.subEntity(i,codim_,cellType.permutation(j),dim), dim));
121 cells.offsets.push_back(old_o += refElem.size(i,codim_,dim));
123 }
124 }
125 }
126 return cells;
127 }
128
130 template <class T, class GlobalFunction>
131 std::vector<T> pointDataImpl (GlobalFunction const& fct) const
132 {
133 std::vector<T> data(numPoints_ * fct.numComponents());
134 auto const& indexSet = gridView().indexSet();
135 auto localFct = localFunction(fct);
136 std::vector<bool> visited(gridView().size(codim_), false);
137 for (auto const& c : elements(gridView(), partition)) {
138 localFct.bind(c);
139 auto refElem = referenceElement(c);
140 for (int i = 0; i < refElem.size(codim_); ++i) {
141 Vtk::CellType cellType(refElem.type(i,codim_));
142 std::size_t edge_idx = indexSet.subIndex(c,i,codim_);
143 if (!visited[edge_idx]) {
144 visited[edge_idx] = true;
145 for (int j = 0; j < refElem.size(i,codim_,dim); ++j) {
146 std::size_t cj = refElem.subEntity(i,codim_,cellType.permutation(j),dim);
147 std::size_t idx = fct.numComponents() * indexSet.subIndex(c,cj,dim);
148 auto local = refElem.position(cj,dim);
149 for (int comp = 0; comp < fct.numComponents(); ++comp)
150 data[idx + comp] = T(localFct.evaluate(comp, local));
151 }
152 }
153 }
154 localFct.unbind();
155 }
156 return data;
157 }
158
160 template <class T, class GlobalFunction>
161 std::vector<T> cellDataImpl (GlobalFunction const& fct) const
162 {
163 std::vector<T> data;
164 data.reserve(numCells_ * fct.numComponents());
165 auto const& indexSet = gridView().indexSet();
166 auto localFct = localFunction(fct);
167 std::vector<bool> visited(gridView().size(codim_), false);
168 for (auto const& c : elements(gridView(), partition)) {
169 localFct.bind(c);
170 auto refElem = referenceElement(c);
171 for (int i = 0; i < refElem.size(codim_); ++i) {
172 std::size_t edge_idx = indexSet.subIndex(c,i,codim_);
173 if (!visited[edge_idx]) {
174 visited[edge_idx] = true;
175 auto local = refElem.position(i,codim_);
176 for (int comp = 0; comp < fct.numComponents(); ++comp)
177 data.push_back(T(localFct.evaluate(comp, local)));
178 }
179 }
180 localFct.unbind();
181 }
182 return data;
183 }
184
185 private:
186 int codim_ = 1;
187 std::uint64_t numPoints_ = 0;
188 std::uint64_t numCells_ = 0;
189 };
190
191} // end namespace Dune::Vtk
Definition writer.hh:16
unspecified value type referenceElement(T &&... t)
bool visited() const
int size() const
size_type dim() const
LocalIndex & local()
IndexType subIndex(const typename Traits::template Codim< cc >::Entity &e, int i, unsigned int codim) const
Types types(int codim) const
IndexType index(const typename Traits::template Codim< cc >::Entity &e) const
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
Implementation of DataCollector for linear cells, with continuous data.
Definition codimdatacollector.hh:19
void updateImpl()
Collect the vertex indices.
Definition codimdatacollector.hh:35
std::vector< T > pointDataImpl(GlobalFunction const &fct) const
Evaluate the fct at the corners of the element edges.
Definition codimdatacollector.hh:131
std::uint64_t numCellsImpl() const
Return number of grid cells.
Definition codimdatacollector.hh:77
std::vector< T > cellDataImpl(GlobalFunction const &fct) const
Evaluate the fct at the corners of the element edges.
Definition codimdatacollector.hh:161
std::uint64_t numPointsImpl() const
Return number of grid vertices.
Definition codimdatacollector.hh:42
std::vector< std::uint64_t > pointIdsImpl() const
Return a vector of global unique ids of the points.
Definition codimdatacollector.hh:65
CodimDataCollector(GridView const &gridView, int codim=1)
Definition codimdatacollector.hh:29
std::vector< T > pointsImpl() const
Return the coordinates of all grid vertices in the order given by the indexSet.
Definition codimdatacollector.hh:49
Cells cellsImpl() const
Definition codimdatacollector.hh:84
Definition unstructureddatacollector.hh:12
std::vector< std::int64_t > offsets
Definition unstructureddatacollector.hh:14
std::vector< std::int64_t > connectivity
Definition unstructureddatacollector.hh:15
std::vector< std::uint8_t > types
Definition unstructureddatacollector.hh:13
Definition unstructureddatacollector.hh:26
@ dim
Definition datacollectorinterface.hh:27
static constexpr auto partition
The partitionset to collect data from.
Definition datacollectorinterface.hh:24
Cells cells() const
Return cell types, offsets, and connectivity.
Definition unstructureddatacollector.hh:45
Mapping of Dune geometry types to VTK cell types.
Definition types.hh:159
int permutation(int idx) const
Return a permutation of Dune element vertices to conform to VTK element numbering.
Definition types.hh:222
T accumulate(T... args)
T push_back(T... args)
T reserve(T... args)