"""Lecture 19, the time, fuel and distance for the Tejas-class model at 8500 kg to accelerate from Mach 0.9 to 1.5
in level flight with full afterburner, against altitude (flight.performance.accelerate_level). Below about 8.3 km it cannot
reach Mach 1.5 at all. Writes img/fig-19-accel-altitude.png."""
import numpy as np
from _visual import plt, save, despine, MAROON, BLUE, GREEN, INK
import _fighter as F

V, MASS = F.TEJ, F.M_REF
HS = np.concatenate([np.arange(8300.0, 8500.0, 50.0), np.arange(8500.0, 15001.0, 250.0)])
RUNS = {h: F.accelerate(V, 0.9, 1.5, MASS, h) for h in HS}
OK = np.array([h for h in HS if RUNS[h] is not None])
TIME = np.array([RUNS[h]["t"][-1] for h in OK])
FUEL = np.array([MASS - RUNS[h]["m"][-1] for h in OK])
DIST = np.array([RUNS[h]["x"][-1] / 1e3 for h in OK])
H_FAST, T_FAST = OK[np.argmin(TIME)], TIME.min()
H_THRIFT, F_THRIFT = OK[np.argmin(FUEL)], FUEL.min()
H_LOWEST = OK.min()

if __name__ == "__main__":
    fig, (a1, a2) = plt.subplots(1, 2, figsize=(11, 4.8))
    fig.subplots_adjust(wspace=0.3)
    a1.plot(TIME, OK / 1e3, color=BLUE, lw=2.6); a1.plot(T_FAST, H_FAST / 1e3, "o", color=BLUE, ms=8)
    a1.set_xlabel("time from Mach 0.9 to 1.5 (s)"); a1.set_ylabel("altitude (km)")
    a2.plot(FUEL, OK / 1e3, color=MAROON, lw=2.6); a2.plot(F_THRIFT, H_THRIFT / 1e3, "o", color=MAROON, ms=8)
    a2.set_xlabel("fuel burnt (kg)"); a2.set_ylabel("altitude (km)")
    despine(a1); despine(a2)
    save(fig, "fig-19-accel-altitude")
