"""Lecture 14: propulsive efficiency 2/(1 + Ve/V) against flight speed for three jets of air with FIXED exit speeds,
Ve = V_ref + extra, taken from the three HYPOTHETICAL streams of anim-14-jets.py (50 kN at 250 m/s). Holding Ve fixed
as V changes is itself a simplification. Writes img/fig-14-prop-eff-speed.png."""
import numpy as np
from _visual import plt, save, despine, INK, GREY
from _scripts import load
from flight import propulsion as P

J = load("anim-14-jets")
VREF, THRUST = 250.0, 50e3
STREAMS = [(lab, VREF + THRUST / md, c) for lab, md, c in J.CASES]


def eta(V, ve):
    return P.propulsive_efficiency(V, ve)


if __name__ == "__main__":
    fig, ax = plt.subplots(figsize=(10, 4.9))
    for lab, ve, c in STREAMS:
        V = np.linspace(1, ve, 300)
        ax.plot(V, [eta(v, ve) for v in V], color=c, lw=2.8, label=f"{lab}: exit speed {ve:.0f} m/s")
        ax.plot(ve, 1.0, "o", color=c, ms=8, clip_on=False)
        ax.plot(VREF, eta(VREF, ve), "s", color=c, ms=7)
    ax.axvline(VREF, color=GREY, lw=1, ls=":")
    ax.set_xlim(0, 780); ax.set_ylim(0, 1.04); ax.set_xlabel("flight speed (m/s)"); ax.set_ylabel("propulsive efficiency")
    ax.legend(frameon=False, fontsize=11.5, loc="lower right")
    despine(ax)
    save(fig, "fig-14-prop-eff-speed")
