Wildmeshing Toolkit
MapValidator.cpp
Go to the documentation of this file.
1 
2 #include "MapValidator.hpp"
3 #include <wmtk/Mesh.hpp>
7 #include <wmtk/utils/Logger.hpp>
10 namespace wmtk::multimesh::utils {
11 
13  : m_mesh(m)
14 {}
16 {
17  bool ok = true;
20  if (!ok) {
21  return ok;
22  }
24 
25  return ok;
26 }
27 
29 {
30  bool ok = true;
31  for (const auto& [cptr, attr] : m_mesh.m_multi_mesh_manager.m_children) {
32  const auto& child = *cptr;
33  auto map_accessor = m_mesh.create_const_accessor(attr);
34 
35  for (int64_t j = 0; j < child.top_cell_dimension(); ++j) {
37 
38  for (const auto& pt : m_mesh.get_all(prim_type)) {
39  wmtk::simplex::Simplex s(m_mesh, prim_type, pt);
40 
42 
43  for (const auto& source_tuple : tups) {
44  const auto [source_mesh_base_tuple, target_mesh_base_tuple] =
45  multimesh::utils::read_tuple_map_attribute(map_accessor, source_tuple);
46  if (source_mesh_base_tuple.is_null() || target_mesh_base_tuple.is_null()) {
47  if (source_mesh_base_tuple.is_null() && target_mesh_base_tuple.is_null()) {
48  ok = false;
49  wmtk::logger().error(
50  "Map from parent {} to child {} on tuple {} (dim {}) fails on {} "
51  "or "
52  "{} null",
53  fmt::join(m_mesh.absolute_multi_mesh_id(), ","),
54  fmt::join(child.absolute_multi_mesh_id(), ","),
55  j,
57  wmtk::utils::TupleInspector::as_string(source_mesh_base_tuple),
58  wmtk::utils::TupleInspector::as_string(target_mesh_base_tuple)
59 
60  );
61  }
62  } else if (!child.is_valid(target_mesh_base_tuple)) {
63  wmtk::logger().error(
64  "Map from parent {} to child {} on tuple {} (dim {}) fails on {} -> "
65  "{}",
66  fmt::join(m_mesh.absolute_multi_mesh_id(), ","),
67  fmt::join(child.absolute_multi_mesh_id(), ","),
68  j,
70  wmtk::utils::TupleInspector::as_string(source_mesh_base_tuple),
71  wmtk::utils::TupleInspector::as_string(target_mesh_base_tuple)
72 
73  );
74  ok = false;
75  }
76  }
77  }
78  }
79  }
80  return ok;
81 }
82 
84 {
85  bool ok = true;
86  const auto& parent_ptr = m_mesh.m_multi_mesh_manager.m_parent;
87  if (parent_ptr == nullptr) {
88  return true;
89  }
91  const auto& parent = *parent_ptr;
92  auto map_accessor = m_mesh.create_const_accessor(attr);
93 
95 
96  for (const auto& source_tuple : m_mesh.get_all(prim_type)) {
97  const auto [source_mesh_base_tuple, target_mesh_base_tuple] =
98  multimesh::utils::read_tuple_map_attribute(map_accessor, source_tuple);
99  if (source_mesh_base_tuple.is_null() || target_mesh_base_tuple.is_null()) {
100  wmtk::logger().error(
101  "Map from child {} to parent {} on tuple {} (dim {}) has null entry {} -> "
102  "{}",
103  fmt::join(m_mesh.absolute_multi_mesh_id(), ","),
104  fmt::join(parent.absolute_multi_mesh_id(), ","),
107  wmtk::utils::TupleInspector::as_string(source_mesh_base_tuple),
108  wmtk::utils::TupleInspector::as_string(target_mesh_base_tuple)
109 
110  );
111  ok = false;
112  } else if (!parent.is_valid(target_mesh_base_tuple)) {
113  wmtk::logger().error(
114  "Map from child {} to parent {} on tuple {} (dim {}) fails on {} -> "
115  "{}",
116  fmt::join(m_mesh.absolute_multi_mesh_id(), ","),
117  fmt::join(parent.absolute_multi_mesh_id(), ","),
120  wmtk::utils::TupleInspector::as_string(source_mesh_base_tuple),
121  wmtk::utils::TupleInspector::as_string(target_mesh_base_tuple)
122 
123  );
124  ok = false;
125  }
126  }
127  return ok;
128 }
129 
130 
132 {
133  bool ok = true;
134  for (const auto& cptr : m_mesh.get_child_meshes()) {
135  ok &= check_child_switch_homomorphism(*cptr);
136  }
137  return ok;
138 }
140 {
141  assert(child.m_multi_mesh_manager.m_parent == &m_mesh);
142  bool ok = true;
144  auto tups = child.get_all(pt);
145  for (const wmtk::Tuple& t : tups) {
146  wmtk::simplex::Simplex s(child, pt, t);
147 
148  wmtk::Tuple parent_tuple = child.map_to_parent_tuple(s);
150  // skip switches over boundaries
151  if (spt == pt &&
152  child.is_boundary(wmtk::PrimitiveType(child.top_cell_dimension() - 1), t)) {
153  continue;
154  }
155 
156  wmtk::simplex::Simplex switched_simplex(child, pt, m_mesh.switch_tuple(t, pt));
157  wmtk::Tuple switch_map = child.map_to_parent_tuple(switched_simplex);
158  wmtk::Tuple map_switch = m_mesh.switch_tuple(parent_tuple, pt);
161  m_mesh,
162  my_pt,
163  switch_map,
164  map_switch);
165  if (!worked) {
166  wmtk::logger().error(
167  "Map from child {0} to parent {1} on tuple {2} (dim {3}) fails on "
168  "switch(map({2}),{4}) = {5} != "
169  "map(switch({2},{4})) = {6} (dim {7} id {8} != {9})",
170  fmt::join(child.absolute_multi_mesh_id(), ","), // 0
171  fmt::join(m_mesh.absolute_multi_mesh_id(), ","), // 1
173  child.top_cell_dimension(), // 3
174  primitive_type_name(pt), // 4
177  primitive_type_name(my_pt), // 7
178  m_mesh.id(map_switch, my_pt), // 8
179  m_mesh.id(switch_map, my_pt) // 9
180  );
181  ok = false;
182  }
183  }
184  }
185  }
186  }
187  return ok;
188 }
189 
190 
191 } // namespace wmtk::multimesh::utils
std::vector< int64_t > absolute_multi_mesh_id() const
returns a unique identifier for this mesh within a single multimesh structure
const attribute::Accessor< T, Mesh, D > create_const_accessor(const attribute::MeshAttributeHandle &handle) const
int64_t id(const Tuple &tuple, PrimitiveType type) const
return the global id of the Tuple of the given dimension
Definition: Mesh.hpp:1020
bool is_boundary(const simplex::Simplex &tuple) const
check if a simplex lies on a boundary or not
Definition: Mesh.cpp:106
std::vector< Tuple > get_all(PrimitiveType type) const
Generate a vector of Tuples from global vertex/edge/triangle/tetrahedron index.
Definition: Mesh.cpp:18
multimesh::MultiMeshManager m_multi_mesh_manager
Definition: Mesh.hpp:841
int64_t top_cell_dimension() const
Definition: Mesh.hpp:992
virtual Tuple switch_tuple(const Tuple &tuple, PrimitiveType type) const =0
switch the orientation of the Tuple of the given dimension
Tuple map_to_parent_tuple(const simplex::Simplex &my_simplex) const
optimized map from a simplex from this mesh to its direct parent
PrimitiveType top_simplex_type() const
Definition: Mesh.hpp:996
std::vector< std::shared_ptr< Mesh > > get_child_meshes() const
returns the direct multimesh child meshes for the current mesh
std::vector< ChildData > m_children
TypedAttributeHandle< int64_t > map_to_parent_handle
bool check_child_switch_homomorphism(const Mesh &child) const
static bool equal(const Mesh &m, const Simplex &s0, const Simplex &s1)
static std::string as_string(const Tuple &t)
std::tuple< Tuple, Tuple > read_tuple_map_attribute(const wmtk::attribute::Accessor< int64_t, MeshType > &accessor, const Tuple &source_tuple)
void top_dimension_cofaces_tuples(const PointMesh &mesh, const Simplex &simplex, SimplexCollection &collection)
std::vector< PrimitiveType > primitive_below(PrimitiveType pt, bool lower_to_upper)
std::string_view primitive_type_name(PrimitiveType t)
spdlog::logger & logger()
Retrieves the current logger.
Definition: Logger.cpp:58