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 theSweptoperation. 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 different sweep directions (indicated by the arrows) result when aSweptoperation 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 aMappedmesh, and the destination face mesh is transferred from the source (via multiple methods, described in thedocumentation). In the following example, a triangular mesh is built on the source face.
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 theDistributionsubnode 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 aSweptmesh operation. Doing so enables you to use mesh operations (e.g.SizeandDistributionsubnodes) to achieve a desired face meshing on the source face, which you can then sweep into a 3D mesh. Examples of which can be seenhere.
When and How to Premesh the Source Faces
Although the surface meshing for a domain can be handled automatically using theSweptoperation, there are cases in which you will want to premesh the source faces to be used by theSweptmesh operation. By premesh, we mean meshed by a previous operation.
Changing the default face meshing method in aSweptmesh operation so that a triangular mesh is used instead of quadrilaterals. The resulting swept mesh will contain prism elements.
In the meshing sequence for the steam reformer tutorial model geometry, multiple mesh operations are used previous to theSweptoperation in order to premesh multiple source faces.
It is important to note that any faces already meshed prior to adding aSweptoperation will automatically be selected as the source faces. You can use aFree Quad,Free Triangular, orMappedoperation to premesh the source faces when needed. Some use cases for premeshing the source faces include when you need:
- ASizeattribute 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.
Note: If multiple faces are meshed prior to theSweptoperation, make sure that: 1. The linking faces are meshed using aMappedoperation. 2. The destination mesh precisely matches the source.
Controlling the Mesh Size and Distribution
As explained in more detail in our blog post onmeshing 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 theparallelizationof the meshing algorithm. TheSweptoperation 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 theSweptnode and selectSizeorDistribution.
Size
The most common usage for theSizenode 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. TheSizenode 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 aSizenode with a boundary selection as a local attribute to theSweptnode, make sure you specify the same boundaries as theSource Faces.
Note that the curvaturealongthe sweep is not considered. The default mapped mesh on the linking faces will have a constant distribution.
The image on the left depicts themean curvatureof a geometry to be meshed. Although the tighter curve (inverted U shape) has a larger mean curvature, the default settings for theSweptoperation (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 theSweptoperation. TheEdgeoperation can take thecurvature factorinto account while maintaining a continuous growth rate change.
This time, the top chain of edges is meshed first. TheEdgeoperation 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
TheDistributionattribute 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 aSizeattribute 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 typical example where theDistributionnode 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 defaultDistribution typeisFixed number of elements. Change this setting toPredefinedto 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 influid mechanics.
When setting up any predefined distribution, the number of elementsand the element ratio(ratio between the largest heightand the smallest height) are the input numbers:
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 whenis even) ifandare replaced byand, respectively.
Expression | Linear | Exponential |
---|---|---|
It might be the case thatand the maximum local growth rate,, between consecutive heights () are known.
Let's say, for example, that you wantto 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 deduceand? Let us find out with an exponential distribution.
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:
From here,andare deduced by rearranging the third line and by definition of:
Finally, using the second line,can be approximated as the closest integer to.
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.
TheSteam Reformertutorial 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.
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.
- UseForm an Assemblyto finalize the geometry.Although the mesh quality will increase, this might induce some interpolation errors during the study. Read more about ithere.
Furthermore, the mesh algorithm can only detect small gapswithindomains that are being meshed, not when the gaps are contained in a yet unmeshed domain.
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 thisblog post. If it is not relevant for the physics, consider collapsing the narrow region using geometric operations.
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.
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.
Finally, if the pyramid insertion fails or if you want to speed up theFree Tetrahedraloperation, it can help to first convert the quads using theConvertoperation. 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.
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.
请提交与此页面相关的反馈,或点击此处联系技术支持。