16 constexpr
static std::array<std::array<int64_t, 4>, 4> n_local_ids = {{
26 const int64_t tag_value)
28 , m_tag_acc(m_mesh.create_const_accessor<int64_t>(tag_handle))
29 , m_tag_value(tag_value)
30 , m_tag_ptype(tag_handle.primitive_type())
77 auto local_id = [pt](
const Tuple& t) -> int64_t {
78 int64_t local_id = -1;
84 default: assert(
false);
break;
94 auto set_id = [&local_id](
97 const int64_t val) ->
void {
103 int64_t simplex_counter = 0;
105 for (
const Tuple& cell_tuple : top_dimension_child_tuples) {
111 for (
const Tuple& s_tuple : simplex_tuples) {
112 if (get_id(id_acc, s_tuple) != -1) {
119 for (
const Tuple& t : s_region) {
120 set_id(id_acc, t, simplex_counter);
128 Eigen::MatrixX<int64_t> id_matrix;
129 id_matrix.resize(top_dimension_child_tuples.size(), id_acc.dimension());
131 coface_vector.resize(simplex_counter);
134 for (
size_t i = 0; i < top_dimension_child_tuples.size(); ++i) {
135 const Tuple& cell_tuple = top_dimension_child_tuples[i];
142 assert(face_tuples.size() == id_acc.dimension());
144 for (
size_t j = 0; j < face_tuples.size(); ++j) {
145 const int64_t
id = get_id(id_acc, face_tuples[j]);
147 id_matrix(i, local_id(face_tuples[j])) = id;
148 coface_vector(
id) = i;
166 std::vector<Tuple> connected_region;
168 std::set<Tuple> touched_tuples;
173 const Tuple t = q.front();
178 const auto [it, did_insert] = touched_tuples.insert(t);
183 connected_region.emplace_back(t);
185 const std::vector<Tuple> pt_intersection =
189 for (
const Tuple& t_version : pt_intersection) {
194 const std::vector<simplex::Simplex> child_faces =
m_mesh.
map_to_child(child, root_face);
196 if (child_faces.size() != 2) {
201 assert(child_faces[0].tuple() == t_version || child_faces[1].tuple() == t_version);
204 child_faces[0].tuple() == t_version ? child_faces[1].tuple()
205 : child_faces[0].tuple());
209 return connected_region;
223 const int64_t connecting_pt_id = tag_ptype_id - 1;
226 auto local_id = [connecting_ptype](
const Tuple& t) -> int64_t {
227 int64_t local_id = -1;
228 switch (connecting_ptype) {
233 default: assert(
false);
break;
248 "multimesh_from_tag_adjacency",
250 n_local_ids[tag_ptype_id][connecting_pt_id],
259 "multimesh_from_tag_top_substructure_simplex_id",
264 auto top_simplex_id_acc = child.
create_accessor<int64_t>(top_simplex_id_handle);
267 for (
size_t i = 0; i < top_dimension_child_tuples.size(); ++i) {
268 top_simplex_id_acc.scalar_attribute(top_dimension_child_tuples[i]) = i;
272 for (
const Tuple& cell_tuple : top_dimension_child_tuples) {
278 for (
const Tuple& ft : face_tuples) {
283 const std::vector<simplex::Simplex> child_faces =
m_mesh.
map_to_child(child, root_face);
285 if (child_faces.size() != 2) {
290 assert(child_faces[0].tuple() == ft || child_faces[1].tuple() == ft);
292 const Tuple neighbor =
293 child_faces[0].tuple() == ft ? child_faces[1].tuple() : child_faces[0].tuple();
296 set_id(adj_acc, ft, top_simplex_id_acc.const_scalar_attribute(neighbor));
300 Eigen::MatrixX<int64_t> adj_matrix;
303 for (
size_t i = 0; i < top_dimension_child_tuples.size(); ++i) {
309 assert(face_tuples.size() == adj_matrix.cols());
311 for (
size_t j = 0; j < face_tuples.size(); ++j) {
312 const int64_t
id = get_id(adj_acc, face_tuples[j]);
313 adj_matrix(i, local_id(face_tuples[j])) = id;
324 std::vector<Tuple> tagged_tuples;
327 for (
const Tuple& t : tag_type_tuples) {
331 tagged_tuples.emplace_back(t);
336 Eigen::MatrixX<int64_t> id_matrix;
337 id_matrix.resize(tagged_tuples.size(), n_vertices_per_simplex);
364 std::vector<std::array<Tuple, 2>> child_to_parent_map(tagged_tuples.size());
368 assert(tagged_tuples.size() == child_top_dimension_tuples.size());
370 for (
size_t i = 0; i < tagged_tuples.size(); ++i) {
371 child_to_parent_map[i] = {{child_top_dimension_tuples[i], tagged_tuples[i]}};
394 std::string(
"multimesh_from_tag_new_ids_") + std::to_string(pt_id),
405 std::vector<Tuple> tagged_tuples;
408 for (
const Tuple& t : tag_type_tuples) {
412 tagged_tuples.emplace_back(t);
448 static_cast<TetMesh&
>(*m_substructure_ptr)
456 std::vector<std::array<Tuple, 2>> child_to_parent_map(tagged_tuples.size());
460 assert(tagged_tuples.size() == child_top_dimension_tuples.size());
462 for (
size_t i = 0; i < tagged_tuples.size(); ++i) {
463 child_to_parent_map[i] = {{child_top_dimension_tuples[i], tagged_tuples[i]}};
480 return s_in_sub.size() < 2;
bool is_connectivity_valid() const override
void initialize_free(int64_t count)
void initialize(Eigen::Ref< const RowVectors2l > E, bool is_free=false)
attribute::MeshAttributeHandle register_attribute(const std::string &name, PrimitiveType type, int64_t size, bool replace=false, T default_value=T(0))
std::vector< Tuple > get_all(PrimitiveType type) const
Generate a vector of Tuples from global vertex/edge/triangle/tetrahedron index.
attribute::Accessor< T, Mesh, D > create_accessor(const attribute::MeshAttributeHandle &handle)
simplex::Simplex map_to_parent(const simplex::Simplex &my_simplex) const
optimized map from a simplex from this mesh to its direct parent
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
void deregister_child_mesh(const std::shared_ptr< Mesh > &child_mesh_ptr)
Deregister a child mesh.
std::vector< simplex::Simplex > map_to_child(const Mesh &child_mesh, const simplex::Simplex &my_simplex) const
optimized map fromsimplex from this mesh to one of its direct children
void initialize(int64_t count)
void initialize_free(int64_t count)
void initialize(Eigen::Ref< const RowVectors4l > TV, Eigen::Ref< const RowVectors6l > TE, Eigen::Ref< const RowVectors4l > TF, Eigen::Ref< const RowVectors4l > TT, Eigen::Ref< const VectorXl > VT, Eigen::Ref< const VectorXl > ET, Eigen::Ref< const VectorXl > FT)
bool is_connectivity_valid() const final override
bool is_connectivity_valid() const final override
void initialize_free(int64_t count)
void initialize(Eigen::Ref< const RowVectors3l > FV, Eigen::Ref< const RowVectors3l > FE, Eigen::Ref< const RowVectors3l > FF, Eigen::Ref< const VectorXl > VF, Eigen::Ref< const VectorXl > EF)
MapResult< D > vector_attribute(const ArgType &t)
T const_scalar_attribute(const ArgType &t) const
ConstMapResult< D > const_vector_attribute(const ArgType &t) const
int64_t dimension() const
void build_adjacency_matrix()
Create the adjacency (stored as attribute) of the substructure.
void remove_soup()
Remove the substructure soup from the multimesh.
const PrimitiveType m_tag_ptype
std::shared_ptr< Mesh > substructure_soup() const
Returns a pointer to the substructure soup.
std::shared_ptr< Mesh > substructure() const
Returns a pointer to the manifold substructure mesh.
Eigen::MatrixX< int64_t > get_new_id_matrix(const PrimitiveType ptype) const
const attribute::Accessor< int64_t > m_tag_acc
std::vector< Tuple > get_connected_region(const Tuple &t, const PrimitiveType ptype)
Get tuples with different global_cid that all represent simplex(t_in, ptype) and are in the same tag-...
std::shared_ptr< Mesh > m_substructure_ptr
std::shared_ptr< Mesh > m_soup_ptr
bool is_root_simplex_manifold(const simplex::Simplex &s) const
std::map< PrimitiveType, VectorXl > m_new_top_coface_vectors
void compute_substructure_mesh()
Create a manifold mesh from the substructure.
std::map< PrimitiveType, attribute::MeshAttributeHandle > m_new_id_handles
const int64_t m_tag_value
Eigen::MatrixX< int64_t > adjacency_matrix() const
MultiMeshFromTag(Mesh &mesh, const attribute::MeshAttributeHandle &tag_handle, const int64_t tag_value)
void create_substructure_soup()
Create a multimesh where the child-mesh is just a soup (no connectivity) of m_mesh.
bool is_substructure_simplex_manifold(const simplex::Simplex &s) const
VectorXl get_new_top_coface_vector(const PrimitiveType ptype) const
std::map< PrimitiveType, Eigen::MatrixX< int64_t > > m_new_id_matrices
attribute::MeshAttributeHandle m_adjacency_handle
Eigen::MatrixX< int64_t > m_adjacency_matrix
void compute_substructure_ids()
Compute the ids of the manifold substructure.
std::vector< Tuple > tuples_preserving_primitive_types(const Mesh &mesh, const Tuple &t, const PrimitiveType simplex_ptype, const PrimitiveType face_ptype)
Compute all tuples that contain simplex(ptype1, t) and that are contained by simplex(ptype2,...
std::vector< Tuple > faces_single_dimension_tuples(const Mesh &mesh, const Simplex &simplex, const PrimitiveType face_type)
std::vector< PrimitiveType > primitive_below(PrimitiveType pt, bool lower_to_upper)
constexpr PrimitiveType get_primitive_type_from_id(int8_t id)
Get the primitive type corresponding to its unique integer id.
void log_and_throw_error(const std::string &msg)
constexpr int8_t get_primitive_type_id(PrimitiveType t)
Get a unique integer id corresponding to each primitive type.
VectorX< int64_t > VectorXl