# 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 math import pi
from proptools import nozzle
"""Check that the nozzle is choked and find the mass flow."""

# Declare engine design parameters
p_c = 10e6    # Chamber pressure [units: pascal]
p_e = 100e3    # Exit pressure [units: pascal]
gamma = 1.2    # Exhaust heat capacity ratio [units: dimensionless]
m_molar = 20e-3    # Exhaust molar mass [units: kilogram mole**1]
T_c = 3000.    # Chamber temperature [units: kelvin]
A_t = pi * (0.1 / 2)**2    # Throat area [units: meter**2]

# Check choking
if nozzle.is_choked(p_c, p_e, gamma):
    print 'The flow is choked'

# Compute the mass flow [units: kilogram second**-1]

# 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: docs/source/examples/choked.py
from math import pi
from proptools import nozzle

"""Check that the nozzle is choked and find the mass flow."""

# Declare engine design parameters
p_c = 10e6    # Chamber pressure [units: pascal]
p_e = 100e3    # Exit pressure [units: pascal]
gamma = 1.2    # Exhaust heat capacity ratio [units: dimensionless]
m_molar = 20e-3    # Exhaust molar mass [units: kilogram mole**1]
T_c = 3000.    # Chamber temperature [units: kelvin]
A_t = pi * (0.1 / 2)**2    # Throat area [units: meter**2]

# Check choking
if nozzle.is_choked(p_c, p_e, gamma):
    print 'The flow is choked'

# Compute the mass flow [units: kilogram second**-1]

m_dot = nozzle.mass_flow(A_t, p_c, T_c, gamma, m_molar)