3#ifndef DUNE_MMESH_GRID_COMMON_HH
4#define DUNE_MMESH_GRID_COMMON_HH
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);
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);
38 sort_indices(std::array<std::size_t, dim> ids) : ids_(ids) {}
40 bool operator()(std::size_t i, std::size_t j)
const {
41 return ids_[i] < ids_[j];
45 std::array<std::size_t, dim> ids_;
49template <
int dim,
typename ctype =
double>
50static inline auto&
ref() {
51 return ReferenceElements<ctype, dim>::simplex();
55template <
typename HostEntity,
int dim>
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;
62 std::sort(indices.begin(), indices.end(), sort_indices<dim + 1>(ids));
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) {
73 for (std::size_t k = 0; k < dim; ++k)
74 sum += cgalIndex[ref<dim>().subEntity(duneFacet, 1, k, dim)];
76 static constexpr int max = (dim == 2) ? 3 : 6;
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;
87 auto duneIndex = cgalIndex;
88 for (std::size_t k = 0; k < dim + 1; ++k) duneIndex[cgalIndex[k]] = k;
91 for (std::size_t k = 0; k < dim; ++k)
92 sum += duneIndex[(i + k + 1) % (dim + 1)];
94 static const int thr = (dim == 2) ? 1 : 3;
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;
104 const auto& cgalIndex = c->info().cgalIndex;
107 auto duneIndex = cgalIndex;
108 for (std::size_t k = 0; k < dim + 1; ++k) duneIndex[cgalIndex[k]] = k;
110 auto i0 = duneIndex[i];
111 auto j0 = duneIndex[j];
113 if (i0 > j0) std::swap(i0, j0);
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