"""Lecture 13, Hull's subsonic business jet: the coefficients of its parabolic polar against Mach number, from Hull
(2007), Table 3.4 (computed by Hull at Re' = 1.0e6 per ft). Left: C_D0 and K. Right: E* = E_max.
Writes img/fig-13-sbj-mach.png."""
import numpy as np
from _visual import plt, save, despine, MAROON, BLUE, GREEN, INK, GREY

# Hull (2007), Table 3.4: M, C_D0, K, C_L*, E*
HULL_3_4 = np.array([
    [0.0, 0.0231, 0.073, 0.563, 12.18], [0.1, 0.0231, 0.073, 0.562, 12.19], [0.2, 0.0230, 0.073, 0.561, 12.21],
    [0.3, 0.0229, 0.073, 0.560, 12.23], [0.4, 0.0228, 0.073, 0.559, 12.26], [0.5, 0.0226, 0.073, 0.556, 12.31],
    [0.6, 0.0224, 0.073, 0.554, 12.37], [0.7, 0.0223, 0.073, 0.552, 12.41], [0.75, 0.0222, 0.073, 0.551, 12.43],
    [0.775, 0.0221, 0.074, 0.547, 12.36], [0.8, 0.0221, 0.078, 0.532, 12.04], [0.825, 0.0218, 0.089, 0.495, 11.36],
    [0.85, 0.0224, 0.109, 0.452, 10.12], [0.875, 0.0255, 0.147, 0.416, 8.173], [0.9, 0.0336, 0.185, 0.426, 6.345]])
M, CD0, K, CLS, ES = HULL_3_4.T

if __name__ == "__main__":
    fig, (a1, a2) = plt.subplots(1, 2, figsize=(11, 4.8))
    fig.subplots_adjust(wspace=0.6)
    a1.plot(M, CD0, "o-", color=BLUE, lw=2.2, ms=5, label="$C_{D_0}$")
    a1.set_ylabel("$C_{D_0}$", color=BLUE); a1.set_ylim(0, 0.04)
    a1b = a1.twinx()
    a1b.plot(M, K, "s-", color=MAROON, lw=2.2, ms=5, label="$K$")
    a1b.set_ylabel("$K$", color=MAROON); a1b.set_ylim(0, 0.2)
    a1.set_xlabel("Mach number"); a1.set_xlim(0, 0.92)
    a1.text(0.05, 0.035, "$C_{D_0}$", color=BLUE, fontsize=13); a1.text(0.05, 0.0165, "$K$", color=MAROON, fontsize=13)
    a2.plot(M, ES, "o-", color=GREEN, lw=2.2, ms=5)
    a2.set_xlabel("Mach number"); a2.set_ylabel("$E_{max}$"); a2.set_xlim(0, 0.92); a2.set_ylim(5, 14)
    a2.axvspan(0.775, 0.92, color="#f3e3c3", zorder=0)
    a2.text(0.79, 13.2, "transonic", fontsize=12)
    for a in (a1, a2):
        a.spines["top"].set_visible(False)
    a2.spines["right"].set_visible(False)
    save(fig, "fig-13-sbj-mach")
