Dune Core Modules (2.11.0)

celltypedatacollector.hh
1#pragma once
2
3#include <vector>
4
5#include <dune/geometry/referenceelements.hh>
7#include <dune/grid/common/partitionset.hh>
8#include <dune/vtk/types.hh>
9
10#include "unstructureddatacollector.hh"
11
12namespace Dune::Vtk
13{
15 template <class GridView>
17 : public UnstructuredDataCollectorInterface<GridView, CellTypeDataCollector<GridView>, Partitions::All>
18 {
20 using Super = UnstructuredDataCollectorInterface<GridView, Self, Partitions::All>;
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:
40 CellTypeDataCollector (GridView const& gridView, Vtk::CellType::Parametrization param = Vtk::CellType::LINEAR)
41 : Super(gridView)
42 , parametrization_(param)
43 , mapper_(nodeMapper(Super::gridView(), param))
44 {}
45
47 void updateImpl ()
48 {
49 mapper_.update(Super::gridView());
50 }
51
53 std::uint64_t numPointsImpl () const
54 {
55 return mapper_.size();
56 }
57
59
63 template <class T>
64 std::vector<T> pointsImpl () const
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
87 std::uint64_t numCellsImpl () const
88 {
89 return gridView().size(0);
90 }
91
93
97 Cells cellsImpl () const
98 {
99 Cells cells;
100 cells.connectivity.reserve(this->numPoints());
101 cells.offsets.reserve(this->numCells());
102 cells.types.reserve(this->numCells());
103
104 std::int64_t old_o = 0;
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 }
115 cells.offsets.push_back(old_o += cellType.size());
116 cells.types.push_back(cellType.type());
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
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
size_type size() const
Return total number of entities in the entity set managed by the mapper.
Definition: mcmgmapper.hh:204
Index subIndex(const typename GV::template Codim< 0 >::Entity &e, int i, unsigned int codim) const
Map subentity of codim 0 entity to starting index in array for dof block.
Definition: mcmgmapper.hh:185
void update(const GV &gridView)
Recalculates indices after grid adaptation.
Definition: mcmgmapper.hh:308
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
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
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
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:158
unspecified value type referenceElement(T &&... t)
Returns a reference element for the objects t....
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
int size() const
Number of nodes.
Definition: types.hh:228
std::uint8_t type() const
Return VTK Cell type.
Definition: types.hh:211
int permutation(int idx) const
Return a permutation of Dune element vertices to conform to VTK element numbering.
Definition: types.hh:222
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Feb 14, 23:39, 2026)