dune-vtk 2.12
Loading...
Searching...
No Matches
discontinuousgridcreator.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 <cassert>
6#include <cstdint>
7#include <limits>
8#include <vector>
9
12#include <dune/grid/common/gridfactory.hh>
13
14#include <dune/vtk/types.hh>
16
17namespace Dune::Vtk
18{
19 // Create a grid where the input points are not connected and the connectivity
20 // describes separated elements.
21 template <class Grid>
23 : public GridCreatorInterface<Grid, DiscontinuousGridCreator<Grid>>
24 {
28
29 struct CoordLess
30 {
31 template <class T, int N>
33 {
34 for (int i = 0; i < N; ++i) {
35 if (std::abs(lhs[i] - rhs[i]) < std::numeric_limits<T>::epsilon())
36 continue;
37 return lhs[i] < rhs[i];
38 }
39 return false;
40 }
41 };
42
43 using Super::Super;
44 using Super::factory;
45
47 std::vector<std::uint64_t> const& /*point_ids*/)
48 {
49 points_ = &points;
50 uniquePoints_.clear();
51 std::size_t idx = 0;
52
53 for (auto const& p : points) {
54 auto b = uniquePoints_.emplace(std::make_pair(p,idx));
55 if (b.second) {
57 ++idx;
58 }
59 }
60 }
61
63 std::vector<std::int64_t> const& offsets,
64 std::vector<std::int64_t> const& connectivity)
65 {
66 assert(points_ != nullptr);
67 std::size_t idx = 0;
68 for (std::size_t i = 0; i < types.size(); ++i) {
69 auto type = Vtk::to_geometry(types[i]);
71
72 int nNodes = offsets[i] - (i == 0 ? 0 : offsets[i-1]);
73 assert(nNodes > 0);
75 for (int j = 0; j < nNodes; ++j) {
76 std::size_t v_j = connectivity[idx++];
77 std::size_t new_idx = uniquePoints_[(*points_)[v_j]];
78 vtk_cell.push_back(new_idx);
79 }
80
81 if (cellType.noPermutation()) {
83 } else {
84 // apply index permutation
86 for (int j = 0; j < nNodes; ++j)
87 cell[j] = vtk_cell[cellType.permutation(j)];
88 factory().insertElement(type,cell);
89 }
90 }
91 }
92
93 private:
94 std::vector<GlobalCoordinate> const* points_ = nullptr;
96 };
97
98 // deduction guides
99 template <class Grid>
102
103} // end namespace Dune::Vtk
Definition datacollector.hh:19
GeometryType to_geometry(std::uint8_t cell)
Definition types.cc:147
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)
Implementation of DataCollector for cells, with continuous data.
Definition celltypedatacollector.hh:20
Base class for grid creators in a CRTP style.
Definition gridcreatorinterface.hh:25
GridFactory< Grid > & factory()
Return the associated GridFactory.
Definition gridcreatorinterface.hh:77
typename Grid::template Codim< 0 >::Entity::Geometry::GlobalCoordinate GlobalCoordinate
Definition gridcreatorinterface.hh:28
Definition discontinuousgridcreator.hh:24
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:62
GridFactory< Grid > & factory()
Return the associated GridFactory.
Definition gridcreatorinterface.hh:77
void insertVerticesImpl(std::vector< GlobalCoordinate > const &points, std::vector< std::uint64_t > const &)
Definition discontinuousgridcreator.hh:46
typename Super::GlobalCoordinate GlobalCoordinate
Definition discontinuousgridcreator.hh:27
Definition discontinuousgridcreator.hh:30
Mapping of Dune geometry types to VTK cell types.
Definition types.hh:161
T make_pair(T... args)
T size(T... args)