# 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/constants.py



import unittest
import numpy as np
from proptools import nozzle
from proptools.constants import R_univ
        """Test mach_from_er against H&H figure 1-12"""
        gamma = 1.4
        er = 4
        M_hh = 3.0
        M = nozzle.mach_from_er(er, gamma)
        self.assertTrue(abs(M - M_hh) < 0.1)


class TestMachFromPr(unittest.TestCase):
    """Unit tests for nozzle.mach_from_pr."""

    def test_rpe_3_1(self):
        """Test mach_from_pr against RPE figure 3-1."""
        M = nozzle.mach_from_pr(1, 1, 1.3)
        M_RPE = 0.
        self.assertTrue(abs(M - M_RPE) < 0.05)
        M = nozzle.mach_from_pr(1, 0.8, 1.3)
        M_RPE = 0.6
        self.assertTrue(abs(M - M_RPE) < 0.05)
        M = nozzle.mach_from_pr(1, 0.1, 1.3)
        M_RPE = 2.2
        self.assertTrue(abs(M - M_RPE) < 0.05)


class TestMachArea(unittest.TestCase):
    """Unit tests for nozzle.area_from_mach."""

    def test_gamma_sonic(self):
        """Test that the sonic area ratio is 1, across range of gamma."""
        for gamma in np.linspace(1.1, 1.6, 10):

# 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/constants.py



# Path: proptools/nozzle_test.py
import unittest
import numpy as np
from proptools import nozzle
from proptools.constants import R_univ

        """Test mach_from_er against H&H figure 1-12"""
        gamma = 1.4
        er = 4
        M_hh = 3.0
        M = nozzle.mach_from_er(er, gamma)
        self.assertTrue(abs(M - M_hh) < 0.1)


class TestMachFromPr(unittest.TestCase):
    """Unit tests for nozzle.mach_from_pr."""

    def test_rpe_3_1(self):
        """Test mach_from_pr against RPE figure 3-1."""
        M = nozzle.mach_from_pr(1, 1, 1.3)
        M_RPE = 0.
        self.assertTrue(abs(M - M_RPE) < 0.05)
        M = nozzle.mach_from_pr(1, 0.8, 1.3)
        M_RPE = 0.6
        self.assertTrue(abs(M - M_RPE) < 0.05)
        M = nozzle.mach_from_pr(1, 0.1, 1.3)
        M_RPE = 2.2
        self.assertTrue(abs(M - M_RPE) < 0.05)


class TestMachArea(unittest.TestCase):
    """Unit tests for nozzle.area_from_mach."""

    def test_gamma_sonic(self):
        """Test that the sonic area ratio is 1, across range of gamma."""
        for gamma in np.linspace(1.1, 1.6, 10):

           self.assertTrue(np.isclose(nozzle.area_from_mach(1, gamma), 1))