Automatized & Modular OpenFOAM Workspace to Generate Large Aerodynamic Databases for Subsonic and Supersonic Vehicles
by Félix Martí Valverde
This project provides a complete toolchain for evaluating different rocket geometries at subsonic, transonic, and supersonic regimes. The work contained in this repository is part of a student project carried out at the Technical University of Munich (TUM) under the Master of Science (M.Sc) in Aerospace (year 2023) which aims to provide a standalone and verified methodology to extract aerodynamic characteristics of a rocket using 3D CFD simulation with pressure and density based solvers found in OpenFOAM (ESI group distribution).
- 🚀Generation of specific OpenFOAM workspace using templates and JSON configuration files. Powered by Jinja2, a Python module.🚀
- 📂Structured Layout for automatic generation of large aerodynamic databases.📂
- 🤖Automatic generation of CFD reports with the generation of predefined images through Paraviews Python API.🤖
- ⚙️Planned execution in series of multiple OpenFOAM simultations⚙️
- 🐋Use of containers to speed up deployment of a CFD server🐳 (5%⬇️ drop in efficiency)
- 🤓Examples of OpenFOAM workspaces using rhoPimpleFOAM and rhoCentralFoam at subsonic, transonic, and supersonic regimes.🤓
Computational Fluid Dynamics (CFD) tools from providers like ANSYS (Fluent) or Siemens (Star-CCM+) can be a financial burden on small businesses and startups alike. Thus, open-source alternatives like OpenFOAM are becoming increasingly appealing to reduce development costs. However, OpenFOAM has largely remained a research tool reserved for academia due to its lack of documentation, the high level of expertise required, and a lack of standardization and Graphical User Interface (GUI). This project identifies these shortcomings and aims to streamline the process, which is generally reserved for academia, thus easing the commercial adoption of this tool.
The entirety of the code has been publicly released in this repository to promote investigation using open-source and free tools. The results obtained during the development phase have been validated against wind tunnel data. The validation methodology can be found in the report "Toolchain for Aerodynamic Characterization of a Rocket During Ascent using OpenFOAM" along with the results obtained. Additionally, a set of simulation files for OpenFOAM (ESI group distribution) are also provided below to give a complete overview of the parameters used.
SIMULATIONS FILES: https://1drv.ms/f/s!AhNN3_xNz6xdhe1IEGJ-niuFxb3V3g?e=uLhchQ
REPORT: https://1drv.ms/b/s!AhNN3_xNz6xdhex7se7BjiaeyGrojg?e=m3ClFa
CAD FILES: https://1drv.ms/f/s!AhNN3_xNz6xdhK0CDDJZs5zly81P_w?e=NSELu2
To set up the workspace download OpenFOAM ESI (www.openfoam.com) and the following additional tools which are necessary to run the full toolchain. Note that SALOME is used to generate the surface of the vehicle from an initial STEP file into an STL file. More information on the procedure can be found in the report, and an example of the SALOME file can be found in the CAD FILES folder link above (file extension .hdf).
- Paraview
- GNUPLOT
- Python 3
- SALOME
- GitHub
Necessary Python modules for the execution of the pipeline are jinja2-cli which can be installed using:
python3 -m pip install jinja2-cli
OPTIONAL
Other additional Python modules need to be installed to test solvers using structured meshes. In the folder sphereMesh a Python file named sphere.py uses a Python module named classyblocks (https://github.com/damogranlabs/classy_blocks) to generate a structured mesh around a sphere.
python3 -m pip install classy-blocks
Additional tools that may interest the user to interact with the server and write the code are:
- MobaXterm
- Visual Studio Code (VSC)
- XLaunch
Also, the project explores different alternatives to execute OpenFOAM on personal computers that might run Windows exclusively. In the report, a performance analysis reveals drops in performance of up to 5% due to the use of containers (with Docker).
The repository contains 3 fundamental folders: rocketMesh, templates, and postProcessingTools
- rocketMesh: This folder contains a set of meshes of increasing resolution named R1 to R6. The user can choose from them to compute the solution.
- templates: This folder contains templates of OpenFOAM workspace which use different solvers (e.g.rhoPimpleFoam, rhoSimpleFoam, etc.) and tune other parameters. The user must provide additional parameters using a JSON file to generate a complete OpenFOAM workspace.
- postProcessingTools: Set of tools to generate:
- Real-time monitoring plots for residuals and aerodynamic coefficients.
- Autogenerated reports on single simulations containing images and stats (nº of iterations, CPU time, final aerodynamic coefficients, etc.).
- Autogenerated Excel table (CSV files) with multiple simulations, same data as reports.
Additional folders contained in the repository are extra resources that might come in handy. The submodule folder OpenFOAM-ToolChain-helperFunctions (https://github.com/WyllDuck/OpenFOAM-ToolChain-helperFunctions) contains all the Python scripts used to calculate atmospheric conditions for each simulation and also scripts to extract the wind tunnel data to compare the CFD results to.
What follows is a diagram found in the report (see link to file above) that shows how to feed a configuration file (JSON file) to a template to obtain a configured OpenFOAM simulation workspace. In the second stage of the diagram we find an explaination of how to automatically execute a series of linked simulations. For that the user must provide a list of OpenFOAM workspaces and an ordering list of execution.
Important
The run folder is automatically generated as the storage location if non-existent when the automatic execution of simulation starts.
Important
Also, the configuration files used to template the OpenFOAM workspace are generated using a Python script. This script can be found in the submodule folder OpenFOAM-ToolChain-helperFunctions (https://github.com/WyllDuck/OpenFOAM-ToolChain-helperFunctions), please visit that repository for further information.
Note
For an easy and reliable setup of OpenFOAM in any local machine it is recommended to use 🐋Docker. For more information on how to use docker in combination with OpenFOAM go to https://github.com/jakobhaervig/openfoam-dockerfiles. The recommended docker file containing extra modules required to run this particular toolchain can be in the repository's main folder.
To execute a single example CFD simulation using the toolchain in this repository follow these instructions:
- Create the specific OpenFOAM file using the templating software. Note that, you must navigate to the templates folder and generate the todo folder, or any other save location for the generated OpenFOAM workspaces.
cd templates
mkdir -p ../todo
./template_run.sh config.json rhoCentralFoam ../todo/rhoCentralFoamExample
The template_run.sh takes 3 parameters. First the address to the JSON configuration file, then the address to the template file (all the templates should be stored in the templates folder), and finally the address where the newly generated OpenFOAM workspace will be stored.
Important
Modify the following parameters in the JSON configuration file to tailor the OpenFOAM workspace to your specific machine and paths: mesh_file, nprocessors (multiply the numbers in the list to get the total nº of threads).
- Go to the rocketMesh folder to generate the mesh that you will be using in this simulation.
cd ../rocketMesh/rocketShort/noFinSupport/R1
./Allclean
./Allrun
It is recommended to first clean the workspace to make sure that no residual files remain in the project.
- Navigate to the main folder and run the OpenFOAM workspace generated in 1. that should be stored in the todo folder.
cd ../../../..
./run.sh input.txt rhoCentralFoamExample
The run.sh script takes 2 arguments. A list setting the order of execution of the simulations and the first element on the list that you want to execute.
OPTIONAL - MONITORING PLOTS
- Monitoring residuals and aerodynamic coefficients of the CFD simulation being executed. You must use a new terminal since the previous terminal is occupied computing the CFD solutions.
cd postProcessingTools
./plot_forceCoeffs.sh ../run/rhoCentralFoamExample/postProcessing/forceCoeffs1/0/coefficient.dat
./plot_residuals.sh ../run/rhoCentralFoamExample/postProcessing/solverInfo1/0/solverInfo.dat
OPTIONAL - AFTER COMPUTATIONS DONE
- Generated a report and predefined images for all simulations located in the run folder, and a CSV file containing all relevant metrics of all simulations in the run folder. Note that in the current example only one simulation, rhoCentralFoamExample should be in the run folder.
python3 genAllTable.py run #FOLDER1 FOLDER2 FOLDER3 ...
The Python script takes as arguments a list of path directories containing OpenFOAM workspaces. In this example, the OpenFOAM workspace rhoCentralFoamExample is stored in the run folder and no other location contains more OpenFOAM workspaces.
Important
This command will only generate images if the Python instruction "from paraview.simple import *" if successfull. This requires a correct installation of Paraview which might be difficult depending on the user's programing experience. A solution is proposed in document postProcessingTools/automaticImg/VTKtoIMAGE.py for the correct importation of the resource.
Navigate to the example configuration JSON file located in the main folder. This file must contain all the parameters that the selected template requires. Following the example previously presented you can visit the template rhoCentralFoam and look for files with the extension .j2. This extension tells the template_run.sh script that that file contains configurable parameters that must be written using Jinja2. Some of these parameters can be directly copied from the JSON file, while others use Jinja2 logic (for loops, if conditions, etc.) which can be found in https://jinja.palletsprojects.com/en/2.10.x/
To add configurable parameters to a template follow these steps
- Change the extension of the file to .j2. It is recommended to use git's commands when changing the file's name to keep track of past changes.
git mv file1 file1.j2
- Add Jinja2 syntax (https://jinja.palletsprojects.com/en/2.10.x/) to template the file
- Add the new parameters to your JSON configuration file.