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