Skip to content

Commit

Permalink
refactor based on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JcDai committed Oct 3, 2023
1 parent 22c615a commit 3844c20
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 321 deletions.
6 changes: 6 additions & 0 deletions src/wmtk/EdgeMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ Tuple EdgeMesh::switch_tuple(const Tuple& tuple, PrimitiveType type) const
auto ee = ee_accessor.vector_attribute(tuple);

long gcid_new = ee(tuple.m_local_vid);

// TODO: This is for special case self-loop, just to make sure the local vid of the returned
// tuple is the same as the input. (When doing double-switch this is needed)
if (gcid_new == tuple.m_global_cid) return tuple;


long lvid_new = -1;

ConstAccessor<long> ev_accessor = create_const_accessor<long>(m_ev_handle);
Expand Down
2 changes: 1 addition & 1 deletion src/wmtk/EdgeMesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class EdgeMesh : public Mesh
bool is_boundary_vertex(const Tuple& tuple) const override;
bool is_boundary_edge(const Tuple& tuple) const override
{
throw("This function doesn't make sense for edgemesh");
throw("This function doesn't make sense for EdgeMesh");
}

void initialize(Eigen::Ref<const RowVectors2l> E);
Expand Down
16 changes: 9 additions & 7 deletions src/wmtk/EdgeMeshOperationExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ std::vector<Tuple> EdgeMesh::EdgeMeshOperationExecutor::prepare_operating_tuples
const
{
// this function is designed as a helper for multi_mesh
throw("this function is not tested");
return MultiMeshManager::map_edge_tuple_to_all_children(m_mesh, m_operating_tuple);
}

Expand Down Expand Up @@ -106,14 +107,14 @@ Tuple EdgeMesh::EdgeMeshOperationExecutor::split_edge_single_mesh()
// for 2 new edges
auto ee_new_0 = ee_accessor.index_access().vector_attribute(new_eids[0]);
auto ee_new_1 = ee_accessor.index_access().vector_attribute(new_eids[1]);
ee_new_0[(local_vid + 1) % 2] = new_eids[1];
ee_new_0[local_vid ^ 1] = new_eids[1];
ee_new_1[local_vid] = new_eids[0];
if (m_is_self_loop) {
ee_new_0[local_vid] = new_eids[1];
ee_new_1[(local_vid + 1) % 2] = new_eids[0];
ee_new_1[local_vid ^ 1] = new_eids[0];
} else {
ee_new_0[local_vid] = m_neighbor_eids[0];
ee_new_1[(local_vid + 1) % 2] = m_neighbor_eids[1];
ee_new_1[local_vid ^ 1] = m_neighbor_eids[1];
// for neighbor edges
for (long i = 0; i < 2; i++) {
if (m_neighbor_eids[i] != -1) {
Expand All @@ -122,7 +123,8 @@ Tuple EdgeMesh::EdgeMeshOperationExecutor::split_edge_single_mesh()
auto ev_neighbor =
ev_accessor.index_access().vector_attribute(m_neighbor_eids[i]);
for (long j = 0; j < 2; j++) {
if (ee_neighbor[j] == m_operating_edge_id && ev_neighbor[j] == m_spine_vids[i]) {
if (ee_neighbor[j] == m_operating_edge_id &&
ev_neighbor[j] == m_spine_vids[i]) {
ee_neighbor[j] = new_eids[i];
break;
}
Expand All @@ -138,9 +140,9 @@ Tuple EdgeMesh::EdgeMeshOperationExecutor::split_edge_single_mesh()
auto ev_new_0 = ev_accessor.index_access().vector_attribute(new_eids[0]);
auto ev_new_1 = ev_accessor.index_access().vector_attribute(new_eids[1]);
ev_new_0[local_vid] = m_spine_vids[0];
ev_new_0[(local_vid + 1) % 2] = v_new;
ev_new_0[local_vid ^ 1] = v_new;
ev_new_1[local_vid] = v_new;
ev_new_1[(local_vid + 1) % 2] = m_spine_vids[1];
ev_new_1[local_vid ^ 1] = m_spine_vids[1];
}

// update ve
Expand Down Expand Up @@ -189,7 +191,7 @@ Tuple EdgeMesh::EdgeMeshOperationExecutor::collapse_edge_single_mesh()
auto ee_neighbor = ee_accessor.index_access().vector_attribute(m_neighbor_eids[i]);
for (long j = 0; j < 2; j++) {
if (ee_neighbor[j] == m_operating_edge_id) {
ee_neighbor[j] = m_neighbor_eids[(i + 1) % 2];
ee_neighbor[j] = m_neighbor_eids[i ^ 1];
break;
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/wmtk/EdgeMeshOperationExecutor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class EdgeMesh::EdgeMeshOperationExecutor
/**
* @brief gather all simplices that are deleted in a split
*
* The deleted simplices are exactly the open star of the edge
* The deleted simplex is the edge itself
*/
static const std::array<std::vector<long>, 2> get_split_simplices_to_delete(
const Tuple& tuple,
Expand All @@ -29,9 +29,7 @@ class EdgeMesh::EdgeMeshOperationExecutor
/**
* @brief gather all simplices that are deleted in a collapse
*
* The deleted simplices are the intersection of the open star of the vertex and the closed star
* of the edge. This comes down to one vertex, three edges, and two faces if the edge is on the
* interior. On the boundary it is one vertex, two edges, and one face.
* The deleted simplices are the vertex and the edge of the input tuple
*/
static const std::array<std::vector<long>, 2> get_collapse_simplices_to_delete(
const Tuple& tuple,
Expand Down
2 changes: 1 addition & 1 deletion src/wmtk/Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <Eigen/Core>

namespace wmtk {
using RowVectors3l = Eigen::Matrix<long, Eigen::Dynamic, 3>;
using RowVectors2l = Eigen::Matrix<long, Eigen::Dynamic, 2>;
using RowVectors3l = Eigen::Matrix<long, Eigen::Dynamic, 3>;
using VectorXl = Eigen::Matrix<long, Eigen::Dynamic, 1>;
using RowVectors4l = Eigen::Matrix<long, Eigen::Dynamic, 4>;
using RowVectors6l = Eigen::Matrix<long, Eigen::Dynamic, 6>;
Expand Down
4 changes: 2 additions & 2 deletions src/wmtk/utils/edgemesh_topology_initialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ std::tuple<RowVectors2l, VectorXl> edgemesh_topology_initialization(
RowVectors2l EE;
VectorXl VE;

long vertex_count = E.maxCoeff() + 1;
const long vertex_count = E.maxCoeff() + 1;

// store the complete vertex-edge connnectivity
std::vector<std::vector<long>> complete_VE(vertex_count);
Expand All @@ -38,7 +38,7 @@ std::tuple<RowVectors2l, VectorXl> edgemesh_topology_initialization(
}
} else {
// non-boundary vertex
for (int k = 0; k < 2; ++k) {
for (long k = 0; k < 2; ++k) {
if (E(complete_VE[i][k], 0) == i) {
EE(complete_VE[i][k], 0) = complete_VE[i][1 - k];
}
Expand Down
42 changes: 26 additions & 16 deletions tests/test_1d_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ TEST_CASE("simplices_to_delete_for_split_1D", "[operations][1D]")

const long edge_id = 0;
Tuple edge = m.tuple_from_edge_id(edge_id);
REQUIRE(m.is_valid_slow(edge));
Accessor<long> hash_accessor = m.get_cell_hash_accessor();
REQUIRE(m.is_valid(edge, hash_accessor));

auto executor = m.get_emoe(edge, hash_accessor);

executor.split_edge();
Expand All @@ -48,8 +49,9 @@ TEST_CASE("simplices_to_delete_for_split_1D", "[operations][1D]")

const long edge_id = 0;
Tuple edge = m.tuple_from_edge_id(edge_id);
REQUIRE(m.is_valid_slow(edge));
Accessor<long> hash_accessor = m.get_cell_hash_accessor();
REQUIRE(m.is_valid(edge, hash_accessor));

auto executor = m.get_emoe(edge, hash_accessor);

executor.split_edge();
Expand All @@ -70,8 +72,8 @@ TEST_CASE("simplices_to_delete_for_collapse_1D", "[operations][1D]")

const long edge_id = 2;
Tuple edge = m.tuple_from_edge_id(edge_id);
REQUIRE(m.is_valid_slow(edge));
Accessor<long> hash_accessor = m.get_cell_hash_accessor();
REQUIRE(m.is_valid(edge, hash_accessor));
auto executor = m.get_emoe(edge, hash_accessor);

executor.collapse_edge();
Expand All @@ -90,8 +92,8 @@ TEST_CASE("simplices_to_delete_for_collapse_1D", "[operations][1D]")

const long edge_id = 0;
Tuple edge = m.tuple_from_edge_id(edge_id);
REQUIRE(m.is_valid_slow(edge));
Accessor<long> hash_accessor = m.get_cell_hash_accessor();
REQUIRE(m.is_valid(edge, hash_accessor));
auto executor = m.get_emoe(edge, hash_accessor);

executor.collapse_edge();
Expand All @@ -113,10 +115,11 @@ TEST_CASE("collapse_edge_1D", "[operations][1D]")

const long edge_id = 2;
Tuple edge = m.tuple_from_edge_id(edge_id);
REQUIRE(m.is_valid_slow(edge));
const long vertex_id = m._debug_id(edge, PV);

Accessor<long> hash_accessor = m.get_cell_hash_accessor();
REQUIRE(m.is_valid(edge, hash_accessor));
const long vertex_id = m._debug_id(edge, PV);

auto executor = m.get_emoe(edge, hash_accessor);

const Tuple ret_tuple = executor.collapse_edge();
Expand Down Expand Up @@ -147,8 +150,9 @@ TEST_CASE("collapse_edge_1D", "[operations][1D]")

const long edge_id = 0;
Tuple edge = m.tuple_from_edge_id(edge_id);
REQUIRE(m.is_valid_slow(edge));
Accessor<long> hash_accessor = m.get_cell_hash_accessor();
REQUIRE(m.is_valid(edge, hash_accessor));

auto executor = m.get_emoe(edge, hash_accessor);

const Tuple ret_tuple = executor.collapse_edge();
Expand All @@ -163,8 +167,8 @@ TEST_CASE("collapse_edge_1D", "[operations][1D]")

const long edge_id = 0;
Tuple edge = m.tuple_from_edge_id(edge_id);
REQUIRE(m.is_valid_slow(edge));
Accessor<long> hash_accessor = m.get_cell_hash_accessor();
REQUIRE(m.is_valid(edge, hash_accessor));
auto executor = m.get_emoe(edge, hash_accessor);

const Tuple ret_tuple = executor.collapse_edge();
Expand All @@ -180,8 +184,9 @@ TEST_CASE("collapse_edge_1D", "[operations][1D]")
const long edge_id = 0;
Tuple edge = m.tuple_from_edge_id(edge_id);
const long vertex_id = m._debug_id(edge, PV);
REQUIRE(m.is_valid_slow(edge));
Accessor<long> hash_accessor = m.get_cell_hash_accessor();
REQUIRE(m.is_valid(edge, hash_accessor));

auto executor = m.get_emoe(edge, hash_accessor);

const Tuple ret_tuple = executor.collapse_edge();
Expand Down Expand Up @@ -213,8 +218,10 @@ TEST_CASE("collapse_edge_1D", "[operations][1D]")
const long edge_id = 0;
Tuple edge = m.tuple_from_edge_id(edge_id);
const long vertex_id = m._debug_id(edge, PV);
REQUIRE(m.is_valid_slow(edge));

Accessor<long> hash_accessor = m.get_cell_hash_accessor();
REQUIRE(m.is_valid(edge, hash_accessor));

auto executor = m.get_emoe(edge, hash_accessor);

const Tuple ret_tuple = executor.collapse_edge();
Expand Down Expand Up @@ -249,10 +256,11 @@ TEST_CASE("split_edge_1D", "[operations][1D]")

const long edge_id = 2;
Tuple edge = m.tuple_from_edge_id(edge_id);
REQUIRE(m.is_valid_slow(edge));
const long vertex_id = m._debug_id(edge, PV);

Accessor<long> hash_accessor = m.get_cell_hash_accessor();
REQUIRE(m.is_valid(edge, hash_accessor));
const long vertex_id = m._debug_id(edge, PV);

auto executor = m.get_emoe(edge, hash_accessor);

const Tuple ret_tuple = executor.split_edge();
Expand Down Expand Up @@ -293,8 +301,8 @@ TEST_CASE("split_edge_1D", "[operations][1D]")
const long edge_id = 0;
Tuple edge = m.tuple_from_edge_id(edge_id);
const long vertex_id = m._debug_id(edge, PV);
REQUIRE(m.is_valid_slow(edge));
Accessor<long> hash_accessor = m.get_cell_hash_accessor();
REQUIRE(m.is_valid(edge, hash_accessor));
auto executor = m.get_emoe(edge, hash_accessor);

const Tuple ret_tuple = executor.split_edge();
Expand Down Expand Up @@ -333,8 +341,8 @@ TEST_CASE("split_edge_1D", "[operations][1D]")
const long edge_id = 0;
Tuple edge = m.tuple_from_edge_id(edge_id);
const long vertex_id = m._debug_id(edge, PV);
REQUIRE(m.is_valid_slow(edge));
Accessor<long> hash_accessor = m.get_cell_hash_accessor();
REQUIRE(m.is_valid(edge, hash_accessor));
auto executor = m.get_emoe(edge, hash_accessor);

const Tuple ret_tuple = executor.split_edge();
Expand Down Expand Up @@ -372,8 +380,9 @@ TEST_CASE("split_edge_1D", "[operations][1D]")
const long edge_id = 0;
Tuple edge = m.tuple_from_edge_id(edge_id);
const long vertex_id = m._debug_id(edge, PV);
REQUIRE(m.is_valid_slow(edge));
Accessor<long> hash_accessor = m.get_cell_hash_accessor();
REQUIRE(m.is_valid(edge, hash_accessor));

auto executor = m.get_emoe(edge, hash_accessor);

const Tuple ret_tuple = executor.split_edge();
Expand Down Expand Up @@ -414,8 +423,9 @@ TEST_CASE("split_edge_1D", "[operations][1D]")
const long edge_id = 0;
Tuple edge = m.tuple_from_edge_id(edge_id);
const long vertex_id = m._debug_id(edge, PV);
REQUIRE(m.is_valid_slow(edge));
Accessor<long> hash_accessor = m.get_cell_hash_accessor();
REQUIRE(m.is_valid(edge, hash_accessor));

auto executor = m.get_emoe(edge, hash_accessor);

const Tuple ret_tuple = executor.split_edge();
Expand Down
Loading

0 comments on commit 3844c20

Please sign in to comment.