dune-vtk 2.8
Loading...
Searching...
No Matches
discontinuousdatacollector.hh
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
5#include <dune/grid/common/partitionset.hh>
6#include <dune/vtk/types.hh>
7
9
10namespace Dune
11{
12 namespace Vtk
13 {
15 template <class GridView, class Partition = Partitions::InteriorBorder>
17 : public UnstructuredDataCollectorInterface<GridView, DiscontinuousDataCollector<GridView,Partition>, Partition>
18 {
21
22 public:
23 using Super::dim;
24 using Super::partition;
25
26 public:
28 : Super(gridView)
29 {}
30
32 void updateImpl ()
33 {
34 numPoints_ = 0;
35 numCells_ = 0;
36 indexMap_.resize(gridView_.size(dim));
37 std::int64_t vertex_idx = 0;
38 auto const& indexSet = gridView_.indexSet();
39 for (auto const& c : elements(gridView_, partition)) {
40 numCells_++;
41 numPoints_ += c.subEntities(dim);
42 for (unsigned int i = 0; i < c.subEntities(dim); ++i)
43 indexMap_[indexSet.subIndex(c, i, dim)] = vertex_idx++;
44 }
45 }
46
48 std::uint64_t numPointsImpl () const
49 {
50 return numPoints_;
51 }
52
54 template <class T>
55 std::vector<T> pointsImpl () const
56 {
57 std::vector<T> data(numPoints_ * 3);
58 auto const& indexSet = gridView_.indexSet();
59 for (auto const& element : elements(gridView_, partition)) {
60 for (unsigned int i = 0; i < element.subEntities(dim); ++i) {
61 std::size_t idx = 3 * indexMap_[indexSet.subIndex(element, i, dim)];
62 auto v = element.geometry().corner(i);
63 for (std::size_t j = 0; j < v.size(); ++j)
64 data[idx + j] = T(v[j]);
65 for (std::size_t j = v.size(); j < 3u; ++j)
66 data[idx + j] = T(0);
67 }
68 }
69 return data;
70 }
71
73 std::uint64_t numCellsImpl () const
74 {
75 return numCells_;
76 }
77
80 {
83 cells.offsets.reserve(numCells_);
84 cells.types.reserve(numCells_);
85
86 std::int64_t old_o = 0;
87 auto const& indexSet = gridView_.indexSet();
88 for (auto const& c : elements(gridView_, partition)) {
89 Vtk::CellType cellType(c.type());
90 for (unsigned int j = 0; j < c.subEntities(dim); ++j) {
91 std::int64_t vertex_idx = indexMap_[indexSet.subIndex(c,cellType.permutation(j),dim)];
92 cells.connectivity.push_back(vertex_idx);
93 }
94 cells.offsets.push_back(old_o += c.subEntities(dim));
95 cells.types.push_back(cellType.type());
96 }
97
98 return cells;
99 }
100
102 template <class T, class GlobalFunction>
103 std::vector<T> pointDataImpl (GlobalFunction const& fct) const
104 {
105 std::vector<T> data(numPoints_ * fct.numComponents());
106 auto const& indexSet = gridView_.indexSet();
107 auto localFct = localFunction(fct);
108 for (auto const& e : elements(gridView_, partition)) {
109 localFct.bind(e);
110 Vtk::CellType cellType{e.type()};
111 auto refElem = referenceElement(e.geometry());
112 for (unsigned int j = 0; j < e.subEntities(dim); ++j) {
113 std::size_t idx = fct.numComponents() * indexMap_[indexSet.subIndex(e, cellType.permutation(j), dim)];
114 for (int comp = 0; comp < fct.numComponents(); ++comp)
115 data[idx + comp] = T(localFct.evaluate(comp, refElem.position(cellType.permutation(j),dim)));
116 }
117 localFct.unbind();
118 }
119 return data;
120 }
121
122 protected:
123 using Super::gridView_;
124 std::uint64_t numCells_ = 0;
125 std::uint64_t numPoints_ = 0;
126 std::vector<std::int64_t> indexMap_;
127 };
128
129 } // end namespace Vtk
130} // end namespace Dune
Definition: writer.hh:13
GridViewType GridView
Definition: datacollectorinterface.hh:25
Implementation of DataCollector for linear cells, with discontinuous data.
Definition: discontinuousdatacollector.hh:18
void updateImpl()
Create an index map the uniquely assigns an index to each pair (element,corner)
Definition: discontinuousdatacollector.hh:32
Cells cellsImpl() const
Connect the corners of each cell. The leads to a global discontinuous grid.
Definition: discontinuousdatacollector.hh:79
DiscontinuousDataCollector(GridView const &gridView)
Definition: discontinuousdatacollector.hh:27
std::uint64_t numCells_
Definition: discontinuousdatacollector.hh:124
std::uint64_t numPointsImpl() const
The number of points approx. #cell * #corners-per-cell.
Definition: discontinuousdatacollector.hh:48
std::vector< T > pointsImpl() const
Return the coordinates of the corners of all cells.
Definition: discontinuousdatacollector.hh:55
std::vector< std::int64_t > indexMap_
Definition: discontinuousdatacollector.hh:126
std::uint64_t numCellsImpl() const
Return number of grid cells.
Definition: discontinuousdatacollector.hh:73
std::uint64_t numPoints_
Definition: discontinuousdatacollector.hh:125
std::vector< T > pointDataImpl(GlobalFunction const &fct) const
Evaluate the fct in the corners of each cell.
Definition: discontinuousdatacollector.hh:103
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:23
@ dim
Definition: datacollectorinterface.hh:28
static constexpr auto partition
The partitionset to collect data from.
Definition: datacollectorinterface.hh:23
Cells cells() const
Return cell types, offsets, and connectivity.
Definition: unstructureddatacollector.hh:36
GridView gridView_
Definition: datacollectorinterface.hh:133
Mapping of Dune geometry types to VTK cell types.
Definition: types.hh:160
std::uint8_t type() const
Return VTK Cell type.
Definition: types.hh:203
int permutation(int idx) const
Return a permutation of Dune elemenr vertices to conform to VTK element numbering.
Definition: types.hh:209