r'''Calculates pressure drop for crossflow across a tube bank
    according to the equivalent-diameter method developed by Kern [1]_,
    presented in [2]_.

    .. math::
        \Delta P = \frac{f (m/S_s)^2 D_s(N_B+1)}{2\rho D_e(\mu/\mu_w)^{0.14}}

        S_S = \frac{D_S (P_T-D_o) L_B}{P_T}

        D_e = \frac{4(P_T^2 - \pi D_o^2/4)}{\pi D_o}

    Parameters
    ----------
    m : float
        Mass flow rate, [kg/s]
    rho : float
        Fluid density, [kg/m^3]
    mu : float
        Fluid viscosity, [Pa*s]
    DShell : float
        Diameter of exchanger shell, [m]
    LSpacing : float
        Baffle spacing, [m]
    pitch : float
        Tube pitch, [m]
    Do : float
        Tube outer diameter, [m]
    NBaffles : float
        Baffle count, []
    mu_w : float
        Fluid viscosity at wall temperature, [Pa*s]

    Returns
    -------
    dP : float
        Pressure drop across bundle, [Pa]

    Notes
    -----
    Adjustment for viscosity left out of this function.
    Example is from [2]_. Roughly 10% difference due to reading of graph.
    Graph scanned from [1]_, and interpolation is used to read it.

    Examples
    --------
    >>> dP_Kern(m=11., rho=995., mu=0.000803, mu_w=0.000657, DShell=0.584,
    ... LSpacing=0.1524, pitch=0.0254, Do=.019, NBaffles=22)
    18980.58768759033

    References
    ----------
    .. [1] Kern, Donald Quentin. Process Heat Transfer. McGraw-Hill, 1950.
    .. [2] Peters, Max, Klaus Timmerhaus, and Ronald West. Plant Design and
       Economics for Chemical Engineers. 5E. New York: McGraw-Hill, 2002.

def dP_Kern(m, rho, mu, DShell, LSpacing, pitch, Do, NBaffles, mu_w=None):
    r'''Calculates pressure drop for crossflow across a tube bank
    according to the equivalent-diameter method developed by Kern [1]_,
    presented in [2]_.

    .. math::
        \Delta P = \frac{f (m/S_s)^2 D_s(N_B+1)}{2\rho D_e(\mu/\mu_w)^{0.14}}

        S_S = \frac{D_S (P_T-D_o) L_B}{P_T}

        D_e = \frac{4(P_T^2 - \pi D_o^2/4)}{\pi D_o}

    Parameters
    ----------
    m : float
        Mass flow rate, [kg/s]
    rho : float
        Fluid density, [kg/m^3]
    mu : float
        Fluid viscosity, [Pa*s]
    DShell : float
        Diameter of exchanger shell, [m]
    LSpacing : float
        Baffle spacing, [m]
    pitch : float
        Tube pitch, [m]
    Do : float
        Tube outer diameter, [m]
    NBaffles : float
        Baffle count, []
    mu_w : float
        Fluid viscosity at wall temperature, [Pa*s]

    Returns
    -------
    dP : float
        Pressure drop across bundle, [Pa]

    Notes
    -----
    Adjustment for viscosity left out of this function.
    Example is from [2]_. Roughly 10% difference due to reading of graph.
    Graph scanned from [1]_, and interpolation is used to read it.

    Examples
    --------
    >>> dP_Kern(m=11., rho=995., mu=0.000803, mu_w=0.000657, DShell=0.584,
    ... LSpacing=0.1524, pitch=0.0254, Do=.019, NBaffles=22)
    18980.58768759033

    References
    ----------
    .. [1] Kern, Donald Quentin. Process Heat Transfer. McGraw-Hill, 1950.
    .. [2] Peters, Max, Klaus Timmerhaus, and Ronald West. Plant Design and
       Economics for Chemical Engineers. 5E. New York: McGraw-Hill, 2002.
    '''
    # Adjustment for viscosity performed if given
    Ss = DShell*(pitch-Do)*LSpacing/pitch
    De = 4*(pitch**2 - pi*Do**2/4.)/pi/Do
    Vs = m/Ss/rho
    Re = rho*De*Vs/mu
    f = float(Kern_f_Re(Re))
    if mu_w:
        return f*(Vs*rho)**2*DShell*(NBaffles+1)/(2*rho*De*(mu/mu_w)**0.14)
    else:
        return f*(Vs*rho)**2*DShell*(NBaffles+1)/(2*rho*De)