Usage

SU2 Installation

Users who are interested in the open-source SU2 CFD solver can install the SU2 suite directly on you devices by following the intallation guide on SU2 official website.

  • Linux and Mac Users: Please find the installation steps here to install SU2 and enable SU2 python library:

    1. Download source code: Please first download the source code from the SU2 download webpage.
    2. Create a configuration using the meson.py: ./meson.py build -Denable-autodiff=true.
    3. Set environment variables: There will be an instruction showing up in the terminal window for setting environment variables after creating the configuration. Users can copy and paste the paths to the ~/.bashrc and source ~/.bashrc. If you miss the instruction, please follow this link to set up the environment variables.
    4. Compile and install SU2: ./ninja -C build install.
  • Windows Users: Please install SU2 and enable SU2 python library using the steps shown here.

We perform the 2D airfoil simulation and optimization using SU2 CFD solver. For user's easy usage, we have pre-built the SU2 suite using a singularity container with the required environments set up. The ready-to-use SU2 singularity container can be pulled or downloaded from https://cloud.sylabs.io/library/junideallab/midbench/su2v7.3.1_conda3.9.12_gmsh.

  • To run the MIDBench API code:

    1. Linux Users: If you are using Linux (e.g., Ubuntu) or Linux VM box), please do the following steps:

      • Install Singularity. If you already have singularity installed on your device, please ignore this step. If not, please follow the 3-step quick installation guide to install Singularity first. Our MID Benchmark Suite uses Singularity version 3.5.3. You should be able to run the SIF container with the same version or higher.
      • Download SU2 SIF container. Please download the SU2 SIF container from Sylabs using this link (https://cloud.sylabs.io/library/junideallab/midbench/su2v7.3.1_conda3.9.12_gmsh). After installing Singularity, you can also pull the SU2 SIF container using the following command: $ singularity pull --arch amd64 library://junideallab/midbench/su2v7.3.1_conda3.9.12_gmsh:latest
      • Enter SU2 SIF container by typing the following command in your terminal: singularity shell /path/to/your/downloaded/su2v7.3.1_conda3.9.12_gmsh_latest.sif
      • Open jupyter notebook or jupyter lab by typing command in your terminal: jupyter lab or jupyter-notebook.
      • In the tutorial directory, there is an iPython notebook "example_usage.ipynb". Please open the notebook in jupyter lab or jupyter notebook.
      • Please run the API demo code in the notebook cell by cell to check out the 2D Airfoil Simulation and Optimization demos in your SU2 SIF container.
    2. Windows Users: If you are using Windows system and not interested in installing the Linux system or subsystem, you can directly implement our MIDBench API demos in Google Colab Notebook by following the installation and implementation steps below (we also include an iPython notebook "singularity_SU2.ipynb" for Windows users to use directly in Colab):

  • Install Singularity: Please follow the 3-step quick installation guide to install Singularity.

  • Pull SU2 SIF Container:
!singularity pull --arch amd64 library://junideallab/midbench/su2v7.3.1_conda3.9.12_gmsh:latest
  • Make sure you have installed midbench:
pip install midbench
  • Clone midbench repo or download midbench repo:
git clone https://github.com/IDEALLab/midbench.git
  • Create and Execute Python Scripts using SIF Container (recommended):
# Simulation
%%writefile midbench/airfoil2d_simu.py
from midbench.envs import make
Env, Design, Condition = make("Airfoil2d-v0")

designs = Design('./midbench/envs/airfoil/airfoils_pred_cbegan_example.npy').meshgen()
conditions = Condition(**{'mach':0.7,'reynolds':7000000,'lift':0.350})
performances = ['lift', 'drag']

lift, drag = Env.simulate(conditions, designs, performances, './midbench/envs/airfoil/results_simu')
print(lift, drag)
# Simulation
%%bash
cd midbench/
singularity exec --userns ../su2v7.3.1_conda3.9.12_gmsh_latest.sif bash -c "python airfoil2d_simu.py"
# Optimization
%%writefile midbench/airfoil2d_opt.py
from midbench.envs import make
Env, Design, Condition = make("Airfoil2d-v0")

designs = Design('./midbench/envs/airfoil/airfoils_pred_cbegan_example.npy')
conditions = Condition(**{'mach':0.6,'reynolds':8000000,'lift':0.320})
objectives = ['drag', 'ld_ratio', 'airfoil_opt']

drag, ld_ratio, airfoil_opt = Env.optimize(conditions, designs, objectives, './midbench/envs/airfoil/results_opt')
print(drag, ld_ratio, airfoil_opt)
# Optimization
%%bash
cd midbench/
singularity exec --userns ../su2v7.3.1_conda3.9.12_gmsh_latest.sif bash -c "python airfoil2d_opt.py"
  • Alternatively, You can Spawn a New Shell within SIF Container:
singularity shell --userns su2v7.3.1_conda3.9.12_gmsh_latest.sif

After entering SU2 SIF container, please run the 2D airfoil simulation and optimization demos using the following commands:

Type python. In the Python environment, please enter the following commands to run demos:

from midbench.envs import make
Env, Design, Condition = make("Airfoil2d-v0")

# Simulation
designs = Design('./midbench/envs/airfoil/airfoils_pred_cbegan_example.npy').meshgen()
conditions = Condition(**{'mach':0.7,'reynolds':7000000,'lift':0.350})
performances = ['lift', 'drag']

lift, drag = Env.simulate(conditions, designs, performances, './midbench/envs/airfoil/results_simu')

# Optimization
designs = Design('./midbench/envs/airfoil/airfoils_pred_cbegan_example.npy')
conditions = Condition(**{'mach':0.6,'reynolds':8000000,'lift':0.320})
objectives = ['drag', 'ld_ratio', 'airfoil_opt']

drag, ld_ratio, airfoil_opt = Env.optimize(conditions, designs, objectives, './midbench/envs/airfoil/results_opt')
print(drag, ld_ratio, airfoil_opt)

NOTE: The singuarity container also includes a 2D airfoil mesh generator AirfoilGeometryConverter. The generator will first convert the 2D coordinates of the airfoil curve points into mesh. The SU2 solver then takes the mesh for the follwoing CFD simulation and shape optimization.