Getting Started: A First Steady Simulation

This tutorial walks through a first steady aerodynamic simulation with Ptera Software. You will build a simple airplane from scratch, one object at a time:

  1. Airfoil

  2. WingCrossSection

  3. Wing

  4. Airplane

  5. OperatingPoint

  6. SteadyProblem

  7. SteadyHorseshoeVortexLatticeMethodSolver

  8. Results

  9. Visualization

  10. Logging

  11. Saving and loading your results

By the end you will have solved for the lift and induced drag of a tapered, swept wing with dihedral and seen how to log, save, and plot the results.

This tutorial uses the steady horseshoe vortex lattice method (VLM). Ptera Software also ships steady ring VLM, unsteady ring VLM (UVLM), aeroelastic, and free flight solvers. The solvers share a similar class structure.

Install

Install the package in your environment if you have not already:

pip install pterasoftware ipywidgets

Then import the package. The examples in this tutorial assume you are working in a Jupyter notebook or an interactive Python session.

import pterasoftware as ps

1. Airfoil

An Airfoil defines the two-dimensional shape of a wing cross section. Ptera Software ships a large database of airfoils (courtesy of the UIUC Airfoil Coordinates Database). You select one by name.

Here we use the classic NACA 2412 airfoil:

airfoil = ps.Airfoil(name="naca2412")

2. WingCrossSection

A WingCrossSection places an Airfoil at a location along the wing and controls how that station is discretized into panels. num_spanwise_panels controls the panel resolution in the spanwise direction, and chord sets the local chord length.

A wing is built from two or more cross sections. Here we define a root station and a tip station. The tip is offset from the root with Lp_Wcsp_Lpp: the second component is the spanwise offset, the first is the streamwise offset (sweep), and the third is the vertical offset (dihedral).

root_wing_cross_section = ps.WingCrossSection(
    airfoil=airfoil,
    num_spanwise_panels=8,
    chord=1.75,
    Lp_Wcsp_Lpp=(0.0, 0.0, 0.0),
    control_surface_symmetry_type="symmetric",
)
tip_wing_cross_section = ps.WingCrossSection(
    airfoil=airfoil,
    num_spanwise_panels=None,
    chord=1.5,
    Lp_Wcsp_Lpp=(0.75, 6.0, 1.0),
    control_surface_symmetry_type="symmetric",
)

3. Wing

A Wing groups the cross sections into a lifting surface and discretizes it into panels in the chordwise direction (num_chordwise_panels).

Setting symmetric=True mirrors the wing about the plane defined by symmetryNormal_G and symmetryPoint_G_Cg. The wing cross sections are the starboard half, and the mirror adds the port half.

wing = ps.Wing(
    wing_cross_sections=[root_wing_cross_section, tip_wing_cross_section],
    symmetric=True,
    symmetryNormal_G=(0.0, 1.0, 0.0),
    symmetryPoint_G_Cg=(0.0, 0.0, 0.0),
    num_chordwise_panels=6,
)

4. Airplane

An Airplane is a collection of one or more Wing objects. This is the top level of the geometry hierarchy.

airplane = ps.Airplane(
    wings=[wing],
)

5. OperatingPoint

An OperatingPoint describes the flight condition: free stream velocity, angle of attack, sideslip, air density, and more. The default values below are a typical low-speed cruise condition.

operating_point = ps.OperatingPoint()

6. SteadyProblem

A SteadyProblem bundles the geometry and the operating point into a single object that the solver can act on.

problem = ps.SteadyProblem(
    airplanes=[airplane],
    operating_point=operating_point,
)

7. SteadyHorseshoeVortexLatticeMethodSolver

The SteadyHorseshoeVortexLatticeMethodSolver solves the problem. Its run method builds the vortex lattice and solves the linear system, which takes less than a second for this geometry thanks to JIT compilation and parallelization.

solver = ps.SteadyHorseshoeVortexLatticeMethodSolver(
    steady_problem=problem,
)
solver.run()

8. Results

The solver stores the results directly on the Airplane object. Common quantities are the total lift and induced drag coefficients:

print("Lift coefficient:", airplane.liftCoefficient_W)
print("Induced drag coefficient:", airplane.inducedDragCoefficient_W)
print("Force vector (wind axes, N):", airplane.forces_W)
Lift coefficient: 0.555695955074969
Induced drag coefficient: 0.01251345594119384
Force vector (wind axes, N): [-1.49457589e+01 -1.04044044e-10 -6.63709356e+02]

9. Visualization

The ps.draw function renders the solved airplane with PyVista. Here it colors the panels by their lift coefficients and shows the streamlines trailing the wing. A window opens so you can orient the view, and pressing any key closes it. Setting save=True then writes the view to a WebP file next to this notebook, which the markdown cell after the code embeds, so the render appears both when you run the notebook and on the documentation website:

ps.draw(
    solver,
    scalar_type="lift",
    show_streamlines=True,
    save=True,
    path="getting_started_draw.webp",
)

The tutorial wing colored by lift coefficient, with streamlines trailing the wing.

10. Logging

Ptera Software can write a formatted log of the simulation setup and results. Call ps.set_up_logging once to configure logging, then use ps.log_results:

ps.set_up_logging(level="Info")
ps.log_results(solver)
INFO    |output                                      |Airplane "Untitled Airplane":
INFO    |output                                      |  Reynolds Number: 1.08E+06
INFO    |output                                      |  Forces (in Geometry Axes):
INFO    |output                                      |    fX_G:           -43.0 N
INFO    |output                                      |    fY_G:       -1.04E-10 N
INFO    |output                                      |    fZ_G:            662. N
INFO    |output                                      |  Moments (in Geometry Axes, Relative to the CG):
INFO    |output                                      |    mX_G_Cg:     8.83E-10 Nm
INFO    |output                                      |    mY_G_Cg:        -619. Nm
INFO    |output                                      |    mZ_G_Cg:     2.14E-10 Nm
INFO    |output                                      |  Force Coefficients (in Geometry Axes):
INFO    |output                                      |    cFX_G:        -0.0360
INFO    |output                                      |    cFY_G:      -8.71E-14
INFO    |output                                      |    cFZ_G:          0.555
INFO    |output                                      |  Moment Coefficients (in Geometry Axes, Relative to the CG):
INFO    |output                                      |    cMX_G_Cg:    6.16E-14
INFO    |output                                      |    cMY_G_Cg:      -0.318
INFO    |output                                      |    cMZ_G_Cg:    1.49E-14
INFO    |output                                      |  Forces (in Wind Axes):
INFO    |output                                      |    fX_W:           -14.9 N     Induced Drag:                       14.9 N
INFO    |output                                      |    fY_W:       -1.04E-10 N     Crosswind Force:                1.04E-10 N
INFO    |output                                      |    fZ_W:           -664. N     Lift:                               664. N
INFO    |output                                      |  Moments (in Wind Axes, Relative to the CG):
INFO    |output                                      |    mX_W_Cg:    -8.98E-10 Nm    Rolling Moment:                -8.98E-10 Nm
INFO    |output                                      |    mY_W_Cg:        -619. Nm    Pitching Moment:                   -619. Nm
INFO    |output                                      |    mZ_W_Cg:    -1.36E-10 Nm    Yawing Moment:                 -1.36E-10 Nm
INFO    |output                                      |  Force Coefficients (in Wind Axes):
INFO    |output                                      |    cFX_W:        -0.0125       Induced Drag Coefficient:         0.0125
INFO    |output                                      |    cFY_W:      -8.71E-14       Crosswind Force Coefficient:    8.71E-14
INFO    |output                                      |    cFZ_W:         -0.556       Lift Coefficient:                  0.556
INFO    |output                                      |  Moment Coefficients (in Wind Axes, Relative to the CG):
INFO    |output                                      |    cMX_W_Cg:   -6.27E-14       Rolling Moment Coefficient:    -6.27E-14
INFO    |output                                      |    cMY_W_Cg:      -0.318       Pitching Moment Coefficient:      -0.318
INFO    |output                                      |    cMZ_W_Cg:   -9.51E-15       Yawing Moment Coefficient:     -9.51E-15

11. Saving and loading

Solved simulations can be saved to a .psz file (a zip archive of JSON members) and reloaded without re-running, which is handy for sharing or post-processing later.

In the output stored below, the saved file's size is replaced with a <size> placeholder because it varies slightly from run to run. When you run the cell yourself, you will see the actual size.

ps.save("getting_started_solution.psz", solver)
loaded = ps.load("getting_started_solution.psz")
print("Lift coefficient after reload:", loaded.airplanes[0].liftCoefficient_W)
INFO    |_serialization                              |Saving SteadyHorseshoeVortexLatticeMethodSolver to getting_started_solution.psz
INFO    |_serialization                              |Saved SteadyHorseshoeVortexLatticeMethodSolver to getting_started_solution.psz (<size> bytes)
INFO    |_serialization                              |Loading from getting_started_solution.psz
INFO    |_serialization                              |Loaded SteadyHorseshoeVortexLatticeMethodSolver from getting_started_solution.psz
Lift coefficient after reload: 0.555695955074969

Summary

You have now run your first Ptera Software simulation. The object model is similar across the solvers, so the same pattern applies to steady ring VLM, unsteady ring VLM, aeroelastic, and free flight simulations:

Airfoil -> WingCrossSection -> Wing -> Airplane
OperatingPoint -> Problem -> Solver -> run()

To go further, look at the example scripts in examples/ and the API reference on the documentation site.