# Path: proptools/nozzle.py
# def thrust_coef(p_c, p_e, gamma, p_a=None, er=None):
# def c_star(gamma, m_molar, T_c):
# def er_from_p(p_c, p_e, gamma):
# def pressure_from_er(er, gamma):
# def throat_area(m_dot, p_c, T_c, gamma, m_molar):
# def mass_flow(A_t, p_c, T_c, gamma, m_molar):
# def thrust(A_t, p_c, p_e, gamma, p_a=None, er=None):
# def mach_from_er(er, gamma):
# def mach_from_pr(p_c, p_e, gamma):
# def is_choked(p_c, p_e, gamma):
# def mach_from_area_subsonic(area_ratio, gamma):
# def area_from_mach(M, gamma):
#     C_F = (2 * gamma**2 / (gamma - 1) \
#         * (2 / (gamma + 1))**((gamma + 1) / (gamma - 1)) \
#         * (1 - (p_e / p_c)**((gamma - 1) / gamma))
#           )**0.5
#     R = R_univ / m_molar
#     X = np.zeros((n,))
#     M = np.zeros((n,))
#     B = (y+1)/(y-1)
#     X[0] = (u*k)**(B/(1-B))
#     M[0] = X[0]
#     P = 2 / (gamma + 1)
#     Q = 1 - P
#     E = 1 / Q
#     R = area_ratio**2
#     X = fsolve(
#         lambda X: (P + Q * X)**E - R * X,
#         X_init
#         )


from proptools import nozzle
from scipy.interpolate import RectBivariateSpline, interp1d
    from matplotlib import pyplot as plt
import math
import numpy as np
        c_p: working gas heat capacity at const pressure
            [units: joule kilogram**-1 kelvin**-1].
    '''
    # Turbine specific enthalpy drop [units: joule kilogram**-1]
    dh_turb_ideal = turbine_enthalpy(p_o, p_te, T_o, gamma, c_p)
    dh_turb = eta * dh_turb_ideal
    # Turbine exit temperature
    T_te = T_o - (dh_turb / c_p)
    return T_te


def gg_dump_isp(p_o, p_te, p_ne, T_o, eta, gamma, c_p, m_molar):
    '''Get the specific impulse of a Gas Generator turbine exhaust dump.
    
    Arguments:
        p_o: turbine inlet stagnation pressure [units: pascal].
        p_te: turbine exit pressure [units: pascal].
        p_ne: Dump nozzle exit pressure [units: pascal].
        T_o: turbine inlet stagnation temperature [units: kelvin].
        eta: turbine efficiency.
        gamma: working gas ratio of specific heats [units: none].
        c_p: working gas heat capacity at const pressure
            [units: joule kilogram**-1 kelvin**-1].
        m_molar: working gas molar mass [units: kilogram mole**-1].
    '''
    T_te = turbine_exit_temperature(p_o, p_te, T_o, eta, gamma, c_p)

    # Dump nozzle thrust coefficient and characteristic velocity.
    # Assume optimal expansion.
    C_f = nozzle.thrust_coef(p_c=p_te, p_e=p_ne, gamma=gamma)

# Path: proptools/nozzle.py
# def thrust_coef(p_c, p_e, gamma, p_a=None, er=None):
# def c_star(gamma, m_molar, T_c):
# def er_from_p(p_c, p_e, gamma):
# def pressure_from_er(er, gamma):
# def throat_area(m_dot, p_c, T_c, gamma, m_molar):
# def mass_flow(A_t, p_c, T_c, gamma, m_molar):
# def thrust(A_t, p_c, p_e, gamma, p_a=None, er=None):
# def mach_from_er(er, gamma):
# def mach_from_pr(p_c, p_e, gamma):
# def is_choked(p_c, p_e, gamma):
# def mach_from_area_subsonic(area_ratio, gamma):
# def area_from_mach(M, gamma):
#     C_F = (2 * gamma**2 / (gamma - 1) \
#         * (2 / (gamma + 1))**((gamma + 1) / (gamma - 1)) \
#         * (1 - (p_e / p_c)**((gamma - 1) / gamma))
#           )**0.5
#     R = R_univ / m_molar
#     X = np.zeros((n,))
#     M = np.zeros((n,))
#     B = (y+1)/(y-1)
#     X[0] = (u*k)**(B/(1-B))
#     M[0] = X[0]
#     P = 2 / (gamma + 1)
#     Q = 1 - P
#     E = 1 / Q
#     R = area_ratio**2
#     X = fsolve(
#         lambda X: (P + Q * X)**E - R * X,
#         X_init
#         )


# Path: proptools/turbopump.py
from proptools import nozzle
from scipy.interpolate import RectBivariateSpline, interp1d
    from matplotlib import pyplot as plt
import math
import numpy as np

        c_p: working gas heat capacity at const pressure
            [units: joule kilogram**-1 kelvin**-1].
    '''
    # Turbine specific enthalpy drop [units: joule kilogram**-1]
    dh_turb_ideal = turbine_enthalpy(p_o, p_te, T_o, gamma, c_p)
    dh_turb = eta * dh_turb_ideal
    # Turbine exit temperature
    T_te = T_o - (dh_turb / c_p)
    return T_te


def gg_dump_isp(p_o, p_te, p_ne, T_o, eta, gamma, c_p, m_molar):
    '''Get the specific impulse of a Gas Generator turbine exhaust dump.
    
    Arguments:
        p_o: turbine inlet stagnation pressure [units: pascal].
        p_te: turbine exit pressure [units: pascal].
        p_ne: Dump nozzle exit pressure [units: pascal].
        T_o: turbine inlet stagnation temperature [units: kelvin].
        eta: turbine efficiency.
        gamma: working gas ratio of specific heats [units: none].
        c_p: working gas heat capacity at const pressure
            [units: joule kilogram**-1 kelvin**-1].
        m_molar: working gas molar mass [units: kilogram mole**-1].
    '''
    T_te = turbine_exit_temperature(p_o, p_te, T_o, eta, gamma, c_p)

    # Dump nozzle thrust coefficient and characteristic velocity.
    # Assume optimal expansion.
    C_f = nozzle.thrust_coef(p_c=p_te, p_e=p_ne, gamma=gamma)

    c_star = nozzle.c_star(gamma=gamma, m_molar=m_molar, T_c=T_te)