Assigning physical groups after `removeAllDuplicates` in tiled geometry
I have a geometry consisting of square subunits. Each subunit has physical groups, and the union of certain physical groups should be used to make a "final" physical group for the total geometry so that not all mesh elements are saved. I also need a contiguous mesh formed from all the subunits so that one "final" mesh is created. This (?) requires that duplicate entities are removed, in this case via gmsh.model.occ.removeAllDuplicates
, and then the desired compound surface is specified via gmsh.model.mesh.setCompound
. I have included my attempt. How can I use these subunit physical groups to inform "final" physical groups, e.g., on the bottom boundary of the total geometry, while also having a contiguous mesh via setCompound
? The call to removeAllDuplicates
destroys any previously physical groups, this is really the crux of my issue, so meshing occurs for all entities in the geometry.
import Gmsh: gmsh
gmsh.initialize()
gmsh.model.add("repeat_rectangles")
# Define the tiled geometry with overlapping edges
r1 = gmsh.model.occ.addRectangle(0, 0, 0, 1, 1)
r2 = gmsh.model.occ.addRectangle(1, 0, 0, 1, 1)
r3 = gmsh.model.occ.addRectangle(0, 1, 0, 1, 1)
r4 = gmsh.model.occ.addRectangle(1, 1, 0, 1, 1)
gmsh.model.occ.synchronize()
# Physical groups for curves that are on the bottom boundary of the bottom rectangles
r1_curve_dimTags = gmsh.model.getBoundary([(2, r1)])
gmsh.model.addPhysicalGroup(1, [r1_curve_dimTags[1][2]], -1, "r1-bottom")
r2_curve_dimTags = gmsh.model.getBoundary([(2, r2)])
gmsh.model.addPhysicalGroup(1, [r2_curve_dimTags[1][2]], -1, "r2-bottom")
# Final mesh physical group corresponding to the union of the r1-bottom and r2-bottom
r1_bottom_dimTags = gmsh.model.getEntitiesForPhysicalName("r1-bottom")
r2_bottom_dimTags = gmsh.model.getEntitiesForPhysicalName("r2-bottom")
final_bottom_tags = [r1_bottom_dimTags[1][2], r2_bottom_dimTags[1][2]]
gmsh.model.addPhysicalGroup(1, final_bottom_tags, -1, "union-r1-r2-bottom")
# TODO: NEED HELP HERE!
# When this is true, the compound mesh is sucesssfully generated
# but physical groups are removed
if true
# Necessary for `setCompound` BUT removes physical groups
gmsh.model.occ.removeAllDuplicates()
gmsh.model.occ.synchronize()
# Define the contiguous mesh
gmsh.model.mesh.setCompound(2, [r1, r2, r3, r4])
end
gmsh.model.mesh.generate(2)
gmsh.fltk.run()
gmsh.finalize()