Dune Core Modules (2.11.0)

discontinuousdatacollector.hh
1#pragma once
2
3#include <vector>
4
5#include <dune/grid/common/partitionset.hh>
6#include <dune/vtk/types.hh>
7
8#include "unstructureddatacollector.hh"
9
10namespace Dune::Vtk
11{
13 template <class GridView, class Partition = Partitions::InteriorBorder>
15 : public UnstructuredDataCollectorInterface<GridView, DiscontinuousDataCollector<GridView,Partition>, Partition>
16 {
18 using Super = UnstructuredDataCollectorInterface<GridView, Self, Partition>;
19
20 public:
21 using Super::dim;
22 using Super::partition;
23 using Super::gridView;
24
25 public:
27 : Super(gridView)
28 {}
29
31 void updateImpl ()
32 {
33 numPoints_ = 0;
34 numCells_ = 0;
35 for (auto const& c : elements(gridView(), partition)) {
36 numCells_++;
37 numPoints_ += c.subEntities(dim);
38 }
39 }
40
42 std::uint64_t numPointsImpl () const
43 {
44 return numPoints_;
45 }
46
48 template <class T>
49 std::vector<T> pointsImpl () const
50 {
51 std::vector<T> data(numPoints_ * 3);
52 std::size_t pointIdx = 0;
53 for (auto const& element : elements(gridView(), partition)) {
54 Vtk::CellType cellType(element.type());
55 for (unsigned int i = 0; i < element.subEntities(dim); ++i,++pointIdx) {
56 std::size_t idx = 3 * pointIdx;
57 auto v = element.geometry().corner(cellType.permutation(i));
58 for (std::size_t j = 0; j < v.size(); ++j)
59 data[idx + j] = T(v[j]);
60 for (std::size_t j = v.size(); j < 3u; ++j)
61 data[idx + j] = T(0);
62 }
63 }
64 return data;
65 }
66
68 std::uint64_t numCellsImpl () const
69 {
70 return numCells_;
71 }
72
74 Cells cellsImpl () const
75 {
76 Cells cells;
77 cells.connectivity.reserve(numPoints_);
78 cells.offsets.reserve(numCells_);
79 cells.types.reserve(numCells_);
80
81 std::int64_t old_o = 0;
82 std::size_t pointIdx = 0;
83 for (auto const& c : elements(gridView(), partition)) {
84 Vtk::CellType cellType(c.type());
85 for (unsigned int j = 0; j < c.subEntities(dim); ++j,++pointIdx) {
86 cells.connectivity.push_back(pointIdx);
87 }
88 cells.offsets.push_back(old_o += c.subEntities(dim));
89 cells.types.push_back(cellType.type());
90 }
91
92 return cells;
93 }
94
96 template <class T, class GlobalFunction>
97 std::vector<T> pointDataImpl (GlobalFunction const& fct) const
98 {
99 std::vector<T> data(numPoints_ * fct.numComponents());
100 auto localFct = localFunction(fct);
101 std::size_t pointIdx = 0;
102 for (auto const& e : elements(gridView(), partition)) {
103 localFct.bind(e);
104 Vtk::CellType cellType{e.type()};
105 auto refElem = referenceElement(e.geometry());
106 for (unsigned int j = 0; j < e.subEntities(dim); ++j,++pointIdx) {
107 std::size_t idx = fct.numComponents() * pointIdx;
108 for (int comp = 0; comp < fct.numComponents(); ++comp)
109 data[idx + comp] = T(localFct.evaluate(comp, refElem.position(cellType.permutation(j),dim)));
110 }
111 localFct.unbind();
112 }
113 return data;
114 }
115
116 private:
117 std::uint64_t numCells_ = 0;
118 std::uint64_t numPoints_ = 0;
119 std::vector<std::int64_t> indexMap_;
120 };
121
122} // end namespace Dune::Vtk
static constexpr auto partition
The partitionset to collect data from.
Definition: datacollectorinterface.hh:24
GridView 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 discontinuous data.
Definition: discontinuousdatacollector.hh:16
void updateImpl()
Create an index map the uniquely assigns an index to each pair (element,corner)
Definition: discontinuousdatacollector.hh:31
Cells cellsImpl() const
Connect the corners of each cell. The leads to a global discontinuous grid.
Definition: discontinuousdatacollector.hh:74
std::uint64_t numPointsImpl() const
The number of points approx. #cell * #corners-per-cell.
Definition: discontinuousdatacollector.hh:42
std::vector< T > pointsImpl() const
Return the coordinates of the corners of all cells.
Definition: discontinuousdatacollector.hh:49
std::uint64_t numCellsImpl() const
Return number of grid cells.
Definition: discontinuousdatacollector.hh:68
std::vector< T > pointDataImpl(GlobalFunction const &fct) const
Evaluate the fct in the corners of each cell.
Definition: discontinuousdatacollector.hh:97
unspecified value type referenceElement(T &&... t)
Returns a reference element for the objects t....
auto elements(const SubDomainGridView< HostGridView > &subDomainGridView)
ADL findable access to element range for a SubDomainGridView.
Definition: subdomain.hh:487
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
int permutation(int idx) const
Return a permutation of Dune element vertices to conform to VTK element numbering.
Definition: types.hh:222
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Feb 14, 23:39, 2026)