Wildmeshing Toolkit
CollapseAlternateFacetData.cpp
Go to the documentation of this file.
2 #include <array>
3 #include <vector>
4 #include <wmtk/Mesh.hpp>
5 #include <wmtk/autogen/Dart.hpp>
13 
15 namespace {
16 constexpr auto sort_op = [](const CollapseAlternateFacetData::Data& a,
17  const CollapseAlternateFacetData::Data& b) -> bool {
18  return a.input.global_id() < b.input.global_id();
19 };
20 constexpr auto sort_int_op = [](const CollapseAlternateFacetData::Data& value,
21  const int64_t& facet_id) -> bool {
22  return value.input.global_id() < facet_id;
23 };
24 } // namespace
25 
26 void CollapseAlternateFacetData::add(const Mesh& m, const Tuple& input_tuple)
27 {
28  m_data.emplace_back(m, input_tuple);
29  // first tuple is different from the input by switching everything but vertex
30  // second one is switch everything
31 }
32 
34 {
35  std::sort(m_data.begin(), m_data.end(), sort_op);
36 }
37 
38 
41 
42 auto CollapseAlternateFacetData::get_alternative_data_it(const int64_t& input_facet) const
43  -> AltData::const_iterator
44 {
45  assert(std::is_sorted(m_data.begin(), m_data.end(), sort_op));
46  auto it = std::lower_bound(m_data.begin(), m_data.end(), input_facet, sort_int_op);
47  auto end = m_data.cend();
48 
49  // if we found
50 
51  // fix case where the lower bound was not the target value
52  if (it != end && it->input.global_id() != input_facet) {
53  it = end;
54  }
55  return it;
56 }
58 {
59  auto it = get_alternative_data_it(t.m_global_cid);
60  assert(it != m_data.cend());
61  return *it;
62 }
64  const PrimitiveType mesh_pt,
65  const Tuple& t,
66  const PrimitiveType simplex_dimension) const
67 {
68  const auto& data = get_alternatives_data(t);
69 
71  const wmtk::autogen::Dart t_dart = sd.dart_from_tuple(t);
72 
73  const int8_t action =
74  wmtk::multimesh::utils::find_local_dart_action(mesh_pt, t_dart, data.input);
75  auto map = [&data](const size_t index) -> Tuple {
76  const wmtk::autogen::Dart& transform = data.alts[index];
77  const int8_t& local_boundary_index = data.local_boundary_indices[index];
78  // const PrimitiveType mappable_dart_dimension = a;
79  // if (transform.is_null() || mappable_dart_dimension < simplex_dimension) {
80  // return {};
81  // } else {
82  // int8_t projected_subdart = sd.convert(action, , mesh_pt - 1);
83  // int8_t mapped_dart = sd.product(tup.local_orientation(), action);
84  // const wmtk::autogen::Dart d(tup.global_id(), mapped_dart);
85  // return sd.tuple_from_dart(d);
86  // }
87  return {};
88  };
89 
90  std::array<Tuple, 2> r{{map(0), map(1)}};
91 
92  return r;
93 }
95  const PrimitiveType mesh_pt,
96  const Tuple& t,
97  const PrimitiveType pt) const
98 {
99  // TODO: map to a valid face
100 
101 
102  auto alts = get_alternatives(mesh_pt, t, pt);
103  assert(!alts[0].is_null() || !alts[1].is_null());
104  if (!alts[0].is_null()) {
105  return alts[0];
106  } else {
107  return alts[1];
108  }
109  return {};
110  //
111 }
112 } // namespace wmtk::operations::internal
static const SimplexDart & get_singleton(wmtk::PrimitiveType simplex_type)
Definition: SimplexDart.cpp:83
Dart dart_from_tuple(const wmtk::Tuple &t) const
AltData::const_iterator get_alternative_data_it(const int64_t &input_facet) const
std::array< Tuple, 2 > get_alternatives(const PrimitiveType mesh_pt, const Tuple &t, const PrimitiveType simplex_dimension) const
Tuple get_alternative(const PrimitiveType mesh_pt, const Tuple &t, const PrimitiveType simplex_dimension) const
int8_t find_local_dart_action(PrimitiveType pt, const Tuple &source, const Tuple &target)