r'''Calculates saltation velocity of the gas for pneumatic conveying,
    according to [1]_ and reproduced in [2]_, [3]_, and [4]_.

    First equation is used if third equation yeilds d* higher than dp.
    Otherwise, use equation 2.

    .. math::
        \mu = 5560\left(\frac{d_p}{D}\right)^{1.43}\left(\frac{Fr_s}{10}\right)^4

        \mu = 0.373 \left(\frac{\rho_p}{\rho_f}\right)^{1.06}\left(\frac{Fr_p}
        {10}\right)^{-3.7}\left(\frac{Fr_s}{10}\right)^{3.61}

        \frac{d_p^*}{D} = 1.39\left(\frac{\rho_p}{\rho_f}\right)^{-0.74}

        Fr_s = \frac{V_{salt}}{\sqrt{gD}}

        Fr_p = \frac{V_{terminal}}{\sqrt{gd_p}}

        \mu = \frac{m_p}{\frac{\pi}{4}D^2V \rho_f}

    Parameters
    ----------
    mp : float
        Solid mass flow rate, [kg/s]
    rhop : float
        Particle density, [kg/m^3]
    dp : float
        Particle diameter, [m]
    rhog : float
        Gas density, [kg/m^3]
    D : float
        Diameter of pipe, [m]
    Vterminal : float
        Terminal velocity of particle settling in gas, [m/s]

    Returns
    -------
        V : float
            Saltation velocity of gas, [m/s]

    Notes
    -----
    Model is rearanged to be explicit in terms of saltation velocity
    internally.

    Examples
    --------
    Example is only a self-test.

    Course routine, terminal velocity input is from example in [2].

    >>> Matsumoto_1977(mp=1., rhop=1000., dp=1E-3, rhog=1.2, D=0.1, Vterminal=5.24)
    16.64284834446686

    References
    ----------
    .. [1] Matsumoto, Shigeru, Makoto Kikuta, and Siro Maeda. "Effect of
       Particle Size on the Minimum Transport Velocity for Horizontal Pneumatic
       Conveying of Solids." Journal of Chemical Engineering of Japan 10,
       no. 4 (1977): 273-79. doi:10.1252/jcej.10.273.
    .. [2] Klinzing, G. E., F. Rizk, R. Marcus, and L. S. Leung. Pneumatic
       Conveying of Solids: A Theoretical and Practical Approach.
       Springer, 2013.
    .. [3] Gomes, L. M., and A. L. Amarante Mesquita. "On the Prediction of
       Pickup and Saltation Velocities in Pneumatic Conveying." Brazilian
       Journal of Chemical Engineering 31, no. 1 (March 2014): 35-46.
       doi:10.1590/S0104-66322014000100005
    .. [4] Rabinovich, Evgeny, and Haim Kalman. "Threshold Velocities of
       Particle-Fluid Flows in Horizontal Pipes and Ducts: Literature Review."
       Reviews in Chemical Engineering 27, no. 5-6 (January 1, 2011).
       doi:10.1515/REVCE.2011.011.

def Matsumoto_1977(mp, rhop, dp, rhog, D, Vterminal=1):
    r'''Calculates saltation velocity of the gas for pneumatic conveying,
    according to [1]_ and reproduced in [2]_, [3]_, and [4]_.

    First equation is used if third equation yeilds d* higher than dp.
    Otherwise, use equation 2.

    .. math::
        \mu = 5560\left(\frac{d_p}{D}\right)^{1.43}\left(\frac{Fr_s}{10}\right)^4

        \mu = 0.373 \left(\frac{\rho_p}{\rho_f}\right)^{1.06}\left(\frac{Fr_p}
        {10}\right)^{-3.7}\left(\frac{Fr_s}{10}\right)^{3.61}

        \frac{d_p^*}{D} = 1.39\left(\frac{\rho_p}{\rho_f}\right)^{-0.74}

        Fr_s = \frac{V_{salt}}{\sqrt{gD}}

        Fr_p = \frac{V_{terminal}}{\sqrt{gd_p}}

        \mu = \frac{m_p}{\frac{\pi}{4}D^2V \rho_f}

    Parameters
    ----------
    mp : float
        Solid mass flow rate, [kg/s]
    rhop : float
        Particle density, [kg/m^3]
    dp : float
        Particle diameter, [m]
    rhog : float
        Gas density, [kg/m^3]
    D : float
        Diameter of pipe, [m]
    Vterminal : float
        Terminal velocity of particle settling in gas, [m/s]

    Returns
    -------
        V : float
            Saltation velocity of gas, [m/s]

    Notes
    -----
    Model is rearanged to be explicit in terms of saltation velocity
    internally.

    Examples
    --------
    Example is only a self-test.

    Course routine, terminal velocity input is from example in [2].

    >>> Matsumoto_1977(mp=1., rhop=1000., dp=1E-3, rhog=1.2, D=0.1, Vterminal=5.24)
    16.64284834446686

    References
    ----------
    .. [1] Matsumoto, Shigeru, Makoto Kikuta, and Siro Maeda. "Effect of
       Particle Size on the Minimum Transport Velocity for Horizontal Pneumatic
       Conveying of Solids." Journal of Chemical Engineering of Japan 10,
       no. 4 (1977): 273-79. doi:10.1252/jcej.10.273.
    .. [2] Klinzing, G. E., F. Rizk, R. Marcus, and L. S. Leung. Pneumatic
       Conveying of Solids: A Theoretical and Practical Approach.
       Springer, 2013.
    .. [3] Gomes, L. M., and A. L. Amarante Mesquita. "On the Prediction of
       Pickup and Saltation Velocities in Pneumatic Conveying." Brazilian
       Journal of Chemical Engineering 31, no. 1 (March 2014): 35-46.
       doi:10.1590/S0104-66322014000100005
    .. [4] Rabinovich, Evgeny, and Haim Kalman. "Threshold Velocities of
       Particle-Fluid Flows in Horizontal Pipes and Ducts: Literature Review."
       Reviews in Chemical Engineering 27, no. 5-6 (January 1, 2011).
       doi:10.1515/REVCE.2011.011.
    '''
    limit = 1.39*D*(rhop/rhog)**-0.74
    A = pi/4*D**2
    if limit < dp:
        # Corase routine
        Frp = Vterminal/(g*dp)**0.5
        Frs_sorta = 1./(g*D)**0.5
        expression1 = 0.373*(rhop/rhog)**1.06*(Frp/10.)**-3.7*(Frs_sorta/10.)**3.61
        expression2 = mp/rhog/A
        V = (expression2/expression1)**(1/4.61)
    else:
        Frs_sorta = 1./(g*D)**0.5
        expression1 = 5560*(dp/D)**1.43*(Frs_sorta/10.)**4
        expression2 = mp/rhog/A
        V = (expression2/expression1)**(0.2)
    return V