Пример #1
0
def test_Panhandle_A():
    # Example 7-18 Gas of Crane TP 410M
    D = 0.340
    P1 = 90E5
    P2 = 20E5
    L = 160E3
    SG=0.693
    Tavg = 277.15
    Q = 42.56082051195928

    # Test all combinations of relevant missing inputs
    assert_close(Panhandle_A(D=D, P1=P1, P2=P2, L=L, SG=SG, Tavg=Tavg), Q)
    assert_close(Panhandle_A(D=D, Q=Q, P2=P2, L=L, SG=SG, Tavg=Tavg), P1)
    assert_close(Panhandle_A(D=D, Q=Q, P1=P1, L=L, SG=SG, Tavg=Tavg), P2)
    assert_close(Panhandle_A(D=D, Q=Q, P1=P1, P2=P2, SG=SG, Tavg=Tavg), L)
    assert_close(Panhandle_A(L=L, Q=Q, P1=P1, P2=P2, SG=SG, Tavg=Tavg), D)

    with pytest.raises(Exception):
        Panhandle_A(D=0.340, P1=90E5, L=160E3, SG=0.693, Tavg=277.15)

    # Sample problem from "Natural Gas Pipeline Flow Calculations" by "Harlan H. Bengtson"
    Q_panhandle = Panhandle_A(SG=0.65, Tavg=F2K(80), Ts=F2K(60), Ps=14.7*psi, L=500*foot, D=12*inch, P1=510*psi,
                          P2=490*psi, Zavg=0.919, E=0.92)
    mmscfd = Q_panhandle*day/foot**3/1e6
    assert_close(mmscfd, 401.3019451856126, rtol=1e-12)
Пример #2
0
def heating_degree_days(T, T_base=F2K(65), truncate=True):
    r'''Calculates the heating degree days for a period of time.

    .. math::
        \text{heating degree days} = max(T - T_{base}, 0)

    Parameters
    ----------
    T : float
        Measured temperature; sometimes an average over a length of time is used,
        other times the average of the lowest and highest temperature in a 
        period are used, [K]
    T_base : float, optional
        Reference temperature for the degree day calculation, defaults
        to 65 °F (18.33 °C, 291.483 K), the value most used in the US, [K]
    truncate : bool
        If truncate is True, no negative values will be returned; if negative, 
        the value is truncated to 0, [-]

    Returns
    -------
    heating_degree_days : float
        Degree above the base temperature multiplied by the length of time of
        the measurement, normally days [day*K]

    Notes
    -----
    Some common base temperatures are 18 °C (Canada), 15.5 °C (EU), 
    17 °C (Denmark, Finland), 12 °C Switzerland. The base temperature
    should always be presented with the results.
    
    The time unit does not have to be days; it can be any time unit, and the
    calculation behaves the same.

    Examples
    --------
    >>> heating_degree_days(303.8)
    12.31666666666672
    
    >>> heating_degree_days(273)
    0.0
    
    >>> heating_degree_days(322, T_base=300)
    22

    References
    ----------
    .. [1] "Heating Degree Day." Wikipedia, January 24, 2018. 
       https://en.wikipedia.org/w/index.php?title=Heating_degree_day&oldid=822187764.
    '''
    dd = T - T_base
    if truncate and dd < 0.0:
        dd = 0.0
    return dd
Пример #3
0
def test_Weymouth():
    D = 0.340
    P1 = 90E5
    P2 = 20E5
    L = 160E3
    SG=0.693
    Tavg = 277.15
    Q = 32.07729055913029
    assert_close(Weymouth(D=D, P1=P1, P2=P2, L=L, SG=SG, Tavg=Tavg), Q)
    assert_close(Weymouth(D=D, Q=Q, P2=P2, L=L, SG=SG, Tavg=Tavg), P1)
    assert_close(Weymouth(D=D, Q=Q, P1=P1, L=L, SG=SG, Tavg=Tavg), P2)
    assert_close(Weymouth(D=D, Q=Q, P1=P1, P2=P2, SG=SG, Tavg=Tavg), L)
    assert_close(Weymouth(L=L, Q=Q, P1=P1, P2=P2, SG=SG, Tavg=Tavg), D)

    with pytest.raises(Exception):
        Weymouth(D=0.340, P1=90E5, L=160E3, SG=0.693, Tavg=277.15)

    Q_Weymouth = Weymouth(SG=0.65, Tavg=F2K(80), Ts=F2K(60), Ps=14.7*psi, L=500*foot, D=12*inch, P1=510*psi,
                              P2=490*psi, Zavg=0.919, E=0.92)
    mmscfd = Q_Weymouth*day/foot**3/1e6
    assert_close(mmscfd, 272.5879686092862, rtol=1e-12)
Пример #4
0
def test_Lorentz_Bray_Clarke():
    # Made up example
    T = 300.0
    P = 1e6
    zs = [.4, .3, .3]
    MWs = [16.04246, 30.06904, 44.09562]
    Tcs = [190.564, 305.32, 369.83]
    Pcs = [4599000.0, 4872000.0, 4248000.0]
    Vcs = [9.86e-05, 0.0001455, 0.0002]
    Vm = 0.002302491921416089

    mu = Lorentz_Bray_Clarke(T, P, Vm, zs, MWs, Tcs, Pcs, Vcs)
    assert_close(mu, 9.925488946486405e-06, rtol=1e-6)

    #  2,000 psig and 160°F.
    zs = [0.875, 0.083, 0.021, 0.006, 0.008, 0.003, 0.002, 0.001, 0.001]
    MWs = [16.04, 30.07, 44.09, 58.12, 58.12, 72.15, 72.15, 86.17, 114.00]
    Pcs = [
        667.8 * psi, 707.8 * psi, 616.3 * psi, 529.1 * psi, 550.7 * psi,
        490.4 * psi, 488.6 * psi, 436.9 * psi, 360.6 * psi
    ]
    Tcs = [
        R2K(343.0),
        R2K(549.8),
        R2K(665.7),
        R2K(734.7),
        R2K(765.3),
        R2K(828.8),
        R2K(845.4),
        R2K(913.4),
        R2K(1023.9)
    ]
    Vcs = [
        1.590 * foot**3 / lb, 2.370 * foot**3 / lb, 3.250 * foot**3 / lb,
        4.208 * foot**3 / lb, 4.080 * foot**3 / lb, 4.899 * foot**3 / lb,
        4.870 * foot**3 / lb, 5.929 * foot**3 / lb, 7.882 * foot**3 / lb
    ]
    P = atm + 2000 * psi
    T = F2K(160.0)

    MW = mixing_simple(zs, MWs)
    rho_mass = 6.74 * lb / foot**3
    rhom = rho_mass / MW
    Vm = 1.0 / rhom

    mu = Lorentz_Bray_Clarke(T, P, Vm, zs, MWs, Tcs, Pcs, Vcs)
    assert_close(mu, 1.636032602394696e-05)
Пример #5
0
def test_fahrenheit_to_kelvin():
    assert_equal(F2K([32, 32]), [273.15, 273.15])
Пример #6
0
def test_API10A32():
    from fluids.core import F2K, R2K
    assert_close(API10A32(T=F2K(60), Tc=R2K(1334), K_W=12.4), 29.577333312096968, rtol=1e-13)
    
    
    
Пример #7
0
    References
    ----------
    .. [1] API Standard 520, Part 1 - Sizing and Selection.
    '''
    P1 = P1 / 1000.  # Pa to kPa
    return (0.02764 * P1 - 1000.) / (0.03324 * P1 - 1061)


_KSH_psigs = [
    15, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300,
    350, 400, 500, 600, 800, 1000, 1250, 1500, 1750, 2000, 2500, 3000
]
_KSH_tempFs = [300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200]
_KSH_Pa = [i * psi + 101325 for i in _KSH_psigs]
_KSH_tempKs = [F2K(i) for i in _KSH_tempFs]
_KSH_factors = [[1, 0.98, 0.93, 0.88, 0.84, 0.8, 0.77, 0.74, 0.72, 0.7],
                [1, 0.98, 0.93, 0.88, 0.84, 0.8, 0.77, 0.74, 0.72, 0.7],
                [1, 0.99, 0.93, 0.88, 0.84, 0.81, 0.77, 0.74, 0.72, 0.7],
                [1, 0.99, 0.93, 0.88, 0.84, 0.81, 0.77, 0.75, 0.72, 0.7],
                [1, 0.99, 0.93, 0.88, 0.84, 0.81, 0.77, 0.75, 0.72, 0.7],
                [1, 0.99, 0.94, 0.89, 0.84, 0.81, 0.77, 0.75, 0.72, 0.7],
                [1, 0.99, 0.94, 0.89, 0.84, 0.81, 0.78, 0.75, 0.72, 0.7],
                [1, 0.99, 0.94, 0.89, 0.85, 0.81, 0.78, 0.75, 0.72, 0.7],
                [1, 0.99, 0.94, 0.89, 0.85, 0.81, 0.78, 0.75, 0.72, 0.7],
                [1, 0.99, 0.94, 0.89, 0.85, 0.81, 0.78, 0.75, 0.72, 0.7],
                [1, 0.99, 0.95, 0.89, 0.85, 0.81, 0.78, 0.75, 0.72, 0.7],
                [1, 0.99, 0.95, 0.89, 0.85, 0.81, 0.78, 0.75, 0.72, 0.7],
                [1, 1, 0.95, 0.9, 0.85, 0.81, 0.78, 0.75, 0.72, 0.7],
                [1, 1, 0.95, 0.9, 0.85, 0.81, 0.78, 0.75, 0.72, 0.7],
                [1, 1, 0.96, 0.9, 0.85, 0.81, 0.78, 0.75, 0.72, 0.7],
Пример #8
0
def test_NFPA_30_classification():
    assert NFPA_30_classification(253.15, 283.55) == 'IA'  # ethylene oxide
    assert NFPA_30_classification(253.15,
                                  Psat_100F=268062) == 'IA'  # ethylene oxide

    assert NFPA_30_classification(227.15, 249.05) == 'IA'  # methyl chloride
    assert NFPA_30_classification(227.15,
                                  Psat_100F=812201) == 'IA'  # methyl chloride

    assert NFPA_30_classification(233.15, 309.21) == 'IA'  # pentane
    assert NFPA_30_classification(233.15, Psat_100F=107351) == 'IA'  # pentane
    assert NFPA_30_classification(
        233.15,
        Psat_100F=101325) == 'IA'  # pentane fake point to trigger border
    assert NFPA_30_classification(
        233.15,
        Psat_100F=101324.99999) == 'IB'  # pentane fake point to trigger border
    assert NFPA_30_classification(
        233.15, Tb=310.92777777777) == 'IA'  # pentane fake point under border
    assert NFPA_30_classification(
        233.15,
        Tb=310.92777777777777) == 'IB'  # pentane fake point above border

    assert NFPA_30_classification(253.15, 329.23) == 'IB'  # acetone
    assert NFPA_30_classification(253.15, Psat_100F=51979) == 'IB'  # acetone

    assert NFPA_30_classification(262.15, 353.23) == 'IB'  # benzene
    assert NFPA_30_classification(262.15, Psat_100F=22215) == 'IB'  # benzene

    assert NFPA_30_classification(308.15, 390.75) == 'IC'  # butyl alcohol
    assert NFPA_30_classification(308.15,
                                  Psat_100F=2158) == 'IC'  # butyl alcohol
    assert NFPA_30_classification(308.15) == 'IC'  # butyl alcohol

    assert NFPA_30_classification(F2K(100)) == 'II'  # made up
    assert NFPA_30_classification(F2K(140) * (1 - 1e-13)) == 'II'  # made up
    assert NFPA_30_classification(F2K(120), Tb=1e100) == 'II'  # made up
    assert NFPA_30_classification(F2K(120), Tb=-1e100) == 'II'  # made up
    assert NFPA_30_classification(F2K(120),
                                  Psat_100F=-1e100) == 'II'  # made up
    assert NFPA_30_classification(F2K(120), Psat_100F=1e100) == 'II'  # made up

    assert NFPA_30_classification(F2K(140)) == 'IIIA'  # made up
    assert NFPA_30_classification(F2K(200) * (1 - 1e-13)) == 'IIIA'  # made up
    assert NFPA_30_classification(F2K(170), Tb=1e100) == 'IIIA'  # made up
    assert NFPA_30_classification(F2K(170), Tb=-1e100) == 'IIIA'  # made up
    assert NFPA_30_classification(F2K(170),
                                  Psat_100F=-1e100) == 'IIIA'  # made up
    assert NFPA_30_classification(F2K(170),
                                  Psat_100F=1e100) == 'IIIA'  # made up

    assert NFPA_30_classification(F2K(200)) == 'IIIB'  # made up
    assert NFPA_30_classification(F2K(200) * (1 + 1e-13)) == 'IIIB'  # made up
    assert NFPA_30_classification(F2K(300), Tb=1e100) == 'IIIB'  # made up
    assert NFPA_30_classification(F2K(3000), Tb=-1e100) == 'IIIB'  # made up
    assert NFPA_30_classification(F2K(300000),
                                  Psat_100F=-1e100) == 'IIIB'  # made up
    assert NFPA_30_classification(F2K(300000000),
                                  Psat_100F=1e100) == 'IIIB'  # made up

    with pytest.raises(ValueError):
        NFPA_30_classification(253.15)
Пример #9
0
def test_fahrenheit_to_kelvin():
    assert_close1d([F2K(32.), F2K(32)], [273.15, 273.15])
Пример #10
0
def NFPA_combustible_classification(Tflash, Tb=None, Psat_100F=None):
    if Tflash < F2K(100):
        if Tflash < F2K(73) and Tb < F2K(100):
            # Also unstable flammable liquids
            return '1A'
        elif Tflash < F2K(73) and Tb >= F2K(100):
            return '1B'
        elif F2K(73) <= Tflash < F2K(100):
            # Class IC liquids shall include those having flash points at or above 73°F (22.8°C) and below 100°F (37.8°C).
            return '1C'
    if F2K(100) <= Tflash < F2K(140):
        return '2'
    if F2K(140) <= Tflash < F2K(200):
        return '3A'
    if F2K(200) <= Tflash:
        return '3B'