From 4dcd1ef487321f2460fa3ee191b6a4ea2aae15b2 Mon Sep 17 00:00:00 2001 From: zlyfunction Date: Thu, 19 Oct 2023 13:02:24 -0400 Subject: [PATCH] in map_tuple_between_meshes, make sure that source_mesh_base_tuple and source_mesh_target_tuple has the same global_cid --- src/wmtk/MultiMeshManager.cpp | 23 ++++- src/wmtk/multimesh/utils/transport_tuple.cpp | 13 +-- tests/test_multi_mesh.cpp | 93 ++++++++++---------- 3 files changed, 71 insertions(+), 58 deletions(-) diff --git a/src/wmtk/MultiMeshManager.cpp b/src/wmtk/MultiMeshManager.cpp index 9ffb18bd28..de80742fd0 100644 --- a/src/wmtk/MultiMeshManager.cpp +++ b/src/wmtk/MultiMeshManager.cpp @@ -19,7 +19,7 @@ Tuple MultiMeshManager::map_tuple_between_meshes( PrimitiveType target_mesh_primitive_type = target_mesh.top_simplex_type(); PrimitiveType min_primitive_type = std::min(source_mesh_primitive_type, target_mesh_primitive_type); - + Tuple source_mesh_target_tuple = source_tuple; const auto [source_mesh_base_tuple, target_mesh_base_tuple] = multimesh::utils::read_tuple_map_attribute(map_accessor, source_tuple); @@ -27,12 +27,31 @@ Tuple MultiMeshManager::map_tuple_between_meshes( return Tuple(); // return null tuple } + if (source_mesh_base_tuple.m_global_cid != source_mesh_target_tuple.m_global_cid) { + assert(source_mesh_primitive_type > target_mesh_primitive_type); + const std::vector equivalent_tuples = simplex::top_level_cofaces_tuples( + source_mesh, + Simplex(target_mesh_primitive_type, source_tuple)); + for (const Tuple& t : equivalent_tuples) { + if (t.m_global_cid == source_mesh_base_tuple.m_global_cid) { + source_mesh_target_tuple = t; + break; + } + } + // return target_mesh_base_tuple; + } + + assert( + source_mesh_base_tuple.m_global_cid == + source_mesh_target_tuple + .m_global_cid); // make sure that local tuple operations will find a valid sequence + // we want to repeat switches from source_base_tuple -> source_tuple to // target_base _tuple -> return value // return multimesh::utils::transport_tuple( source_mesh_base_tuple, - source_tuple, + source_mesh_target_tuple, source_mesh_primitive_type, target_mesh_base_tuple, target_mesh_primitive_type); diff --git a/src/wmtk/multimesh/utils/transport_tuple.cpp b/src/wmtk/multimesh/utils/transport_tuple.cpp index ec52cd607c..76d2785241 100644 --- a/src/wmtk/multimesh/utils/transport_tuple.cpp +++ b/src/wmtk/multimesh/utils/transport_tuple.cpp @@ -1,4 +1,5 @@ #include "transport_tuple.hpp" +#include #include "find_local_switch_sequence.hpp" #include "local_switch_tuple.hpp" @@ -11,14 +12,8 @@ Tuple transport_tuple( const Tuple& source, PrimitiveType primitive_type) { - if (base_primitive_type <= primitive_type) { - std::vector operations = - find_local_switch_sequence(base_source, base_target, base_primitive_type); - return local_switch_tuples(primitive_type, source, operations); - } else { - // TODO: implement this - // in top_level_cofaces find the one with the same - return Tuple(); - } + std::vector operations = + find_local_switch_sequence(base_source, base_target, base_primitive_type); + return local_switch_tuples(primitive_type, source, operations); } } // namespace wmtk::multimesh::utils diff --git a/tests/test_multi_mesh.cpp b/tests/test_multi_mesh.cpp index 051763b391..8da3dad4b0 100644 --- a/tests/test_multi_mesh.cpp +++ b/tests/test_multi_mesh.cpp @@ -376,53 +376,52 @@ TEST_CASE("multi_mesh_register_between_2D_and_1D", "[multimesh][1D][2D]") } // test map_to_child_tuples and map_to_parent_tuple - // TODO: this will fail before getting local_switch_tuple for EdgeMesh Working. - // { - // std::vector p_to_c0_map{child0.tuple_from_id(PE, 0), Tuple(), Tuple()}; - - // std::vector p_to_c1_map{ - // child1.tuple_from_id(PE, 0), - // Tuple(), - // child1.tuple_from_id(PE, 1)}; - - // std::vector c0_to_p_map{parent.tuple_from_id(PE, 0)}; - - // std::vector c1_to_p_map{ - // parent.tuple_from_id(PE, 0), - // parent.tuple_from_id(PE, 2)}; - - - // for (long parent_index = 0; parent_index < 3; ++parent_index) { - // auto ptuple = parent.tuple_from_id(PE, parent_index); - // Simplex psimplex = Simplex(PE, ptuple); - - // Tuple c0_expected = p_to_c0_map[parent_index]; - // if (!c0_expected.is_null()) { - // auto c0tuples = parent.map_to_child_tuples(child0, psimplex); - // REQUIRE(c0tuples.size() == 1); - // CHECK(c0tuples[0] == c0_expected); - // } - - // Tuple c1_expected = p_to_c1_map[parent_index]; - // if (!c1_expected.is_null()) { - // auto c1tuples = parent.map_to_child_tuples(child1, psimplex); - // REQUIRE(c1tuples.size() == 1); - // CHECK(c1tuples[0] == c1_expected); - // } - // } - // for (size_t child0_index = 0; child0_index < c0_to_p_map.size(); ++child0_index) { - // auto tuple = child0.tuple_from_id(PE, child0_index); - // Simplex csimplex = Simplex(PE, tuple); - // auto ptuple = child0.map_to_parent_tuple(csimplex); - // CHECK(ptuple == c0_to_p_map[child0_index]); - // } - // for (size_t child1_index = 0; child1_index < c1_to_p_map.size(); ++child1_index) { - // auto tuple = child1.tuple_from_id(PE, child1_index); - // Simplex csimplex = Simplex(PE, tuple); - // auto ptuple = child1.map_to_parent_tuple(csimplex); - // CHECK(ptuple == c1_to_p_map[child1_index]); - // } - // } + { + std::vector p_to_c0_map{child0.tuple_from_id(PE, 0), Tuple(), Tuple()}; + + std::vector p_to_c1_map{ + child1.tuple_from_id(PE, 0), + Tuple(), + child1.tuple_from_id(PE, 1)}; + + std::vector c0_to_p_map{parent.tuple_from_id(PE, 0)}; + + std::vector c1_to_p_map{ + parent.tuple_from_id(PE, 0), + parent.tuple_from_id(PE, 2)}; + + + for (long parent_index = 0; parent_index < 3; ++parent_index) { + auto ptuple = parent.tuple_from_id(PE, parent_index); + Simplex psimplex = Simplex(PE, ptuple); + + Tuple c0_expected = p_to_c0_map[parent_index]; + if (!c0_expected.is_null()) { + auto c0tuples = parent.map_to_child_tuples(child0, psimplex); + REQUIRE(c0tuples.size() == 1); + CHECK(c0tuples[0] == c0_expected); + } + + Tuple c1_expected = p_to_c1_map[parent_index]; + if (!c1_expected.is_null()) { + auto c1tuples = parent.map_to_child_tuples(child1, psimplex); + REQUIRE(c1tuples.size() == 1); + CHECK(c1tuples[0] == c1_expected); + } + } + for (size_t child0_index = 0; child0_index < c0_to_p_map.size(); ++child0_index) { + auto tuple = child0.tuple_from_id(PE, child0_index); + Simplex csimplex = Simplex(PE, tuple); + auto ptuple = child0.map_to_parent_tuple(csimplex); + CHECK(ptuple == c0_to_p_map[child0_index]); + } + for (size_t child1_index = 0; child1_index < c1_to_p_map.size(); ++child1_index) { + auto tuple = child1.tuple_from_id(PE, child1_index); + Simplex csimplex = Simplex(PE, tuple); + auto ptuple = child1.map_to_parent_tuple(csimplex); + CHECK(ptuple == c1_to_p_map[child1_index]); + } + } } }