diff --git a/src/wmtk/Mesh.hpp b/src/wmtk/Mesh.hpp index 5220b3ef3b..71fed7ca9f 100644 --- a/src/wmtk/Mesh.hpp +++ b/src/wmtk/Mesh.hpp @@ -15,6 +15,8 @@ #include "attribute/AttributeManager.hpp" #include "attribute/AttributeScopeHandle.hpp" #include "attribute/MeshAttributes.hpp" +// included to make a friend as this requires IDs +#include #include "simplex/Simplex.hpp" @@ -47,6 +49,10 @@ class Mesh : public std::enable_shared_from_this friend class ParaviewWriter; friend class MeshReader; friend class MultiMeshManager; + friend std::vector> multimesh::same_simplex_dimension_surjection( + const Mesh& parent, + const Mesh& child, + const std::vector& parent_simplices); virtual PrimitiveType top_simplex_type() const = 0; @@ -358,7 +364,8 @@ class Mesh : public std::enable_shared_from_this // std::shared_ptr request_accesor_cache(); //[[nodiscard]] AccessorScopeHandle push_accesor_scope(); -protected: // THese are protected so unit tests can access - do not use manually in other derived classes? +protected: // THese are protected so unit tests can access - do not use manually in other derived + // classes? attribute::AttributeManager m_attribute_manager; MultiMeshManager m_multi_mesh_manager; diff --git a/src/wmtk/multimesh/CMakeLists.txt b/src/wmtk/multimesh/CMakeLists.txt index 512d2b1553..d41a4a8680 100644 --- a/src/wmtk/multimesh/CMakeLists.txt +++ b/src/wmtk/multimesh/CMakeLists.txt @@ -1 +1,8 @@ + +set(SRC_FILES + same_simplex_dimension_surjection.hpp + same_simplex_dimension_surjection.cpp + ) +target_sources(wildmeshing_toolkit PRIVATE ${SRC_FILES}) + add_subdirectory(utils) diff --git a/src/wmtk/multimesh/same_simplex_dimension_surjection.cpp b/src/wmtk/multimesh/same_simplex_dimension_surjection.cpp new file mode 100644 index 0000000000..54d7ff32d5 --- /dev/null +++ b/src/wmtk/multimesh/same_simplex_dimension_surjection.cpp @@ -0,0 +1,51 @@ +#include "same_simplex_dimension_surjection.hpp" +#include +#include + + +namespace wmtk::multimesh { +std::vector> same_simplex_dimension_surjection( + const Mesh& parent, + const Mesh& child) +{ + PrimitiveType primitive_type = parent.top_simplex_type(); + assert(primitive_type == child.top_simplex_type()); + long size = parent.capacity(primitive_type); + assert(size == child.capacity(primitive_type)); + std::vector ps; + ps.reserve(size); + std::iota(ps.begin(), ps.end(), 0); + return same_simplex_dimension_surjection(parent, child, ps); +} + +std::vector> same_simplex_dimension_surjection( + const Mesh& parent, + const Mesh& child, + const std::vector& parent_simplices) +{ + PrimitiveType primitive_type = parent.top_simplex_type(); + assert(primitive_type == child.top_simplex_type()); + + long size = child.capacity(primitive_type); + assert(size == long(parent_simplices.size())); + std::vector> ret; + ret.reserve(size); + + auto parent_flag_accessor = parent.get_const_flag_accessor(primitive_type); + auto child_flag_accessor = child.get_const_flag_accessor(primitive_type); + + 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) { + continue; + } + if (child_flag_accessor.const_scalar_attribute(pt) & 1 == 0) { + continue; + } + + ret.emplace_back(std::array{{pt, ct}}); + } + return ret; +} +} // namespace wmtk::multimesh diff --git a/src/wmtk/multimesh/same_simplex_dimension_surjection.hpp b/src/wmtk/multimesh/same_simplex_dimension_surjection.hpp new file mode 100644 index 0000000000..81fb2c75c4 --- /dev/null +++ b/src/wmtk/multimesh/same_simplex_dimension_surjection.hpp @@ -0,0 +1,27 @@ +#pragma once +#include +#include +#include + +namespace wmtk { +class Mesh; +} + +namespace wmtk::multimesh { + +// Handles the "trivial " mapping case as we see in OBJ files +// parent and child are assumed to be homogeneous meshes of the same dimension and the same number +// of top level simplices It is assumed that for each index between [0,num_top_level_simplices) it +// is assumed that the tuple parent.tuple_from_id(pt,index) should be mapped to +// child.tuple_from_id(pt,index) +std::vector> same_simplex_dimension_surjection( + const Mesh& parent, + const Mesh& child); +// same as above except the mapping selects a subset of parent_simplices +// the tuple parent.tuple_from_id(pt,parent_simplices[index]) should be mapped to +// child.tuple_from_id(pt,index) +std::vector> same_simplex_dimension_surjection( + const Mesh& parent, + const Mesh& child, + const std::vector& parent_simplices); +} // namespace wmtk::multimesh