From 15465031d2822e1f49db4a89d0e442140a70af7b Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Thu, 5 Oct 2023 09:51:20 -0400 Subject: [PATCH] updates to map_tuples to fix assert in debug + adding some comments --- src/wmtk/MultiMeshManager.cpp | 21 +++++++++++++++++---- src/wmtk/MultiMeshManager.hpp | 2 ++ tests/test_multi_mesh.cpp | 11 ++++++----- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/wmtk/MultiMeshManager.cpp b/src/wmtk/MultiMeshManager.cpp index 0d70448e76..15152ae6e1 100644 --- a/src/wmtk/MultiMeshManager.cpp +++ b/src/wmtk/MultiMeshManager.cpp @@ -192,19 +192,32 @@ std::vector MultiMeshManager::map_tuples( // bieng lazy about how i set cur_mesh to nullptr above - could simplify the loop to optimize cur_mesh = &get_root_mesh(other_mesh); + + + // note that (cur_mesh, tuples) always match (i.e tuples are tuples from cur_mesh) std::vector tuples; + tuples.emplace_back(cur_tuple); + for (auto it = other_id.rbegin(); it != other_id.rend(); ++it) { + // get the select ID from the child map long child_index = *it; - std::vector new_tuples; const ChildData& cd = cur_mesh->m_multi_mesh_manager.m_children.at(child_index); + + // for every tuple we have try to collect all versions + std::vector new_tuples; for (const Tuple& t : tuples) { + // get new tuples for every version that exists std::vector n = cur_mesh->m_multi_mesh_manager.map_to_child_tuples(*cur_mesh, cd, Simplex(pt, t)); + // append to teh current set of new tuples new_tuples.insert(new_tuples.end(), n.begin(), n.end()); } + // update teh (mesh,tuples) pair tuples = std::move(new_tuples); cur_mesh = cd.mesh.get(); - assert(cur_mesh->absolute_multi_mesh_id() == child_index); + + // the front id of the current mesh should be the child index from this iteration + assert(cur_mesh->m_multi_mesh_manager.m_child_id == child_index); } // visitor.map(equivalent_tuples, my_simplex.primitive_type()); @@ -421,10 +434,10 @@ std::vector> MultiMeshManager::same_simplex_dimension_surje for (long index = 0; index < size; ++index) { const Tuple ct = child.tuple_from_id(primitive_type, index); const Tuple pt = parent.tuple_from_id(primitive_type, parent_simplices.at(index)); - if (parent_flag_accessor.const_scalar_attribute(pt) & 1 == 0) { + if ((parent_flag_accessor.const_scalar_attribute(pt) & 1) == 0) { continue; } - if (child_flag_accessor.const_scalar_attribute(pt) & 1 == 0) { + if ((child_flag_accessor.const_scalar_attribute(pt) & 1) == 0) { continue; } diff --git a/src/wmtk/MultiMeshManager.hpp b/src/wmtk/MultiMeshManager.hpp index ad5b3d98dd..6eaf910d94 100644 --- a/src/wmtk/MultiMeshManager.hpp +++ b/src/wmtk/MultiMeshManager.hpp @@ -147,6 +147,8 @@ class MultiMeshManager const ConstAccessor& source_to_target_map_accessor, const Tuple& source_tuple); + const std::vector& children() const { return m_children; } + private: // this is defined internally but is preferablly invoked through the multimesh free function static std::vector> same_simplex_dimension_surjection( diff --git a/tests/test_multi_mesh.cpp b/tests/test_multi_mesh.cpp index d84a67c779..9bc96ac2de 100644 --- a/tests/test_multi_mesh.cpp +++ b/tests/test_multi_mesh.cpp @@ -1,6 +1,7 @@ #include #include +#include #include "tools/DEBUG_TriMesh.hpp" #include "tools/TriMesh_examples.hpp" @@ -20,17 +21,17 @@ TEST_CASE("test_register_child_mesh", "[multimesh][2D]") { DEBUG_TriMesh parent = two_neighbors(); std::shared_ptr child0_ptr = std::make_shared(single_triangle()); - std::vector child0_map = {0}; + auto child0_map = multimesh::same_simplex_dimension_surjection(*parent, *child0_ptr, {0}); std::shared_ptr child1_ptr = std::make_shared(one_ear()); - std::vector child1_map = {0, 1}; + auto child1_map = multimesh::same_simplex_dimension_surjection(*parent, *child1_ptr, {0, 1}); parent.register_child_mesh(child0_ptr, child0_map); parent.register_child_mesh(child1_ptr, child1_map); const auto& p_mul_manager = parent.multi_mesh_manager(); - REQUIRE(p_mul_manager.child_meshes.size() == 2); - REQUIRE(p_mul_manager.child_meshes[0] == child0_ptr); - REQUIRE(p_mul_manager.child_meshes[1] == child1_ptr); + REQUIRE(p_mul_manager.m_children.size() == 2); + REQUIRE(p_mul_manager.m_children[0] == child0_ptr); + REQUIRE(p_mul_manager.m_children[1] == child1_ptr); auto [tuple1, tuple2] = multimesh::utils::read_tuple_map_attribute_slow( p_mul_manager.map_to_child_handles[0],