Allow mesh renumbering
Background
QGIS' recent introduction of mesh editing capability allows users to edit mesh files within the GIS application itself.
Issue
Deleting nodes or elements in QGIS does not alter the IDs of any other nodes or elements in the mesh, creating gaps in the ID range. These meshes are not valid as per the 2DM standard and may need renumbering for further processing.
Solutions
-
Add a QGIS processing toolbox algorithm that renumbers mesh IDs. This could be done in three modes:
a. Fill gaps (default) 1. Scan all mesh IDs, keeping track of the number of missing IDs (-> N) 2. Remove N entities from the end of the ID list 3. Reinsert the removed entities into the previous identified gaps to create consecutive ID blocks
b. Regenerate (faster but more destructive) This mode reads nodes and elements with no concern for their current ID and re-saves them in ascending order. This mode could also read meshes with invalid or malformed node entries, i.e. unsorted or using invalid IDs.
c. Optimise (slower but more efficient, might take exceedingly long for large meshes) This mode would utilise NumPy matrix indices to optimise the layout of the node ID order to reduce the banded diagonal matrix bandwidth.
-
We could drop the ID sorting and gap requirement for meshes. This hurts compatibility with other programs as it violates the 2DM format, and additionally may have significant performance impacts for large meshes as the mesh IDs will no longer be sorted on-disk.
This would require us to perform a random search when retrieving IDs (
O(n)
). A sorted approach replaces this with a binary search (O(log(n))
), while a gapless sorted approach can be treated as a map where a given ID immediately translates to the storage location in the file (O(1)
not accounting for file seek overhead). -
As a less restrictive variant, we could use material IDs to blank out regions of the mesh without deleting the associated element. This would keep our files a valid 2DM representation but would require an additional conversion step for use in BASEMENT as there is no native "ignore" flag for elements.