Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions src/wmtk/TetMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <wmtk/utils/tetmesh_topology_initialization.h>
#include <numeric>
#include <wmtk/autogen/tet_mesh/get_tuple_from_simplex_local_id.hpp>
#include <wmtk/autogen/tet_mesh/is_ccw.hpp>
#include <wmtk/autogen/tet_mesh/local_switch_tuple.hpp>
#include <wmtk/simplex/SimplexCollection.hpp>
Expand Down Expand Up @@ -162,13 +163,7 @@ Tuple TetMesh::vertex_tuple_from_id(int64_t id) const
}
}

const auto [nlvid, leid, lfid] = autogen::tet_mesh::auto_3d_table_complete_vertex[lvid];
assert(lvid == nlvid);

if (lvid < 0 || leid < 0 || lfid < 0) throw std::runtime_error("vertex_tuple_from_id failed");

Tuple v_tuple = Tuple(lvid, leid, lfid, t);
assert(is_ccw(v_tuple));
Tuple v_tuple = autogen::tet_mesh::get_tuple_from_simplex_local_vertex_id(lvid, t);
assert(is_valid(v_tuple));
return v_tuple;
}
Expand All @@ -186,14 +181,7 @@ Tuple TetMesh::edge_tuple_from_id(int64_t id) const
break;
}
}
const auto [lvid, nleid, lfid] = autogen::tet_mesh::auto_3d_table_complete_edge[leid];
assert(leid == nleid);


if (lvid < 0 || leid < 0 || lfid < 0) throw std::runtime_error("edge_tuple_from_id failed");

Tuple e_tuple = Tuple(lvid, leid, lfid, t);
assert(is_ccw(e_tuple));
Tuple e_tuple = autogen::tet_mesh::get_tuple_from_simplex_local_edge_id(leid, t);
assert(is_valid(e_tuple));
return e_tuple;
}
Expand All @@ -212,13 +200,9 @@ Tuple TetMesh::face_tuple_from_id(int64_t id) const
}
}

const auto [lvid, leid, nlfid] = autogen::tet_mesh::auto_3d_table_complete_face[lfid];
assert(lfid == nlfid);

if (lvid < 0 || leid < 0 || lfid < 0) throw std::runtime_error("face_tuple_from_id failed");

Tuple f_tuple = Tuple(lvid, leid, lfid, t);
assert(is_ccw(f_tuple));
assert(lfid >= 0);
Tuple f_tuple = autogen::tet_mesh::get_tuple_from_simplex_local_face_id(lfid, t);
assert(is_valid(f_tuple));
return f_tuple;
}
Expand Down
17 changes: 3 additions & 14 deletions src/wmtk/TriMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <wmtk/autogen/tri_mesh/is_ccw.hpp>
#include <wmtk/autogen/tri_mesh/local_switch_tuple.hpp>
#include <wmtk/utils/Logger.hpp>
#include "wmtk/autogen/tri_mesh/get_tuple_from_simplex_local_id.hpp"

namespace wmtk {

Expand Down Expand Up @@ -291,12 +292,7 @@ Tuple TriMesh::vertex_tuple_from_id(int64_t id) const
auto fv = m_fv_accessor->index_access().const_vector_attribute<3>(f);
for (int64_t i = 0; i < 3; ++i) {
if (fv(i) == id) {
assert(autogen::tri_mesh::auto_2d_table_complete_vertex[i][0] == i);
const int64_t leid = autogen::tri_mesh::auto_2d_table_complete_vertex[i][1];
Tuple v_tuple = Tuple(i, leid, -1, f);
// accessor as parameter
assert(is_ccw(v_tuple)); // is_ccw also checks for validity
return v_tuple;
return autogen::tri_mesh::get_tuple_from_simplex_local_vertex_id(i, f);
}
}
assert(false); // "vertex_tuple_from_id failed"
Expand All @@ -310,14 +306,7 @@ Tuple TriMesh::edge_tuple_from_id(int64_t id) const
auto fe = m_fe_accessor->index_access().const_vector_attribute<3>(f);
for (int64_t i = 0; i < 3; ++i) {
if (fe(i) == id) {
assert(autogen::tri_mesh::auto_2d_table_complete_edge[i][1] == i);
const int64_t lvid = autogen::tri_mesh::auto_2d_table_complete_edge[i][0];


Tuple e_tuple = Tuple(lvid, i, -1, f);
assert(is_ccw(e_tuple));
assert(is_valid(e_tuple));
return e_tuple;
return autogen::tri_mesh::get_tuple_from_simplex_local_edge_id(i, f);
}
}
assert(false); // "edge_tuple_from_id failed"
Expand Down
2 changes: 2 additions & 0 deletions src/wmtk/autogen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ foreach(MESH_TYPE edge_mesh tri_mesh tet_mesh)

subdart_maximal_action_to_face.hpp
subdart_maximal_action_to_face.cpp

get_tuple_from_simplex_local_id.hpp
)
set(SRC_FILES ${SRC_FILES} ${MESH_TYPE}/${FILE_NAME})
endforeach()
Expand Down
28 changes: 28 additions & 0 deletions src/wmtk/autogen/edge_mesh/get_tuple_from_simplex_local_id.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once
#include <cassert>
#include <wmtk/Tuple.hpp>
#include "autogenerated_tables.hpp"
#if !defined(_NDEBUG)
#include "is_ccw.hpp"
#endif

namespace wmtk::autogen::edge_mesh {

inline Tuple get_tuple_from_simplex_local_vertex_id(int8_t local_id, int64_t global_id = 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it reasonable to have the global_id default to 0? I feel like having no default value makes more sense.

{
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 = 0)
{
switch (pt) {
case PrimitiveType::Vertex: return get_tuple_from_simplex_local_vertex_id(local_id, global_fid);
case PrimitiveType::Edge:
case PrimitiveType::Triangle:
default:
case PrimitiveType::Tetrahedron: assert(false); return {};
}
}
} // namespace wmtk::autogen::edge_mesh
87 changes: 87 additions & 0 deletions src/wmtk/autogen/tet_mesh/get_tuple_from_simplex_local_id.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#pragma once
#include <cassert>
#include <wmtk/Tuple.hpp>
#include "autogenerated_tables.hpp"
#if !defined(_NDEBUG)
#include "is_ccw.hpp"
#endif

namespace wmtk::autogen::tet_mesh {
/*
namespace {
template <size_t Dim>
inline Tuple get_tuple_from_simplex_local_id_T(int8_t local_id, int64_t global_id = 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that commented out code still relevant? If not, it should be deleted.

{
const auto& arr = autogen::tet_mesh::auto_3d_table_complete_edge[local_id];
assert(arr[Dim] == local_id);
const auto& [lvid, leid, lfid] = arr;


if (lvid < 0 || leid < 0 || lfid < 0) {
throw std::runtime_error("tuple_from_id failed");
}
Tuple tuple = Tuple(lvid, leid, lfid, global_id);
// accessor as parameter
assert(is_ccw(tuple)); // is_ccw also checks for validity
return tuple;
}
} // namespace
*/

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];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An assert for local_id would be nice. You have it for the edge mesh.

const auto& [lvid, leid, lfid] = arr;
assert(lvid == local_id);


if (lvid < 0 || leid < 0 || lfid < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that even possible? That sounds like something that should be checked for in a test and not in here.

throw std::runtime_error("tuple_from_vertex_id failed");
}
Tuple tuple = Tuple(lvid, leid, lfid, global_id);
// accessor as parameter
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 = 0)
{
const auto& arr = autogen::tet_mesh::auto_3d_table_complete_edge[local_id];
const auto& [lvid, leid, lfid] = arr;
assert(leid == local_id);


if (lvid < 0 || leid < 0 || lfid < 0) {
throw std::runtime_error("tuple_from_edge_id failed");
}
Tuple tuple = Tuple(lvid, leid, lfid, global_id);
// accessor as parameter
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 = 0)
{
const auto& arr = autogen::tet_mesh::auto_3d_table_complete_face[local_id];
const auto& [lvid, leid, lfid] = arr;
assert(lfid == local_id);


if (lvid < 0 || leid < 0 || lfid < 0) {
throw std::runtime_error("tuple_from_face_id failed");
}
Tuple tuple = Tuple(lvid, leid, lfid, global_id);
// accessor as parameter
assert(is_ccw(tuple)); // is_ccw also checks for validity
return tuple;
}
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);
case PrimitiveType::Triangle: return get_tuple_from_simplex_local_face_id(local_id, global_fid);
default:
case PrimitiveType::Tetrahedron: assert(false); return {};
}
}
} // namespace wmtk::autogen::tet_mesh
39 changes: 39 additions & 0 deletions src/wmtk/autogen/tri_mesh/get_tuple_from_simplex_local_id.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once
#include "autogenerated_tables.hpp"
#include <wmtk/Tuple.hpp>
#include <cassert>
#if !defined(_NDEBUG)
#include "is_ccw.hpp"
#endif

namespace wmtk::autogen::tri_mesh {
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];
Tuple v_tuple = Tuple(local_id, leid, -1, global_fid);
// accessor as parameter
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 = 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];


Tuple e_tuple = Tuple(lvid, local_id, -1, global_fid);
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 = 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);
default:
case PrimitiveType::Triangle:
case PrimitiveType::Tetrahedron:
assert(false);
return {};
}
}
}
1 change: 0 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ target_link_libraries(wmtk_test_tools PUBLIC
set(TEST_SOURCES
test_topology.cpp
test_mesh.cpp
test_autogen.cpp
test_tuple.cpp
test_tuple_1d.cpp
test_tuple_2d.cpp
Expand Down
1 change: 1 addition & 0 deletions tests/autogen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
set(TEST_SOURCES
dart.cpp
actions.cpp
tables.cpp
)
target_sources(wmtk_tests PRIVATE ${TEST_SOURCES})
Loading