Improved Functionality and Tips for Importing STL and NASTRAN® Files

Hanna Gothäll September 14, 2016
Share this on Facebook Share this on Twitter Share this on Google+ Share this on LinkedIn

When addressing your geometry- and mesh-related support questions, we’ve noticed an increased use of STL files originating from 3D scan sources and meshes in NASTRAN® file format as bases for geometries. Performing simulations on these realistic objects can be challenging, particularly when preparing the geometry. Dealing with these files is now easier thanks to updates in the COMSOL Multiphysics® software. 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 that can contain several of these sections in one file. Importing this type of file now results in multiple geometric objects, the number of which depends on how many such sections are found.

Image showing an STL file of a vertebra imported into COMSOL Multiphysics.
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., UK.

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 on the contents of the files. The mesh in a NASTRAN® file may already be of a good enough 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 we need to modify the imported mesh in some way. Modifications can include, for example, that we need to create a solid object from the imported surface mesh, or that we need to add a surrounding domain, or sometimes just to partition and delete 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

A couple of versions back, the steps to create a geometry from a mesh in COMSOL Multiphysics became more user friendly and intuitive. Now, when you import an STL file or a mesh in 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 list.

The Go to Source button in the Geometry Settings window.
The Go to Source button in the Geometry Settings window will take you 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. 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. Then there’s the default Automatic boundary partitioning, which is best suited for cases where the imported mesh has a natural face partitioning (i.e., when the mesh is from a CAD design). There’s also an option to manually set the parameters by choosing Detect faces.

Boundary partitioning settings of the mesh import.
An image depicting an STL file imported with the Minimal boundary partitioning setting in COMSOL Multiphysics.

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., UK.

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 decreased the Minimum relative area to 0.001 and increased the Maximum neighbor angle to 1 degree.

The Detect faces boundary partitioning feature.
An image showing the resulting geometry.

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., UK.

If we need a boundary at a specific position, we can use the different partition features found under the Mesh Part menu. Using a Ball, Box, or Cylinder partitioning operation of a specified size can create boundaries that are not automatically detected or act as a complement to the Minimal boundary partitioning setting.

Making the Geometry Smooth

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.

A screenshot showing the Simplify mesh settings.
The geometry import settings highlighting the Simplify mesh settings.

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 NASTRAN® file format than with STL files.

Crankshaft mesh in NASTRAN® file format.
The created geometry with default settings.
The geometry with the addition of a lowered Relative simplification factor and Defect removal factor.

Left: Crankshaft mesh in 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 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.

Image showing two anisotropic triangles among isotropic triangles.
The geometry created with default import settings.
The geometry after the Defect removal factor is increased.

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., UK.

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 problems that occur when generating 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 window of the Mesh Part and the Geometry nodes.

A screenshot depicting how to set the proper Length unit for the Mesh Part.
Setting the Length unit for the Geometry.
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 is originating 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. For more information about this topic and related areas of modeling, check out the resources below:

If you have questions about this blog post or need help importing your meshes, please do not hesitate to contact us.

NASTRAN is a registered trademark of NASA.


Post Tags

Technical Content
Loading Comments...

Categories


Tags