From c7cfccf045ba83e60aab8832cf0a150d74bbc039 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Wed, 4 Dec 2024 21:06:55 -0500 Subject: [PATCH] fixing and adding unit tests for tuple_from_id unit etsts --- .../edge_mesh/get_tuple_from_simplex_local_id.hpp | 6 ++++-- .../tet_mesh/get_tuple_from_simplex_local_id.hpp | 10 +++++----- .../tri_mesh/get_tuple_from_simplex_local_id.hpp | 6 +++--- tests/autogen/tables.cpp | 9 +++++---- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/wmtk/autogen/edge_mesh/get_tuple_from_simplex_local_id.hpp b/src/wmtk/autogen/edge_mesh/get_tuple_from_simplex_local_id.hpp index af6fa7b9c6..9abf1914d0 100644 --- a/src/wmtk/autogen/edge_mesh/get_tuple_from_simplex_local_id.hpp +++ b/src/wmtk/autogen/edge_mesh/get_tuple_from_simplex_local_id.hpp @@ -8,12 +8,14 @@ namespace wmtk::autogen::edge_mesh { -inline Tuple get_tuple_from_simplex_local_vertex_id(int8_t local_id, int64_t global_id = -1) +inline Tuple get_tuple_from_simplex_local_vertex_id(int8_t local_id, int64_t global_id = 0) { + assert(local_id >= 0); + assert(local_id < 2); return Tuple(local_id, -1, -1, global_id); } inline Tuple -get_tuple_from_simplex_local_id(PrimitiveType pt, int8_t local_id, int64_t global_fid = -1) +get_tuple_from_simplex_local_id(PrimitiveType pt, int8_t local_id, int64_t global_fid = 0) { switch (pt) { case PrimitiveType::Vertex: return get_tuple_from_simplex_local_vertex_id(local_id, global_fid); diff --git a/src/wmtk/autogen/tet_mesh/get_tuple_from_simplex_local_id.hpp b/src/wmtk/autogen/tet_mesh/get_tuple_from_simplex_local_id.hpp index e7697d1a50..80d6245ec0 100644 --- a/src/wmtk/autogen/tet_mesh/get_tuple_from_simplex_local_id.hpp +++ b/src/wmtk/autogen/tet_mesh/get_tuple_from_simplex_local_id.hpp @@ -10,7 +10,7 @@ namespace wmtk::autogen::tet_mesh { /* namespace { template -inline Tuple get_tuple_from_simplex_local_id_T(int8_t local_id, int64_t global_id = -1) +inline Tuple get_tuple_from_simplex_local_id_T(int8_t local_id, int64_t global_id = 0) { const auto& arr = autogen::tet_mesh::auto_3d_table_complete_edge[local_id]; assert(arr[Dim] == local_id); @@ -28,7 +28,7 @@ return tuple; } // namespace */ -inline Tuple get_tuple_from_simplex_local_vertex_id(int8_t local_id, int64_t global_id = -1) +inline Tuple get_tuple_from_simplex_local_vertex_id(int8_t local_id, int64_t global_id = 0) { const auto& arr = autogen::tet_mesh::auto_3d_table_complete_vertex[local_id]; const auto& [lvid, leid, lfid] = arr; @@ -43,7 +43,7 @@ inline Tuple get_tuple_from_simplex_local_vertex_id(int8_t local_id, int64_t glo assert(is_ccw(tuple)); // is_ccw also checks for validity return tuple; } -inline Tuple get_tuple_from_simplex_local_edge_id(int8_t local_id, int64_t global_id = -1) +inline Tuple get_tuple_from_simplex_local_edge_id(int8_t local_id, int64_t global_id = 0) { const auto& arr = autogen::tet_mesh::auto_3d_table_complete_edge[local_id]; const auto& [lvid, leid, lfid] = arr; @@ -58,7 +58,7 @@ inline Tuple get_tuple_from_simplex_local_edge_id(int8_t local_id, int64_t globa assert(is_ccw(tuple)); // is_ccw also checks for validity return tuple; } -inline Tuple get_tuple_from_simplex_local_face_id(int8_t local_id, int64_t global_id = -1) +inline Tuple get_tuple_from_simplex_local_face_id(int8_t local_id, int64_t global_id = 0) { const auto& arr = autogen::tet_mesh::auto_3d_table_complete_face[local_id]; const auto& [lvid, leid, lfid] = arr; @@ -74,7 +74,7 @@ inline Tuple get_tuple_from_simplex_local_face_id(int8_t local_id, int64_t globa return tuple; } inline Tuple -get_tuple_from_simplex_local_id(PrimitiveType pt, int8_t local_id, int64_t global_fid = -1) +get_tuple_from_simplex_local_id(PrimitiveType pt, int8_t local_id, int64_t global_fid = 0) { switch (pt) { case PrimitiveType::Vertex: return get_tuple_from_simplex_local_vertex_id(local_id, global_fid); diff --git a/src/wmtk/autogen/tri_mesh/get_tuple_from_simplex_local_id.hpp b/src/wmtk/autogen/tri_mesh/get_tuple_from_simplex_local_id.hpp index 0776db71a3..13c28586f3 100644 --- a/src/wmtk/autogen/tri_mesh/get_tuple_from_simplex_local_id.hpp +++ b/src/wmtk/autogen/tri_mesh/get_tuple_from_simplex_local_id.hpp @@ -7,7 +7,7 @@ #endif namespace wmtk::autogen::tri_mesh { - inline Tuple get_tuple_from_simplex_local_vertex_id(int8_t local_id, int64_t global_fid = -1) { + inline Tuple get_tuple_from_simplex_local_vertex_id(int8_t local_id, int64_t global_fid = 0) { assert(autogen::tri_mesh::auto_2d_table_complete_vertex[local_id][0] == local_id); const int64_t leid = autogen::tri_mesh::auto_2d_table_complete_vertex[local_id][1]; @@ -16,7 +16,7 @@ namespace wmtk::autogen::tri_mesh { assert(is_ccw(v_tuple)); // is_ccw also checks for validity return v_tuple; } - inline Tuple get_tuple_from_simplex_local_edge_id(int8_t local_id, int64_t global_fid = -1) { + inline Tuple get_tuple_from_simplex_local_edge_id(int8_t local_id, int64_t global_fid = 0) { assert(autogen::tri_mesh::auto_2d_table_complete_edge[local_id][1] == local_id); const int64_t lvid = autogen::tri_mesh::auto_2d_table_complete_edge[local_id][0]; @@ -25,7 +25,7 @@ namespace wmtk::autogen::tri_mesh { assert(is_ccw(e_tuple)); return e_tuple; } - inline Tuple get_tuple_from_simplex_local_id(PrimitiveType pt, int8_t local_id, int64_t global_fid = -1) { + inline Tuple get_tuple_from_simplex_local_id(PrimitiveType pt, int8_t local_id, int64_t global_fid = 0) { switch(pt) { case PrimitiveType::Vertex: return get_tuple_from_simplex_local_vertex_id(local_id, global_fid); case PrimitiveType::Edge: return get_tuple_from_simplex_local_edge_id(local_id, global_fid); diff --git a/tests/autogen/tables.cpp b/tests/autogen/tables.cpp index 14fff4e56d..d2e88d561f 100644 --- a/tests/autogen/tables.cpp +++ b/tests/autogen/tables.cpp @@ -274,7 +274,8 @@ TEST_CASE("tuple_autogen_from_id_is_ccw", "[tuple]") Tuple t2 = wmtk::autogen::edge_mesh::get_tuple_from_simplex_local_id(PrimitiveType::Vertex, i); CHECK(t == t2); CHECK(edge_mesh::tuple_is_valid_for_ccw(t)); - CHECK(edge_mesh::is_ccw(t)); + // edge mesh does not always have a ccw tuple for every simplex + CHECK(edge_mesh::is_ccw(t) == (i == 0)); } for(int i = 0; i < 3; ++i) { Tuple t = wmtk::autogen::tri_mesh::get_tuple_from_simplex_local_vertex_id(i); @@ -284,7 +285,7 @@ TEST_CASE("tuple_autogen_from_id_is_ccw", "[tuple]") CHECK(tri_mesh::is_ccw(t)); } for(int i = 0; i < 3; ++i) { - Tuple t = wmtk::autogen::tri_mesh::get_tuple_from_simplex_local_vertex_id(i); + Tuple t = wmtk::autogen::tri_mesh::get_tuple_from_simplex_local_edge_id(i); Tuple t2 = wmtk::autogen::tri_mesh::get_tuple_from_simplex_local_id(PrimitiveType::Edge, i); CHECK(t == t2); CHECK(tri_mesh::tuple_is_valid_for_ccw(t)); @@ -299,14 +300,14 @@ TEST_CASE("tuple_autogen_from_id_is_ccw", "[tuple]") CHECK(tet_mesh::is_ccw(t)); } for(int i = 0; i < 6; ++i) { - Tuple t = wmtk::autogen::tet_mesh::get_tuple_from_simplex_local_vertex_id(i); + Tuple t = wmtk::autogen::tet_mesh::get_tuple_from_simplex_local_edge_id(i); Tuple t2 = wmtk::autogen::tet_mesh::get_tuple_from_simplex_local_id(PrimitiveType::Edge, i); CHECK(t == t2); CHECK(tet_mesh::tuple_is_valid_for_ccw(t)); CHECK(tet_mesh::is_ccw(t)); } for(int i = 0; i < 4; ++i) { - Tuple t = wmtk::autogen::tet_mesh::get_tuple_from_simplex_local_vertex_id(i); + Tuple t = wmtk::autogen::tet_mesh::get_tuple_from_simplex_local_face_id(i); Tuple t2 = wmtk::autogen::tet_mesh::get_tuple_from_simplex_local_id(PrimitiveType::Triangle, i); CHECK(t == t2); CHECK(tet_mesh::tuple_is_valid_for_ccw(t));