学习中心

Course:

Using Swept Meshes for Model Geometries

Building a Quality Swept Mesh


In the previous Learning Center article, we discussed the requirements for a geometry in COMSOL Multiphysics® to be meshed using the Swept operation. In this article, we expand upon this by discussing how to obtain a quality swept mesh. What are the most important settings and considerations for generating a good quality swept mesh? We will address this question and more in this article. For our purposes here, we assume that each of the domains to be swept meshed are fulfilling every requirement discussed in the previous article.

Choosing the Source and Destination Faces

We learned in Part 2 that the direction of the sweep is important (because the software needs to be able to imprint the source faces over the destination faces). Does this mean that you need to manually make the selections for the source and destination faces? Not always; in the majority of cases, the source and destination faces are automatically detected by the software. The only cases when you would need to manually select the source or destination face is when the direction of the sweep is ambiguous: There are different paths that the sweep can take, and there may be one that is preferable, depending on the physics. This is especially true if you are meshing multiple domains in parallel; however, even in such a case it is usually sufficient to select the source faces, as COMSOL Multiphysics® will automatically detect the destination faces based on the source faces you choose.

Two images of a block geometry with two arrows pointing in the different possible directions that a Swept mesh operation can take. Two different sweep directions (indicated by the arrows) result when a Swept operation is used to mesh a block. On the left, COMSOL Multiphysics® has automatically picked the source face (in magenta) and the destination face (in orange) by default. In contrast, the image on the right shows a sweep performed with a user-defined source face, where COMSOL Multiphysics® has automatically detected the destination face. (Front boundaries are hidden for visibility.)

The surface mesh is generated automatically by the Swept operation: The source face is meshed using a quadrilateral (i.e., quad) mesh (optionally triangular), while the linking faces are meshed with a Mapped mesh, and the destination face mesh is transferred from the source (via multiple methods, described in the documentation). In the following example, a triangular mesh is built on the source face.

Two images of a block geometry meshed with different sweep directions; in the left image, the left face of the block is purple, and the right face of the block is orange. In the right image, the top face of the block is purple, and the bottom face of the block is orange. The resulting surface meshes for the two sweeps depicted above. (Front boundaries hidden; linking face meshes depicted by the gray grids.) Because the source face was user-defined for the swept mesh on the right and detected by the software for the mesh on the left (and because the Distribution subnode acts along the sweep direction in both cases — more on this below) two different meshes were generated. Depending on the physics, one mesh might be preferable to the other.


There is also the option to manually generate the surface mesh for the source face first, and then follow this with adding a Swept mesh operation. Doing so enables you to use mesh operations (e.g. Size and Distribution subnodes) to achieve a desired face meshing on the source face, which you can then sweep into a 3D mesh. Examples of which can be seen here.

When and How to Premesh the Source Faces

Although the surface meshing for a domain can be handled automatically using the Swept operation, there are cases in which you will want to premesh the source faces to be used by the Swept mesh operation. By premesh, we mean meshed by a previous operation.

A screenshot of the COMSOL Multiphysics user interface showing the face meshing method options in the Swept operation settings.
Changing the default face meshing method in a Swept mesh operation so that a triangular mesh is used instead of quadrilaterals. The resulting swept mesh will contain prism elements.

A screenshot of the COMSOL Multiphysics user interface showing the mesh operations used previous to the Swept operation to premesh several source faces in the steam reformer tutorial model geometry.
In the meshing sequence for the steam reformer tutorial model geometry, multiple mesh operations are used previous to the Swept operation in order to premesh multiple source faces.

It is important to note that any faces already meshed prior to adding a Swept operation will automatically be selected as the source faces. You can use a Free Quad, Free Triangular, or Mapped operation to premesh the source faces when needed. Some use cases for premeshing the source faces include when you need:

  • A Size attribute to control the mesh size on the source faces.
  • A boundary layer mesh. For a swept mesh, it is recommended to add the boundary layers on the source faces before it is swept. (See the below image.)
  • A mapped mesh on the source faces.
Three side-by-side figures of the Steam Reformer tutorial model geometry showing the boundary layer mesh. Three side-by-side figures of the Steam Reformer tutorial model geometry showing the boundary layer mesh. The Steam Reformer tutorial model geometry. The boundary layer mesh is added to the source faces first.

Note: If multiple faces are meshed prior to the Swept operation, make sure that: 1. The linking faces are meshed using a Mapped operation. 2. The destination mesh precisely matches the source.

Controlling the Mesh Size and Distribution

As explained in more detail in our blog post on meshing domains with different size settings, it is a good practice to use one mesh operation with many local size attributes instead of repeating several mesh operations. This also relates to the parallelization of the meshing algorithm. The Swept operation is no exception to this rule, so let's have a look at the two attributes that are available. To add an attribute, right-click the Swept node and select Size or Distribution.

Size

The most common usage for the Size node is for setting up a maximum or minimum element size in the domains. This number can be dependent on physics variables, parameters, or expressions that include variables and parameters. The Size node can also be used on the boundary level for source faces; however, premeshing the source faces in a separate operation is advised. If you add a Size node with a boundary selection as a local attribute to the Swept node, make sure you specify the same boundaries as the Source Faces.

Note that the curvature along the sweep is not considered. The default mapped mesh on the linking faces will have a constant distribution.

A graphic of a cylindrical geometry curved into an S shape, where the bottom curve is larger and the top curve is tighter, forming an inverted U shape. A graphic of a cylindrical geometry curved into an S shape, where the bottom curve is larger and the top curve is tighter, forming an inverted U shape.
A graphic showing a swept mesh of a cylindrical geometry curved into an S shape with the same element size along the entire length. A graphic showing a swept mesh of a cylindrical geometry curved into an S shape with the same element size along the entire length.

The image on the left depicts the mean curvature of a geometry to be meshed. Although the tighter curve (inverted U shape) has a larger mean curvature, the default settings for the Swept operation (on the right) use the same element size along the entire geometry, and the mesh layers are evenly distributed.

If varying curvature is important for your model and you want to have more control of the distribution, mesh some edges before the Swept operation. The Edge operation can take the curvature factor into account while maintaining a continuous growth rate change.

A graphic of a cylindrical geometry curved into an S shape, where the bottom curve is larger and the top curve is tighter, forming an inverted U shape. A graphic of a cylindrical geometry curved into an S shape, where the bottom curve is larger and the top curve is tighter, forming an inverted U shape.
A graphic showing a swept mesh of a cylindrical geometry curved into an S shape that used a Size node to incrementally change the mesh size according to the varying curvature of the geometry. A graphic showing a swept mesh of a cylindrical geometry curved into an S shape that used a Size node to incrementally change the mesh size according to the varying curvature of the geometry.

This time, the top chain of edges is meshed first. The Edge operation can itself have several size attributes. In this example, the top curve has a curvature factor of 0.1, while the bottom one has a curvature factor of 0.2. Note that the mesh size changes incrementally across the domains to create a smooth transition.

Distribution

The Distribution attribute specifies the number of layers in a domain, and is determined by the distribution method type used. If a similar element size is wanted in several domains, consider using a Size attribute instead. As discussed in the "Choosing the Source and Destination Faces" section, it works on the domain level and is therefore dependent on the direction of the sweep.

A simulation of the acoustic domains surrounding an ear bud. Domains are distinguished blue, green and yellow colors corresponding to different mesh sizes and shapes.

A typical example where the Distribution node is used. An acoustics simulation of an ear bud where the surrounding domains are defined as Perfectly Matched Layers with a specification of eight elements.

The default Distribution type is Fixed number of elements. Change this setting to Predefined to specify an element distribution that is either linearly or exponentially growing. This helps to obtain a smooth size transition between adjacent domain, required by some physics, such as in fluid mechanics.

When setting up any predefined distribution, the number of elements and the element ratio (ratio between the largest height and the smallest height ) are the input numbers:

A graph shows the lengths of the domains in an asymmetric distribution. A graph shows the lengths of the domains in an asymmetric distribution.
A graph shows the lengths of the domains in a symmetric distribution. A graph shows the lengths of the domains in a symmetric distribution.

Definition of the different lengths for an asymmetric (left) and symmetric (right) distribution. The total length is noted as .


While, most of the time, the parameters can be tweaked manually so that the mesh is satisfactory, one might want to have more control of the mesh growth rate. In the table below, some useful relations for the asymmetric distributions are presented. The symmetric distributions depend on the parity of , but are approximated (equal when  is even) if  and  are replaced by  and , respectively.

Expression Linear Exponential

It might be the case that  and the maximum local growth rate, , between consecutive heights () are known. 

Let's say, for example, that you want  to be equal to the size of the mesh on the cross section, and that the maximum growth rate is fixed by the global size node. How do you deduce  and ? Let us find out with an exponential distribution.

  1. Generally, the height is bounded, so that . The first step is to ensure this is true even when . (The goal is to use the least amount of elements.) Consequently, from the last line of the table:

  2. From here,  and  are deduced by rearranging the third line and by definition of :

  3. Finally, using the second line,  can be approximated as the closest integer to .

The mesh for the fluid flow domain surrounding an Ahmed body, where the coarser mesh that's farther from the body is yellow and the finer mesh that's closer to the body is green. The mesh for the fluid flow domain surrounding an Ahmed body, where the coarser mesh that's farther from the body is yellow and the finer mesh that's closer to the body is green. The Swept mesh (in yellow) behind the Ahmed body has been modified to make use of the exponential distribution in order to smoothly increase the size of the mesh elements.


Adding a boundary layer mesh can sometimes be an alternative to using a predefined distribution in the sweep. This is shown below with the pictured example.

Two side-by-side figures of the Steam Reformer tutorial model geometry showing the inserted boundary layer mesh highlighted in blue on the right. The Steam Reformer tutorial model geometry. Here, a boundary layer mesh is added at the beginning of the geometry, instead of a symmetric distribution. The inserted boundary layer mesh elements are highlighted in blue.

Consideration of the Adjacent Domains

Any domain adjacent to the one where the mesh is swept can either be meshed before or after the sweep. If an adjacent domain is meshed before the sweep, the face meshes can be considered to be premeshed. (Refer to the section on when and how to premesh source faces for more information.) But what can we consider the face meshes when the swept meshing is performed first? This is especially important when the domain to be swept is surrounded by a larger domain.

The swept mesher generates a mapped mesh on the linking faces. This means that quads are created along the sweep (yellow in the animation below). If the surrounding domains are meshed with a free tetrahedral mesh (i.e., volume mesh elements with only triangular mesh faces), the mesh algorithm will automatically insert pyramids (magenta in the animation below) along the linking faces so that the transition between quad and tetrahedral elements is possible and the mesh becomes conforming.

In the carbon fibers tutorial, the fibers are first swept meshed before the surrounding domain is filled by a Free Tetrahedral mesh; pyramids are inserted automatically to connect the two mesh types. For visualization purposes, the front tetrahedra are hidden.

A swept meshed cylinder with five element layers, with the skewness quality depicted as green pyramids with relatively high peaks. A swept meshed cylinder with five element layers, with the skewness quality depicted as green pyramids with relatively high peaks.
A swept meshed cylinder with one element layer, with the skewness quality depicted as flat orange pyramids. A swept meshed cylinder with one element layer, with the skewness quality depicted as flat orange pyramids.
A swept meshed cylinder with 100 element layers, with the skewness quality depicted as small orange pyramids. A swept meshed cylinder with 100 element layers, with the skewness quality depicted as small orange pyramids.

A cylinder is swept meshed with five elements layers on the left (aspect ratio close to 1), only one in the middle (high aspect ratio), and 100 on the right (high aspect ratio also but in the other direction). The skewness quality is depicted for the pyramids. It is lower for large aspect ratios.


There are different ways the mesh quality can be improved, in case the aspect ratio is too extreme:

  • Change the distribution of the elements along the sweep, so that the aspect ratio gets closer to 1. This is dependent on the physics, as it might require a certain distribution.
  • Premesh the source faces. Do this with a different size setting such that the mesh along the outer edges better matches the distribution of element layers in the sweep.
  • Include the surrounding domains in the sweep, if possible. We will discuss how to partition adjacent domains in future parts of this course.
  • Use Form an Assembly to finalize the geometry. Although the mesh quality will increase, this might induce some interpolation errors during the study. Read more about it here.

Furthermore, the mesh algorithm can only detect small gaps within domains that are being meshed, not when the gaps are contained in a yet unmeshed domain.

Two identical meshed cubic geometries, one above the other with a thin space between. Two identical meshed cubic geometries, one above the other with a thin space between.
A close-up of the meshed space between the two blocks, showing low quality, flat pyramids. A close-up of the meshed space between the two blocks, showing low quality, flat pyramids.

When swept meshing the two block-shaped domains above, the narrow domain region between them is not considered. Although the quads have an aspect ratio very close to 1, the pyramids will be flat due to the thin domain region. The low quality is visualized by the red color in the image to the right. (Only the pyramids and hexahedrons near the narrow domain region are shown.)


If the thin domain represents a thin layer, consider if it is possible to replace modeling it explicitly with a boundary condition. An example of this is explained in this blog post. If it is not relevant for the physics, consider collapsing the narrow region using geometric operations.

A thin layer of space between two vertically stacked blocks has been collapsed into a boundary condition so the blocks share a face. A thin layer of space between two vertically stacked blocks has been collapsed into a boundary condition so the blocks share a face.
Mesh of the two stacked blocks that have been merged (shown in yellow) with pyramid-shaped mesh (shown in purple) on the outer faces. Mesh of the two stacked blocks that have been merged (shown in yellow) with pyramid-shaped mesh (shown in purple) on the outer faces.

The narrow domain region was not needed or is representing a thin layer. On the left, the two blocks are merged (by changing the geometry sequence, for example) so that they share one face. On the right, the resulting mesh is partially shown: Pyramids were only inserted on the sides of the blocks.


If the thin domain region must be included, one solution is to refine the mesh size on the source faces close to the narrow domain region and increase the number of element layers. This will result in more mesh elements in total, compared to the earlier cases.

A thin layer of space between two vertically stacked blocks is meshed with a refined size. A thin layer of space between two vertically stacked blocks is meshed with a refined size.
A close-up of the meshed space between two stacked blocks, showing an increased number of mesh elements. A close-up of the meshed space between two stacked blocks, showing an increased number of mesh elements.

A good quality mesh can be generated between the two block-shaped domains by premeshing the source faces with a finer size setting near the narrow region. The image to the right shows that the quality of the pyramids are reasonable. (Only the pyramids and hexahedrons near the narrow domain region are shown.)


This technique can sometimes require a lot of mesh elements in order to correctly resolve the gap. At some point you reach a limit where a free tetrahedral mesh is preferred.

In this example geometry, it is also possible to sweep all domains together in one Swept operation. This will guarantee that the final mesh has good quality because prisms or hexahedrons better handle large aspect ratios compared to pyramids or tetrahedrons. In future parts of this course, we will look into how to modify geometries in order to enable domains to be swept meshed.

A mesh of several cubic domains all swept together, with prism and hexahedron mesh elements. A mesh of several cubic domains all swept together, with prism and hexahedron mesh elements.
A close-up of the hexahedron mesh of the thin domain included in a sweep of several cubic domains. A close-up of the hexahedron mesh of the thin domain included in a sweep of several cubic domains.

In this swept mesh (left), no pyramid elements needed to be inserted. The image to the right shows that the quality of the hexahedrons is very good. (Only the hexahedrons near the narrow domain region are shown.)


Finally, if the pyramid insertion fails or if you want to speed up the Free Tetrahedral operation, it can help to first convert the quads using the Convert operation. By converting the quad elements, no pyramids need to be inserted. However, this also splits some of the elements in the swept mesh. With this in mind, make sure you monitor the mesh quality.

Triangular mesh elements of a thin domain between two stacked blocks, with the top block hidden for visibility. Triangular mesh elements of a thin domain between two stacked blocks, with the top block hidden for visibility.
A close-up of the low quality tetrahedra that result from converting the mesh elements of a thin domain between two stacked blocks from quad to triangular. A close-up of the low quality tetrahedra that result from converting the mesh elements of a thin domain between two stacked blocks from quad to triangular.

The faces near the narrow domain region are converted from quad mesh elements to triangular mesh elements. (The mesh from the top cube is hidden in the left image.) This means that no pyramids have to be inserted into the thin region, but the resulting mesh quality is not necessarily improved (as can be seen in the right picture, where the tetrahedra are low quality).

Further Learning

Several examples were depicted in this article that complemented our discussion on the most important aspects to take into account so that a swept mesh of good quality can be generated. You can find the MPH-files for these examples attached to this article and see firsthand for yourself how this was accomplished for several types of geometries.


请提交与此页面相关的反馈,或点击此处联系技术支持