Skip to content

Commit

Permalink
updates to map_tuples to fix assert in debug + adding some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mtao committed Oct 5, 2023
1 parent b0318d5 commit 1546503
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
21 changes: 17 additions & 4 deletions src/wmtk/MultiMeshManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,32 @@ std::vector<Tuple> MultiMeshManager::map_tuples(

// bieng lazy about how i set cur_mesh to nullptr above - could simplify the loop to optimize
cur_mesh = &get_root_mesh(other_mesh);


// note that (cur_mesh, tuples) always match (i.e tuples are tuples from cur_mesh)
std::vector<Tuple> tuples;
tuples.emplace_back(cur_tuple);

for (auto it = other_id.rbegin(); it != other_id.rend(); ++it) {
// get the select ID from the child map
long child_index = *it;
std::vector<Tuple> new_tuples;
const ChildData& cd = cur_mesh->m_multi_mesh_manager.m_children.at(child_index);

// for every tuple we have try to collect all versions
std::vector<Tuple> new_tuples;
for (const Tuple& t : tuples) {
// get new tuples for every version that exists
std::vector<Tuple> n =
cur_mesh->m_multi_mesh_manager.map_to_child_tuples(*cur_mesh, cd, Simplex(pt, t));
// append to teh current set of new tuples
new_tuples.insert(new_tuples.end(), n.begin(), n.end());
}
// update teh (mesh,tuples) pair
tuples = std::move(new_tuples);
cur_mesh = cd.mesh.get();
assert(cur_mesh->absolute_multi_mesh_id() == child_index);

// the front id of the current mesh should be the child index from this iteration
assert(cur_mesh->m_multi_mesh_manager.m_child_id == child_index);
}

// visitor.map(equivalent_tuples, my_simplex.primitive_type());
Expand Down Expand Up @@ -421,10 +434,10 @@ std::vector<std::array<Tuple, 2>> MultiMeshManager::same_simplex_dimension_surje
for (long index = 0; index < size; ++index) {
const Tuple ct = child.tuple_from_id(primitive_type, index);
const Tuple pt = parent.tuple_from_id(primitive_type, parent_simplices.at(index));
if (parent_flag_accessor.const_scalar_attribute(pt) & 1 == 0) {
if ((parent_flag_accessor.const_scalar_attribute(pt) & 1) == 0) {
continue;
}
if (child_flag_accessor.const_scalar_attribute(pt) & 1 == 0) {
if ((child_flag_accessor.const_scalar_attribute(pt) & 1) == 0) {
continue;
}

Expand Down
2 changes: 2 additions & 0 deletions src/wmtk/MultiMeshManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class MultiMeshManager
const ConstAccessor<long>& source_to_target_map_accessor,
const Tuple& source_tuple);

const std::vector<ChildData>& children() const { return m_children; }

private:
// this is defined internally but is preferablly invoked through the multimesh free function
static std::vector<std::array<Tuple, 2>> same_simplex_dimension_surjection(
Expand Down
11 changes: 6 additions & 5 deletions tests/test_multi_mesh.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <catch2/catch_test_macros.hpp>

#include <wmtk/TriMeshOperationExecutor.hpp>
#include <wmtk/multimesh/same_simplex_dimension_surjection.hpp>
#include "tools/DEBUG_TriMesh.hpp"
#include "tools/TriMesh_examples.hpp"

Expand All @@ -20,17 +21,17 @@ TEST_CASE("test_register_child_mesh", "[multimesh][2D]")
{
DEBUG_TriMesh parent = two_neighbors();
std::shared_ptr<DEBUG_TriMesh> child0_ptr = std::make_shared<DEBUG_TriMesh>(single_triangle());
std::vector<long> child0_map = {0};
auto child0_map = multimesh::same_simplex_dimension_surjection(*parent, *child0_ptr, {0});
std::shared_ptr<DEBUG_TriMesh> child1_ptr = std::make_shared<DEBUG_TriMesh>(one_ear());
std::vector<long> child1_map = {0, 1};
auto child1_map = multimesh::same_simplex_dimension_surjection(*parent, *child1_ptr, {0, 1});

parent.register_child_mesh(child0_ptr, child0_map);
parent.register_child_mesh(child1_ptr, child1_map);

const auto& p_mul_manager = parent.multi_mesh_manager();
REQUIRE(p_mul_manager.child_meshes.size() == 2);
REQUIRE(p_mul_manager.child_meshes[0] == child0_ptr);
REQUIRE(p_mul_manager.child_meshes[1] == child1_ptr);
REQUIRE(p_mul_manager.m_children.size() == 2);
REQUIRE(p_mul_manager.m_children[0] == child0_ptr);
REQUIRE(p_mul_manager.m_children[1] == child1_ptr);

auto [tuple1, tuple2] = multimesh::utils::read_tuple_map_attribute_slow(
p_mul_manager.map_to_child_handles[0],
Expand Down

0 comments on commit 1546503

Please sign in to comment.