Loading [MathJax]/extensions/MathZoom.js

dune-mmesh (1.4)

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