dune-vtk 2.12
Loading...
Searching...
No Matches
continuousdatacollector.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, ContinuousDataCollector<GridView,Partition>, Partition>
19 {
22
23 public:
24 using Super::dim;
25 using Super::partition;
26 using Super::gridView;
27
28 public:
32
33 template <bool b>
37
39 void updateImpl ()
40 {
41 numPoints_ = 0;
42 indexMap_.resize(gridView().size(dim));
43 auto const& indexSet = gridView().indexSet();
44 for (auto const& vertex : vertices(gridView(), partition))
45 indexMap_[indexSet.index(vertex)] = std::int64_t(numPoints_++);
46
47 if (gridView().comm().size() > 1) {
48 auto&& e = elements(gridView(), partition);
49 numCells_ = std::distance(std::begin(e), std::end(e));
50 } else {
51 numCells_ = gridView().size(0);
52 }
53 }
54
57 {
58 return numPoints_;
59 }
60
62 template <class T>
64 {
65 std::vector<T> data;
66 data.reserve(numPoints_ * 3);
67 for (auto const& vertex : vertices(gridView(), partition)) {
68 auto v = vertex.geometry().center();
69 for (std::size_t j = 0; j < v.size(); ++j)
70 data.emplace_back(v[j]);
71 for (std::size_t j = v.size(); j < 3u; ++j)
72 data.emplace_back(0);
73 }
74 return data;
75 }
76
79 {
81 data.reserve(numPoints_);
83 for (auto const& vertex : vertices(gridView(), partition)) {
84 data.emplace_back(globalIndexSet.index(vertex));
85 }
86 return data;
87 }
88
91 {
92 return numCells_;
93 }
94
98 {
99 auto const& indexSet = gridView().indexSet();
100 auto types = indexSet.types(0);
101 int maxVertices = std::accumulate(types.begin(), types.end(), 1, [](int m, GeometryType t) {
102 auto refElem = referenceElement<double,dim>(t);
103 return std::max(m, refElem.size(dim));
104 });
105
106 Cells cells;
108 cells.offsets.reserve(numCells_);
109 cells.types.reserve(numCells_);
110
112 for (auto const& c : elements(gridView(), partition)) {
113 Vtk::CellType cellType(c.type());
114 auto refElem = referenceElement(c);
115 for (int j = 0; j < refElem.size(dim); ++j)
116 cells.connectivity.emplace_back(indexMap_[indexSet.subIndex(c,cellType.permutation(j),dim)]);
117 cells.offsets.push_back(old_o += c.subEntities(dim));
119 }
120 return cells;
121 }
122
124 template <class T, class GlobalFunction>
125 std::vector<T> pointDataImpl (GlobalFunction const& fct) const
126 {
127 std::vector<T> data(numPoints_ * fct.numComponents());
128 auto const& indexSet = gridView().indexSet();
129 auto localFct = localFunction(fct);
130 for (auto const& e : elements(gridView(), partition)) {
131 localFct.bind(e);
133 auto refElem = referenceElement(e);
134 for (int j = 0; j < refElem.size(dim); ++j) {
135 std::size_t idx = fct.numComponents() * indexMap_[indexSet.subIndex(e,cellType.permutation(j),dim)];
136 for (int comp = 0; comp < fct.numComponents(); ++comp)
137 data[idx + comp] = T(localFct.evaluate(comp, refElem.position(cellType.permutation(j),dim)));
138 }
139 localFct.unbind();
140 }
141 return data;
142 }
143
144 private:
145 std::uint64_t numPoints_ = 0;
146 std::uint64_t numCells_ = 0;
148 };
149
150} // end namespace Dune::Vtk
Definition writer.hh:16
unspecified value type referenceElement(T &&... t)
int size() const
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
auto comm() const
Definition datacollectorinterface.hh:110
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 continuousdatacollector.hh:19
std::uint64_t numPointsImpl() const
Return number of grid vertices.
Definition continuousdatacollector.hh:56
ContinuousDataCollector(GridView const &gridView)
Definition continuousdatacollector.hh:29
std::vector< T > pointDataImpl(GlobalFunction const &fct) const
Evaluate the fct at the corners of the elements.
Definition continuousdatacollector.hh:125
ContinuousDataCollector(GridView const &gridView, WritePointIDs< b > writePointIDs)
Definition continuousdatacollector.hh:34
std::vector< T > pointsImpl() const
Return the coordinates of all grid vertices in the order given by the indexSet.
Definition continuousdatacollector.hh:63
void updateImpl()
Collect the vertex indices.
Definition continuousdatacollector.hh:39
std::uint64_t numCellsImpl() const
Return number of grid cells.
Definition continuousdatacollector.hh:90
Cells cellsImpl() const
Definition continuousdatacollector.hh:97
std::vector< std::uint64_t > pointIdsImpl() const
Return a vector of global unique ids of the points.
Definition continuousdatacollector.hh:78
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:20
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
std::uint8_t type() const
Return VTK Cell type.
Definition types.hh:211
T accumulate(T... args)
T begin(T... args)
T distance(T... args)
T emplace_back(T... args)
T end(T... args)
T push_back(T... args)
T reserve(T... args)
T resize(T... args)