LEONSIM Workbench demo

Tutorial · 2D · Code comparison passed against OpenFOAM

A NACA 0012 airfoil, checked against OpenFOAM

Build the body-fitted C-grid, run the solver on your CPU, and read the forces and the wall pressure next to the OpenFOAM reference. Five steps, each with a recording of the real run.

Level
Beginner
Time
About 25 minutes, 20 of them the solver
Cost
$0, one CPU core
Needs
Python 3.11 or newer, a laptop
Status
Code comparison passed against OpenFOAM at 320 per side

Status. Code comparison passed: the solver in this tutorial is the one of the code comparison rows. Against OpenFOAM, on the same 320-per-side mesh, with the same model, LeonSim agrees with it in every region of the wall (the comparison). Against the wind tunnel, lift at 10° and drag at 0° hold; drag at 10° is 15 % high and is not validated. The tutorial itself runs a mesh 15 times smaller so that it finishes in minutes; its numbers are a preview, unvalidated, and step 4 shows how far they are from the 320-per-side rows.

You will run the NACA 0012 at a chord Reynolds number of 6 million, at 0° and 10°, and compare the result with an OpenFOAM v2412 run that is stored in the repository. The point is the habit as much as the airfoil: a total drag that looks right proves little, so you will look at the pressure along the wall and at the split between pressure and friction.

One thing to know first. The Workbench in the browser does not run this solver yet. The body-fitted 2D solver is used from the command line, which is what the recordings show; the terminal clips replay the saved console output of the real runs with their measured timing (the first one is a live capture). The Workbench has its own aerodynamics solver (a cut-cell one); its airfoil drag is a preview, unvalidated, and the Ahmed tutorial uses it.

  1. 1 Install
  2. 2 Mesh
  3. 3 Solve
  4. 4 Compare
  5. 5 Check against the rows

1 Install

Get the code and check it runs

From a checkout of the repository, install LeonSim and ask it what it found. The solver needs NumPy and SciPy; Numba and Warp are used by other parts of LeonSim and are not needed for this tutorial.

pip install -e .
leonsim doctor

leonsim doctor lists the Python and library versions. “native core not installed” is fine here: it is an optional speed-up for the 3D solvers.

Clip `leonsim doctor` printing the versions found

2 Mesh

Build the C-grid

One command builds the mesh and runs the solver; its first line is the mesh.

python3 tools/tutorial_naca0012.py \
  --alpha 10 --output out/naca10

The same case runs from the leonsim command (leonsim mesh airfoil builds and draws the mesh alone; leonsim airfoil --alpha 10 --out out/naca10 runs it) and in the Workbench: pick the NACA 0012 tutorial example, press Mesh to see the C-grid, then Run. Each one ends with the same comparison with OpenFOAM.

The mesh is a C-grid: one block of quadrilaterals whose lines follow the wall, wrap around the nose and close behind the trailing edge in a wake cut. The wall is a grid line, so there is no cell cut by the wall. That is why this solver, unlike the cut-cell one, can be compared with OpenFOAM cell for cell.

This tutorial’s mesh has 48 faces per side, 9,112 cells, a first cell 2·10⁻⁵ chords high and a far field 30 chords away. The reference mesh of the rows has 320 faces per side, 139,776 cells, a first cell of 2·10⁻⁶ and a far field 200 chords away. The script writes mesh.png; the clip ends on it, zooming into the nose.

Clip The command starts, the mesh line prints, then mesh.png zooms into the nose

3 Solve

Iterate until the answer stops moving

The solver is steady incompressible RANS with the k-ω SST model, a SIMPLE pressure-velocity iteration and under-relaxation 0.7 for velocity and 0.5 for pressure. Every 100 iterations it prints the lift and drag coefficients and the velocity update, the largest change of velocity in the last iteration.

Do not stop at the first quiet-looking number. Lift and drag here stop changing in the fourth digit after about 1,500 iterations, but the velocity update keeps falling for a few thousand more; the script runs 4,000 (10°) and 3,000 (0°). The recording is a time-lapse replay of the real run’s log: 10° took 620 s on one core of a four-core sandbox with a second run alongside.

If you run it yourself, expect 8 to 10 minutes per angle.

Clip The iteration log of the 10 degree run in time-lapse

4 Compare

Read the forces next to OpenFOAM

The run ends by printing its forces against the OpenFOAM reference (results/openfoam_sbs/: v2412, 320 per side, the same model) and the root-mean-square difference of the wall pressure coefficient. Then it writes cp.png, shown at the end of the clip: LeonSim in cyan over the OpenFOAM curve in grey.

Read it in three passes: the pressure curve, then pressure drag and friction drag separately, then the totals.

At 0° the 9,112-cell mesh is 4.6 % low in drag (pressure 4.8 % low, friction 4.5 % low) and the pressure curves differ by 0.019 rms. At 10° the pressure curve is close over most of the chord but the nose suction peak is visibly lower, lift is 7.0 % low, and drag is 68 % high, almost all of it pressure drag (+137 %). The small mesh is too coarse at the nose and its far field is too near for a lifting airfoil; we have not tested which of the two matters more here (earlier far-field tests on the reference meshes show how much the far field alone can move lifting drag: the post).

That is the lesson of the step: a pressure curve that looks right can still carry a badly wrong drag, because drag is a small difference of large forces concentrated at the nose.

Clip The forces table prints, then cp.png shows both pressure curves
9,112 cells, this tutorialCLCDCD pressureCD friction
0°, this run00.007670.001280.00639
0°, OpenFOAM (320 per side, 16,000 it)00.008040.001350.00669
10°, this run0.98920.022620.017190.00543
10°, OpenFOAM (320 per side, 8,000 it)1.06380.013440.007250.00619

The 0° reference is the 16,000-iteration file; OpenFOAM’s 40,000-iteration value is 0.0080274, 0.2 % lower, so that reference had not fully converged when it was stored. It does not change the reading here.

5 Check against the rows

What “code comparison passed” means, and how to get there

On the reference mesh the same solver gives, at OpenFOAM’s own relaxation (0.8 and 0.7):

  • 0°: CD 0.0080275 against OpenFOAM’s 0.0080274; pressure and friction drag in every one of ten wall regions within 6.5·10⁻⁷ and 1.5·10⁻⁷.
  • 10°: CL 1.06372 against 1.06362, pressure drag +0.15 %, friction drag within 0.01 %.

Against Ladson’s wind-tunnel data, CD at 0° is −0.5 % (0.00803 against 0.00807) and CL at 10° is +0.1 % (1.0637 against 1.063). CD at 10° is +15 % (0.01344 against 0.01169) in both codes: it is the model and the 200-chord far field, not a LeonSim fault, and it is not a validated figure.

To run the reference mesh yourself, the CPU solver needs hours; the GPU port needs minutes. One 320-per-side run on a Modal A100 costs about $0.2 (the C-grid GPU spend log, docs/cgrid-gpu/spend.md):

python3 tools/modal_job.py start naca10 --max-minutes 30 -- \
  bench/modal_cgrid_gpu.py --gpu A100-40GB --fetch out/naca10 \
  --cmd "python3 tools/airfoil_cgrid_gpu.py --alpha 10 \
  --iterations 3000 --output out/naca10 --device cuda \
  --linsolve gpu --alpha-u 0.9 --alpha-p 0.9 --no-early-stop"

Those GPU states are at relaxation 0.9/0.9, which moves 10° pressure drag by about 0.7 % against OpenFOAM’s 0.8/0.7; the post above has the details. The clip scrolls through the region-by-region comparison on this site.

Clip The blog post with the region-by-region comparison: the tables of LeonSim against OpenFOAM, then the wall figure
C-grid, 320 per sideCLCDCD pressureCD friction
0°, OpenFOAM (40,000 it)00.00802740.00133740.0066900
0°, LeonSim (16,000 it)−4·10⁻⁸0.00802750.00133750.0066900
10°, OpenFOAM (16,000 it)1.063620.0134340.00724370.0061903
10°, LeonSim (10,000 it)1.063720.0134450.00725460.0061907

What this tutorial does not show

  • The Workbench does not run this solver. Nothing here is a statement about the Workbench’s own airfoil results.
  • No experimental pressure distribution: the usual data set (Gregory and O’Reilly) is at a Reynolds number near 3 million, not 6.
  • No grid-convergence order for the CPU solver: the 142-per-side mesh at 10° is not a steady state. The GPU port’s orders are in the post.
  • Code-to-code agreement on one mesh cannot reveal an error both codes share: the model, the far-field size, the transition.

Sources: tools/tutorial_naca0012.py (this tutorial), docs/airfoil-cgrid-report/comparison.md and the NACA 0012 section of docs/validation/validation-root-cause.md (the code comparison rows), results/openfoam_sbs/ (the references).