Make conformal mesh from abutting volumes, preserving volume entity tags
I am using the python gmsh API to create a mesh from planar volumes "stacked" atop one-another, like in this SE post. I have robust code generating the coordinates of the stacked shapes, so it should be a simple matter of plugging these into gmsh and meshing - yet I'm having a lot of trouble creating a conformal mesh.
My geometric scene contains lots of abutting volumes with ergo overlapping boundary surfaces. At some point, these must be cleaned/merged/deleted. For simplicity, let's imagine I am simply extruding simple (hole-free) polygons.
My current attempt looks like:
- add a new volume (potentially abutting but not overlapping existing volumes) to the geometric scene, ignoring any existing geometry, via:
_FACTORY = gmsh.model.occ def extrude_polygon(xy, z0, z1) point_tags = [_FACTORY.add_point(x,y,z0, mesh_size) for x,y in xy] line_tags = [_FACTORY.add_line(point_tags[i], point_tags[i+1]) for i in range(len(point_tags)-1)] face_tag = _FACTORY.add_plane_surface([_FACTORY.add_curve_loop(line_tags)]) object_tags = _FACTORY.extrude([(2,face_tag)], 0,0, z1-z0) volume_tags = [obj for obj in objs if obj[0]==3] return volume_tags[0]
- restore conformance via:
_FACTORY.removeAllDuplicates()
The latter consequence of removeAllDuplicates()
is the killer. If my volume entity tags change, I completely lose a handle to my existing geometric structures, of which I need later reference. A change of tag is fine if I could know the mapping of old to new tags.
I have also tried:
- replacing
occ.removeAllDuplicates
withocc.healShapes()
, although this appears to delete all of the volume mesh points! - healing only the low-dimensional shapes, via:
_FACTORY.synchronize() # get all points, lines and surfaces non_vol_entities = [] for d in [0,1,2]: non_vol_entities += gmsh.model.occ.getEntities(dim=d) # heal them, leaving volumes unchanged _FACTORY.healShapes(non_vol_entities)
- leaves some superfluous edges (embedded in surfaces) behind (not too bad)
- causes an error when the resulting geometry is meshed of "Invalid boundary mesh (overlapping facets)", even for the incredibly simple scenario of two cubes sharing a single face!
What is the correct way to produce a conformal mesh from a coordinate-based geometric scene description containing abutting volumes? How can I retain the tags or some kind of reference to particular volume entities which survive conformance?