31 std::vector<Tuple> tagged_tuples;
33 if (tags.const_scalar_attribute(t) == tag_value) {
34 tagged_tuples.emplace_back(t);
38 auto run_edge = [&]() {
39 std::map<int64_t, int64_t> parent_to_child_vertex_map;
43 edge_mesh_matrix.resize(tagged_tuples.size(), 2);
45 for (
size_t i = 0; i < tagged_tuples.size(); ++i) {
46 const std::array<int64_t, 2> vs = {
54 for (
int k = 0; k < 2; k++) {
55 size_t size = parent_to_child_vertex_map.size();
56 parent_to_child_vertex_map.try_emplace(vs[k], size);
57 edge_mesh_matrix(i, k) = parent_to_child_vertex_map[vs[k]];
61 std::shared_ptr<EdgeMesh> child_ptr = std::make_shared<EdgeMesh>();
62 auto& child = *child_ptr;
63 child.initialize(edge_mesh_matrix);
67 auto run_face = [&]() {
68 std::map<int64_t, int64_t> parent_to_child_vertex_map;
69 int64_t child_vertex_count = 0;
72 tri_mesh_matrix.resize(tagged_tuples.size(), 3);
73 for (int64_t i = 0; i < tagged_tuples.size(); ++i) {
75 const std::array<int64_t, 3> vs = {
83 {PrimitiveType::Edge, PrimitiveType::Vertex}),
87 for (
int k = 0; k < 3; k++) {
88 size_t size = parent_to_child_vertex_map.size();
89 parent_to_child_vertex_map.try_emplace(vs[k], size);
90 tri_mesh_matrix(i, k) = parent_to_child_vertex_map.at(vs[k]);
93 std::shared_ptr<TriMesh> child_ptr = std::make_shared<TriMesh>();
94 auto& child = *child_ptr;
95 child.initialize(tri_mesh_matrix);
100 auto run_tet = [&]() {
101 std::map<int64_t, int64_t> parent_to_child_vertex_map;
102 int64_t child_vertex_count = 0;
106 tet_mesh_matrix.resize(tagged_tuples.size(), 4);
107 for (int64_t i = 0; i < tagged_tuples.size(); ++i) {
108 const std::array<int64_t, 4> vs = {
116 {PrimitiveType::Triangle, PrimitiveType::Edge, PrimitiveType::Vertex}),
121 {PrimitiveType::Edge, PrimitiveType::Vertex}),
124 for (
int k = 0; k < 4; ++k) {
125 size_t size = parent_to_child_vertex_map.size();
126 parent_to_child_vertex_map.try_emplace(vs[k], size);
127 tet_mesh_matrix(i, k) = parent_to_child_vertex_map[vs[k]];
134 std::shared_ptr<TetMesh> child_ptr = std::make_shared<TetMesh>();
135 auto& child = *child_ptr;
136 child.initialize(tet_mesh_matrix);
141 std::shared_ptr<Mesh> child_mesh_ptr;
147 std::shared_ptr<EdgeMesh> meshptr = std::make_shared<EdgeMesh>();
148 meshptr->initialize_free(tagged_tuples.size());
149 child_mesh_ptr = meshptr;
153 std::shared_ptr<TriMesh> meshptr = std::make_shared<TriMesh>();
154 meshptr->initialize_free(tagged_tuples.size());
155 child_mesh_ptr = meshptr;
159 std::shared_ptr<TetMesh> meshptr = std::make_shared<TetMesh>();
160 meshptr->initialize_free(tagged_tuples.size());
161 child_mesh_ptr = meshptr;
164 default:
throw(
"invalid child mesh type");
171 child_mesh_ptr = run_edge();
175 child_mesh_ptr = run_face();
179 child_mesh_ptr = run_tet();
182 default:
throw(
"invalid child mesh type");
186 assert(
bool(child_mesh_ptr));
187 auto& child = *child_mesh_ptr;
189 std::vector<std::array<Tuple, 2>> child_to_parent_map(tagged_tuples.size());
190 assert(tagged_tuples.size() == child.capacity(pt));
192 const auto child_top_dimension_tuples = child.get_all(pt);
194 for (
size_t i = 0; i < tagged_tuples.size(); ++i) {
195 child_to_parent_map[i] = {{child_top_dimension_tuples[i], tagged_tuples[i]}};
199 return child_mesh_ptr;
204 const std::string& tag,
205 const int64_t tag_value,
217 const int64_t tag_value,
233 [&](
auto&& handle) noexcept -> std::shared_ptr<Mesh> {
234 using HandleType =
typename std::decay_t<decltype(handle)>;
235 using T =
typename HandleType::Type;
236 if constexpr (wmtk::attribute::MeshAttributeHandle::template handle_type_is_basic<
239 [&](
auto&& value) noexcept -> std::shared_ptr<Mesh> {
240 if constexpr (std::is_convertible_v<std::decay_t<decltype(value)>, T>) {
249 "Tried to use a tag value that was not convertible to "
250 "the tag attribute type");
257 "extracting a child mesh fro ma tag");
attribute::MeshAttributeHandle get_attribute_handle(const std::string &name, const PrimitiveType ptype) const
const attribute::Accessor< T, Mesh, D > create_const_accessor(const attribute::MeshAttributeHandle &handle) const
int64_t id(const Tuple &tuple, PrimitiveType type) const
return the global id of the Tuple of the given dimension
std::vector< Tuple > get_all(PrimitiveType type) const
Generate a vector of Tuples from global vertex/edge/triangle/tetrahedron index.
Tuple switch_tuples(const Tuple &tuple, const ContainerType &op_sequence) const
virtual Tuple switch_tuple(const Tuple &tuple, PrimitiveType type) const =0
switch the orientation of the Tuple of the given dimension
PrimitiveType top_simplex_type() const
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
std::variant< char, int64_t, double, wmtk::Rational, std::tuple< char, wmtk::Rational, double > > ValueVariant
Handle that represents attributes for some mesh.
PrimitiveType primitive_type() const
static std::shared_ptr< Mesh > extract_and_register_child_mesh_from_tag_handle(Mesh &m, const wmtk::attribute::TypedAttributeHandle< T > &tag_handle, const T &tag_value, bool child_is_free)
std::shared_ptr< Mesh > extract_and_register_child_mesh_from_tag_handle(Mesh &m, const wmtk::attribute::TypedAttributeHandle< int64_t > &tag_handle, const int64_t tag_value, bool child_is_free)
extract a child mesh based on the tag handle and the tag value, and register it to the input (parent)...
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
RowVectors< int64_t, 3 > RowVectors3l
void log_and_throw_error(const std::string &msg)
RowVectors< int64_t, 4 > RowVectors4l
RowVectors< int64_t, 2 > RowVectors2l