Wildmeshing Toolkit
SimplexDart.cpp
Go to the documentation of this file.
1 #include "SimplexDart.hpp"
2 #include <cassert>
7 #include "subgroup/convert.hpp"
12 
13 namespace wmtk::autogen {
14 namespace {
15 
16 
17 /*
18 int8_t empty_binary(int8_t,int8_t){
19  assert(false);
20 }
21 
22 int8_t empty_unary(int8_t){
23  assert(false);
24 }
25 int8_t empty_unary(){
26  assert(false);
27 }
28 
29 template <typename T>
30  void f();
31 
32 template <typename
33  */
34 
35 
36 #define GET_OP(NAME, RETTYPE) \
37  auto get_##NAME(PrimitiveType pt)->SimplexDart::RETTYPE \
38  { \
39  switch (pt) { \
40  case PrimitiveType::Edge: return &edge_mesh::SimplexDart::NAME; \
41  case PrimitiveType::Triangle: return &tri_mesh::SimplexDart::NAME; \
42  case PrimitiveType::Tetrahedron: return &tet_mesh::SimplexDart::NAME; \
43  case PrimitiveType::Vertex: return &point_mesh::SimplexDart::NAME; \
44  default: assert(false); \
45  } \
46  return nullptr; \
47  }
48 GET_OP(product, binary_op_type)
49 GET_OP(inverse, unary_op_type)
50 GET_OP(primitive_to_index, primitive_to_index_type)
51 GET_OP(identity, nullary_op_type)
52 GET_OP(opposite, nullary_op_type)
53 } // namespace
54 
55 #define FORWARD_OP(NAME, OP, RETTYPE, DEFAULT) \
56  auto SimplexDart::NAME() const -> RETTYPE \
57  { \
58  switch (m_simplex_type) { \
59  case PrimitiveType::Edge: return edge_mesh::SimplexDart::OP(); \
60  case PrimitiveType::Triangle: return tri_mesh::SimplexDart::OP(); \
61  case PrimitiveType::Tetrahedron: return tet_mesh::SimplexDart::OP(); \
62  case PrimitiveType::Vertex: return point_mesh::SimplexDart::OP(); \
63  default: assert(false); \
64  } \
65  return DEFAULT; \
66  }
67 
68 FORWARD_OP(size, size, size_t, {})
70 namespace {
71 const static DynamicIntMap nullmap = DynamicIntMap(nullptr, 0);
72 }
73 FORWARD_OP(valid_indices, valid_indices_dynamic, DynamicIntMap, nullmap)
74 
76  : m_simplex_type(simplex_type)
77  , m_product(get_product(simplex_type))
78  , m_inverse(get_inverse(simplex_type))
79  , m_primitive_to_index(get_primitive_to_index(simplex_type))
80  , m_identity(get_identity(simplex_type))
81  , m_opposite(get_opposite(simplex_type))
82 {}
84 {
85  const static std::array<SimplexDart, 4> singletons = {
90  return singletons[get_primitive_type_id(simplex_type)];
91 }
92 
93 int8_t SimplexDart::product(int8_t a, int8_t b) const
94 {
95  return m_product(a, b);
96 }
97 int8_t SimplexDart::inverse(int8_t a) const
98 {
99  return m_inverse(a);
100 }
101 Dart SimplexDart::act(const Dart& d, int8_t action) const
102 {
103  return Dart(d.global_id(), product(action, d.local_orientation()));
104 }
105 
107 {
108  return m_primitive_to_index(pt);
109 }
110 int8_t SimplexDart::identity() const
111 {
112  return m_identity();
113 }
114 int8_t SimplexDart::opposite() const
115 {
116  return m_opposite();
117 }
118 wmtk::Tuple SimplexDart::tuple_from_valid_index(int64_t gid, int8_t index) const
119 {
121 }
123 {
127  index);
128 }
130 {
132 }
133 
134 int8_t SimplexDart::convert(int8_t valid_index, const SimplexDart& target) const
135 {
136  if (target.m_simplex_type == PrimitiveType::Vertex) {
137  return 0;
138  } else if (m_simplex_type == PrimitiveType::Vertex) {
139  return target.identity();
140  } else {
141  return subgroup::convert(m_simplex_type, target.m_simplex_type, valid_index);
142  }
143 }
144 
146 {
147  return tuple_from_valid_index(dart.global_id(), dart.local_orientation());
148 }
150 {
151  return Dart{
154 }
155 
156 int8_t SimplexDart::simplex_index(const Dart& dart, PrimitiveType simplex_type) const
157 {
159 }
160  int8_t SimplexDart::simplex_index(const int8_t valid_index, PrimitiveType simplex_type) const {
162  }
163 } // namespace wmtk::autogen
164 
#define GET_OP(NAME, RETTYPE)
Definition: SimplexDart.cpp:36
#define FORWARD_OP(NAME, OP, RETTYPE, DEFAULT)
Definition: SimplexDart.cpp:55
int8_t & local_orientation()
Definition: Dart.hpp:18
int64_t & global_id()
Definition: Dart.hpp:15
const nullary_op_type m_identity
Definition: SimplexDart.hpp:65
wmtk::Tuple tuple_from_dart(const Dart &dart) const
int8_t simplex_index(const int8_t valid_index, PrimitiveType simplex_type) const
int8_t valid_index_from_tuple(const wmtk::Tuple &t) const
const wmtk::PrimitiveType m_simplex_type
Definition: SimplexDart.hpp:61
static const SimplexDart & get_singleton(wmtk::PrimitiveType simplex_type)
Definition: SimplexDart.cpp:83
const unary_op_type m_inverse
Definition: SimplexDart.hpp:63
SimplexDart(wmtk::PrimitiveType simplex_type)
Definition: SimplexDart.cpp:75
wmtk::Tuple update_tuple_from_valid_index(const Tuple &t, int8_t valid_index) const
wmtk::PrimitiveType simplex_type() const
Definition: SimplexDart.hpp:58
const primitive_to_index_type m_primitive_to_index
Definition: SimplexDart.hpp:64
const binary_op_type m_product
Definition: SimplexDart.hpp:62
int8_t primitive_as_index(wmtk::PrimitiveType pt) const
int8_t inverse(int8_t a) const
Definition: SimplexDart.cpp:97
int8_t product(int8_t a, int8_t b) const
Definition: SimplexDart.cpp:93
const nullary_op_type m_opposite
Definition: SimplexDart.hpp:66
Dart act(const Dart &d, int8_t action) const
Dart dart_from_tuple(const wmtk::Tuple &t) const
int8_t convert(int8_t valid_index, const SimplexDart &target) const
wmtk::Tuple tuple_from_valid_index(int64_t gid, int8_t valid_index) const
static int64_t global_cid(const Tuple &t)
int8_t convert(PrimitiveType from, PrimitiveType to, int8_t source)
Definition: convert.hxx:8
int8_t simplex_index_from_valid_index(PrimitiveType mesh_type, int8_t valid_tuple_index, PrimitiveType simplex_type)
int8_t valid_index_from_tuple(PrimitiveType mesh_type, const Tuple &t)
Tuple tuple_from_valid_index(PrimitiveType mesh_type, const int64_t global_cid, int8_t valid_tuple_index)
VectorX< int8_t >::ConstMapType DynamicIntMap
Definition: SimplexDart.cpp:69
Definition: Accessor.hpp:6
constexpr int8_t get_primitive_type_id(PrimitiveType t)
Get a unique integer id corresponding to each primitive type.
Vector< T, Eigen::Dynamic > VectorX
Definition: Types.hpp:19