From 94b6e7a03d0eb97c2d6d29c6c4bed62b80dfcf4e Mon Sep 17 00:00:00 2001 From: zlyfunction Date: Thu, 19 Oct 2023 01:14:55 -0400 Subject: [PATCH 1/2] finish implementation for edge and traingle --- .../utils/find_local_switch_sequence.cpp | 94 +++++++++++++------ 1 file changed, 66 insertions(+), 28 deletions(-) diff --git a/src/wmtk/multimesh/utils/find_local_switch_sequence.cpp b/src/wmtk/multimesh/utils/find_local_switch_sequence.cpp index 393c50dc9a..ce781de9fe 100644 --- a/src/wmtk/multimesh/utils/find_local_switch_sequence.cpp +++ b/src/wmtk/multimesh/utils/find_local_switch_sequence.cpp @@ -1,45 +1,69 @@ #include "find_local_switch_sequence.hpp" +#include #include "local_switch_tuple.hpp" namespace wmtk::multimesh::utils { namespace { - -std::vector find_local_switch_sequence_trimesh( +std::pair> find_local_switch_sequence_on_edge( const Tuple& source, - const Tuple& target) + const Tuple& target, + const PrimitiveType mesh_pt) { - // TODO: assert that base_source and base_target use the same global CID + if (source == target) { + return {true, std::vector{}}; + } else if (local_switch_tuple(mesh_pt, source, PrimitiveType::Vertex) == target) { + return {true, std::vector{PrimitiveType::Vertex}}; + } + return {false, std::vector{}}; +} +std::pair> find_local_switch_sequence_on_triangle( + const Tuple& source, + const Tuple& target, + const PrimitiveType mesh_pt) +{ // circulate Tuple cur_tuple = source; std::vector switches; - auto try_and_record = [&](PrimitiveType pt) -> bool { - cur_tuple = local_switch_tuple(PrimitiveType::Face, cur_tuple, pt); - switches.emplace_back(pt); - return cur_tuple == target; - }; - for (long j = 0; j < 3; ++j) { - for (PrimitiveType pt : {PrimitiveType::Vertex, PrimitiveType::Edge}) { - if (try_and_record(pt)) { - return switches; - } + + { + auto [success, edge_local_operations] = + find_local_switch_sequence_on_edge(cur_tuple, target, mesh_pt); + if (success) { + return {true, edge_local_operations}; } } - throw "switch sequence was unable to find a sequence of switches to match tuples"; - return switches; -} -std::vector find_local_switch_sequence_edgemesh( - const Tuple& source, - const Tuple& target) -{ - if (source != target) { - return std::vector{PrimitiveType::Vertex}; - } else { - return std::vector{}; + switches.emplace_back(PrimitiveType::Edge); + cur_tuple = local_switch_tuples(mesh_pt, source, switches); + { + auto [success, edge_local_operations] = + find_local_switch_sequence_on_edge(cur_tuple, target, mesh_pt); + if (success) { + switches.insert( + switches.end(), + edge_local_operations.begin(), + edge_local_operations.end()); + return {true, switches}; + } } - throw "switch sequence was unable to find a sequence of switches to match tuples"; + + switches.insert(switches.begin(), PrimitiveType::Vertex); + cur_tuple = local_switch_tuples(mesh_pt, source, switches); + { + auto [success, edge_local_operations] = + find_local_switch_sequence_on_edge(cur_tuple, target, mesh_pt); + if (success) { + switches.insert( + switches.end(), + edge_local_operations.begin(), + edge_local_operations.end()); + return {true, switches}; + } + } + return {false, std::vector{}}; } + } // namespace // Maps the tuple source according to the operation sequence @@ -49,8 +73,22 @@ std::vector find_local_switch_sequence(const Tuple& source, const Tuple& target, PrimitiveType primitive_type) { switch (primitive_type) { - case PrimitiveType::Face: return find_local_switch_sequence_trimesh(source, target); - case PrimitiveType::Edge: return find_local_switch_sequence_edgemesh(source, target); + case PrimitiveType::Face: { + auto [success, operations] = + find_local_switch_sequence_on_triangle(source, target, PrimitiveType::Face); + if (!success) { + throw "switch sequence was unable to find a sequence of switches to match tuples"; + } + return operations; + } + case PrimitiveType::Edge: { + auto [success, operations] = + find_local_switch_sequence_on_edge(source, target, PrimitiveType::Edge); + if (!success) { + throw "switch sequence was unable to find a sequence of switches to match tuples"; + } + return operations; + } case PrimitiveType::Vertex: return {}; case PrimitiveType::Tetrahedron: default: return {}; From e99021df9ce3c0266c1bb96372b610fcede15824 Mon Sep 17 00:00:00 2001 From: zlyfunction Date: Thu, 19 Oct 2023 01:30:40 -0400 Subject: [PATCH 2/2] add implementation for tet --- .../utils/find_local_switch_sequence.cpp | 82 +++++++++++++++++-- 1 file changed, 76 insertions(+), 6 deletions(-) diff --git a/src/wmtk/multimesh/utils/find_local_switch_sequence.cpp b/src/wmtk/multimesh/utils/find_local_switch_sequence.cpp index ce781de9fe..0cc8e85bc1 100644 --- a/src/wmtk/multimesh/utils/find_local_switch_sequence.cpp +++ b/src/wmtk/multimesh/utils/find_local_switch_sequence.cpp @@ -1,5 +1,5 @@ #include "find_local_switch_sequence.hpp" -#include +#include #include "local_switch_tuple.hpp" namespace wmtk::multimesh::utils { @@ -10,6 +10,7 @@ std::pair> find_local_switch_sequence_on_edge( const Tuple& target, const PrimitiveType mesh_pt) { + assert(mesh_pt >= PrimitiveType::Edge); if (source == target) { return {true, std::vector{}}; } else if (local_switch_tuple(mesh_pt, source, PrimitiveType::Vertex) == target) { @@ -23,10 +24,10 @@ std::pair> find_local_switch_sequence_on_triang const Tuple& target, const PrimitiveType mesh_pt) { - // circulate + assert(mesh_pt >= PrimitiveType::Face); + Tuple cur_tuple = source; std::vector switches; - { auto [success, edge_local_operations] = find_local_switch_sequence_on_edge(cur_tuple, target, mesh_pt); @@ -64,6 +65,68 @@ std::pair> find_local_switch_sequence_on_triang return {false, std::vector{}}; } +std::pair> find_local_switch_sequence_on_tet( + const Tuple& source, + const Tuple& target, + const PrimitiveType mesh_pt) +{ + // TODO: test it in the future + throw "not tested yet"; + assert(mesh_pt == PrimitiveType::Tetrahedron); + Tuple cur_tuple = source; + std::vector switches; + + { + auto [success, triangle_local_operations] = + find_local_switch_sequence_on_triangle(cur_tuple, target, mesh_pt); + if (success) { + return {true, triangle_local_operations}; + } + } + switches.emplace_back(PrimitiveType::Face); + cur_tuple = local_switch_tuples(mesh_pt, source, switches); + { + auto [success, triangle_local_operations] = + find_local_switch_sequence_on_triangle(cur_tuple, target, mesh_pt); + if (success) { + switches.insert( + switches.end(), + triangle_local_operations.begin(), + triangle_local_operations.end()); + return {true, switches}; + } + } + + switches.insert(switches.begin(), PrimitiveType::Edge); + cur_tuple = local_switch_tuples(mesh_pt, source, switches); + { + auto [success, triangle_local_operations] = + find_local_switch_sequence_on_triangle(cur_tuple, target, mesh_pt); + if (success) { + switches.insert( + switches.end(), + triangle_local_operations.begin(), + triangle_local_operations.end()); + return {true, switches}; + } + } + + switches.insert(switches.begin(), PrimitiveType::Vertex); + cur_tuple = local_switch_tuples(mesh_pt, source, switches); + { + auto [success, triangle_local_operations] = + find_local_switch_sequence_on_triangle(cur_tuple, target, mesh_pt); + if (success) { + switches.insert( + switches.end(), + triangle_local_operations.begin(), + triangle_local_operations.end()); + return {true, switches}; + } + } + return {false, std::vector{}}; +} + } // namespace // Maps the tuple source according to the operation sequence @@ -73,6 +136,14 @@ std::vector find_local_switch_sequence(const Tuple& source, const Tuple& target, PrimitiveType primitive_type) { switch (primitive_type) { + case PrimitiveType::Edge: { + auto [success, operations] = + find_local_switch_sequence_on_edge(source, target, PrimitiveType::Edge); + if (!success) { + throw "switch sequence was unable to find a sequence of switches to match tuples"; + } + return operations; + } case PrimitiveType::Face: { auto [success, operations] = find_local_switch_sequence_on_triangle(source, target, PrimitiveType::Face); @@ -81,16 +152,15 @@ find_local_switch_sequence(const Tuple& source, const Tuple& target, PrimitiveTy } return operations; } - case PrimitiveType::Edge: { + case PrimitiveType::Tetrahedron: { auto [success, operations] = - find_local_switch_sequence_on_edge(source, target, PrimitiveType::Edge); + find_local_switch_sequence_on_tet(source, target, PrimitiveType::Tetrahedron); if (!success) { throw "switch sequence was unable to find a sequence of switches to match tuples"; } return operations; } case PrimitiveType::Vertex: return {}; - case PrimitiveType::Tetrahedron: default: return {}; } }