Skip to content

Commit

Permalink
adding an initial implementation of the "identity map" multimesh mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
mtao committed Oct 5, 2023
1 parent b3a38a3 commit fe969ee
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/wmtk/Mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <wmtk/multimesh/same_simplex_dimension_surjection.hpp>

#include "simplex/Simplex.hpp"

Expand Down Expand Up @@ -47,6 +49,10 @@ class Mesh : public std::enable_shared_from_this<Mesh>
friend class ParaviewWriter;
friend class MeshReader;
friend class MultiMeshManager;
friend std::vector<std::array<Tuple, 2>> multimesh::same_simplex_dimension_surjection(
const Mesh& parent,
const Mesh& child,
const std::vector<long>& parent_simplices);

virtual PrimitiveType top_simplex_type() const = 0;

Expand Down Expand Up @@ -358,7 +364,8 @@ class Mesh : public std::enable_shared_from_this<Mesh>
// std::shared_ptr<AccessorCache> 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;
Expand Down
7 changes: 7 additions & 0 deletions src/wmtk/multimesh/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
51 changes: 51 additions & 0 deletions src/wmtk/multimesh/same_simplex_dimension_surjection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "same_simplex_dimension_surjection.hpp"
#include <numeric>
#include <wmtk/Mesh.hpp>


namespace wmtk::multimesh {
std::vector<std::array<Tuple, 2>> 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<long> ps;
ps.reserve(size);
std::iota(ps.begin(), ps.end(), 0);
return same_simplex_dimension_surjection(parent, child, ps);
}

std::vector<std::array<Tuple, 2>> same_simplex_dimension_surjection(
const Mesh& parent,
const Mesh& child,
const std::vector<long>& 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<std::array<Tuple, 2>> 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<Tuple, 2>{{pt, ct}});
}
return ret;
}
} // namespace wmtk::multimesh
27 changes: 27 additions & 0 deletions src/wmtk/multimesh/same_simplex_dimension_surjection.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once
#include <array>
#include <vector>
#include <wmtk/Tuple.hpp>

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<std::array<Tuple, 2>> 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<std::array<Tuple, 2>> same_simplex_dimension_surjection(
const Mesh& parent,
const Mesh& child,
const std::vector<long>& parent_simplices);
} // namespace wmtk::multimesh

0 comments on commit fe969ee

Please sign in to comment.