Dune Core Modules (2.11.0)

continuousdatacollector.hh
1#pragma once
2
3#include <numeric>
4#include <vector>
5
6#include <dune/geometry/referenceelements.hh>
7#include <dune/grid/common/partitionset.hh>
9#include <dune/vtk/types.hh>
10
11#include "unstructureddatacollector.hh"
12
13namespace Dune::Vtk
14{
16 template <class GridView, class Partition = Partitions::InteriorBorder>
18 : public UnstructuredDataCollectorInterface<GridView, ContinuousDataCollector<GridView,Partition>, Partition>
19 {
21 using Super = UnstructuredDataCollectorInterface<GridView, Self, Partition>;
22
23 public:
24 using Super::dim;
25 using Super::partition;
26 using Super::gridView;
27
28 public:
30 : Super(gridView)
31 {}
32
33 template <bool b>
34 ContinuousDataCollector (GridView const& gridView, WritePointIDs<b> writePointIDs)
35 : Super(gridView, writePointIDs)
36 {}
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
56 std::uint64_t numPointsImpl () const
57 {
58 return numPoints_;
59 }
60
62 template <class T>
63 std::vector<T> pointsImpl () const
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
78 std::vector<std::uint64_t> pointIdsImpl () const
79 {
80 std::vector<std::uint64_t> data;
81 data.reserve(numPoints_);
82 GlobalIndexSet<GridView> globalIndexSet(gridView(), dim);
83 for (auto const& vertex : vertices(gridView(), partition)) {
84 data.emplace_back(globalIndexSet.index(vertex));
85 }
86 return data;
87 }
88
90 std::uint64_t numCellsImpl () const
91 {
92 return numCells_;
93 }
94
97 Cells cellsImpl () const
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;
107 cells.connectivity.reserve(numCells_ * maxVertices);
108 cells.offsets.reserve(numCells_);
109 cells.types.reserve(numCells_);
110
111 std::int64_t old_o = 0;
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));
118 cells.types.push_back(cellType.type());
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);
132 Vtk::CellType cellType{e.type()};
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;
147 std::vector<std::int64_t> indexMap_;
148 };
149
150} // end namespace Dune::Vtk
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:114
Calculate globally unique index over all processes in a Dune grid.
Definition: globalindexset.hh:63
Index index(const Entity &entity) const
Return the global index of a given entity.
Definition: globalindexset.hh:453
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
std::vector< T > pointDataImpl(GlobalFunction const &fct) const
Evaluate the fct at the corners of the elements.
Definition: continuousdatacollector.hh:125
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
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
Provides a globally unique index for all entities of a distributed Dune grid.
unspecified value type referenceElement(T &&... t)
Returns a reference element for the objects t....
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:492
constexpr T accumulate(Range &&range, T value, F &&f)
Accumulate values.
Definition: hybridutilities.hh:284
auto elements(const SubDomainGridView< HostGridView > &subDomainGridView)
ADL findable access to element range for a SubDomainGridView.
Definition: subdomain.hh:487
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
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)