Dune Core Modules (2.11.0)

discontinuouslagrangedatacollector.hh
1#pragma once
2
3#include <cassert>
4#include <map>
5#include <vector>
6
7#include <dune/geometry/referenceelements.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{
26 template <class GridView, int ORDER = -1>
28 : public UnstructuredDataCollectorInterface<GridView, DiscontinuousLagrangeDataCollector<GridView,ORDER>, Partitions::All>
29 {
31 using Super = UnstructuredDataCollectorInterface<GridView, Self, Partitions::All>;
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:
51 DiscontinuousLagrangeDataCollector (GridView const& gridView, int order = ORDER)
52 : Super(gridView)
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
75 std::uint64_t numPointsImpl () const
76 {
77 return numPoints_;
78 }
79
81
85 template <class T>
86 std::vector<T> pointsImpl () const
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
111 std::uint64_t numCellsImpl () const
112 {
113 return gridView().size(0);
114 }
115
117
121 Cells cellsImpl () const
122 {
123 Cells cells;
124 cells.connectivity.reserve(this->numPoints());
125 cells.offsets.reserve(this->numCells());
126 cells.types.reserve(this->numCells());
127
128 auto const& mapper = pointSetMapper();
129
130
131 std::int64_t old_o = 0;
132 for (auto const& element : elements(gridView(), partition)) {
133 Vtk::CellType cellType(element.type(), Vtk::CellType::LAGRANGE);
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);
139 cells.connectivity.push_back(std::int64_t(idx));
140 }
141
142 cells.offsets.push_back(old_o += pointSet.size());
143 cells.types.push_back(cellType.type());
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
179 std::map<GeometryType, PointSet> pointSets_;
180 };
181
182} // 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: discontinuouslagrangedatacollector.hh:29
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
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)