Improved Functionality and Tips for Importing STL and NASTRAN® Files
STL files originating from 3D scan sources and meshes in the NASTRAN® file format are often used as bases for geometries. However, performing simulations on these realistic objects can be challenging, particularly when preparing the geometry. The COMSOL Multiphysics® software contains features for dealing with these files. Learn how to utilize this functionality as well as how to achieve good results when importing STL and NASTRAN® files.
The STL and NASTRAN® Formats
The STL format, as mentioned previously on the blog, is one of the standard file formats for 3D printing, but it is also often used as the format for 3D scans. STL files contain only the triangulated surface, which we can also call a surface mesh, of a 3D object. COMSOL Multiphysics supports multiple objects in a single STL file, according to a widely used nonstandard extension of the format.
In its standard form, a text STL file begins with a line starting with
solid and ends with a line starting with
endsolid. Many programs support text STL files, which can contain several of these sections in one file. Importing this type of file results in multiple geometric objects, the number of which depends on how many such sections are found.
An STL file of a vertebra imported into COMSOL Multiphysics. This sequence shows a number of the steps that can be taken to simplify the mesh and thus the simulation of this geometry: the imported surface mesh; the generated geometry; the geometry after partitioning; and, finally, embedding this geometry into a surrounding volume and the final mesh that results from this. Image credit: Mark Yeoman, Continuum Blue Ltd., U.K.
The NASTRAN® file format is the most common format for exchanging 3D meshes among simulation tools. This format supports hundreds of NASTRAN® file entries describing various mesh elements, loads, and materials — making it possible to define a complete finite element model. The COMSOL Multiphysics software supports the import of the mesh, selections, and materials.
If we compare these two formats from the point of view of a COMSOL Multiphysics user, we will find some similarities. Both formats contain a mesh, although the NASTRAN® format can contain both volume and boundary mesh in addition to all of the other information mentioned above. When importing these files into COMSOL Multiphysics, the most important concern is how to prepare them for simulation. What we need to do depends on the type of simulation as well as the contents of the files. The mesh in a NASTRAN® file may already be of adequate quality to suit our simulation; in this case, we don’t really need to do anything else but import and start defining the physics.
This blog post concerns all other cases when we need to create a new mesh in COMSOL Multiphysics or modify the imported mesh in some way. Modifications can include, for example, creating a solid object from the imported surface mesh, adding a surrounding domain, or sometimes just partitioning and deleting portions of what is imported. All of these operations, including the creation of a new mesh, require working with a geometry in COMSOL Multiphysics. To help address cases like these, let’s take a look at how to create a geometry using an imported STL or NASTRAN® file.
Creating a Geometry from an Imported Mesh
The steps to create a geometry from a mesh in COMSOL Multiphysics are user friendly and intuitive. When we import an STL file or a mesh in the NASTRAN® file format as a geometry, the software automatically creates a Mesh Part that we can easily access by clicking the Go To Source button next to the Mesh drop-down menu.
The Go to Source button in the Geometry Settings window takes us to the created Mesh Part.
Using the Boundary Partitioning Settings
In the Mesh Part, we can influence how the boundary of the mesh is partitioned by using the Boundary partitioning setting of the Import node. Using a Minimal boundary partitioning creates as few faces as possible — sometimes only one. The Minimal setting is usually a good choice when the source is a 3D scan. The default Automatic boundary partitioning is best suited for cases where the imported mesh has a natural face partitioning (i.e., when the mesh is from a CAD file). There’s also an option to manually set the parameters by choosing Detect faces.
Left: The Boundary partitioning settings of the mesh import. Right: An STL file imported with the Minimal boundary partitioning setting. Geometry image credit: Mark Yeoman, Continuum Blue Ltd., U.K.
The Detect faces option is most useful when a mesh comes from a 3D scan and has one or more planar faces. In this case, we prefer to have as few faces as possible, but we want the planar faces to have their own boundaries. To accomplish this, we can set the Maximum boundary neighbor angle to 180 degrees, as this produces the same behavior as the Minimal setting. To detect the planar faces, it is important to keep the Detect planar boundaries check box selected.
For times when changing the Maximum boundary neighbor angle is not satisfactory for our needs, we may also need to adjust the Minimum relative area and the Maximum neighbor angle. The Minimum relative area setting limits how small the detected planar faces can be relative to the total area of the surface mesh, while the Maximum neighbor angle setting sets the maximum tolerated angle between neighboring boundary elements in the same planar face.
For example, to detect the two highlighted boundaries in the example below, we decrease the Minimum relative area to 0.001 and increase the Maximum neighbor angle to 1 degree.
The Detect faces boundary partitioning feature (left) showing the exact settings used to create the geometry (right). Geometry image credit: Mark Yeoman, Continuum Blue Ltd., U.K.
Manual Partitioning of the Mesh
For more precise control over the partitioning of domains and boundaries for assigning material properties and boundary conditions, we can use several partition operations to manually group the elements of the imported mesh. These operations are found on the Mesh toolbar under Partitions, and can be added after the Import node in the Mesh Part or Mesh sequence.
The Ball, Box, and Cylinder operations found there group together elements that are inside the region defined by the selected shape with a user-specified size and location. For even more flexibility, the Logical Expression operation enables us to use the x-, y-, and z-coordinates in a logical expression, such as
(y2.5), to partition an imported mesh into new domains or boundaries. Also available from the Partitions menu, the Detect Faces operation is the same as the Detect Faces option for the mesh import, but by using this standalone operation, we can partition selected parts of the imported mesh.
Making the Geometry Smooth
When we are satisfied with the partitioning of the mesh, the next step in the import process involves creating a geometry with smooth edges and faces. The import settings involved influence how easy it is to build a working geometry out of the mesh.
The geometry import settings, highlighting the Simplify mesh selection.
To make meshing the resulting geometry more robust, keep the Simplify mesh check box selected. If the triangles in the imported mesh are isotropic and define a relatively smooth surface, we can lower the Relative simplification tolerance and the Defect removal factor so that less simplification is performed.
By setting a tighter Relative simplification tolerance, we reduce the degree to which the mesh simplification algorithm can modify the mesh. This tolerance is relative to the entire geometry, while the Defect removal factor is relative to the local feature size. The two together limit how much the imported mesh can be modified at a certain location before it converts to a geometry. Based on personal experience, lowering one or both of these factors is more commonly required with meshes in the NASTRAN® file format than with STL files.
Left: Crankshaft mesh in the NASTRAN® file format with fairly isotropic triangles and good representation of the shape. Middle: The created geometry with default settings. Right: The geometry with a lowered Relative simplification factor and Defect removal factor.
On the other hand, raising the Relative simplification tolerance and Defect removal factor in the settings helps when the mesh triangles are anisotropic and the surface mesh doesn’t accurately represent the surfaces (i.e., when the mesh comes from scanned data). Increasing one or both of these parameters fixes more issues in the mesh, although it may result in a less accurate representation of the imported surface mesh.
Left: Two anisotropic triangles among isotropic triangles. Middle: The geometry created with default import settings. Right: The geometry after increasing the Defect removal factor. Image credit: Mark Yeoman, Continuum Blue Ltd., U.K.
If a face appears strange, as pictured in the middle image above, it is usually due to problems that occur when generating the rendering mesh or the on-screen visualization of the face. This could indicate that there is an underlying problem that will cause issues when, for example, partitioning the geometry, combining it with other objects, or even meshing. In this case, the geometry meshed without a problem and increasing the Defect removal factor produced a more “well-behaved” face.
The last import setting is the Form solids from surface objects check box, which creates solid objects from surface meshes with a “watertight” region. This check box does not need to be selected when working with shells.
Another important note is that mesh files do not contain information about the Length unit, so this must be set manually in the settings windows of the Mesh Part and the Geometry nodes.
It is important to remember to set the correct Length unit for the Mesh Part and Geometry.
Partitioning and Combining Objects
After the mesh has been turned into a geometry, it is possible to add primitives, including blocks and spheres. It is also possible to introduce intersecting surfaces when performing Boolean operations where one geometry object is created from the mesh.
As the geometry’s surfaces are interpolated, they are not exact. Due to this, we can’t assume that the surfaces of an STL sphere, for example, are perfectly spherical. It is also difficult to combine these objects when they are expected to contain perfectly matching faces that are supposed to touch. In this case, it may help to apply the Form an assembly option and define Identity pairs, either automatically or manually, rather than using the default Form Union method to form the geometry for meshing.
STL Files Saved in a CAD Software
For a design created in a CAD software, we recommend exporting it in an MCAD format and importing it with the CAD Import Module. In an earlier blog post, we discussed which module to choose for CAD import and concluded that the STL format is best when the data originates from a 3D scan or when exporting deformed geometries or plots from COMSOL Multiphysics.
Concluding Thoughts on Creating Geometries from Meshes
While changing the import parameters is not an exact science and involves some trial and error, we have demonstrated some best practices for creating a geometry from an imported mesh. We hope that you find these tips to be helpful as you utilize STL and NASTRAN® files within your own modeling processes.
Learn about the modeling tools available to you in COMSOL Multiphysics by clicking the button below.
For more information about this topic and related areas of modeling, check out these resources:
- To learn how to inspect the STL mesh and remove unwanted triangles, try out this tutorial: From Surface Mesh to Geometry: STL import of a Vertebra
- Browse this comprehensive blog series on modeling irregular shapes
- Watch this video on preparing imported meshes for analysis in COMSOL Multiphysics
Editor’s note: This blog post was updated on 7/20/2018 to include more details.
NASTRAN is a registered trademark of NASA.
- COMSOL Now
- Today in Science