Gmsh not recognizing separate surfaces in .stl

Hello,

I am working on a simulation project where I have been running simulations on a geometry (.msh) provided in the simulation software download package. However, now I would like to import a custom geometry made by a lab member. I was handed a .stl file and was able to accomplish (1) writing a .geo file to convert .stl to .msh, and (2) running simulations to completion and visualizing results. However, the results are meaningless, and this can be traced back to the fact that I have not properly ‘calibrated’ the software to my custom geometry-- the simulation input file requires boundary tags to be specified. The problem is, I have not been able to identify boundary tags for my custom 3D geometry, and the issue seems to be that in Gmsh or blender, when I try to select one of the two distinct surfaces I’m intending to tag, the entire surface of the geometry is selected as one contiguous surface. I even re-CAD’ed the .stl I was provided using two separate surfaces in the CAD software (onshape), but this led to the same result of Gmsh recognizing only one contiguous surface.

I looked up my problem online and it was suggested that I somehow break up the surface into two separate .stl files, so I tried this. It was not successful as I selected a single surface on Onshape and exported to .stl, but when I opened it in Gmsh, the entire geometry was opened. I tried a different approach to exporting one surface by selecting the surface in the side panel on Onshape then exporting, but my only options for exporting were DXF or DWG, both of which resulted in error messages when attempting to open in Gmsh.

I would appreciate any guidance and assistance anyone can offer. It seems like more experienced people may have run into this issue before!

p.s. I looked at this post which seems to ask similar question:

Hi,

Working with STL files can be quite complex, and as far as I know, there’s no standard methodology for handling them—except perhaps in some commercial software.

However, it’s possible to manage them using tools like Gmsh, Meshmixer, or Salome, either individually or in combination. Here are a few approaches that might help:

  • Using Gmsh
    There’s a helpful tutorial here: Gmsh 4.13.1
    The method is based on computing the cosine between triangle normals. By choosing an appropriate angle threshold, Gmsh can automatically separate different surface regions. Once that’s done, you can easily define Physical Groups, which are essential when assigning boundary markers in FEniCS.
  • Using Meshmixer
    You can use Meshmixer to manually or semi-automatically separate surfaces by creating distinct groups. Afterward, export the modified mesh and load it into Gmsh to define your physical tags.
  • Using Salome
    Salome is another alternative, although I personally found it more complex to use. Still, it can be quite powerful for certain workflows.
  • If none of these work
    Then you might need to develop a custom script to process the STL file—e.g., by analyzing the triangle normals to group regions based on geometry.

In summary, the first two approaches (Gmsh or Meshmixer + Gmsh) usually work well, even for moderately complex cases.

Best,

1 Like

Thank you for the advice, I will check these out!