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