Unsteady Ring VLM Solver with Ground Effect

"""Demonstrates running Ptera Software's UnsteadyRingVortexLatticeMethodSolver with
surface effects enabled.

The script uses the method of images to model ground effect by defining a horizontal
image surface (the ground) beneath an airplane, and will log simulation results in a log
file.
"""

import logging

# First, import the software's main package. Note that if you wished to import this
# software into another package, you would first install it by running "pip install
# pterasoftware" in your terminal.
import pterasoftware as ps

# Configure logging to write info level messages to a file. To display log messages on
# the console alongside progress bars instead, omit the handler argument.
ps.set_up_logging(level="Info", handler=logging.FileHandler("example_solver.log"))

# Create an Airplane with our custom geometry. This is the same Airplane used in the
# unsteady_ring_vortex_lattice_method_solver_static.py example. For details about each
# parameter, read the detailed class docstring.
example_airplane = ps.Airplane(
    wings=[
        ps.Wing(
            wing_cross_sections=[
                ps.WingCrossSection(
                    num_spanwise_panels=8,
                    chord=1.75,
                    Lp_Wcsp_Lpp=(0.0, 0.0, 0.0),
                    angles_Wcsp_to_Wcs_ixyz=(0.0, 0.0, 0.0),
                    control_surface_symmetry_type="symmetric",
                    control_surface_hinge_point=0.75,
                    control_surface_deflection=0.0,
                    spanwise_spacing="cosine",
                    airfoil=ps.Airfoil(
                        name="naca2412",
                        outline_A_Lp=None,
                        resample=True,
                        n_points_per_side=400,
                    ),
                ),
                ps.WingCrossSection(
                    num_spanwise_panels=None,
                    chord=1.5,
                    Lp_Wcsp_Lpp=(0.75, 6.0, 1.0),
                    angles_Wcsp_to_Wcs_ixyz=(0.0, 5.0, 0.0),
                    control_surface_symmetry_type="symmetric",
                    control_surface_hinge_point=0.75,
                    control_surface_deflection=0.0,
                    spanwise_spacing=None,
                    airfoil=ps.Airfoil(
                        name="naca2412",
                        outline_A_Lp=None,
                        resample=True,
                        n_points_per_side=400,
                    ),
                ),
            ],
            name="Main Wing",
            Ler_Gs_Cgs=(0.0, 0.0, 0.0),
            angles_Gs_to_Wn_ixyz=(0.0, 0.0, 0.0),
            symmetric=True,
            mirror_only=False,
            symmetryNormal_G=(0.0, 1.0, 0.0),
            symmetryPoint_G_Cg=(0.0, 0.0, 0.0),
            num_chordwise_panels=6,
            chordwise_spacing="uniform",
        ),
        ps.Wing(
            wing_cross_sections=[
                ps.WingCrossSection(
                    num_spanwise_panels=8,
                    chord=1.5,
                    Lp_Wcsp_Lpp=(0.0, 0.0, 0.0),
                    angles_Wcsp_to_Wcs_ixyz=(0.0, 0.0, 0.0),
                    control_surface_symmetry_type="symmetric",
                    control_surface_hinge_point=0.75,
                    control_surface_deflection=0.0,
                    spanwise_spacing="uniform",
                    airfoil=ps.Airfoil(
                        name="naca0012",
                        outline_A_Lp=None,
                        resample=True,
                        n_points_per_side=400,
                    ),
                ),
                ps.WingCrossSection(
                    num_spanwise_panels=None,
                    chord=1.0,
                    Lp_Wcsp_Lpp=(0.5, 2.0, 1.0),
                    angles_Wcsp_to_Wcs_ixyz=(0.0, 0.0, 0.0),
                    control_surface_symmetry_type="symmetric",
                    control_surface_hinge_point=0.75,
                    control_surface_deflection=0.0,
                    spanwise_spacing=None,
                    airfoil=ps.Airfoil(
                        name="naca0012",
                        outline_A_Lp=None,
                        resample=True,
                        n_points_per_side=400,
                    ),
                ),
            ],
            name="V-Tail",
            Ler_Gs_Cgs=(5.0, 0.0, 0.0),
            angles_Gs_to_Wn_ixyz=(0.0, -5.0, 0.0),
            symmetric=True,
            mirror_only=False,
            symmetryNormal_G=(0.0, 1.0, 0.0),
            symmetryPoint_G_Cg=(0.0, 0.0, 0.0),
            num_chordwise_panels=6,
            chordwise_spacing="uniform",
        ),
    ],
    name="Example Airplane",
    Cg_GP1_CgP1=(0.0, 0.0, 0.0),
    weight=0.0,
    s_ref=None,
    c_ref=None,
    b_ref=None,
)

# Now define the main Wing's root and tip WingCrossSections' WingCrossSectionMovements.
main_wing_root_wing_cross_section_movement = ps.WingCrossSectionMovement(
    base_wing_cross_section=example_airplane.wings[0].wing_cross_sections[0],
    ampLp_Wcsp_Lpp=(0.0, 0.0, 0.0),
    periodLp_Wcsp_Lpp=(0.0, 0.0, 0.0),
    spacingLp_Wcsp_Lpp=("sine", "sine", "sine"),
    phaseLp_Wcsp_Lpp=(0.0, 0.0, 0.0),
    ampAngles_Wcsp_to_Wcs_ixyz=(0.0, 0.0, 0.0),
    periodAngles_Wcsp_to_Wcs_ixyz=(0.0, 0.0, 0.0),
    spacingAngles_Wcsp_to_Wcs_ixyz=("sine", "sine", "sine"),
    phaseAngles_Wcsp_to_Wcs_ixyz=(0.0, 0.0, 0.0),
)
main_wing_tip_wing_cross_section_movement = ps.WingCrossSectionMovement(
    base_wing_cross_section=example_airplane.wings[0].wing_cross_sections[1],
    ampLp_Wcsp_Lpp=(0.0, 0.0, 0.0),
    periodLp_Wcsp_Lpp=(0.0, 0.0, 0.0),
    spacingLp_Wcsp_Lpp=("sine", "sine", "sine"),
    phaseLp_Wcsp_Lpp=(0.0, 0.0, 0.0),
    ampAngles_Wcsp_to_Wcs_ixyz=(0.0, 0.0, 0.0),
    periodAngles_Wcsp_to_Wcs_ixyz=(0.0, 0.0, 0.0),
    spacingAngles_Wcsp_to_Wcs_ixyz=("sine", "sine", "sine"),
    phaseAngles_Wcsp_to_Wcs_ixyz=(0.0, 0.0, 0.0),
)

# Now define the V-tail's root and tip WingCrossSections' WingCrossSectionMovements.
v_tail_root_wing_cross_section_movement = ps.WingCrossSectionMovement(
    base_wing_cross_section=example_airplane.wings[1].wing_cross_sections[0],
    ampLp_Wcsp_Lpp=(0.0, 0.0, 0.0),
    periodLp_Wcsp_Lpp=(0.0, 0.0, 0.0),
    spacingLp_Wcsp_Lpp=("sine", "sine", "sine"),
    phaseLp_Wcsp_Lpp=(0.0, 0.0, 0.0),
    ampAngles_Wcsp_to_Wcs_ixyz=(0.0, 0.0, 0.0),
    periodAngles_Wcsp_to_Wcs_ixyz=(0.0, 0.0, 0.0),
    spacingAngles_Wcsp_to_Wcs_ixyz=("sine", "sine", "sine"),
    phaseAngles_Wcsp_to_Wcs_ixyz=(0.0, 0.0, 0.0),
)
v_tail_tip_wing_cross_section_movement = ps.WingCrossSectionMovement(
    base_wing_cross_section=example_airplane.wings[1].wing_cross_sections[1],
    ampLp_Wcsp_Lpp=(0.0, 0.0, 0.0),
    periodLp_Wcsp_Lpp=(0.0, 0.0, 0.0),
    spacingLp_Wcsp_Lpp=("sine", "sine", "sine"),
    phaseLp_Wcsp_Lpp=(0.0, 0.0, 0.0),
    ampAngles_Wcsp_to_Wcs_ixyz=(0.0, 0.0, 0.0),
    periodAngles_Wcsp_to_Wcs_ixyz=(0.0, 0.0, 0.0),
    spacingAngles_Wcsp_to_Wcs_ixyz=("sine", "sine", "sine"),
    phaseAngles_Wcsp_to_Wcs_ixyz=(0.0, 0.0, 0.0),
)

# Now define the main Wing's WingMovement and the V-tail's WingMovement.
main_wing_movement = ps.WingMovement(
    base_wing=example_airplane.wings[0],
    wing_cross_section_movements=[
        main_wing_root_wing_cross_section_movement,
        main_wing_tip_wing_cross_section_movement,
    ],
    ampLer_Gs_Cgs=(0.0, 0.0, 0.0),
    periodLer_Gs_Cgs=(0.0, 0.0, 0.0),
    spacingLer_Gs_Cgs=("sine", "sine", "sine"),
    phaseLer_Gs_Cgs=(0.0, 0.0, 0.0),
    ampAngles_Gs_to_Wn_ixyz=(0.0, 0.0, 0.0),
    periodAngles_Gs_to_Wn_ixyz=(0.0, 0.0, 0.0),
    spacingAngles_Gs_to_Wn_ixyz=("sine", "sine", "sine"),
    phaseAngles_Gs_to_Wn_ixyz=(0.0, 0.0, 0.0),
)
v_tail_movement = ps.WingMovement(
    base_wing=example_airplane.wings[1],
    wing_cross_section_movements=[
        v_tail_root_wing_cross_section_movement,
        v_tail_tip_wing_cross_section_movement,
    ],
    ampLer_Gs_Cgs=(0.0, 0.0, 0.0),
    periodLer_Gs_Cgs=(0.0, 0.0, 0.0),
    spacingLer_Gs_Cgs=("sine", "sine", "sine"),
    phaseLer_Gs_Cgs=(0.0, 0.0, 0.0),
    ampAngles_Gs_to_Wn_ixyz=(0.0, 0.0, 0.0),
    periodAngles_Gs_to_Wn_ixyz=(0.0, 0.0, 0.0),
    spacingAngles_Gs_to_Wn_ixyz=("sine", "sine", "sine"),
    phaseAngles_Gs_to_Wn_ixyz=(0.0, 0.0, 0.0),
)

# Delete the extraneous pointers to the WingCrossSectionMovements, as these are now
# contained within the WingMovements. This is optional, but it can make debugging
# easier.
del main_wing_root_wing_cross_section_movement
del main_wing_tip_wing_cross_section_movement
del v_tail_root_wing_cross_section_movement
del v_tail_tip_wing_cross_section_movement

# Now define the example Airplane's AirplaneMovement.
airplane_movement = ps.AirplaneMovement(
    base_airplane=example_airplane,
    wing_movements=[main_wing_movement, v_tail_movement],
    ampCg_GP1_CgP1=(0.0, 0.0, 0.0),
    periodCg_GP1_CgP1=(0.0, 0.0, 0.0),
    spacingCg_GP1_CgP1=("sine", "sine", "sine"),
    phaseCg_GP1_CgP1=(0.0, 0.0, 0.0),
)

# Delete the extraneous pointers to the WingMovements.
del main_wing_movement
del v_tail_movement

# Define a new OperatingPoint with surface effects enabled. To model ground effect, we
# define a horizontal ground plane at z = 0.0 in Earth axes by specifying its unit
# normal vector and a point on the plane. We also set CgP1_E_Eo to place the Airplane's
# CG 5.0 meters above the ground (negative z is up in Earth axes). We leave the body
# orientation (angles_E_to_BP1_izyx) unset, which resolves to the level-flight default.
# The airplane is pitched nose up by the angle of attack (with zero sideslip), placing
# its velocity along the horizontal Earth x axis so it flies level over the ground
# rather than descending into it.
example_operating_point = ps.OperatingPoint(
    rho=1.225,
    vCg__E=10.0,
    alpha=1.0,
    beta=0.0,
    CgP1_E_Eo=(0.0, 0.0, -5.0),
    surfaceNormal_E=(0.0, 0.0, 1.0),
    surfacePoint_E_Eo=(0.0, 0.0, 0.0),
    externalFX_W=0.0,
    nu=14.61e-6,
)

# Define the OperatingPoint's OperatingPointMovement.
operating_point_movement = ps.OperatingPointMovement(
    base_operating_point=example_operating_point,
    ampVCg__E=0.0,
    periodVCg__E=0.0,
    spacingVCg__E="sine",
    phaseVCg__E=0.0,
)

# Delete the extraneous pointer.
del example_operating_point

# Define the Movement. This contains the AirplaneMovement and the
# OperatingPointMovement.
movement = ps.Movement(
    airplane_movements=[airplane_movement],
    operating_point_movement=operating_point_movement,
    delta_time=None,
    num_cycles=None,
    num_chords=10,
    num_steps=None,
)

# Delete the extraneous pointers.
del airplane_movement
del operating_point_movement

# Define the UnsteadyProblem.
example_problem = ps.UnsteadyProblem(
    movement=movement,
)

# Define a new solver. We'll create an UnsteadyRingVortexLatticeMethodSolver, which
# requires an UnsteadyProblem.
example_solver = ps.UnsteadyRingVortexLatticeMethodSolver(
    unsteady_problem=example_problem,
)

# Delete the extraneous pointer.
del example_problem

# Run the solver. The image surface contributions are automatically included at every
# Biot-Savart call site.
example_solver.run(
    prescribed_wake=True,
    show_progress=True,
)

# Save the solved solver to a .psz file. This allows us to load the results later
# without re-running the simulation.
ps.save("example_solver.psz", example_solver)

# Load the saved solver. The loaded object is identical to the original and can be
# passed to any output function.
loaded_solver = ps.load("example_solver.psz")

# The load function is annotated as returning object because a saved file can hold any
# Ptera Software object. This assert narrows the type for type checkers and guards
# against loading the wrong file.
assert isinstance(
    loaded_solver,
    ps.UnsteadyRingVortexLatticeMethodSolver,
)

ps.log_results(loaded_solver)

# Call the draw function on the loaded solver. The image surface and reflected geometry
# are automatically rendered. Press any key to close the plotter after it draws the
# output.
ps.draw(
    loaded_solver,
    scalar_type="lift",
    show_streamlines=True,
    show_wake_vortices=False,
    save=True,
)

# Call the animate function on the loaded solver. This produces an animated WebP of the
# wake being shed, saved in the same directory as this script. Press any key, after
# orienting the view, to begin the animation.
ps.animate(
    loaded_solver,
    scalar_type="lift",
    show_wake_vortices=True,
    save=True,
)

# Call the plotting function on the loaded solver. This produces graphs of the loads
# with respect to time.
ps.plot_results_versus_time(
    loaded_solver,
    show=True,
    save=True,
)

Output

Rendered geometry of the unsteady ring VLM ground-effect example airplane. Animation of the unsteady ring VLM simulation with ground effect. Airplane force coefficients over time. Airplane moment coefficients over time.