dune-vtk 2.12
Loading...
Searching...
No Matches
discontinuouslagrangedatacollector.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{
26 template <class GridView, int ORDER = -1>
28 : public UnstructuredDataCollectorInterface<GridView, DiscontinuousLagrangeDataCollector<GridView,ORDER>, Partitions::All>
29 {
32
33 auto pointSetMapper () const
34 {
35 auto pointSetLayout = [&](Dune::GeometryType gt, int dimgrid) -> unsigned int {
36 if (int(gt.dim()) == dimgrid)
37 return pointSets_.at(gt).size();
38 else
39 return 0;
40 };
42 }
43
44 public:
45 static_assert(ORDER != 0, "Order 0 not supported");
46 using Super::dim;
47 using Super::partition; // NOTE: Lagrange data-collector currently implemented for the All partition only
48 using Super::gridView;
49
50 public:
53 , order_(order)
54 {
55 assert(order > 0 && "Order 0 not supported");
56 assert(ORDER < 0 || order == ORDER);
57 }
58
60 void updateImpl ()
61 {
62 auto const& indexSet = gridView().indexSet();
63
64 pointSets_.clear();
65 for (auto gt : indexSet.types(0))
66 pointSets_.emplace(gt, order_);
67
68 for (auto& pointSet : pointSets_)
69 pointSet.second.build(pointSet.first);
70
71 numPoints_ = pointSetMapper().size();
72 }
73
76 {
77 return numPoints_;
78 }
79
81
85 template <class T>
87 {
88 std::vector<T> data(this->numPoints() * 3);
89 auto const& mapper = pointSetMapper();
90
91 for (auto const& element : elements(gridView(), partition)) {
92 auto geometry = element.geometry();
93
94 auto const& pointSet = pointSets_.at(element.type());
95
96 for (std::size_t i = 0; i < pointSet.size(); ++i) {
97 auto const& p = pointSet[i];
98 std::size_t idx = 3 * (mapper.index(element) + i);
99
100 auto v = geometry.global(p.point());
101 for (std::size_t j = 0; j < v.size(); ++j)
102 data[idx + j] = T(v[j]);
103 for (std::size_t j = v.size(); j < 3u; ++j)
104 data[idx + j] = T(0);
105 }
106 }
107 return data;
108 }
109
112 {
113 return gridView().size(0);
114 }
115
117
122 {
123 Cells cells;
125 cells.offsets.reserve(this->numCells());
126 cells.types.reserve(this->numCells());
127
128 auto const& mapper = pointSetMapper();
129
130
132 for (auto const& element : elements(gridView(), partition)) {
134
135 auto const& pointSet = pointSets_.at(element.type());
136
137 for (std::size_t i = 0; i < pointSet.size(); ++i) {
138 std::size_t idx = (mapper.index(element) + i);
140 }
141
144 }
145 return cells;
146 }
147
149 template <class T, class GlobalFunction>
150 std::vector<T> pointDataImpl (GlobalFunction const& fct) const
151 {
152 int nComps = fct.numComponents();
153 std::vector<T> data(this->numPoints() * nComps);
154 auto const& mapper = pointSetMapper();
155
156 auto localFct = localFunction(fct);
157 for (auto const& element : elements(gridView(), partition)) {
158 localFct.bind(element);
159
160 auto const& pointSet = pointSets_.at(element.type());
161
162 for (std::size_t i = 0; i < pointSet.size(); ++i) {
163 auto const& p = pointSet[i];
164 std::size_t idx = nComps*(mapper.index(element) + i);
165
166 for (int comp = 0; comp < nComps; ++comp)
167 data[idx + comp] = T(localFct.evaluate(comp, p.point()));
168 }
169 localFct.unbind();
170 }
171 return data;
172 }
173
174 private:
175 unsigned int order_;
176 std::uint64_t numPoints_ = 0;
177
180 };
181
182} // 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 discontinuouslagrangedatacollector.hh:29
DiscontinuousLagrangeDataCollector(GridView const &gridView, int order=ORDER)
Definition discontinuouslagrangedatacollector.hh:51
void updateImpl()
Construct the point sets.
Definition discontinuouslagrangedatacollector.hh:60
Cells cellsImpl() const
Return cell types, offsets, and connectivity.
Definition discontinuouslagrangedatacollector.hh:121
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 discontinuouslagrangedatacollector.hh:150
std::vector< T > pointsImpl() const
Return a vector of point coordinates.
Definition discontinuouslagrangedatacollector.hh:86
std::uint64_t numCellsImpl() const
Return number of grid cells.
Definition discontinuouslagrangedatacollector.hh:111
std::uint64_t numPointsImpl() const
Return number of Lagrange nodes.
Definition discontinuouslagrangedatacollector.hh:75
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)