r'''Calculates internal convection Nusselt number for turbulent vertical
    upward flow in a pipe under supercritical conditions according to [1]_.
        
    .. math::
        Nu_b = 0.0138 Re_b^{0.85}Pr_b^{0.8}F
        
        F = \left(\frac{\bar C_p}{C_{p,b}}\right)^{n_2} \text{ if } 
        \frac{T_{pc}-T_b}{T_w-T_b} < 0

        F = 0.67Pr_{pc}^{-0.05} \left(\frac{\bar C_p}{C_{p,b}}\right)^{n_1} 
        \text{ if } 0 < \frac{T_{pc}-T_b}{T_w-T_b}  < 1

        F = 1\text{ if } \frac{T_{pc}-T_b}{T_w-T_b} > 1

        n_1 = -0.77(1 + 1/Pr_{pc}) + 1.49
        
        n_2 = 1.44(1 + 1/Pr_{pc}) - 0.53
    
        \bar{Cp} = \frac{H_w-H_b}{T_w-T_b}
        
    Parameters
    ----------
    Re : float
        Reynolds number with bulk fluid properties, [-]
    Pr : float
        Prandtl number with bulk fluid properties, [-]
    Pr_pc : float, optional
        Prandtl number at the pseudocritical temperature, [-]
    Cp_avg : float, optional
        Average heat capacity between the wall and bulk temperatures, [J/kg/K]
    Cp_b : float, optional
        Heat capacity at the bulk temperature, [J/kg/K]
    T_b : float
        Bulk temperature, [K]
    T_w : float
        Wall temperature, [K]
    T_pc : float
        Pseudocritical temperature, i.e. temperature at P where Cp is at a 
        maximum, [K]

    Returns
    -------
    Nu : float
        Nusselt number with bulk fluid properties, [-]

    Notes
    -----
    For the data used to develop the correlation, P varied from 22.6 to 29.4 
    MPa, and D was 7.5 and 10 mm. G varied from 310-1830 kg/m^2/s, q varied 
    from 116 to 930 kW/m^2, and bulk temperature varied from 230 to 540 decrees 
    Celsius. 
    
    In the database in [3]_, the correlation was considered but not tested.
    In [2]_, the correlation was considered but no results were reported.
    
    For enhanced heat transfer database in [2]_, this correlation was the
    second best with a MAD of 11.5%. In the database in [3]_, the correlation
    was the second best as well.
    
    If the extra information is not provided, the correlation will be used
    without the corrections.

    Examples
    --------

    References
    ----------
    .. [1] Yamagata, K, K Nishikawa, S Hasegawa, T Fujii, and S Yoshida. 
       "Forced Convective Heat Transfer to Supercritical Water Flowing in 
       Tubes." International Journal of Heat and Mass Transfer 15, no. 12 
       (December 1, 1972): 2575-93. doi:10.1016/0017-9310(72)90148-2.
    .. [2] Chen, Weiwei, Xiande Fang, Yu Xu, and Xianghui Su. "An Assessment of
       Correlations of Forced Convection Heat Transfer to Water at 
       Supercritical Pressure." Annals of Nuclear Energy 76 (February 2015): 
       451-60. doi:10.1016/j.anucene.2014.10.027.
    .. [3] Yu, Jiyang, Baoshan Jia, Dan Wu, and Daling Wang. "Optimization of 
       Heat Transfer Coefficient Correlation at Supercritical Pressure Using 
       Genetic Algorithms." Heat and Mass Transfer 45, no. 6 (January 8, 2009): 
       757-66. doi:10.1007/s00231-008-0475-4.
    .. [4] Jäger, Wadim, Victor Hugo Sánchez Espinoza, and Antonio Hurtado. 
       "Review and Proposal for Heat Transfer Predictions at Supercritical 
       Water Conditions Using Existing Correlations and Experiments." Nuclear 
       Engineering and Design, (W3MDM) University of Leeds International 
       Symposium: What Where When? Multi-dimensional Advances for Industrial 
       Process Monitoring, 241, no. 6 (June 2011): 2184-2203. 
       doi:10.1016/j.nucengdes.2011.03.022.

def Nu_Yamagata(Re, Pr, Pr_pc=None, Cp_avg=None, Cp_b=None, T_b=None,
               T_w=None, T_pc=None):
    r'''Calculates internal convection Nusselt number for turbulent vertical
    upward flow in a pipe under supercritical conditions according to [1]_.
        
    .. math::
        Nu_b = 0.0138 Re_b^{0.85}Pr_b^{0.8}F
        
        F = \left(\frac{\bar C_p}{C_{p,b}}\right)^{n_2} \text{ if } 
        \frac{T_{pc}-T_b}{T_w-T_b} < 0

        F = 0.67Pr_{pc}^{-0.05} \left(\frac{\bar C_p}{C_{p,b}}\right)^{n_1} 
        \text{ if } 0 < \frac{T_{pc}-T_b}{T_w-T_b}  < 1

        F = 1\text{ if } \frac{T_{pc}-T_b}{T_w-T_b} > 1

        n_1 = -0.77(1 + 1/Pr_{pc}) + 1.49
        
        n_2 = 1.44(1 + 1/Pr_{pc}) - 0.53
    
        \bar{Cp} = \frac{H_w-H_b}{T_w-T_b}
        
    Parameters
    ----------
    Re : float
        Reynolds number with bulk fluid properties, [-]
    Pr : float
        Prandtl number with bulk fluid properties, [-]
    Pr_pc : float, optional
        Prandtl number at the pseudocritical temperature, [-]
    Cp_avg : float, optional
        Average heat capacity between the wall and bulk temperatures, [J/kg/K]
    Cp_b : float, optional
        Heat capacity at the bulk temperature, [J/kg/K]
    T_b : float
        Bulk temperature, [K]
    T_w : float
        Wall temperature, [K]
    T_pc : float
        Pseudocritical temperature, i.e. temperature at P where Cp is at a 
        maximum, [K]

    Returns
    -------
    Nu : float
        Nusselt number with bulk fluid properties, [-]

    Notes
    -----
    For the data used to develop the correlation, P varied from 22.6 to 29.4 
    MPa, and D was 7.5 and 10 mm. G varied from 310-1830 kg/m^2/s, q varied 
    from 116 to 930 kW/m^2, and bulk temperature varied from 230 to 540 decrees 
    Celsius. 
    
    In the database in [3]_, the correlation was considered but not tested.
    In [2]_, the correlation was considered but no results were reported.
    
    For enhanced heat transfer database in [2]_, this correlation was the
    second best with a MAD of 11.5%. In the database in [3]_, the correlation
    was the second best as well.
    
    If the extra information is not provided, the correlation will be used
    without the corrections.

    Examples
    --------

    References
    ----------
    .. [1] Yamagata, K, K Nishikawa, S Hasegawa, T Fujii, and S Yoshida. 
       "Forced Convective Heat Transfer to Supercritical Water Flowing in 
       Tubes." International Journal of Heat and Mass Transfer 15, no. 12 
       (December 1, 1972): 2575-93. doi:10.1016/0017-9310(72)90148-2.
    .. [2] Chen, Weiwei, Xiande Fang, Yu Xu, and Xianghui Su. "An Assessment of
       Correlations of Forced Convection Heat Transfer to Water at 
       Supercritical Pressure." Annals of Nuclear Energy 76 (February 2015): 
       451-60. doi:10.1016/j.anucene.2014.10.027.
    .. [3] Yu, Jiyang, Baoshan Jia, Dan Wu, and Daling Wang. "Optimization of 
       Heat Transfer Coefficient Correlation at Supercritical Pressure Using 
       Genetic Algorithms." Heat and Mass Transfer 45, no. 6 (January 8, 2009): 
       757-66. doi:10.1007/s00231-008-0475-4.
    .. [4] Jäger, Wadim, Victor Hugo Sánchez Espinoza, and Antonio Hurtado. 
       "Review and Proposal for Heat Transfer Predictions at Supercritical 
       Water Conditions Using Existing Correlations and Experiments." Nuclear 
       Engineering and Design, (W3MDM) University of Leeds International 
       Symposium: What Where When? Multi-dimensional Advances for Industrial 
       Process Monitoring, 241, no. 6 (June 2011): 2184-2203. 
       doi:10.1016/j.nucengdes.2011.03.022. 
    '''
    F = 1
    if all([T_b, T_w, T_pc, Pr_pc, Cp_avg, Cp_b]):
        E = (T_pc - T_b)/(T_w - T_b)
        if E < 0:
            n2 = 1.44*(1 + 1/Pr_pc) - 0.53
            F = (Cp_avg/Cp_b)**n2
        elif 0 < E < 1:
            n1 = -0.77*(1 + 1/Pr_pc) + 1.49
            F = 0.67*Pr_pc**-0.05*(Cp_avg/Cp_b)**n1
    return 0.0138*Re**0.85*Pr**0.8*F