diff --git a/src/wmtk/autogen/CMakeLists.txt b/src/wmtk/autogen/CMakeLists.txt index 5f184c75e4..072ca7d923 100644 --- a/src/wmtk/autogen/CMakeLists.txt +++ b/src/wmtk/autogen/CMakeLists.txt @@ -18,10 +18,14 @@ set(SRC_FILES tri_mesh/local_id_table_offset.cpp tri_mesh/local_id_table_offset.hpp + edge_mesh/local_switch_tuple.hpp + edge_mesh/local_switch_tuple.cpp + edge_mesh/is_ccw.hpp + edge_mesh/is_ccw.cpp + is_ccw.hpp is_ccw.cpp local_switch_tuple.hpp local_switch_tuple.cpp - ) target_sources(wildmeshing_toolkit PRIVATE ${SRC_FILES}) diff --git a/src/wmtk/autogen/edge_mesh/is_ccw.cpp b/src/wmtk/autogen/edge_mesh/is_ccw.cpp new file mode 100644 index 0000000000..5c53f4eba8 --- /dev/null +++ b/src/wmtk/autogen/edge_mesh/is_ccw.cpp @@ -0,0 +1,17 @@ + +#include "is_ccw.hpp" +#include +#include + +namespace wmtk::autogen::edge_mesh { +bool is_ccw(const Tuple& tuple) +{ + assert(tuple_is_valid_for_ccw(tuple)); + using namespace utils; + return TupleInspector::local_vid(tuple) == 0; +} +bool tuple_is_valid_for_ccw(const Tuple& tuple) +{ + return true; +} +} // namespace wmtk::autogen::edge_mesh diff --git a/src/wmtk/autogen/edge_mesh/is_ccw.hpp b/src/wmtk/autogen/edge_mesh/is_ccw.hpp new file mode 100644 index 0000000000..51de3cb523 --- /dev/null +++ b/src/wmtk/autogen/edge_mesh/is_ccw.hpp @@ -0,0 +1,8 @@ +#pragma once +#include + +namespace wmtk::autogen::edge_mesh { +bool is_ccw(const Tuple& t); +// validates whether the tuple local ids are valid for computing ccw'ness +bool tuple_is_valid_for_ccw(const Tuple& t); +} // namespace wmtk::autogen::edge_mesh diff --git a/src/wmtk/autogen/edge_mesh/local_switch_tuple.cpp b/src/wmtk/autogen/edge_mesh/local_switch_tuple.cpp new file mode 100644 index 0000000000..32ebad89d4 --- /dev/null +++ b/src/wmtk/autogen/edge_mesh/local_switch_tuple.cpp @@ -0,0 +1,27 @@ +#include "local_switch_tuple.hpp" +#include +#include + +namespace wmtk::autogen::edge_mesh { +Tuple local_switch_tuple(const Tuple& tuple, PrimitiveType pt) +{ + using namespace utils; + const long global_cid = TupleInspector::global_cid(tuple); + const long hash = TupleInspector::hash(tuple); + switch (pt) { + case PrimitiveType::Vertex: + return Tuple( + 1 - TupleInspector::local_vid(tuple), + TupleInspector::local_eid(tuple), + TupleInspector::local_fid(tuple), + global_cid, + hash); + + case PrimitiveType::Edge: + case PrimitiveType::Face: + case PrimitiveType::Tetrahedron: + default: throw std::runtime_error("Tuple switch: Invalid primitive type"); break; + } + return Tuple(); +} +} // namespace wmtk::autogen::edge_mesh diff --git a/src/wmtk/autogen/edge_mesh/local_switch_tuple.hpp b/src/wmtk/autogen/edge_mesh/local_switch_tuple.hpp new file mode 100644 index 0000000000..1f84830ff4 --- /dev/null +++ b/src/wmtk/autogen/edge_mesh/local_switch_tuple.hpp @@ -0,0 +1,7 @@ +#pragma once +#include +#include + +namespace wmtk::autogen::edge_mesh { +Tuple local_switch_tuple(const Tuple& t, PrimitiveType pt); +} diff --git a/src/wmtk/autogen/is_ccw.cpp b/src/wmtk/autogen/is_ccw.cpp index 67f0a164c9..c7ba716076 100644 --- a/src/wmtk/autogen/is_ccw.cpp +++ b/src/wmtk/autogen/is_ccw.cpp @@ -1,15 +1,17 @@ #include "is_ccw.hpp" #include +#include #include #include + namespace wmtk::autogen { bool is_ccw(PrimitiveType pt, const Tuple& t) { switch (pt) { case PrimitiveType::Face: return tri_mesh::is_ccw(t); case PrimitiveType::Tetrahedron: return tet_mesh::is_ccw(t); + case PrimitiveType::Edge: return edge_mesh::is_ccw(t); case PrimitiveType::Vertex: - case PrimitiveType::Edge: default: throw "notimplemented"; } return false; @@ -21,8 +23,8 @@ bool tuple_is_valid_for_ccw(PrimitiveType pt, const Tuple& t) switch (pt) { case PrimitiveType::Face: return tri_mesh::tuple_is_valid_for_ccw(t); case PrimitiveType::Tetrahedron: return tet_mesh::tuple_is_valid_for_ccw(t); + case PrimitiveType::Edge: return edge_mesh::tuple_is_valid_for_ccw(t); case PrimitiveType::Vertex: - case PrimitiveType::Edge: default: throw "notimplemented"; } return false; diff --git a/src/wmtk/autogen/local_switch_tuple.cpp b/src/wmtk/autogen/local_switch_tuple.cpp index ae0745bbe2..d3ab39dda7 100644 --- a/src/wmtk/autogen/local_switch_tuple.cpp +++ b/src/wmtk/autogen/local_switch_tuple.cpp @@ -1,4 +1,5 @@ #include "local_switch_tuple.hpp" +#include #include #include namespace wmtk::autogen { @@ -7,8 +8,8 @@ Tuple local_switch_tuple(PrimitiveType mesh_type, const Tuple& t, PrimitiveType switch (mesh_type) { case PrimitiveType::Face: return tri_mesh::local_switch_tuple(t, pt); case PrimitiveType::Tetrahedron: return tet_mesh::local_switch_tuple(t, pt); - case PrimitiveType::Vertex: - case PrimitiveType::Edge: throw "notimplemented"; + case PrimitiveType::Edge: return edge_mesh::local_switch_tuple(t, pt); + case PrimitiveType::Vertex: throw("not implemented"); } return Tuple(); } diff --git a/src/wmtk/multimesh/utils/local_switch_tuple.cpp b/src/wmtk/multimesh/utils/local_switch_tuple.cpp index 757cf0ac19..d5902d9f62 100644 --- a/src/wmtk/multimesh/utils/local_switch_tuple.cpp +++ b/src/wmtk/multimesh/utils/local_switch_tuple.cpp @@ -1,8 +1,8 @@ #include "local_switch_tuple.hpp" #include +#include #include #include - namespace wmtk::multimesh::utils { Tuple local_switch_tuple( @@ -14,8 +14,8 @@ Tuple local_switch_tuple( case PrimitiveType::Face: return autogen::tri_mesh::local_switch_tuple(source, primitive_type); case PrimitiveType::Tetrahedron: return autogen::tet_mesh::local_switch_tuple(source, primitive_type); + case PrimitiveType::Edge: return autogen::edge_mesh::local_switch_tuple(source, primitive_type); case PrimitiveType::Vertex: - case PrimitiveType::Edge: default: return Tuple(); } } diff --git a/tests/test_autogen.cpp b/tests/test_autogen.cpp index f2d60fe9d4..f8b77879a8 100644 --- a/tests/test_autogen.cpp +++ b/tests/test_autogen.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include #include #include @@ -42,8 +44,8 @@ long max_tuple_count(PrimitiveType pt) case PrimitiveType::Face: return long(std::size(wmtk::autogen::tri_mesh::auto_2d_table_ccw)); case PrimitiveType::Tetrahedron: return long(std::size(wmtk::autogen::tet_mesh::auto_3d_table_ccw)); - case PrimitiveType::Vertex: - case PrimitiveType::Edge: break; + case PrimitiveType::Edge: return 2; + case PrimitiveType::Vertex: break; } return -1; } @@ -65,8 +67,10 @@ Tuple tuple_from_offset_id(PrimitiveType pt, int offset) leid = r[1]; lfid = r[2]; } break; - case PrimitiveType::Vertex: - case PrimitiveType::Edge: break; + case PrimitiveType::Edge: { + lvid = offset; + } break; + case PrimitiveType::Vertex: break; } Tuple r(lvid, leid, lfid, gcid, hash); @@ -183,6 +187,13 @@ TEST_CASE("tuple_autogen_id_inversion", "[tuple]") TEST_CASE("tuple_autogen_ptype_is_ccw_equivalent", "[tuple]") { + { + auto tuples = all_valid_local_tuples(PrimitiveType::Edge); + for (const auto& t : tuples) { + CHECK(edge_mesh::is_ccw(t) == is_ccw(PrimitiveType::Edge, t)); + } + } + { auto tuples = all_valid_local_tuples(PrimitiveType::Face); for (const auto& t : tuples) { @@ -230,6 +241,16 @@ TEST_CASE("tuple_autogen_local_id_inversion", "[tuple]") TEST_CASE("tuple_autogen_ptype_local_switch_tuple_equivalent", "[tuple]") { + { + auto tuples = all_valid_local_tuples(PrimitiveType::Edge); + for (const auto& t : tuples) { + for (PrimitiveType pt : primitives_up_to(PrimitiveType::Edge)) { + CHECK( + edge_mesh::local_switch_tuple(t, pt) == + local_switch_tuple(PrimitiveType::Edge, t, pt)); + } + } + } { auto tuples = all_valid_local_tuples(PrimitiveType::Face); for (const auto& t : tuples) {