dune-vtk 2.12
Loading...
Searching...
No Matches
lagrangedatacollector.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 <cassert>
6#include <map>
7#include <vector>
8
12#include <dune/vtk/types.hh>
14
16
17namespace Dune::Vtk
18{
20 template <class GridView, int ORDER = -1>
22 : public UnstructuredDataCollectorInterface<GridView, LagrangeDataCollector<GridView,ORDER>, Partitions::All>
23 {
26
27 auto pointSetMapper() const
28 {
29 auto pointSetLayout = [&](Dune::GeometryType gt, int dimgrid) -> unsigned int {
30 if (gt.dim()==dim)
31 {
32 auto refElem = Dune::referenceElement<double,dim>(gt);
33 return pointSets_.at(gt).size() - refElem.size(dim);
34 }
35 else if (gt.dim()==0)
36 return 1;
37 else
38 return 0;
39 };
41 }
42
43 public:
44 static_assert(ORDER != 0, "Order 0 not supported");
45 using Super::dim;
46 using Super::partition; // NOTE: Lagrange data-collector currently implemented for the All partition only
47 using Super::gridView;
48
49 public:
52 , order_(order)
53 {
54 assert(order > 0 && "Order 0 not supported");
55 assert(ORDER < 0 || order == ORDER);
56 }
57
59 void updateImpl ()
60 {
61 auto const& indexSet = gridView().indexSet();
62
63 pointSets_.clear();
64 for (auto gt : indexSet.types(0))
65 pointSets_.emplace(gt, order_);
66
67 for (auto& pointSet : pointSets_)
68 pointSet.second.build(pointSet.first);
69
70 numPoints_ = pointSetMapper().size();
71 }
72
75 {
76 return numPoints_;
77 }
78
80
84 template <class T>
86 {
87 std::vector<T> data(this->numPoints() * 3);
88 auto const& mapper = pointSetMapper();
89
90 for (auto const& element : elements(gridView(), partition)) {
91 auto geometry = element.geometry();
92 auto refElem = referenceElement<T,dim>(element.type());
93
94 auto const& pointSet = pointSets_.at(element.type());
95 unsigned int vertexDOFs = refElem.size(dim);
96
97 for (std::size_t i = 0; i < pointSet.size(); ++i) {
98 auto const& p = pointSet[i];
99 if (i < vertexDOFs)
100 assert(p.localKey().codim() == dim);
101
102 auto const& localKey = p.localKey();
103 std::size_t idx = 3 * (localKey.codim() == dim
104 ? mapper.subIndex(element, localKey.subEntity(), dim)
105 : mapper.index(element) + (i - vertexDOFs));
106
107 auto v = geometry.global(p.point());
108 for (std::size_t j = 0; j < v.size(); ++j)
109 data[idx + j] = T(v[j]);
110 for (std::size_t j = v.size(); j < 3u; ++j)
111 data[idx + j] = T(0);
112 }
113 }
114 return data;
115 }
116
119 {
120 return gridView().size(0);
121 }
122
124
129 {
130 Cells cells;
132 cells.offsets.reserve(this->numCells());
133 cells.types.reserve(this->numCells());
134
135 auto const& mapper = pointSetMapper();
136
138 for (auto const& element : elements(gridView(), partition)) {
139 auto refElem = referenceElement<double,dim>(element.type());
141
142 auto const& pointSet = pointSets_.at(element.type());
143 unsigned int vertexDOFs = refElem.size(dim);
144
145 for (std::size_t i = 0; i < pointSet.size(); ++i) {
146 auto const& p = pointSet[i];
147 auto const& localKey = p.localKey();
148 std::size_t idx = (localKey.codim() == dim
149 ? mapper.subIndex(element, localKey.subEntity(), dim)
150 : mapper.index(element) + (i - vertexDOFs));
152 }
153
156 }
157 return cells;
158 }
159
161 template <class T, class GlobalFunction>
162 std::vector<T> pointDataImpl (GlobalFunction const& fct) const
163 {
164 int nComps = fct.numComponents();
165 std::vector<T> data(this->numPoints() * nComps);
166 auto const& mapper = pointSetMapper();
167
168 auto localFct = localFunction(fct);
169 for (auto const& element : elements(gridView(), partition)) {
170 localFct.bind(element);
171 auto refElem = referenceElement<T,dim>(element.type());
172
173 auto const& pointSet = pointSets_.at(element.type());
174 unsigned int vertexDOFs = refElem.size(dim);
175
176 for (std::size_t i = 0; i < pointSet.size(); ++i) {
177 auto const& p = pointSet[i];
178 auto const& localKey = p.localKey();
179 std::size_t idx = nComps * (localKey.codim() == dim
180 ? mapper.subIndex(element, localKey.subEntity(), dim)
181 : mapper.index(element) + (i - vertexDOFs));
182
183 for (int comp = 0; comp < nComps; ++comp)
184 data[idx + comp] = T(localFct.evaluate(comp, p.point()));
185 }
186 localFct.unbind();
187 }
188 return data;
189 }
190
191 private:
192 unsigned int order_;
193 std::uint64_t numPoints_ = 0;
194
197 };
198
199} // end namespace Dune::Vtk
Definition datacollector.hh:19
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:59
std::uint64_t numPoints() const
Return the number of points in (this partition of the) grid.
Definition datacollectorinterface.hh:65
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 Lagrange cells.
Definition lagrangedatacollector.hh:23
std::uint64_t numPointsImpl() const
Return number of Lagrange nodes.
Definition lagrangedatacollector.hh:74
void updateImpl()
Construct the point sets.
Definition lagrangedatacollector.hh:59
Cells cellsImpl() const
Return cell types, offsets, and connectivity.
Definition lagrangedatacollector.hh:128
LagrangeDataCollector(GridView const &gridView, int order=ORDER)
Definition lagrangedatacollector.hh:50
std::vector< T > pointsImpl() const
Return a vector of point coordinates.
Definition lagrangedatacollector.hh:85
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:162
std::uint64_t numCellsImpl() const
Return number of grid cells.
Definition lagrangedatacollector.hh:118
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
@ LAGRANGE
Definition types.hh:166
T push_back(T... args)
T reserve(T... args)