Skip to content

Commit

Permalink
in map_tuple_between_meshes, make sure that source_mesh_base_tuple an…
Browse files Browse the repository at this point in the history
…d source_mesh_target_tuple has the same global_cid
  • Loading branch information
zlyfunction committed Oct 19, 2023
1 parent 95bc719 commit 4dcd1ef
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 58 deletions.
23 changes: 21 additions & 2 deletions src/wmtk/MultiMeshManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,39 @@ Tuple MultiMeshManager::map_tuple_between_meshes(
PrimitiveType target_mesh_primitive_type = target_mesh.top_simplex_type();
PrimitiveType min_primitive_type =
std::min(source_mesh_primitive_type, target_mesh_primitive_type);

Tuple source_mesh_target_tuple = source_tuple;
const auto [source_mesh_base_tuple, target_mesh_base_tuple] =
multimesh::utils::read_tuple_map_attribute(map_accessor, source_tuple);

if (source_mesh_base_tuple.is_null() || target_mesh_base_tuple.is_null()) {
return Tuple(); // return null tuple
}

if (source_mesh_base_tuple.m_global_cid != source_mesh_target_tuple.m_global_cid) {
assert(source_mesh_primitive_type > target_mesh_primitive_type);
const std::vector<Tuple> equivalent_tuples = simplex::top_level_cofaces_tuples(
source_mesh,
Simplex(target_mesh_primitive_type, source_tuple));
for (const Tuple& t : equivalent_tuples) {
if (t.m_global_cid == source_mesh_base_tuple.m_global_cid) {
source_mesh_target_tuple = t;
break;
}
}
// return target_mesh_base_tuple;
}

assert(
source_mesh_base_tuple.m_global_cid ==
source_mesh_target_tuple
.m_global_cid); // make sure that local tuple operations will find a valid sequence

// we want to repeat switches from source_base_tuple -> source_tuple to
// target_base _tuple -> return value
//
return multimesh::utils::transport_tuple(
source_mesh_base_tuple,
source_tuple,
source_mesh_target_tuple,
source_mesh_primitive_type,
target_mesh_base_tuple,
target_mesh_primitive_type);
Expand Down
13 changes: 4 additions & 9 deletions src/wmtk/multimesh/utils/transport_tuple.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "transport_tuple.hpp"
#include <wmtk/simplex/top_level_cofaces.hpp>
#include "find_local_switch_sequence.hpp"
#include "local_switch_tuple.hpp"

Expand All @@ -11,14 +12,8 @@ Tuple transport_tuple(
const Tuple& source,
PrimitiveType primitive_type)
{
if (base_primitive_type <= primitive_type) {
std::vector<PrimitiveType> operations =
find_local_switch_sequence(base_source, base_target, base_primitive_type);
return local_switch_tuples(primitive_type, source, operations);
} else {
// TODO: implement this
// in top_level_cofaces find the one with the same
return Tuple();
}
std::vector<PrimitiveType> operations =
find_local_switch_sequence(base_source, base_target, base_primitive_type);
return local_switch_tuples(primitive_type, source, operations);
}
} // namespace wmtk::multimesh::utils
93 changes: 46 additions & 47 deletions tests/test_multi_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,53 +376,52 @@ TEST_CASE("multi_mesh_register_between_2D_and_1D", "[multimesh][1D][2D]")
}

// test map_to_child_tuples and map_to_parent_tuple
// TODO: this will fail before getting local_switch_tuple for EdgeMesh Working.
// {
// std::vector<Tuple> p_to_c0_map{child0.tuple_from_id(PE, 0), Tuple(), Tuple()};

// std::vector<Tuple> p_to_c1_map{
// child1.tuple_from_id(PE, 0),
// Tuple(),
// child1.tuple_from_id(PE, 1)};

// std::vector<Tuple> c0_to_p_map{parent.tuple_from_id(PE, 0)};

// std::vector<Tuple> c1_to_p_map{
// parent.tuple_from_id(PE, 0),
// parent.tuple_from_id(PE, 2)};


// for (long parent_index = 0; parent_index < 3; ++parent_index) {
// auto ptuple = parent.tuple_from_id(PE, parent_index);
// Simplex psimplex = Simplex(PE, ptuple);

// Tuple c0_expected = p_to_c0_map[parent_index];
// if (!c0_expected.is_null()) {
// auto c0tuples = parent.map_to_child_tuples(child0, psimplex);
// REQUIRE(c0tuples.size() == 1);
// CHECK(c0tuples[0] == c0_expected);
// }

// Tuple c1_expected = p_to_c1_map[parent_index];
// if (!c1_expected.is_null()) {
// auto c1tuples = parent.map_to_child_tuples(child1, psimplex);
// REQUIRE(c1tuples.size() == 1);
// CHECK(c1tuples[0] == c1_expected);
// }
// }
// for (size_t child0_index = 0; child0_index < c0_to_p_map.size(); ++child0_index) {
// auto tuple = child0.tuple_from_id(PE, child0_index);
// Simplex csimplex = Simplex(PE, tuple);
// auto ptuple = child0.map_to_parent_tuple(csimplex);
// CHECK(ptuple == c0_to_p_map[child0_index]);
// }
// for (size_t child1_index = 0; child1_index < c1_to_p_map.size(); ++child1_index) {
// auto tuple = child1.tuple_from_id(PE, child1_index);
// Simplex csimplex = Simplex(PE, tuple);
// auto ptuple = child1.map_to_parent_tuple(csimplex);
// CHECK(ptuple == c1_to_p_map[child1_index]);
// }
// }
{
std::vector<Tuple> p_to_c0_map{child0.tuple_from_id(PE, 0), Tuple(), Tuple()};

std::vector<Tuple> p_to_c1_map{
child1.tuple_from_id(PE, 0),
Tuple(),
child1.tuple_from_id(PE, 1)};

std::vector<Tuple> c0_to_p_map{parent.tuple_from_id(PE, 0)};

std::vector<Tuple> c1_to_p_map{
parent.tuple_from_id(PE, 0),
parent.tuple_from_id(PE, 2)};


for (long parent_index = 0; parent_index < 3; ++parent_index) {
auto ptuple = parent.tuple_from_id(PE, parent_index);
Simplex psimplex = Simplex(PE, ptuple);

Tuple c0_expected = p_to_c0_map[parent_index];
if (!c0_expected.is_null()) {
auto c0tuples = parent.map_to_child_tuples(child0, psimplex);
REQUIRE(c0tuples.size() == 1);
CHECK(c0tuples[0] == c0_expected);
}

Tuple c1_expected = p_to_c1_map[parent_index];
if (!c1_expected.is_null()) {
auto c1tuples = parent.map_to_child_tuples(child1, psimplex);
REQUIRE(c1tuples.size() == 1);
CHECK(c1tuples[0] == c1_expected);
}
}
for (size_t child0_index = 0; child0_index < c0_to_p_map.size(); ++child0_index) {
auto tuple = child0.tuple_from_id(PE, child0_index);
Simplex csimplex = Simplex(PE, tuple);
auto ptuple = child0.map_to_parent_tuple(csimplex);
CHECK(ptuple == c0_to_p_map[child0_index]);
}
for (size_t child1_index = 0; child1_index < c1_to_p_map.size(); ++child1_index) {
auto tuple = child1.tuple_from_id(PE, child1_index);
Simplex csimplex = Simplex(PE, tuple);
auto ptuple = child1.map_to_parent_tuple(csimplex);
CHECK(ptuple == c1_to_p_map[child1_index]);
}
}
}
}

Expand Down

0 comments on commit 4dcd1ef

Please sign in to comment.