dune-vtk 2.12
Loading...
Searching...
No Matches
discontinuousgridcreator.hh
Go to the documentation of this file.
1#pragma once
2
3#include <cassert>
4#include <cstdint>
5#include <limits>
6#include <vector>
7
10#include <dune/grid/common/gridfactory.hh>
11
12#include <dune/vtk/types.hh>
14
15namespace Dune::Vtk
16{
17 // Create a grid where the input points are not connected and the connectivity
18 // describes separated elements.
19 template <class Grid>
21 : public GridCreatorInterface<Grid, DiscontinuousGridCreator<Grid>>
22 {
26
27 struct CoordLess
28 {
29 template <class T, int N>
31 {
32 for (int i = 0; i < N; ++i) {
33 if (std::abs(lhs[i] - rhs[i]) < std::numeric_limits<T>::epsilon())
34 continue;
35 return lhs[i] < rhs[i];
36 }
37 return false;
38 }
39 };
40
41 using Super::Super;
42 using Super::factory;
43
45 std::vector<std::uint64_t> const& /*point_ids*/)
46 {
47 points_ = &points;
48 uniquePoints_.clear();
49 std::size_t idx = 0;
50
51 for (auto const& p : points) {
52 auto b = uniquePoints_.emplace(std::make_pair(p,idx));
53 if (b.second) {
55 ++idx;
56 }
57 }
58 }
59
61 std::vector<std::int64_t> const& offsets,
62 std::vector<std::int64_t> const& connectivity)
63 {
64 assert(points_ != nullptr);
65 std::size_t idx = 0;
66 for (std::size_t i = 0; i < types.size(); ++i) {
67 auto type = Vtk::to_geometry(types[i]);
68 Vtk::CellType cellType{type};
69
70 int nNodes = offsets[i] - (i == 0 ? 0 : offsets[i-1]);
71 assert(nNodes > 0);
72 std::vector<unsigned int> vtk_cell; vtk_cell.reserve(nNodes);
73 for (int j = 0; j < nNodes; ++j) {
74 std::size_t v_j = connectivity[idx++];
75 std::size_t new_idx = uniquePoints_[(*points_)[v_j]];
76 vtk_cell.push_back(new_idx);
77 }
78
79 if (cellType.noPermutation()) {
80 factory().insertElement(type,vtk_cell);
81 } else {
82 // apply index permutation
83 std::vector<unsigned int> cell(nNodes);
84 for (int j = 0; j < nNodes; ++j)
85 cell[j] = vtk_cell[cellType.permutation(j)];
86 factory().insertElement(type,cell);
87 }
88 }
89 }
90
91 private:
92 std::vector<GlobalCoordinate> const* points_ = nullptr;
94 };
95
96 // deduction guides
97 template <class Grid>
100
101} // end namespace Dune::Vtk
Definition writer.hh:16
GeometryType to_geometry(std::uint8_t cell)
Definition types.cc:145
X & lhs()
Y & rhs()
static constexpr size_type N()
virtual void operator()()=0
virtual void insertElement(const GeometryType &type, const std::vector< unsigned int > &vertices)
virtual void insertVertex(const FieldVector< ctype, dimworld > &pos)
Base class for grid creators in a CRTP style.
Definition gridcreatorinterface.hh:23
GridFactory< Grid > & factory()
Return the associated GridFactory.
Definition gridcreatorinterface.hh:75
typename Grid::template Codim< 0 >::Entity::Geometry::GlobalCoordinate GlobalCoordinate
Definition gridcreatorinterface.hh:26
Definition discontinuousgridcreator.hh:22
void insertElementsImpl(std::vector< std::uint8_t > const &types, std::vector< std::int64_t > const &offsets, std::vector< std::int64_t > const &connectivity)
Definition discontinuousgridcreator.hh:60
GridFactory< Grid > & factory()
Return the associated GridFactory.
Definition gridcreatorinterface.hh:75
void insertVerticesImpl(std::vector< GlobalCoordinate > const &points, std::vector< std::uint64_t > const &)
Definition discontinuousgridcreator.hh:44
typename Super::GlobalCoordinate GlobalCoordinate
Definition discontinuousgridcreator.hh:25
Definition discontinuousgridcreator.hh:28
Mapping of Dune geometry types to VTK cell types.
Definition types.hh:159
T make_pair(T... args)
T push_back(T... args)
T reserve(T... args)
T size(T... args)