Adaptive mesh refinement is an important technique for accurately capturing and resolving flow features in discretized domains. Upon completing this tutorial, the user will be familiar with performing adaptive mesh refinement for a simple, two-dimensional grid. The concepts and material presented here are immediately applicable to more complex, three-dimensional grids. The geometry chosen for the tutorial is a NACA 0012 airfoil moving at transonic speed in an inviscid fluid.
In this tutorial, the use of the following SU2 tools will be demonstrated:
SU2_CFD - performs the direct and the adjoint flow simulations
- SU2_MAC - identifies cells in the computational domain and performs mesh refinement
- mesh_adaptation.py - automates the adaptation process by executing the SU2 tools and manages the input and output files
NOTE: If you downloaded SU2 version 2.0 or earlier, some minor bugs were detected in the mesh_adaptation.py script. These bugs have been corrected in the attached mesh_adaptation.py script included here. Simply overwrite mesh_adaptation.py in your $SU2_HOME/SU2Py and $SU2_RUN directories with the attached mesh_adaptation.py script below. This updated script will be included in the upcoming monthly development release of SU2. Thanks for your understanding!
In the future, these files will be available in the TestCases/mesh_adaptation/ directory. You will need the updated mesh_adaptation.py script, the configuration file (adapt_NACA0012.cfg) and the mesh file (mesh_NACA0012_inv.su2).
This tutorial will guide you through two of the most common strategies for performing adaptive mesh refinement: feature-based adaptation (using flow gradient information) and goal-oriented adaptation (using an adjoint solution).
This tutorial utilizes the NACA 0012 mesh from the Quick Start Tutorial and Tutorial 8 - Optimal Shape Design of a Rotating Airfoil.
High-quality solutions require accurate resolution of flow features within the computational domain. Adaptive mesh refinement is a procedure by which the computational grid can be strategically refined to resolve these flow features using information from the direct and/or adjoint solutions. This problem deals, again, with the NACA 0012 airfoil in a transonic free stream. As seen in the Quick Start Tutorial and in Tutorial 8 - Optimal Shape Design of a Rotating Airfoil, the airfoil shape and free stream conditions are such that shocks form on the upper and lower surfaces of the airfoil. These shocks are important in determining the expected performance of this airfoil at the specified conditions and insufficient resolution of these features could lead to inaccuracies in the predicted performance. Although this is a simple example, these same issues are prevalent in large-scale computations over complex geometries. In this tutorial, we will use the mesh adaptation tools within the SU2 suite to ensure accuracy in the solution.
This problem will solve the Euler equations on the NACA0012 airfoil at an angle of attack of 1.25o, using air with the following freestream conditions:
- Pressure = 101325 Nm-2
- Temperature = 273.15 K
- Mach number = 0.8
The mesh from the Quick Start Tutorial is used again here as the initial geometry. It consists of a far-field boundary and an Euler wall along the airfoil shape. The specific airfoil is the NACA 0012, and more information on this airfoil can be found in the Quick Start Tutorial. The mesh can be seen in Figure (1).
Figure (1): Far-field and zoom view of the computational mesh.
Configuration File Options
We discuss an overview of grid deformation configuration file options here, with specific examples for different adaptation cases to follow. Full description of these parameters, along with a complete description of the other configuration file settings can be found on the Configuration file page.
Mesh adaptation specifications:
- NEW_ELEMS: defines the number of new elements to add to the adapted grid as a percentage of of the number of elements in the baseline grid.
- KIND_ADAPT: specifies the adaptation methodology to be used at each adaptation cycle. Several adaptation methodologies are available that range in sophistication from a full isotropic subdivision of all cells in the domain to more advanced methodologies that utilize adjoint solution information to reduce 'computable' error in the grid. A more complete discussion of these different methodologies can be found in the Configuration file page.
- ANALYTICAL_SURFDEF: specifies an analytical surface to be used as boundary cells are refined during the adaptation process. Available analytical geometries include NACA 0012 airfoils, biparabolic airfoils, NACA 4412 airfoils and cylinders. If no analytical surface is used, boundary edge refinement occurs at the midpoint between the nodes defining the edge.
- ADAPT_BOUNDARY: toggles refinement of the boundaries on and off.
Orchestration of the different modules required for running the mesh adaptation strategy are handled by the mesh_adaptation.py scripts. Depending on the adaptation strategy selected, you will need to run a direct, adjoint, or linearized (or some combination thereof) solution. Direct calls to SU2_MAC are also possible for simple, quick adaptations on existing solutions (simply call the executable and pass in the appropriate configuration file), but use of the python script is highly recommended. The mesh_adaptation.py script can be called with the following options:
A brief description of the mesh_adaptation.py script follows:
- -f: Specify the configuration file with this flag
- -p: Set the number of processors if the simulation is to be run in parallel using MPI.
- -c: The adaptation strategy can be repeated for further adaptation of the grid. These repetitions are called "cycles" and can be specified with the -c flag
- -o: This option overwrites the original mesh with the adapted mesh
- -s: Saves all flow/adjoint solution files and all mesh files at each adaptation cycle.
Specific examples of calls to the mesh_adaptation.py script will be shown in the subsequent sections.
The feature-based adaptation strategically adapts cells within the grid by identifying cells with the largest gradients in the flow variables. We will perform this type of adaptation by setting the following parameters in the configuration file:
We also need to set the filename for the mesh file that is generated by SU2_MAC, so set the MESH_OUT_FILENAME tag in the configuration file:
Run the adaptation scheme by executing the following steps:
- Copy the attached configuration (adapt_NACA0012.cfg) and mesh file (mesh_NACA0012_inv.su2) to your working directory directory
- Execute the adaptation strategy by issuing the following command: "mesh_adaptation.py -f adapt_NACA0012.cfg" (please be sure you have set the $SU2_RUN and $SU2_HOME environment variables as specified in the Installation procedure!)
- Observe the startup of SU2_CFD and monitor the residuals to ensure convergence of the direct solution
- Note that at the completion of the simulation, SU2_MAC is called automatically by the python script and the adaptation is performed (adding 15% additional cells according to our specifications in the configuration file)
- Solution files and the adapted grid are written to the current working directory and should include:
- All standard flow solution files - flow.plt, history.plt, surface_flow.plt, surface_flow.csv, restart_flow.dat
- A tecplot file of the baseline grid - original_grid.plt
- A tecplot file of the adapted grid - adapted_grid.plt
- An adapted SU2 grid file - mesh_out.su2
Figure (2a): Converged baseline solution.
Figure (2b): Baseline mesh.
Figure (2c): Adapted grid using flow gradient information
Goal-oriented approaches to mesh adaptation utilize direct and adjoint solutions to identify regions in the computational domain that strongly affect a particular function of interest (drag or lift for example) and refine in those areas. These strategies require a direct and an adjoint solution, which together make for a more computationally expensive adaptation scheme as compared to the feature-based approach above, but can lead to optimal grid refinement since the functional of interest is included in the adaptation criterion.
Let's change our adaptation strategy to refine based on the 'computable' error in the discretized domain, leaving all other settings in the Grid Adaptation section of the configuration file the same as before.
We must choose a functional of interest, for this adjoint-based approach. Let's specify lift in the Adjoint-Flow Numerical Method section in the configuration file.
This time, let's perform multiple cycles of adaptation to highly resolve the mesh. Execute the adaptation strategy and pay special attention to the following items:
- Type the following at the command line to initiate the adaptation strategy: "mesh_adaptation.py -f adapt_NACA0012.cfg -c 2 -s True"
- This indicates that we should use the mesh adaptation script with the parameters specified in the adapt_NACA0012 configuration file. Additionally, we should perform two total cycles of adaptation, adding 15% more cells at each adaptation cycle. Lastly, the -s True flag tells the script to save outputs and meshes at each cycle of adaptation.
- Observe the startup of the direct solver on the baseline grid. In principle, we could use the baseline solution restart file that was generated in the previous section by setting the appropriate restart flags in the configuration file.
- At the completion of the baseline direct solution, the mesh_adaptation.py calls SU2_CFD again to obtain an adjoint solution.
- Once both the direct and adjoint solutions have been converged, mesh_adaptation.py performs a full-grid adaptation, cutting each cell in the mesh isotropically and performs one iteration to calculate the residuals. An inner product of these fine-grid residuals with the adjoint variables are our adaptation indicators.
- After all this, SU2_MAC is called to refine the grid according to our specifications.
- The whole procedure is then repeated once more for an additional cycle of refinement.
Note that by setting the -s flag to "true", we can now access the flow and adjoint solutions used to refine the mesh at each cycle. These are denoted by the "*_cycle*" tags on the filenames. An examination of these refined grids, shown in Figure (3), show differences as compared to the feature-based approach of the previous section. If you're confused by the "computable" adaptation procedure, please consult the existing body of work on mesh adaptation using the computable error. Is feature-based or goal-oriented better for your application? Which is the most efficient approach? Try performing your own grid convergence studies and see for yourself!
Figure (3a): Baseline mesh.
Figure (3b): Lift-adapted mesh after one adaptation cycle.
Figure (3b): Lift-adapted mesh after two adaptation cycles.
Want to re-run the direct solver on the twice-adapted grid? Simply set the mesh filename to our mesh output filename (note that the cycle tags on the file names are 0-based indexing) and call SU2_CFD
Notice that the shock around the airfoil is much better resolved on the adapted grid. Strategic adaptation using SU2 is a great way to increase the accuracy of your simulations in an efficient way!
Figure (4a): Baseline solution.
Figure (4b): Solution on the twice-adapted mesh.