def two_phase_dP_gravitational(angle, z, alpha_i, rho_li, rho_gi,  
                               alpha_o=None, rho_lo=None, rho_go=None, g=g):
    r'''This function handles calculation of two-phase liquid-gas pressure drop
    due to gravitation for flow inside channels. This is a discrete 
    calculation for a segment with a known difference in elevation (and ideally
    known inlet and outlet pressures so density dependence can be included). 
    
    .. math::
        - \Delta P_{grav} =  g \sin \theta z \left\{\frac{ [\alpha_o\rho_{g,o} 
        + (1-\alpha_o)\rho_{l,o}] + [\alpha_i\rho_{g,i} + (1-\alpha_i)\rho_{l,i}]}
        {2}\right\}
        
    Parameters
    ----------
    angle : float
        The angle of the pipe with respect to the horizontal, [degrees]
    z : float
        The total length of the pipe, [m]
    alpha_i : float
        Void fraction at inlet (area of gas / total area of channel), [-]
    rho_li : float
        Liquid phase density at inlet, [kg/m^3]
    rho_gi : float
        Gas phase density at inlet, [kg/m^3]
    alpha_o : float, optional
        Void fraction at outlet (area of gas / total area of channel), [-]
    rho_lo : float, optional
        Liquid phase density at outlet, [kg/m^3]
    rho_go : float, optional
        Gas phase density at outlet, [kg/m^3]
    g : float, optional
        Acceleration due to gravity, [m/s^2]

    Returns
    -------
    dP : float
        Gravitational component of pressure drop for two-phase flow, [Pa]
        
    Notes
    -----
    The use of different gas and liquid phase densities and void fraction 
    at the inlet and outlet is optional; the outlet densities and void fraction
    will be assumed to be those of the inlet if they are not specified. This
    does not add much accuracy.
    
    There is a continuous variant of this method which can be integrated over,
    at the expense of a speed. The differential form of this is as follows 
    ([1]_, [2]_):
        
    .. math::
        -\left(\frac{dP}{dz} \right)_{grav} =  [\alpha\rho_g + (1-\alpha)
        \rho_l]g \sin \theta
        
    Examples
    --------
    Example calculation, page 13-2 from [3]_:
    
    >>> two_phase_dP_gravitational(angle=90, z=2, alpha_i=0.9685, rho_li=1518., 
    ... rho_gi=2.6)
    987.237416829999

    The same calculation, but using average inlet and outlet conditions:
    
    >>> two_phase_dP_gravitational(angle=90, z=2, alpha_i=0.9685, rho_li=1518.,
    ... rho_gi=2.6,  alpha_o=0.968, rho_lo=1517.9, rho_go=2.59)
    994.5416058829999
    
    References
    ----------
    .. [1] Rohsenow, Warren and James Hartnett and Young Cho. Handbook of Heat
       Transfer, 3E. New York: McGraw-Hill, 1998.
    .. [2] Kim, Sung-Min, and Issam Mudawar. "Review of Databases and
       Predictive Methods for Pressure Drop in Adiabatic, Condensing and
       Boiling Mini/Micro-Channel Flows." International Journal of Heat and
       Mass Transfer 77 (October 2014): 74-97.
       doi:10.1016/j.ijheatmasstransfer.2014.04.035.
    .. [3] Thome, John R. "Engineering Data Book III." Wolverine Tube Inc
       (2004). http://www.wlv.com/heat-transfer-databook/
    '''
    if rho_lo is None:
        rho_lo = rho_li
    if rho_go is None:
        rho_go = rho_gi
    if alpha_o is None:
        alpha_o = alpha_i
    angle = radians(angle)
    in_term = alpha_i*rho_gi + (1. - alpha_i)*rho_li
    out_term = alpha_o*rho_go + (1. - alpha_o)*rho_lo
    return g*z*sin(angle)*(out_term + in_term)/2.
r'''This function handles calculation of two-phase liquid-gas pressure drop
    due to gravitation for flow inside channels. This is a discrete 
    calculation for a segment with a known difference in elevation (and ideally
    known inlet and outlet pressures so density dependence can be included). 
    
    .. math::
        - \Delta P_{grav} =  g \sin \theta z \left\{\frac{ [\alpha_o\rho_{g,o} 
        + (1-\alpha_o)\rho_{l,o}] + [\alpha_i\rho_{g,i} + (1-\alpha_i)\rho_{l,i}]}
        {2}\right\}
        
    Parameters
    ----------
    angle : float
        The angle of the pipe with respect to the horizontal, [degrees]
    z : float
        The total length of the pipe, [m]
    alpha_i : float
        Void fraction at inlet (area of gas / total area of channel), [-]
    rho_li : float
        Liquid phase density at inlet, [kg/m^3]
    rho_gi : float
        Gas phase density at inlet, [kg/m^3]
    alpha_o : float, optional
        Void fraction at outlet (area of gas / total area of channel), [-]
    rho_lo : float, optional
        Liquid phase density at outlet, [kg/m^3]
    rho_go : float, optional
        Gas phase density at outlet, [kg/m^3]
    g : float, optional
        Acceleration due to gravity, [m/s^2]

    Returns
    -------
    dP : float
        Gravitational component of pressure drop for two-phase flow, [Pa]
        
    Notes
    -----
    The use of different gas and liquid phase densities and void fraction 
    at the inlet and outlet is optional; the outlet densities and void fraction
    will be assumed to be those of the inlet if they are not specified. This
    does not add much accuracy.
    
    There is a continuous variant of this method which can be integrated over,
    at the expense of a speed. The differential form of this is as follows 
    ([1]_, [2]_):
        
    .. math::
        -\left(\frac{dP}{dz} \right)_{grav} =  [\alpha\rho_g + (1-\alpha)
        \rho_l]g \sin \theta
        
    Examples
    --------
    Example calculation, page 13-2 from [3]_:
    
    >>> two_phase_dP_gravitational(angle=90, z=2, alpha_i=0.9685, rho_li=1518., 
    ... rho_gi=2.6)
    987.237416829999

    The same calculation, but using average inlet and outlet conditions:
    
    >>> two_phase_dP_gravitational(angle=90, z=2, alpha_i=0.9685, rho_li=1518.,
    ... rho_gi=2.6,  alpha_o=0.968, rho_lo=1517.9, rho_go=2.59)
    994.5416058829999
    
    References
    ----------
    .. [1] Rohsenow, Warren and James Hartnett and Young Cho. Handbook of Heat
       Transfer, 3E. New York: McGraw-Hill, 1998.
    .. [2] Kim, Sung-Min, and Issam Mudawar. "Review of Databases and
       Predictive Methods for Pressure Drop in Adiabatic, Condensing and
       Boiling Mini/Micro-Channel Flows." International Journal of Heat and
       Mass Transfer 77 (October 2014): 74-97.
       doi:10.1016/j.ijheatmasstransfer.2014.04.035.
    .. [3] Thome, John R. "Engineering Data Book III." Wolverine Tube Inc
       (2004). http://www.wlv.com/heat-transfer-databook/