r'''Returns the Shape factor `S` of a pipe of constant outer temperature
    and of outer diameter `D1` which is `w` distance from another infinite
    pipe of outer diameter`D2`. Length `L` must be provided, but can be set to
    1 to obtain a dimensionless shape factor used in some sources.

    .. math::
        S = \frac{2\pi L}{\cosh^{-1}\left(\frac{4w^2-D_1^2-D_2^2}{2D_1D_2}\right)}

    Parameters
    ----------
    D1 : float
        Diameter of one pipe, [m]
    D2 : float
        Diameter of the other pipe, [m]
    W : float
        Distance from the middle of one pipe to the middle of the other, [m]
    L : float, optional
        Length of the pipe, [m]

    Returns
    -------
    S : float
        Shape factor [m]

    Examples
    --------
    >>> S_isothermal_pipe_to_isothermal_pipe(.1, .2, 1, 1)
    1.188711034982268

    Notes
    -----
    L should be much larger than both diameters. L should be larger than W.

    .. math::
        Q = Sk(T_1 - T_2) \\ R_{\text{shape}}=\frac{1}{Sk}

    References
    ----------
    .. [1] Kreith, Frank, Raj Manglik, and Mark Bohn. Principles of Heat
       Transfer. Cengage, 2010.
    .. [2] Bergman, Theodore L., Adrienne S. Lavine, Frank P. Incropera, and
       David P. DeWitt. Introduction to Heat Transfer. 6E. Hoboken, NJ:
       Wiley, 2011.

def S_isothermal_pipe_to_isothermal_pipe(D1, D2, W, L=1.):
    r'''Returns the Shape factor `S` of a pipe of constant outer temperature
    and of outer diameter `D1` which is `w` distance from another infinite
    pipe of outer diameter`D2`. Length `L` must be provided, but can be set to
    1 to obtain a dimensionless shape factor used in some sources.

    .. math::
        S = \frac{2\pi L}{\cosh^{-1}\left(\frac{4w^2-D_1^2-D_2^2}{2D_1D_2}\right)}

    Parameters
    ----------
    D1 : float
        Diameter of one pipe, [m]
    D2 : float
        Diameter of the other pipe, [m]
    W : float
        Distance from the middle of one pipe to the middle of the other, [m]
    L : float, optional
        Length of the pipe, [m]

    Returns
    -------
    S : float
        Shape factor [m]

    Examples
    --------
    >>> S_isothermal_pipe_to_isothermal_pipe(.1, .2, 1, 1)
    1.188711034982268

    Notes
    -----
    L should be much larger than both diameters. L should be larger than W.

    .. math::
        Q = Sk(T_1 - T_2) \\ R_{\text{shape}}=\frac{1}{Sk}

    References
    ----------
    .. [1] Kreith, Frank, Raj Manglik, and Mark Bohn. Principles of Heat
       Transfer. Cengage, 2010.
    .. [2] Bergman, Theodore L., Adrienne S. Lavine, Frank P. Incropera, and
       David P. DeWitt. Introduction to Heat Transfer. 6E. Hoboken, NJ:
       Wiley, 2011.
    '''
    return 2.*pi*L/acosh((4*W**2 - D1**2 - D2**2)/(2.*D1*D2))