Skip to content

Commit

Permalink
add implementation and test
Browse files Browse the repository at this point in the history
  • Loading branch information
zlyfunction committed Oct 19, 2023
1 parent 51b298c commit c060f20
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/wmtk/autogen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ set(SRC_FILES

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
Expand Down
17 changes: 17 additions & 0 deletions src/wmtk/autogen/edge_mesh/is_ccw.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

#include "is_ccw.hpp"
#include <cassert>
#include <wmtk/utils/TupleInspector.hpp>

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
8 changes: 8 additions & 0 deletions src/wmtk/autogen/edge_mesh/is_ccw.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once
#include <wmtk/Tuple.hpp>

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
27 changes: 27 additions & 0 deletions src/wmtk/autogen/edge_mesh/local_switch_tuple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "local_switch_tuple.hpp"
#include <stdexcept>
#include <wmtk/utils/TupleInspector.hpp>

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
7 changes: 7 additions & 0 deletions src/wmtk/autogen/edge_mesh/local_switch_tuple.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once
#include <wmtk/Primitive.hpp>
#include <wmtk/Tuple.hpp>

namespace wmtk::autogen::edge_mesh {
Tuple local_switch_tuple(const Tuple& t, PrimitiveType pt);
}
6 changes: 4 additions & 2 deletions src/wmtk/autogen/is_ccw.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#include "is_ccw.hpp"
#include <wmtk/Tuple.hpp>
#include <wmtk/autogen/edge_mesh/is_ccw.hpp>
#include <wmtk/autogen/tet_mesh/is_ccw.hpp>
#include <wmtk/autogen/tri_mesh/is_ccw.hpp>

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;
Expand All @@ -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;
Expand Down
29 changes: 25 additions & 4 deletions tests/test_autogen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <iostream>
#include <tuple>
#include <wmtk/Tuple.hpp>
#include <wmtk/autogen/edge_mesh/is_ccw.hpp>
#include <wmtk/autogen/edge_mesh/local_switch_tuple.hpp>
#include <wmtk/autogen/is_ccw.hpp>
#include <wmtk/autogen/local_switch_tuple.hpp>
#include <wmtk/autogen/tet_mesh/autogenerated_tables.hpp>
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c060f20

Please sign in to comment.