"""Lecture 13, a flat plate at Mach 2.5: lift and drag coefficients against angle of attack by linear (Ackeret)
theory and by exact shock-expansion theory (flight.aero), with Sadraey's Example 3.3 (5 deg, C_Dw = 0.0134).
Writes img/fig-13-linear-exact.png."""
import numpy as np
from _visual import plt, save, despine, MAROON, BLUE, INK, GREY
from flight import aero as AE

M = 2.5
ALPHA = np.radians(np.linspace(0.2, 15, 100))
LIN = np.array([AE.ackeret_flat_plate(a, M) for a in ALPHA])
EXA = np.array([AE.shock_expansion_flat_plate(a, M) for a in ALPHA])

if __name__ == "__main__":
    fig, (a1, a2) = plt.subplots(1, 2, figsize=(11, 4.8))
    fig.subplots_adjust(wspace=0.3)
    deg = np.degrees(ALPHA)
    for a, k, lab in ((a1, 0, "$C_L$"), (a2, 1, "$C_D$")):
        a.plot(deg, EXA[:, k], color=INK, lw=2.6, label="shock-expansion (exact)")
        a.plot(deg, LIN[:, k], color=MAROON, lw=2.2, ls="--", label="linear theory")
        a.set_xlabel("angle of attack (deg)"); a.set_ylabel(lab); a.set_xlim(0, 15)
        despine(a)
    a2.plot(5, 0.0134, "o", color=BLUE, ms=8)
    a2.text(5.5, 0.0134 - 0.004, "Sadraey Ex. 3.3", color=BLUE, fontsize=12)
    a1.legend(frameon=False, fontsize=12, loc="lower right")
    a1.set_title(f"flat plate, $M={M}$", fontsize=13, loc="left")
    save(fig, "fig-13-linear-exact")
