r'''Calculates internal convection Nusselt number for turbulent vertical
    upward flow in a pipe under supercritical conditions according to [1]_.
        
    .. math::
        Nu_b = Nu_0\left(\frac{\rho_w}{\rho_b}\right)^{0.3}\left(
        \frac{\bar C_p}{C_{p,b}}\right)^{n}
        
        Nu_0 = \frac{(f/8)Re_b \bar Pr_b}{1.07+12.7(f/8)^{1/2}
        (\bar Pr_b^{2/3}-1)}
        
        f_d = [1.82\log_{10}(Re_b) - 1.64]^{-2}
        
        n = 0.4 \text{ for } T_b < T_w < T_{pc} \text{ or }
        1.2T_{pc} < T_b < T_w
        
        n = n_1 = 0.22 + 0.18T_w/T_{pc} \text{ for } 1 < T_w/T_{pc} < 2.5
        
        n = n_1 + (5n_1 - 2)(1 - T_b/T_{pc}) \text{ for } T_{pc} < T_b < 
        1.2T_{pc} \text{ and } T_{b} < T_w

    Parameters
    ----------
    Re : float
        Reynolds number with bulk fluid properties, [-]
    Pr : float
        Prandtl number with bulk fluid properties, [-]
    rho_w : float, optional
        Density at the wall temperature, [kg/m^3]
    rho_b : float, optional
        Density at the bulk temperature, [kg/m^3]
    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
    -----
    The range of examined parameters is as follows: 
    P from 23.4 to 29.3 MPa; G from 700-3600 kg/m^2/s; 
    q from 46 to 2600 kW/m^2; Re from 8E4 to 5E5; D from 1.6 to 20 mm.
    
    If the extra information is not provided, the correlation will be used
    without the corrections.

    Examples
    --------
    >>> Nu_Krasnoshchekov(1E5, 1.2)
    234.82855185610364

    References
    ----------
    .. [1] Krasnoshchekov, E.A., Protopopov, V.S., Van Fen, Kuraeva, I.V., 
       1967. Experimental investigation of heat transfer for carbon dioxide in
       the supercritical region. In Proceedings of the Second All-Soviet Union 
       Conference on Heat and Mass Transfer, Minsk, Belarus, May.
    .. [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.

def Nu_Krasnoshchekov(Re, Pr, rho_w=None, rho_b=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 = Nu_0\left(\frac{\rho_w}{\rho_b}\right)^{0.3}\left(
        \frac{\bar C_p}{C_{p,b}}\right)^{n}
        
        Nu_0 = \frac{(f/8)Re_b \bar Pr_b}{1.07+12.7(f/8)^{1/2}
        (\bar Pr_b^{2/3}-1)}
        
        f_d = [1.82\log_{10}(Re_b) - 1.64]^{-2}
        
        n = 0.4 \text{ for } T_b < T_w < T_{pc} \text{ or }
        1.2T_{pc} < T_b < T_w
        
        n = n_1 = 0.22 + 0.18T_w/T_{pc} \text{ for } 1 < T_w/T_{pc} < 2.5
        
        n = n_1 + (5n_1 - 2)(1 - T_b/T_{pc}) \text{ for } T_{pc} < T_b < 
        1.2T_{pc} \text{ and } T_{b} < T_w

    Parameters
    ----------
    Re : float
        Reynolds number with bulk fluid properties, [-]
    Pr : float
        Prandtl number with bulk fluid properties, [-]
    rho_w : float, optional
        Density at the wall temperature, [kg/m^3]
    rho_b : float, optional
        Density at the bulk temperature, [kg/m^3]
    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
    -----
    The range of examined parameters is as follows: 
    P from 23.4 to 29.3 MPa; G from 700-3600 kg/m^2/s; 
    q from 46 to 2600 kW/m^2; Re from 8E4 to 5E5; D from 1.6 to 20 mm.
    
    If the extra information is not provided, the correlation will be used
    without the corrections.

    Examples
    --------
    >>> Nu_Krasnoshchekov(1E5, 1.2)
    234.82855185610364

    References
    ----------
    .. [1] Krasnoshchekov, E.A., Protopopov, V.S., Van Fen, Kuraeva, I.V., 
       1967. Experimental investigation of heat transfer for carbon dioxide in
       the supercritical region. In Proceedings of the Second All-Soviet Union 
       Conference on Heat and Mass Transfer, Minsk, Belarus, May.
    .. [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.
    '''
    if all([T_b, T_w, T_pc]):
        n1 = 0.22 + 0.18*T_w/T_pc
        if T_b < T_w < T_pc or 1.2*T_pc < T_b < T_w:      
            n = 0.4
        elif 1 < T_w/T_pc < 2.5:
            n = n1
        else:
            n = n1 + (5*n1 - 2)*(1 - T_b/T_pc)
    else:
        n = 0.4
    fd = (1.82*log10(Re) - 1.64)**-2
    Nu = (fd/8.)*Re*Pr/(1.07 + 12.7*(fd/8.)**0.5*(Pr**(2/3.)-1))
    if rho_w and rho_b:
        Nu *= (rho_w/rho_b)**0.3
    if Cp_avg and Cp_b:
        Nu *= (Cp_avg/Cp_b)**n
    return Nu