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