Dune Core Modules (2.11.0)

lagrangedatacollector.hh
1#pragma once
2
3#include <cassert>
4#include <map>
5#include <vector>
6
7#include <dune/geometry/referenceelement.hh>
8#include <dune/grid/common/partitionset.hh>
10#include <dune/vtk/types.hh>
11#include <dune/vtk/utility/lagrangepoints.hh>
12
13#include "unstructureddatacollector.hh"
14
15namespace Dune::Vtk
16{
18 template <class GridView, int ORDER = -1>
20 : public UnstructuredDataCollectorInterface<GridView, LagrangeDataCollector<GridView,ORDER>, Partitions::All>
21 {
23 using Super = UnstructuredDataCollectorInterface<GridView, Self, Partitions::All>;
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:
48 LagrangeDataCollector (GridView const& gridView, int order = ORDER)
49 : Super(gridView)
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
72 std::uint64_t numPointsImpl () const
73 {
74 return numPoints_;
75 }
76
78
82 template <class T>
83 std::vector<T> pointsImpl () const
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
116 std::uint64_t numCellsImpl () const
117 {
118 return gridView().size(0);
119 }
120
122
126 Cells cellsImpl () const
127 {
128 Cells cells;
129 cells.connectivity.reserve(this->numPoints());
130 cells.offsets.reserve(this->numCells());
131 cells.types.reserve(this->numCells());
132
133 auto const& mapper = pointSetMapper();
134
135 std::int64_t old_o = 0;
136 for (auto const& element : elements(gridView(), partition)) {
137 auto refElem = referenceElement<double,dim>(element.type());
138 Vtk::CellType cellType(element.type(), Vtk::CellType::LAGRANGE);
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));
149 cells.connectivity.push_back(std::int64_t(idx));
150 }
151
152 cells.offsets.push_back(old_o += pointSet.size());
153 cells.types.push_back(cellType.type());
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
194 std::map<GeometryType, PointSet> pointSets_;
195 };
196
197} // end namespace Dune::Vtk
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:114
Implementation class for a multiple codim and multiple geometry type mapper.
Definition: mcmgmapper.hh:129
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
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 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
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
A set of lagrange points compatible with the numbering of VTK and Gmsh.
Definition: lagrangepoints.hh:29
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:158
auto elements(const SubDomainGridView< HostGridView > &subDomainGridView)
ADL findable access to element range for a SubDomainGridView.
Definition: subdomain.hh:487
Mapper for multiple codim and multiple geometry types.
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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Feb 14, 23:39, 2026)