Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite entity maps to be MeshTags #3371

Open
jorgensd opened this issue Aug 28, 2024 · 0 comments
Open

Rewrite entity maps to be MeshTags #3371

jorgensd opened this issue Aug 28, 2024 · 0 comments
Labels
enhancement New feature or request proposal Suggested change or addition

Comments

@jorgensd
Copy link
Member

Describe new/missing feature

Instead of having entity_maps as a dictionary, it should be a dolfinx::mesh::MeshTags object,
where the topology of the MeshTag is the mesh we are mapping to, the indices the entities in the input mesh topology, while the values are the entity number in the mesh we are mapping from.

This means that inverting the map is as easy as switching order of indices and values (and attaching the correct mesh topology), and we avoid storing -1 indices (that currently are resulting in segfaults whenever there are issues with user input, making it very hard to debug).

We would also no longer need a dictionary for the maps, as the topology is stored as part of the MeshTag, and we can create a topology -> list_index_in_input_entity_tags.

Internally in DOLFINx, we could unravel these to avoid calling find many times (similar to what we do with Dirichlet BC dofs), but then with explicit handling of the negative/non-existent entities.

Also note that creating the "parent_to_sub_mesh" map is a simpler operation than its inverse (as we do not have to sort the input entities to entity_map.

Suggested user interface

mesh = .....
sub_indices = ....
submesh, sub_to_parent, _, _ = dolfinx.mesh.create_submesh(mesh, dim, entities)
entity_map = dolfinx.mesh.meshtags(submesh, dim, np.arange(len(sub_to_parent), dtype=np.int32), sub_to_parent)

# Given a parent cell `c` find cell in submesh
sub_cell = entity_map.find(c)

# Invert map
parent_sort = np.argsort(sub_to_parent)
sub_cells = np.arange(len(sub_to_parent), dtype=np.int32)[parent_sort]
inverted_map = dolfinx.mesh.meshtags(mesh, dim, sub_to_parent[parent_sort], sub_cells)

# Given a child cell `d` find parent_cell
p_cell = inverted_map.find(d)
@jorgensd jorgensd added the enhancement New feature or request label Aug 28, 2024
@mscroggs mscroggs added the proposal Suggested change or addition label Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request proposal Suggested change or addition
Projects
None yet
Development

No branches or pull requests

2 participants