Wildmeshing Toolkit
Loading...
Searching...
No Matches
multimesh.cpp
Go to the documentation of this file.
1#include "multimesh.hpp"
2
8#include "from_boundary.hpp"
10
12
13
15 std::pair<std::shared_ptr<Mesh>, std::shared_ptr<Mesh>> multimesh(
16 const MultiMeshType& type,
17 Mesh& parent,
18 std::shared_ptr<Mesh> child,
19 const attribute::MeshAttributeHandle parent_position_handle,
20 const std::string& tag_name,
21 const int64_t tag_value,
22 const int64_t primitive)
23{
25 if (parent.top_simplex_type() == child->top_simplex_type() &&
26 parent.capacity(parent.top_simplex_type()) ==
27 child->capacity(child->top_simplex_type())) {
28#if defined(USE_NEW_IMPL_MM)
29 from_facet_bijection(parent, *child);
30#else
31 auto child_map = wmtk::multimesh::same_simplex_dimension_bijection(parent, *child);
32
33 parent.register_child_mesh(child, child_map);
34#endif
35
36 return std::make_pair(parent.shared_from_this(), child);
37 } else {
38 throw std::runtime_error("unsupported multimesh mapping");
39 }
40 } else if (
43 const bool use_boundary = type == wmtk::components::multimesh::MultiMeshType::Boundary;
44 std::string tag;
45 int64_t value;
46 PrimitiveType ptype;
47
48 bool use_rational_position = parent_position_handle.held_type() ==
49 wmtk::attribute::MeshAttributeHandle::HeldType::Rational;
50
51 if (use_boundary) {
52 tag = "is_boundary";
53 value = 1;
55
56#if defined(USE_NEW_IMPL_MM)
57 child = from_boundary(parent, ptype, tag, value);
58#else
59 auto is_boundary_handle = parent.register_attribute<int64_t>(tag, ptype, 1);
60 auto is_boundary_accessor = parent.create_accessor(is_boundary_handle.as<int64_t>());
61
62 for (const auto& t : parent.get_all(ptype)) {
63 is_boundary_accessor.scalar_attribute(t) = parent.is_boundary(ptype, t) ? value : 0;
64 }
65#endif
66 } else {
67 tag = tag_name;
68 value = tag_value;
69 ptype = get_primitive_type_from_id(primitive);
70 }
71
72#if defined(USE_NEW_IMPL_MM)
74 parent,
75 tag,
76 value,
77 ptype);
78 }
79
80#else
82 parent,
83 tag,
84 value,
85 ptype);
86 child = child_mesh;
87#endif
88
89 if (!use_rational_position) {
90 auto child_position_handle = child->register_attribute<double>(
91 "vertices", // TODO fix me
93 parent_position_handle.dimension());
94
95 auto propagate_to_child_position = [](const Eigen::MatrixXd& P) -> Eigen::VectorXd {
96 return P;
97 };
98 auto update_child_positon =
99 std::make_shared<wmtk::operations::SingleAttributeTransferStrategy<double, double>>(
100 child_position_handle,
101 parent_position_handle,
102 propagate_to_child_position);
103 update_child_positon->run_on_all();
104 } else {
105 auto child_position_handle = child->register_attribute<Rational>(
106 "vertices", // TODO fix me
108 parent_position_handle.dimension());
109
110 auto propagate_to_child_position =
111 [](const Eigen::MatrixX<Rational>& P) -> Eigen::VectorX<Rational> { return P; };
112 auto update_child_positon = std::make_shared<
114 child_position_handle,
115 parent_position_handle,
116 propagate_to_child_position);
117 update_child_positon->run_on_all();
118 }
119
120 return std::make_pair(parent.shared_from_this(), child);
121 }
122
123 throw std::runtime_error("unsupported multimesh type");
124}
125
126} // namespace wmtk::components::multimesh
attribute::MeshAttributeHandle register_attribute(const std::string &name, PrimitiveType type, int64_t size, bool replace=false, T default_value=T(0))
int64_t capacity(PrimitiveType type) const
read in the m_capacities return the upper bound for the number of entities of the given dimension
bool is_boundary(const simplex::Simplex &tuple) const
check if a simplex lies on a boundary or not
Definition Mesh.cpp:107
std::vector< Tuple > get_all(PrimitiveType type) const
Generate a vector of Tuples from global vertex/edge/triangle/tetrahedron index.
Definition Mesh.cpp:18
void register_child_mesh(const std::shared_ptr< Mesh > &child_mesh_ptr, const std::vector< std::array< Tuple, 2 > > &map_tuples)
register a mesh as the child of this mesh
int64_t top_cell_dimension() const
Definition Mesh.hpp:976
PrimitiveType top_simplex_type() const
Definition Mesh.hpp:980
attribute::Accessor< T, Mesh, attribute::CachingAttribute< T >, D > create_accessor(const attribute::MeshAttributeHandle &handle)
void from_facet_bijection(Mesh &parent, Mesh &child)
std::pair< std::shared_ptr< Mesh >, std::shared_ptr< Mesh > > multimesh(const MultiMeshType &type, Mesh &parent, std::shared_ptr< Mesh > child, const attribute::MeshAttributeHandle parent_position_handle, const std::string &tag_name, const int64_t tag_value, const int64_t primitive)
Definition multimesh.cpp:15
std::shared_ptr< Mesh > from_boundary(Mesh &mesh, const PrimitiveType ptype, const std::string &attribute_name, char value, const std::vector< wmtk::attribute::MeshAttributeHandle > &passed_attributes)
std::shared_ptr< Mesh > extract_and_register_child_mesh_from_tag(Mesh &m, const std::string &tag, const int64_t tag_value, const PrimitiveType pt, bool child_is_free)
extract a child mesh based on the given tag and tag value, and register it to the input (parent) mesh
std::vector< std::array< Tuple, 2 > > same_simplex_dimension_bijection(const Mesh &parent, const Mesh &child)
constexpr PrimitiveType get_primitive_type_from_id(int8_t id)
Get the primitive type corresponding to its unique integer id.