dune-vtk 2.12
Loading...
Searching...
No Matches
discontinuousdatacollector.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
8#include <dune/vtk/types.hh>
9
11
12namespace Dune::Vtk
13{
15 template <class GridView, class Partition = Partitions::InteriorBorder>
17 : public UnstructuredDataCollectorInterface<GridView, DiscontinuousDataCollector<GridView,Partition>, Partition>
18 {
21
22 public:
23 using Super::dim;
24 using Super::partition;
25 using Super::gridView;
26
27 public:
31
33 void updateImpl ()
34 {
35 numPoints_ = 0;
36 numCells_ = 0;
37 for (auto const& c : elements(gridView(), partition)) {
38 numCells_++;
39 numPoints_ += c.subEntities(dim);
40 }
41 }
42
45 {
46 return numPoints_;
47 }
48
50 template <class T>
52 {
53 std::vector<T> data(numPoints_ * 3);
55 for (auto const& element : elements(gridView(), partition)) {
56 Vtk::CellType cellType(element.type());
57 for (unsigned int i = 0; i < element.subEntities(dim); ++i,++pointIdx) {
59 auto v = element.geometry().corner(cellType.permutation(i));
60 for (std::size_t j = 0; j < v.size(); ++j)
61 data[idx + j] = T(v[j]);
62 for (std::size_t j = v.size(); j < 3u; ++j)
63 data[idx + j] = T(0);
64 }
65 }
66 return data;
67 }
68
71 {
72 return numCells_;
73 }
74
77 {
79 cells.connectivity.reserve(numPoints_);
80 cells.offsets.reserve(numCells_);
81 cells.types.reserve(numCells_);
82
85 for (auto const& c : elements(gridView(), partition)) {
86 Vtk::CellType cellType(c.type());
87 for (unsigned int j = 0; j < c.subEntities(dim); ++j,++pointIdx) {
89 }
90 cells.offsets.push_back(old_o += c.subEntities(dim));
92 }
93
94 return cells;
95 }
96
98 template <class T, class GlobalFunction>
99 std::vector<T> pointDataImpl (GlobalFunction const& fct) const
100 {
101 std::vector<T> data(numPoints_ * fct.numComponents());
102 auto localFct = localFunction(fct);
104 for (auto const& e : elements(gridView(), partition)) {
105 localFct.bind(e);
106 Vtk::CellType cellType{e.type()};
107 auto refElem = referenceElement(e.geometry());
108 for (unsigned int j = 0; j < e.subEntities(dim); ++j,++pointIdx) {
109 std::size_t idx = fct.numComponents() * pointIdx;
110 for (int comp = 0; comp < fct.numComponents(); ++comp)
111 data[idx + comp] = T(localFct.evaluate(comp, refElem.position(cellType.permutation(j),dim)));
112 }
113 localFct.unbind();
114 }
115 return data;
116 }
117
118 private:
119 std::uint64_t numCells_ = 0;
120 std::uint64_t numPoints_ = 0;
122 };
123
124} // end namespace Dune::Vtk
Definition datacollector.hh:19
unspecified value type referenceElement(T &&... t)
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 linear cells, with discontinuous data.
Definition discontinuousdatacollector.hh:18
void updateImpl()
Create an index map the uniquely assigns an index to each pair (element,corner)
Definition discontinuousdatacollector.hh:33
Cells cellsImpl() const
Connect the corners of each cell. The leads to a global discontinuous grid.
Definition discontinuousdatacollector.hh:76
DiscontinuousDataCollector(GridView const &gridView)
Definition discontinuousdatacollector.hh:28
std::uint64_t numPointsImpl() const
The number of points approx. #cell * #corners-per-cell.
Definition discontinuousdatacollector.hh:44
std::vector< T > pointsImpl() const
Return the coordinates of the corners of all cells.
Definition discontinuousdatacollector.hh:51
std::uint64_t numCellsImpl() const
Return number of grid cells.
Definition discontinuousdatacollector.hh:70
std::vector< T > pointDataImpl(GlobalFunction const &fct) const
Evaluate the fct in the corners of each cell.
Definition discontinuousdatacollector.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
T push_back(T... args)
T reserve(T... args)