Editing and Repairing Imported Meshes in COMSOL Multiphysics®

February 25, 2021

Modifying an imported mesh can prove useful in certain scenarios. This blog post will discuss functionality for editing, repairing, and connecting imported surface meshes in the COMSOL Multiphysics® software. We will compare the results of different operations, discuss some use cases, and point to existing tutorials and other relevant resources for learning more.

Formats and Procedures for Importing Surface Meshes

Some of the operations to edit meshes are only supported on surface meshes. All file formats you can use for geometry and mesh import in COMSOL Multiphysics have support for surface meshes, but the following three formats are most common:

  1. STL
  2. 3MF
  3. PLY

As the use of these formats does not originate from FEA simulations, the quality of the meshes has not been as important. By poor quality, from a simulation perspective, we mean:

  1. Triangles with very large or very small angles
  2. Triangles that differ very much in size
  3. Problematic areas such as holes, thin spikes, or other types of irregularities in the shape that are unwanted

For imported meshes of poor quality, repairing and editing is often needed, as well as remeshing the faces to smooth over small irregularities. We will discuss this in more detail below.

Different Ways of Editing Surface Meshes

There are several operations that can be used for editing imported surface meshes:

Create Entities Intersect, Partition, and Join/Delete Entities Generate and Modify Mesh
Create Vertices Intersect with Plane Free Quad
Create Edges Intersect with Line Free Triangular
Create Faces Partition with Ball/Box/Cylinder Free Tetrahedral
Create Domains Partition by Expression Adapt
Fill Holes Join/Delete Entities Refine

Let’s look into some use cases and some of the differences between the categories of operations.

Adapting Vs. Remeshing a Face

To refine a mesh without changing the shape at all, you can use the Refine operation. However, if you are looking to smooth out small irregularities in the mesh, then you use the operations Adapt and Free Triangular. These operations also support coarsening of the mesh. To discuss the difference between adapting and remeshing a face mesh, let’s use the following coarse surface mesh of a unit sphere as an example.

An image of a unit sphere meshed with coarse triangles.

Coarse triangular mesh of a unit sphere. The edge size of the triangles is about 0.6 m.

The coarse mesh of a unit sphere (see image above) is imported into two different models to let us compare the results of the operations Adapt and Free Triangular side by side. The edge size of the triangles in the imported mesh is about 0.6 m. The user interfaces for the Adapt and Free Triangular operations allow us to specify a target element size, in this case set to 0.05 m, that will guide these operations.

A sphere that has been meshed using the Free Triangular operation.
A sphere after being remeshed from a coarse triangular option by using the Adapt operation.

The coarse surface mesh of the sphere is remeshed using Free Triangular with the size set to 0.05 m (left). The image to the right shows the result after the coarse mesh of the unit sphere has been adapted using the Adapt operation, setting the size expression to 0.05 m. Remeshing the face gives a smoother result than the adapted mesh. The adapted mesh is still following the original mesh quite close when the target mesh element size is set to a finer value than the original mesh.

When a face is remeshed, the Free Triangular operation creates a smooth geometry face in the background before creating a new free triangular mesh. The Adapt operation instead places the new mesh vertices of the new elements on the original mesh, which keeps the shape of the original mesh to a greater extent (this is seen in the images above). Adding more than one Adapt operation for the same selection will smooth out the mesh, as there is no memory of the mesh prior to the current operation.

Connecting Two Imported Meshes by Creating Edges and Faces in Empty Space

The operations Create Vertices, Create Edges, and Create Faces can be used without having any imported mesh to begin with. Here, we will see how this can be used to bridge a gap between two imported disconnected meshes.

Start out by using Create Vertices to make sure there are enough vertices on both meshes. Connect the vertices with meshed edges using Create Edges.

Two meshed pipes with their disconnected edges highlighted in blue.
Two meshed pipes with their disconnected edges joined by the Create Edges operation, visualized in blue lines.

Two imported, disconnected meshes of pipes; one with an oval cross section (S-shaped pipe to the left) and one with a circular cross section (the pipe to the right). The goal is to connect the edges highlighted in blue in the image to the left. This is done by using Create Edges to connect vertices in the two meshes. The resulting edges are highlighted in blue in the image on the right. Created edges are always straight, meshed edges.

Use Create Faces to fill each edge loop with a meshed face. The created faces will always be as planar as possible, so it might be necessary to add more mesh vertices and edges in order to resolve a curved face. The Create Faces operation is the equivalent of the Cap Faces operation, which is available for geometries. To smooth out the generated faces and get a good quality mesh with elements of similar size, the faces can be adapted or remeshed, as discussed in the previous section.

Two disconnected meshed pipes that are joined using the Create Faces operation.
An image of two originally disconnected meshed pipes that have been joined and smoothed out via the Free Triangular operation.

Faces are created within each edge loop, using the operation Create Faces (edges highlighted in blue in the image to the left). Lastly, the faces are joined and remeshed using Free Triangular (right image). As seen in the image to the right, remeshing the joined face makes it smoother, and it is now hard to see that the two pipes were not connected to begin with.

Intersecting Vs. Partitioning a Surface Mesh

Sometimes, it is necessary to partition or intersect a mesh in order to arrive at the wanted boundaries for assigning boundary conditions. Let us take a look at an important distinction between intersecting and partitioning a surface mesh by intersecting and partitioning the following surface mesh at z = 1.

A surface mesh that has a plan intersecting it at z=1, highlighted in blue.

A surface mesh with a plane placed in z = 1, highlighted in blue. The plane intersects the surface mesh at the upper edge of the blue area.

The operation Intersect with Plane is supported for surface meshes only. It intersects the mesh elements, which means that triangles are divided at the location of the plane and new mesh vertices, edges, and triangles are introduced where needed. As a result, the intersected faces are partitioned with a straight edge, as shown in the left image below. There is also an algorithm to clean up the resulting mesh such that short mesh edges and small elements that may have been introduced are being removed. The operation is used and discussed in more detail in the STL Import Tutorial Series. In 2D, the corresponding operation is called Intersect with Line.

The partition operations are supported on any type of mesh; both volume meshes and surface meshes. It is possible to partition the domains or faces of a mesh using the different shapes, including:

  • Ball
  • Box
  • Sphere
  • User-defined expression

The word partition here means that new entities are formed based on whether an element is included within the shape or not. This means that the number of mesh elements in the domains and on the faces stays the same and the created edges will be following the existing mesh edges, as seen in the image to the right.

A close-up image of the meshed sphere after using the Intersect with plane operation, with the affected region highlighted in blue.
A close-up image of the meshed sphere after using the Partition with box operation, with the affected region highlighted in blue.

Two images showing the result after the Intersect with plane (left) and Partition with box (right) operations have been built. In the image to the left, the resulting upper boundary (highlighted in blue) has a straight lower edge. All triangle elements that were intersected with the plane have been divided, introducing new mesh edges and triangles where needed. In the image to the right, the edge follows the existing mesh elements as close to z = 1 as possible.

Partition Operations Vs. Create Edges

As seen above, it is possible to partition a face using a partition operation, but it is also possible to use a Create Edges operation. The partition operations are restricted to certain shapes or logical expression with their respective settings, but can provide a quick way to partition a mesh. On the other hand, the Create Edges operation is more flexible as each mesh edge is selected manually. As this is a manual process, this is typically used when isolating a smaller number of mesh elements. The Create Edges operation is used in the STL Import Tutorial Series.

A view of the meshed object with the spike highlighted in blue and a pink circle highlighting the Partition with ball operation including all of the mesh element vertices.
A meshed object with a spike highlighted in blue and a pink circle highlighting the Partition with ball operation that includes some mesh element vertices.

The Partition with ball operation (outlined by the pink edges) is used to isolate the portion of the face forming a spike in the mesh. In the image to the left, the condition for the partition is set to include a mesh element if all its vertices are inside the ball, while the image to the right shows the same operation with the condition to include a mesh element if some of its vertices are inside the ball. In both cases, the edge of the new face (highlighted in blue) becomes jagged.

A close-up image of a meshed spike with each mesh edge selected and highlighted with blue lines.
A closeup view of the spike in a meshed object after the Create Edges operation is used, giving the bottom edge an even shape.

The Create Edges operation gives more control in terms of which mesh edges to convert into edges that bound the new face. Here, clicking each mesh edge in the Graphics window (left image) is a rather quick process and results in a more even shape of the bottom edge of the selected face (highlighted in blue to the right).

Automating Commonly Used Operations

Working with similar types of imported meshes, you might use some operations more than others or realize that a particular sequence of operations is used every time you set up a new simulation. One way of automating your modeling workflow, or parts of it, is setting up a model method or an add-in.

For example, when working with imported meshes representing porous structures, there are often narrow “bridges” connecting one part of the mesh with another. These bridges can be problematic when creating a geometry or when remeshing the faces, as the face of the bridge easily becomes self-intersecting. Therefore, it is sometimes necessary to remove them from the mesh. A quick way of doing so is to use the Ball Partition add-in, which creates a Partition with ball operation at the rotation center (shown in the left image below). The rotation center is set at a boundary by middle-clicking with the mouse. This add-in makes it easy to remove the narrow bridge, as shown in the images below.

An image of the surface mesh of a porous structure shown in red, with the center of rotation set with a small icon.
A meshed porous structure with a Partition with Ball operation shown in pink lines around the center of rotation.

A surface mesh of a porous structure. The pillar-like part in the middle of the image creates a narrow bridge from one part of the surface to another. Bridges like this one can cause problems when creating geometries, remeshing the faces, or adapting the mesh. Use a Partition with Ball operation to isolate a portion of the face as a separate boundary. Here, this is done by setting the rotation center on the bridge (left image) and using the Ball Partition add-in to position a Partition with Ball operation based on the position of the rotation center (right image).

An image of a meshed object with a bridge between a gap that is isolated and visualized in blue.
An image of a meshed object with a gap in its center.

The bridge is isolated as a separate boundary and selected (highlighted in blue, left) to be deleted. The image on the right shows the adapted mesh after the holes have been filled and the mesh has been adapted.

Volume Meshes

The examples above assume that you have a surface mesh. If you instead want to remesh an imported volume mesh, you can delete the tetrahedral elements while keeping the triangle surface mesh. To do this, use a Delete Entities operation, select the domains, and clear the check box Delete adjacent lower-dimensional entities.

A screenshot of the Settings window for the Delete Entities operation, with the Geometric Entity Selection section expanded.

The domains can later be restored using a Create Domains operation before filling the domains with a tetrahedral mesh using the Free Tetrahedral operation.

Creating Meshes from Simulation Results

There is also the possibility to create meshes from simulation results within the software. This is done by creating a surface mesh from Filter or Partition datasets. As discussed in a previous blog post, the procedure can be used to set up verification studies of topology optimization results. More general purposes are discussed in this previously recorded webinar.

Concluding Thoughts

There are many possibilities to edit imported meshes in COMSOL Multiphysics. This blog post, along with the links for further learning, cover many situations you might run into.

If you haven’t already, check out the two-part tutorial series available in the Application Libraries. In the first part of the series, a geometry object is created based on the STL mesh and is later intersected with a block, while in the second part of the series, two surface meshes are imported and filled with a tetrahedral mesh directly, without creating a geometry based on the STL mesh. Together, these tutorials showcase repairing and editing imported surface meshes that apply to any type of imported surface mesh.

Learn More

Categorias


Comentários (0)

Faça um Comentário
Log In | Registration
Carregando...
EXPLORE O BLOG COMSOL