Skip to content

Commit

Permalink
Merge pull request #418 from mtao/mtao/autogen_tests
Browse files Browse the repository at this point in the history
adding some unit tests for autogen
  • Loading branch information
mtao authored Oct 4, 2023
2 parents 1652704 + a0cb1e6 commit b93f12a
Show file tree
Hide file tree
Showing 16 changed files with 392 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/wmtk/autogen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ set(SRC_FILES
tri_mesh/local_id_table_offset.cpp
tri_mesh/local_id_table_offset.hpp

is_ccw.hpp
is_ccw.cpp
local_switch_tuple.hpp
local_switch_tuple.cpp

utils/TupleInspector.hpp
)
target_sources(wildmeshing_toolkit PRIVATE ${SRC_FILES})
30 changes: 30 additions & 0 deletions src/wmtk/autogen/is_ccw.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "is_ccw.hpp"
#include <wmtk/Tuple.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::Vertex:
case PrimitiveType::Edge:
default: throw "notimplemented";
}
return false;
}

// validates whether the tuple local ids are valid for computing ccw'ness
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::Vertex:
case PrimitiveType::Edge:
default: throw "notimplemented";
}
return false;
}
} // namespace wmtk::autogen
14 changes: 14 additions & 0 deletions src/wmtk/autogen/is_ccw.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
#include <wmtk/Primitive.hpp>

namespace wmtk {
class Tuple;
}

// NOTE: this header primarily exists to simplify unit testing, not really for use
namespace wmtk::autogen {
bool is_ccw(PrimitiveType ptype, const Tuple& t);

// validates whether the tuple local ids are valid for computing ccw'ness
bool tuple_is_valid_for_ccw(PrimitiveType ptype, const Tuple& t);
} // namespace wmtk::autogen
15 changes: 15 additions & 0 deletions src/wmtk/autogen/local_switch_tuple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "local_switch_tuple.hpp"
#include <wmtk/autogen/tet_mesh/local_switch_tuple.hpp>
#include <wmtk/autogen/tri_mesh/local_switch_tuple.hpp>
namespace wmtk::autogen {
Tuple local_switch_tuple(PrimitiveType mesh_type, const Tuple& t, PrimitiveType pt)
{
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";
}
return Tuple();
}
} // namespace wmtk::autogen
9 changes: 9 additions & 0 deletions src/wmtk/autogen/local_switch_tuple.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

#pragma once
#include <wmtk/Primitive.hpp>
#include <wmtk/Tuple.hpp>

// NOTE: this header primarily exists to simplify unit testing, not really for use
namespace wmtk::autogen {
Tuple local_switch_tuple(PrimitiveType mesh_type, const Tuple& t, PrimitiveType pt);
}
3 changes: 3 additions & 0 deletions src/wmtk/autogen/tet_mesh/is_ccw.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@

#include "is_ccw.hpp"
#include <cassert>
#include <wmtk/Tuple.hpp>
#include <wmtk/autogen/utils/TupleInspector.hpp>
#include "autogenerated_tables.hpp"
#include "local_id_table_offset.hpp"

namespace wmtk::autogen::tet_mesh {
bool is_ccw(const Tuple& tuple)
{
assert(tuple_is_valid_for_ccw(tuple));
using namespace utils;
const long offset = local_id_table_offset(tuple);
return auto_3d_table_ccw[offset] == 1;
Expand Down
4 changes: 3 additions & 1 deletion src/wmtk/autogen/tet_mesh/is_ccw.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once
#include <wmtk/Tuple.hpp>
namespace wmtk {
class Tuple;
}

namespace wmtk::autogen::tet_mesh {
bool is_ccw(const Tuple& t);
Expand Down
21 changes: 19 additions & 2 deletions src/wmtk/autogen/tet_mesh/local_id_table_offset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,25 @@ namespace wmtk::autogen::tet_mesh {
long local_id_table_offset(const Tuple& tuple)
{
using namespace utils;
return TupleInspector::local_vid(tuple) * 6 * 4 + TupleInspector::local_eid(tuple) * 4 +
TupleInspector::local_fid(tuple);
long value = TupleInspector::local_vid(tuple) * 6 * 4 + TupleInspector::local_eid(tuple) * 4 +
TupleInspector::local_fid(tuple);


// value = (TupleInspector::local_vid(tuple) * 6 + TupleInspector::local_eid(tuple)) * 4 +
// TupleInspector::local_fid(tuple);
return value;
}

std::array<long, 3> lvid_leid_lfid_from_table_offset(long table_offset)
{
std::array<long, 3> r;
auto& [lvid, leid, lfid] = r;
lfid = table_offset % 4;

long ve_offset = table_offset / 4;
leid = ve_offset % 6;
lvid = ve_offset / 6;
return r;
}

} // namespace wmtk::autogen::tet_mesh
4 changes: 4 additions & 0 deletions src/wmtk/autogen/tet_mesh/local_id_table_offset.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#pragma once
#include <array>
#include <wmtk/Tuple.hpp>


namespace wmtk::autogen::tet_mesh {
// computes the offset of a tuple's local ids in the tables
long local_id_table_offset(const Tuple& t);

// returns a lvid/leid/lfid associated iwth a particular tuple offset
std::array<long, 3> lvid_leid_lfid_from_table_offset(long table_offset);

} // namespace wmtk::autogen::tet_mesh
1 change: 1 addition & 0 deletions src/wmtk/autogen/tet_mesh/local_switch_tuple.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <wmtk/Primitive.hpp>
#include <wmtk/Tuple.hpp>

namespace wmtk::autogen::tet_mesh {
Expand Down
2 changes: 2 additions & 0 deletions src/wmtk/autogen/tri_mesh/is_ccw.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

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

namespace wmtk::autogen::tri_mesh {
bool is_ccw(const Tuple& tuple)
{
assert(tuple_is_valid_for_ccw(tuple));
using namespace utils;
const long offset = local_id_table_offset(tuple);
return auto_2d_table_ccw[offset] == 1;
Expand Down
10 changes: 10 additions & 0 deletions src/wmtk/autogen/tri_mesh/local_id_table_offset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,14 @@ long local_id_table_offset(const Tuple& tuple)
return TupleInspector::local_vid(tuple) * 3 + TupleInspector::local_eid(tuple);
}

std::array<long, 2> lvid_leid_from_table_offset(long table_offset)
{
std::array<long, 2> r;
auto& [lvid, leid] = r;

lvid = table_offset / 3;
leid = table_offset % 3;
return r;
}

} // namespace wmtk::autogen::tri_mesh
4 changes: 4 additions & 0 deletions src/wmtk/autogen/tri_mesh/local_id_table_offset.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#pragma once
#include <array>
#include <wmtk/Tuple.hpp>


namespace wmtk::autogen::tri_mesh {
// computes the offset of a tuple's local ids in the tables
long local_id_table_offset(const Tuple& t);

// returns a lvid/leid associated iwth a particular tuple offset
std::array<long, 2> lvid_leid_from_table_offset(long table_offset);

} // namespace wmtk::autogen::tri_mesh

1 change: 1 addition & 0 deletions src/wmtk/autogen/tri_mesh/local_switch_tuple.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <wmtk/Primitive.hpp>
#include <wmtk/Tuple.hpp>

namespace wmtk::autogen::tri_mesh {
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ lagrange_include_modules(io)
# Sources
set(TEST_SOURCES
test_topology.cpp
test_autogen.cpp
test_tuple.cpp
test_tuple_2d.cpp
test_tuple_3d.cpp
Expand Down
Loading

0 comments on commit b93f12a

Please sign in to comment.