r'''Basic helper calculator which accepts a transformed R1 and NTU1 as 
    inputs for a common term used in the calculation of the P-NTU method for 
    plate exchangers.
    
    Returns a value which is normally used in other calculations before the 
    actual P1 is calculated. Nominally used in counterflow calculations 

    .. math::
        P_c(x, y) = \frac{1 - \exp[-x(1 - y)]}{1 - y\exp[-x(1 - y)]}
        
    Parameters
    ----------
    x : float
        A modification of NTU1, the Thermal Number of Transfer Units [-]
    y : float
        A modification of R1, the thermal effectiveness [-]

    Returns
    -------
    z : float
        Just another term in the calculation, [-]

    Notes
    -----
    Used with the P-NTU plate method for heat exchanger design. At y =-1,
    this function has a ZeroDivisionError but can be evaluated at the limit
    to be :math:`z = \frac{x}{1+x}`.

    Examples
    --------
    >>> Pc(5, .7)
    0.9206703686051108

    References
    ----------
    .. [1] Shah, Ramesh K., and Dusan P. Sekulic. Fundamentals of Heat 
       Exchanger Design. 1st edition. Hoboken, NJ: Wiley, 2002.
    .. [2] Rohsenow, Warren and James Hartnett and Young Cho. Handbook of Heat
       Transfer, 3E. New York: McGraw-Hill, 1998.

def Pc(x, y):
    r'''Basic helper calculator which accepts a transformed R1 and NTU1 as 
    inputs for a common term used in the calculation of the P-NTU method for 
    plate exchangers.
    
    Returns a value which is normally used in other calculations before the 
    actual P1 is calculated. Nominally used in counterflow calculations 

    .. math::
        P_c(x, y) = \frac{1 - \exp[-x(1 - y)]}{1 - y\exp[-x(1 - y)]}
        
    Parameters
    ----------
    x : float
        A modification of NTU1, the Thermal Number of Transfer Units [-]
    y : float
        A modification of R1, the thermal effectiveness [-]

    Returns
    -------
    z : float
        Just another term in the calculation, [-]

    Notes
    -----
    Used with the P-NTU plate method for heat exchanger design. At y =-1,
    this function has a ZeroDivisionError but can be evaluated at the limit
    to be :math:`z = \frac{x}{1+x}`.

    Examples
    --------
    >>> Pc(5, .7)
    0.9206703686051108

    References
    ----------
    .. [1] Shah, Ramesh K., and Dusan P. Sekulic. Fundamentals of Heat 
       Exchanger Design. 1st edition. Hoboken, NJ: Wiley, 2002.
    .. [2] Rohsenow, Warren and James Hartnett and Young Cho. Handbook of Heat
       Transfer, 3E. New York: McGraw-Hill, 1998.
    '''
    try:
        term = exp(-x*(1. - y))
        return (1. - term)/(1. - y*term)
    except ZeroDivisionError:
        return x/(1. + x)