"""Lecture 13: the stagnation-point pressure coefficient behind a normal shock against Mach number
(flight.aero.modified_newtonian_cpmax, air with gamma = 1.4), with Newton's value 2 and the large-Mach limit.
Writes img/fig-13-cpmax.png."""
import numpy as np
from _visual import plt, save, despine, MAROON, BLUE, INK, GREY
from flight import aero as AE

M = np.geomspace(2, 30, 200)


def cpmax(m):
    return AE.modified_newtonian_cpmax(m)


LIMIT = float(cpmax(1e4))

if __name__ == "__main__":
    fig, ax = plt.subplots(figsize=(10, 4.8))
    ax.plot(M, [cpmax(m) for m in M], color=MAROON, lw=3, label="behind a normal shock")
    ax.axhline(2.0, color=BLUE, lw=1.6, ls="--", label="Newton: 2")
    ax.axhline(LIMIT, color=GREY, lw=1.6, ls=":", label=f"limit at very high Mach number: {LIMIT:.2f}")
    for m in (2.0, 6.0, 28.0):
        ax.plot(m, cpmax(m), "o", color=INK, ms=8, clip_on=False)
        ax.annotate(f"M {m:.0f}: {cpmax(m):.3f}", (m, cpmax(m)), xytext=(8, -17), textcoords="offset points", fontsize=11.5)
    ax.set_xscale("log"); ax.set_xticks([2, 3, 5, 10, 20, 30], ["2", "3", "5", "10", "20", "30"]); ax.set_xlim(2, 30); ax.set_ylim(1.6, 2.06)
    ax.set_xlabel("free-stream Mach number"); ax.set_ylabel("$C_{p,\\max}$")
    ax.legend(frameon=False, fontsize=11.5, loc="lower right")
    despine(ax)
    save(fig, "fig-13-cpmax")
