dune-vtk 2.12
Loading...
Searching...
No Matches
celltypedatacollector.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 <vector>
6
10#include <dune/vtk/types.hh>
11
13
14namespace Dune::Vtk
15{
17 template <class GridView>
19 : public UnstructuredDataCollectorInterface<GridView, CellTypeDataCollector<GridView>, Partitions::All>
20 {
23
24 static auto nodeMapper (const GridView& gridView, Vtk::CellType::Parametrization param)
25 {
26 auto layout = [param](Dune::GeometryType gt, int dimgrid) -> unsigned int {
27 auto cellType = Dune::Vtk::CellType{gt,param};
28 return cellType.layout(gt.dim());
29 };
31 }
32
33 Vtk::CellType::Parametrization parametrization_;
35
36 public:
37 using Super::dim;
38 using Super::partition; // NOTE: cell-type data-collector currently implemented for the All partition only
39 using Super::gridView;
40
41 public:
44 , parametrization_(param)
45 , mapper_(nodeMapper(Super::gridView(), param))
46 {}
47
49 void updateImpl ()
50 {
51 mapper_.update(Super::gridView());
52 }
53
56 {
57 return mapper_.size();
58 }
59
61
65 template <class T>
67 {
68 std::vector<T> data(this->numPoints() * 3);
69 for (auto const& c : elements(gridView(), partition)) {
70 auto geometry = c.geometry();
71 Vtk::CellType cellType(c.type(), parametrization_);
72 auto refElem = referenceElement<T,dim>(c.type());
73
74 for (int codim = dim, j = 0; codim >= 0 && j < cellType.size(); --codim) {
75 for (int i = 0; i < refElem.size(codim) && j < cellType.size(); ++i,++j) {
76 std::int64_t idx = 3 * mapper_.subIndex(c,i,codim);
77 auto v = geometry.global(refElem.position(i,codim));
78 for (std::size_t j = 0; j < v.size(); ++j)
79 data[idx + j] = T(v[j]);
80 for (std::size_t j = v.size(); j < 3u; ++j)
81 data[idx + j] = T(0);
82 }
83 }
84 }
85 return data;
86 }
87
90 {
91 return gridView().size(0);
92 }
93
95
100 {
101 Cells cells;
103 cells.offsets.reserve(this->numCells());
104 cells.types.reserve(this->numCells());
105
107 for (auto const& c : elements(gridView(), partition)) {
108 Vtk::CellType cellType(c.type(), parametrization_);
109 auto refElem = referenceElement(c);
110
111 for (int codim = dim, j = 0; codim >= 0 && j < cellType.size(); --codim) {
112 for (int i = 0; i < refElem.size(codim) && j < cellType.size(); ++i,++j) {
113 int k = cellType.permutation(j);
114 cells.connectivity.push_back(mapper_.subIndex(c,k,codim));
115 }
116 }
119 }
120 return cells;
121 }
122
124 template <class T, class GlobalFunction>
125 std::vector<T> pointDataImpl (GlobalFunction const& fct) const
126 {
127 std::vector<T> data(this->numPoints() * fct.numComponents());
128 auto localFct = localFunction(fct);
129 for (auto const& c : elements(gridView(), partition)) {
130 localFct.bind(c);
131 Vtk::CellType cellType{c.type(), parametrization_};
132 auto refElem = referenceElement(c);
133
134 for (int codim = dim, j = 0; codim >= 0 && j < cellType.size(); --codim) {
135 for (int i = 0; i < refElem.size(codim) && j < cellType.size(); ++i,++j) {
136 int k = cellType.permutation(j);
137 std::int64_t idx = fct.numComponents() * mapper_.subIndex(c,k,codim);
138 auto v = refElem.position(k,codim);
139 for (int comp = 0; comp < fct.numComponents(); ++comp)
140 data[idx + comp] = T(localFct.evaluate(comp, v));
141 }
142 }
143 localFct.unbind();
144 }
145 return data;
146 }
147 };
148
149} // end namespace Dune::Vtk
Definition datacollector.hh:19
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: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
std::vector< T > pointsImpl() const
Return a vector of point coordinates.
Definition celltypedatacollector.hh:66
CellTypeDataCollector(GridView const &gridView, Vtk::CellType::Parametrization param=Vtk::CellType::LINEAR)
Definition celltypedatacollector.hh:42
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:125
std::uint64_t numPointsImpl() const
Return number of vertices + number of edge.
Definition celltypedatacollector.hh:55
void updateImpl()
Update the mapper.
Definition celltypedatacollector.hh:49
std::uint64_t numCellsImpl() const
Return number of grid cells.
Definition celltypedatacollector.hh:89
Cells cellsImpl() const
Return cell types, offsets, and connectivity.
Definition celltypedatacollector.hh:99
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
Parametrization
Definition types.hh:162
@ LINEAR
Definition types.hh:163
T push_back(T... args)
T reserve(T... args)