# Path: proptools/convection.py
# def adiabatic_wall_temperature(T_c, M, gamma, r=0.9, Pr=None):
# def long_tube_coeff(mass_flux, D, c_p, mu, k):
# def bartz(p_c, c_star, D_t, D, c_p, mu_e, Pr, sigma=1.):
# def bartz_sigma_sanchez(T_e, T_avg, w=0.6):
# def bartz_sigma_huzel(T_c, T_w, M, gamma):
# def film_adiabatic_wall_temperature(eta_film, T_aw, T_f):
# def film_efficiency(x, D, m_dot_core, m_dot_film, mu_core, Pr_film=1, film_param=1, cp_ratio=1):
# def rannie_transpiration_cooling(cool_flux_fraction, Pr_film, Re_bulk):
#     G = cool_flux_fraction
#     R = Re_bulk**0.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
#         )


import unittest
from math import pi
from proptools import convection, nozzle
    def test_1(self):
        """No examples are given in Hill & Peterson, I had to come up with this."""
        # Setup
        Re = 1e6
        Pr = 0.7
        mass_flux = 1.
        mu = 2e-5
        c_p = 1000.
        k = mu * c_p / Pr
        D = Re * mu / mass_flux

        # Action
        h = convection.long_tube_coeff(mass_flux, D, c_p, mu, k)

        # Verification
        # Lefthand side of equation 11.35 from H & P
        #  = h / (c_p mass_flux)
        # units: dimensionless
        lhs = 0.023 * Re**-0.2 * Pr**-0.67
        self.assertTrue(abs(lhs - h / (c_p * mass_flux)) < 1e-6)


class TestBartz(unittest.TestCase):
    """Unit tests for convection.bartz."""

    def test_ssme(self):
        """Test agaisnt the SSME example from 16.512 Lecture 7."""
        T_e = 3200.
        T_w = 1000.
        T_avg = (T_e + T_w) / 2

# Path: proptools/convection.py
# def adiabatic_wall_temperature(T_c, M, gamma, r=0.9, Pr=None):
# def long_tube_coeff(mass_flux, D, c_p, mu, k):
# def bartz(p_c, c_star, D_t, D, c_p, mu_e, Pr, sigma=1.):
# def bartz_sigma_sanchez(T_e, T_avg, w=0.6):
# def bartz_sigma_huzel(T_c, T_w, M, gamma):
# def film_adiabatic_wall_temperature(eta_film, T_aw, T_f):
# def film_efficiency(x, D, m_dot_core, m_dot_film, mu_core, Pr_film=1, film_param=1, cp_ratio=1):
# def rannie_transpiration_cooling(cool_flux_fraction, Pr_film, Re_bulk):
#     G = cool_flux_fraction
#     R = Re_bulk**0.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: proptools/convection_test.py
import unittest
from math import pi
from proptools import convection, nozzle

    def test_1(self):
        """No examples are given in Hill & Peterson, I had to come up with this."""
        # Setup
        Re = 1e6
        Pr = 0.7
        mass_flux = 1.
        mu = 2e-5
        c_p = 1000.
        k = mu * c_p / Pr
        D = Re * mu / mass_flux

        # Action
        h = convection.long_tube_coeff(mass_flux, D, c_p, mu, k)

        # Verification
        # Lefthand side of equation 11.35 from H & P
        #  = h / (c_p mass_flux)
        # units: dimensionless
        lhs = 0.023 * Re**-0.2 * Pr**-0.67
        self.assertTrue(abs(lhs - h / (c_p * mass_flux)) < 1e-6)


class TestBartz(unittest.TestCase):
    """Unit tests for convection.bartz."""

    def test_ssme(self):
        """Test agaisnt the SSME example from 16.512 Lecture 7."""
        T_e = 3200.
        T_w = 1000.
        T_avg = (T_e + T_w) / 2

        sigma = convection.bartz_sigma_sanchez(T_e, T_avg)