Wildmeshing Toolkit
SplitAlternateFacetData.cpp
Go to the documentation of this file.
2 #include <algorithm>
3 #include <array>
4 #include <cassert>
5 #include <vector>
6 #include <wmtk/Mesh.hpp>
10 #include "ear_actions.hpp"
12 namespace {
13 auto sort_op = [](const SplitAlternateFacetData::Data& a,
14  const SplitAlternateFacetData::Data& b) -> bool {
15  return a.input.global_id() < b.input.global_id();
16 };
17 
18 auto sort_int_op = [](const SplitAlternateFacetData::Data& value, const int64_t& facet_id) -> bool {
19  return value.input.global_id() < facet_id;
20 };
21 } // namespace
22 
24 {
25  std::sort(m_facet_maps.begin(), m_facet_maps.end(), sort_op);
26 }
27 
28 // assumes the split cell map has been sorted
29 auto SplitAlternateFacetData::get_alternative_facets_it(const int64_t& input_cell) const
30  -> AltData::const_iterator
31 {
32  assert(std::is_sorted(m_facet_maps.begin(), m_facet_maps.end(), sort_op));
33 
34 
35  auto it = std::lower_bound(m_facet_maps.begin(), m_facet_maps.end(), input_cell, sort_int_op);
36  auto end = m_facet_maps.cend();
37  // fix case where the lower bound was not the target value
38  if (it != end && it->input.global_id() != input_cell) {
39  it = end;
40  }
41  return it;
42 }
44  -> const Data&
45 {
46  const PrimitiveType pt = mesh.top_simplex_type();
47  const std::vector<int64_t> new_eids = EdgeOperationData::request_simplex_indices(mesh, pt, 2);
48  std::array<int64_t,2> dat;
49  std::copy(new_eids.begin(),new_eids.end(),dat.begin());
50  return add_facet(mesh, edge_tuple,dat);
51 }
52 auto SplitAlternateFacetData::add_facet(const wmtk::Mesh& mesh, const wmtk::Tuple& edge_tuple, const std::array<int64_t,2>& nfa)
53  -> const Data&
54 {
55  const PrimitiveType mesh_pt = mesh.top_simplex_type();
56  const auto& sd = wmtk::autogen::SimplexDart::get_singleton(mesh_pt);
57  return m_facet_maps.emplace_back(sd.dart_from_tuple(edge_tuple), nfa);
58 }
59 
60 auto SplitAlternateFacetData::get_alternative_facets(const int64_t& input_cell) const
61  -> const std::array<int64_t, 2>&
62 {
63  auto it = get_alternative_facets_it(input_cell);
64  assert(it != m_facet_maps.cend());
65  return it->new_facet_indices;
66 }
68  const PrimitiveType mesh_pt,
69  const Tuple& t,
70  const PrimitiveType simplex_dimension) const -> Tuple
71 {
72  assert(mesh_pt > PrimitiveType::Vertex);
73  const auto alts_it = get_alternative_facets_it(wmtk::utils::TupleInspector::global_cid(t));
74  assert(alts_it != m_facet_maps.end());
75 
76  const auto& sd = wmtk::autogen::SimplexDart::get_singleton(mesh_pt);
77 
78  int64_t new_global_cid = alts_it->new_gid(mesh_pt, sd.valid_index_from_tuple(t));
79 
80 
81  return {
85  new_global_cid};
86 }
87 } // namespace wmtk::operations::internal
static const SimplexDart & get_singleton(wmtk::PrimitiveType simplex_type)
Definition: SimplexDart.cpp:83
static std::vector< int64_t > request_simplex_indices(Mesh &mesh, const PrimitiveType type, int64_t count)
Tuple get_alternative(const PrimitiveType mesh_pt, const Tuple &t, const PrimitiveType simplex_dimension) const
const Data & add_facet(const wmtk::Mesh &mesh, const wmtk::Tuple &edge_tuple, const std::array< int64_t, 2 > &new_facet_indices)
const std::array< int64_t, 2 > & get_alternative_facets(const int64_t &input_facet) const
AltData::const_iterator get_alternative_facets_it(const int64_t &input_facet) const
static int8_t local_eid(const Tuple &t)
static int64_t global_cid(const Tuple &t)
static int8_t local_vid(const Tuple &t)
static int8_t local_fid(const Tuple &t)