"""Lecture 13, the lift-curve slope of a thin section against Mach number: Prandtl-Glauert 2 pi/sqrt(1 - M^2) below
Mach 1 and Ackeret 4/sqrt(M^2 - 1) above (flight.aero.compressible_lift_slope), after McCormick (1995), Fig. 5.1.
Both fail near Mach 1. Writes img/fig-13-lift-slope.png."""
import numpy as np
from _visual import plt, save, despine, MAROON, BLUE, INK, GREY
from flight import aero as AE

M_SUB = np.linspace(0.0, 0.9, 200)
M_SUP = np.linspace(1.12, 4.0, 200)

if __name__ == "__main__":
    fig, ax = plt.subplots(figsize=(10, 5.2))
    ax.plot(M_SUB, [AE.compressible_lift_slope(2 * np.pi, m) for m in M_SUB], color=BLUE, lw=2.6)
    ax.plot(M_SUP, [AE.compressible_lift_slope(2 * np.pi, m) for m in M_SUP], color=MAROON, lw=2.6)
    ax.axvspan(0.9, 1.12, color="#f3e3c3", zorder=0)
    ax.text(1.01, 13.3, "neither\ntheory", ha="center", fontsize=12)
    ax.text(0.05, 10.2, "Prandtl–Glauert\n$2\\pi/\\sqrt{1-M^2}$", color=BLUE, fontsize=13)
    ax.text(1.9, 4.2, "Ackeret\n$4/\\sqrt{M^2-1}$", color=MAROON, fontsize=13)
    ax.axhline(2 * np.pi, color=GREY, ls=":", lw=1)
    ax.set_xlim(0, 4); ax.set_ylim(0, 15)
    ax.set_xlabel("Mach number"); ax.set_ylabel("section lift-curve slope (1/rad)")
    despine(ax)
    save(fig, "fig-13-lift-slope")
