Loading [MathJax]/extensions/tex2jax.js

dune-mmesh (unstable)

common.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_MMESH_GRID_COMMON_HH
4#define DUNE_MMESH_GRID_COMMON_HH
5
10namespace Dune {
11
14 std::size_t operator()(const std::vector<std::size_t>& a) const {
15 std::size_t hash = std::hash<std::size_t>{}(a[0]);
16 for (std::size_t i = 1; i < a.size(); ++i)
17 hash = hash ^ (std::hash<std::size_t>{}(a[i]) << i);
18 return hash;
19 }
20};
21
24 template <std::size_t dim>
25 std::size_t operator()(const std::array<std::size_t, dim>& a) const {
26 std::size_t hash = std::hash<std::size_t>{}(a[0]);
27 for (std::size_t i = 1; i < a.size(); ++i)
28 hash = hash ^ (std::hash<std::size_t>{}(a[i]) << i);
29 return hash;
30 }
31};
32
33namespace MMeshImpl {
34
35template <int dim>
36class sort_indices {
37 public:
38 sort_indices(std::array<std::size_t, dim> ids) : ids_(ids) {}
39
40 bool operator()(std::size_t i, std::size_t j) const {
41 return ids_[i] < ids_[j];
42 }
43
44 private:
45 std::array<std::size_t, dim> ids_;
46};
47
49template <int dim, typename ctype = double>
50static inline auto& ref() {
51 return ReferenceElements<ctype, dim>::simplex();
52}
53
55template <typename HostEntity, int dim>
56static inline auto computeCGALIndices(const HostEntity& hostEntity) {
57 std::array<std::size_t, dim + 1> ids, indices;
58 for (std::size_t i = 0; i < dim + 1; ++i) {
59 ids[i] = hostEntity->vertex(i)->info().id;
60 indices[i] = i;
61 }
62 std::sort(indices.begin(), indices.end(), sort_indices<dim + 1>(ids));
63
64 return indices;
65}
66
67// for a given dune facet index compute corresponding CGAL .second value
68template <std::size_t dim>
69static inline std::size_t duneFacetToCgalSecond(
70 const std::size_t duneFacet,
71 const std::array<std::size_t, dim + 1>& cgalIndex) {
72 std::size_t sum = 0;
73 for (std::size_t k = 0; k < dim; ++k)
74 sum += cgalIndex[ref<dim>().subEntity(duneFacet, 1, k, dim)];
75
76 static constexpr int max = (dim == 2) ? 3 : 6;
77 return max - sum;
78}
79
80// for a given CGAL .second value compute corresponding dune facet index
81template <std::size_t dim, typename HostFacet>
82static inline std::size_t cgalFacetToDuneFacet(const HostFacet& facet) {
83 const auto& i = facet.second;
84 const auto& cgalIndex = facet.first->info().cgalIndex;
85
86 // invert cgalIndex
87 auto duneIndex = cgalIndex;
88 for (std::size_t k = 0; k < dim + 1; ++k) duneIndex[cgalIndex[k]] = k;
89
90 std::size_t sum = 0;
91 for (std::size_t k = 0; k < dim; ++k)
92 sum += duneIndex[(i + k + 1) % (dim + 1)];
93
94 static const int thr = (dim == 2) ? 1 : 3;
95 return sum - thr;
96}
97
98template <std::size_t dim, typename HostEdge>
99static inline std::size_t cgalEdgeToDuneEdge(const HostEdge& cgalEdge) {
100 const auto& c = cgalEdge.first;
101 const auto& i = cgalEdge.second;
102 const auto& j = cgalEdge.third;
103
104 const auto& cgalIndex = c->info().cgalIndex;
105
106 // invert cgalIndex
107 auto duneIndex = cgalIndex;
108 for (std::size_t k = 0; k < dim + 1; ++k) duneIndex[cgalIndex[k]] = k;
109
110 auto i0 = duneIndex[i];
111 auto j0 = duneIndex[j];
112
113 if (i0 > j0) std::swap(i0, j0);
114
115 if (j0 != 3)
116 return i0 + j0 - 1;
117 else
118 return 3 + i0;
119}
120
121} // namespace MMeshImpl
122
123} // namespace Dune
124
125#endif
static auto & ref()
return reference element
Definition: common.hh:50
static auto computeCGALIndices(const HostEntity &hostEntity)
Return list of indices sorted by id.
Definition: common.hh:56
Hash a UInt array.
Definition: common.hh:23
Hash a UInt vector.
Definition: common.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Mar 16, 23:47, 2025)