dune-vtk 2.12
Loading...
Searching...
No Matches
celltypedatacollector.hh
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
8#include <dune/vtk/types.hh>
9
11
12namespace Dune::Vtk
13{
15 template <class GridView>
17 : public UnstructuredDataCollectorInterface<GridView, CellTypeDataCollector<GridView>, Partitions::All>
18 {
21
22 static auto nodeMapper (const GridView& gridView, Vtk::CellType::Parametrization param)
23 {
24 auto layout = [param](Dune::GeometryType gt, int dimgrid) -> unsigned int {
25 auto cellType = Dune::Vtk::CellType{gt,param};
26 return cellType.layout(gt.dim());
27 };
29 }
30
31 Vtk::CellType::Parametrization parametrization_;
33
34 public:
35 using Super::dim;
36 using Super::partition; // NOTE: cell-type data-collector currently implemented for the All partition only
37 using Super::gridView;
38
39 public:
42 , parametrization_(param)
43 , mapper_(nodeMapper(Super::gridView(), param))
44 {}
45
47 void updateImpl ()
48 {
49 mapper_.update(Super::gridView());
50 }
51
54 {
55 return mapper_.size();
56 }
57
59
63 template <class T>
65 {
66 std::vector<T> data(this->numPoints() * 3);
67 for (auto const& c : elements(gridView(), partition)) {
68 auto geometry = c.geometry();
69 Vtk::CellType cellType(c.type(), parametrization_);
70 auto refElem = referenceElement<T,dim>(c.type());
71
72 for (int codim = dim, j = 0; codim >= 0 && j < cellType.size(); --codim) {
73 for (int i = 0; i < refElem.size(codim) && j < cellType.size(); ++i,++j) {
74 std::int64_t idx = 3 * mapper_.subIndex(c,i,codim);
75 auto v = geometry.global(refElem.position(i,codim));
76 for (std::size_t j = 0; j < v.size(); ++j)
77 data[idx + j] = T(v[j]);
78 for (std::size_t j = v.size(); j < 3u; ++j)
79 data[idx + j] = T(0);
80 }
81 }
82 }
83 return data;
84 }
85
88 {
89 return gridView().size(0);
90 }
91
93
98 {
101 cells.offsets.reserve(this->numCells());
102 cells.types.reserve(this->numCells());
103
105 for (auto const& c : elements(gridView(), partition)) {
106 Vtk::CellType cellType(c.type(), parametrization_);
107 auto refElem = referenceElement(c);
108
109 for (int codim = dim, j = 0; codim >= 0 && j < cellType.size(); --codim) {
110 for (int i = 0; i < refElem.size(codim) && j < cellType.size(); ++i,++j) {
111 int k = cellType.permutation(j);
112 cells.connectivity.push_back(mapper_.subIndex(c,k,codim));
113 }
114 }
117 }
118 return cells;
119 }
120
122 template <class T, class GlobalFunction>
123 std::vector<T> pointDataImpl (GlobalFunction const& fct) const
124 {
125 std::vector<T> data(this->numPoints() * fct.numComponents());
126 auto localFct = localFunction(fct);
127 for (auto const& c : elements(gridView(), partition)) {
128 localFct.bind(c);
129 Vtk::CellType cellType{c.type(), parametrization_};
130 auto refElem = referenceElement(c);
131
132 for (int codim = dim, j = 0; codim >= 0 && j < cellType.size(); --codim) {
133 for (int i = 0; i < refElem.size(codim) && j < cellType.size(); ++i,++j) {
134 int k = cellType.permutation(j);
135 std::int64_t idx = fct.numComponents() * mapper_.subIndex(c,k,codim);
136 auto v = refElem.position(k,codim);
137 for (int comp = 0; comp < fct.numComponents(); ++comp)
138 data[idx + comp] = T(localFct.evaluate(comp, v));
139 }
140 }
141 localFct.unbind();
142 }
143 return data;
144 }
145 };
146
147} // end namespace Dune::Vtk
Definition writer.hh:16
unspecified value type referenceElement(T &&... t)
Index subIndex(const typename GV::template Codim< 0 >::Entity &e, int i, unsigned 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 cells, with continuous data.
Definition celltypedatacollector.hh:18
std::vector< T > pointsImpl() const
Return a vector of point coordinates.
Definition celltypedatacollector.hh:64
CellTypeDataCollector(GridView const &gridView, Vtk::CellType::Parametrization param=Vtk::CellType::LINEAR)
Definition celltypedatacollector.hh:40
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 celltypedatacollector.hh:123
std::uint64_t numPointsImpl() const
Return number of vertices + number of edge.
Definition celltypedatacollector.hh:53
void updateImpl()
Update the mapper.
Definition celltypedatacollector.hh:47
std::uint64_t numCellsImpl() const
Return number of grid cells.
Definition celltypedatacollector.hh:87
Cells cellsImpl() const
Return cell types, offsets, and connectivity.
Definition celltypedatacollector.hh:97
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
Parametrization
Definition types.hh:160
@ LINEAR
Definition types.hh:161
std::uint8_t type() const
Return VTK Cell type.
Definition types.hh:211
T push_back(T... args)
T reserve(T... args)