dune-vtk 2.12
Loading...
Searching...
No Matches
lagrangedatacollector.hh
Go to the documentation of this file.
1#pragma once
2
3#include <cassert>
4#include <map>
5#include <vector>
6
10#include <dune/vtk/types.hh>
12
14
15namespace Dune::Vtk
16{
18 template <class GridView, int ORDER = -1>
20 : public UnstructuredDataCollectorInterface<GridView, LagrangeDataCollector<GridView,ORDER>, Partitions::All>
21 {
24
25 auto pointSetMapper() const
26 {
27 auto pointSetLayout = [&](Dune::GeometryType gt, int dimgrid) -> unsigned int {
28 if (gt.dim()==dim)
29 {
30 auto refElem = Dune::referenceElement<double,dim>(gt);
31 return pointSets_.at(gt).size() - refElem.size(dim);
32 }
33 else if (gt.dim()==0)
34 return 1;
35 else
36 return 0;
37 };
39 }
40
41 public:
42 static_assert(ORDER != 0, "Order 0 not supported");
43 using Super::dim;
44 using Super::partition; // NOTE: Lagrange data-collector currently implemented for the All partition only
45 using Super::gridView;
46
47 public:
50 , order_(order)
51 {
52 assert(order > 0 && "Order 0 not supported");
53 assert(ORDER < 0 || order == ORDER);
54 }
55
57 void updateImpl ()
58 {
59 auto const& indexSet = gridView().indexSet();
60
61 pointSets_.clear();
62 for (auto gt : indexSet.types(0))
63 pointSets_.emplace(gt, order_);
64
65 for (auto& pointSet : pointSets_)
66 pointSet.second.build(pointSet.first);
67
68 numPoints_ = pointSetMapper().size();
69 }
70
73 {
74 return numPoints_;
75 }
76
78
82 template <class T>
84 {
85 std::vector<T> data(this->numPoints() * 3);
86 auto const& mapper = pointSetMapper();
87
88 for (auto const& element : elements(gridView(), partition)) {
89 auto geometry = element.geometry();
90 auto refElem = referenceElement<T,dim>(element.type());
91
92 auto const& pointSet = pointSets_.at(element.type());
93 unsigned int vertexDOFs = refElem.size(dim);
94
95 for (std::size_t i = 0; i < pointSet.size(); ++i) {
96 auto const& p = pointSet[i];
97 if (i < vertexDOFs)
98 assert(p.localKey().codim() == dim);
99
100 auto const& localKey = p.localKey();
101 std::size_t idx = 3 * (localKey.codim() == dim
102 ? mapper.subIndex(element, localKey.subEntity(), dim)
103 : mapper.index(element) + (i - vertexDOFs));
104
105 auto v = geometry.global(p.point());
106 for (std::size_t j = 0; j < v.size(); ++j)
107 data[idx + j] = T(v[j]);
108 for (std::size_t j = v.size(); j < 3u; ++j)
109 data[idx + j] = T(0);
110 }
111 }
112 return data;
113 }
114
117 {
118 return gridView().size(0);
119 }
120
122
127 {
128 Cells cells;
130 cells.offsets.reserve(this->numCells());
131 cells.types.reserve(this->numCells());
132
133 auto const& mapper = pointSetMapper();
134
136 for (auto const& element : elements(gridView(), partition)) {
137 auto refElem = referenceElement<double,dim>(element.type());
139
140 auto const& pointSet = pointSets_.at(element.type());
141 unsigned int vertexDOFs = refElem.size(dim);
142
143 for (std::size_t i = 0; i < pointSet.size(); ++i) {
144 auto const& p = pointSet[i];
145 auto const& localKey = p.localKey();
146 std::size_t idx = (localKey.codim() == dim
147 ? mapper.subIndex(element, localKey.subEntity(), dim)
148 : mapper.index(element) + (i - vertexDOFs));
150 }
151
154 }
155 return cells;
156 }
157
159 template <class T, class GlobalFunction>
160 std::vector<T> pointDataImpl (GlobalFunction const& fct) const
161 {
162 int nComps = fct.numComponents();
163 std::vector<T> data(this->numPoints() * nComps);
164 auto const& mapper = pointSetMapper();
165
166 auto localFct = localFunction(fct);
167 for (auto const& element : elements(gridView(), partition)) {
168 localFct.bind(element);
169 auto refElem = referenceElement<T,dim>(element.type());
170
171 auto const& pointSet = pointSets_.at(element.type());
172 unsigned int vertexDOFs = refElem.size(dim);
173
174 for (std::size_t i = 0; i < pointSet.size(); ++i) {
175 auto const& p = pointSet[i];
176 auto const& localKey = p.localKey();
177 std::size_t idx = nComps * (localKey.codim() == dim
178 ? mapper.subIndex(element, localKey.subEntity(), dim)
179 : mapper.index(element) + (i - vertexDOFs));
180
181 for (int comp = 0; comp < nComps; ++comp)
182 data[idx + comp] = T(localFct.evaluate(comp, p.point()));
183 }
184 localFct.unbind();
185 }
186 return data;
187 }
188
189 private:
190 unsigned int order_;
191 std::uint64_t numPoints_ = 0;
192
195 };
196
197} // end namespace Dune::Vtk
Definition writer.hh:16
GridView(const Implementation &imp)
Types types(int codim) const
std::uint64_t numCells() const
Return the number of cells in (this partition of the) grid.
Definition datacollectorinterface.hh:57
std::uint64_t numPoints() const
Return the number of points in (this partition of the) grid.
Definition datacollectorinterface.hh:63
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 Lagrange cells.
Definition lagrangedatacollector.hh:21
std::uint64_t numPointsImpl() const
Return number of Lagrange nodes.
Definition lagrangedatacollector.hh:72
void updateImpl()
Construct the point sets.
Definition lagrangedatacollector.hh:57
Cells cellsImpl() const
Return cell types, offsets, and connectivity.
Definition lagrangedatacollector.hh:126
LagrangeDataCollector(GridView const &gridView, int order=ORDER)
Definition lagrangedatacollector.hh:48
std::vector< T > pointsImpl() const
Return a vector of point coordinates.
Definition lagrangedatacollector.hh:83
std::vector< T > pointDataImpl(GlobalFunction const &fct) const
Evaluate the fct at element vertices and edge centers in the same order as the point coords.
Definition lagrangedatacollector.hh:160
std::uint64_t numCellsImpl() const
Return number of grid cells.
Definition lagrangedatacollector.hh:116
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: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
@ LAGRANGE
Definition types.hh:164
A set of lagrange points compatible with the numbering of VTK and Gmsh.
Definition lagrangepoints.hh:29
T push_back(T... args)
T reserve(T... args)