def test_PSDInterpolated_discrete_range_pts():
    import numpy as np
    ds = [
        360, 450, 562.5, 703, 878, 1097, 1371, 1713, 2141, 2676, 3345, 4181,
        5226, 6532
    ]
    ds = [i * 1e-6 for i in ds]
    numbers = [
        65, 119, 232, 410, 629, 849, 990, 981, 825, 579, 297, 111, 21, 1
    ]
    psd = ParticleSizeDistribution(ds=ds, fractions=numbers, order=0)
    # test fractions_discrete vs input
    assert_close1d(psd.fractions_discrete(ds), psd.fractions)

    # test cdf_discrete
    assert_close1d(psd.cdf_discrete(ds), psd.interpolated.fraction_cdf[1:])
    # test that dn solves backwards for exactly the right value
    cumulative_fractions = np.cumsum(psd.fractions)
    ds_for_fractions = np.array([psd.dn(f) for f in cumulative_fractions])
    assert_close1d(ds, ds_for_fractions)

    # test _pdf
    test_pdf = psd.pdf(1e-3)
    assert_close(test_pdf, 106.28284463095554)

    # test _cdf
    test_cdf = psd.cdf(1e-3)
    assert_close(test_cdf, 0.02278897476363087)

    # test _pdf_basis_integral
    test_int = psd._pdf_basis_integral(1e-3, 2)
    assert_close(test_int, 1.509707233427664e-08)

    assert not isclose(psd.mean_size(3, 2), psd.interpolated.mean_size(3, 2))
예제 #2
0
def test_C_eccentric_orifice_ISO_15377_1998():
    C =  C_eccentric_orifice_ISO_15377_1998(.2, .075)
    assert_close(C, 0.6351923828125)

    # Does not perfectly match - like error in ISO.
    D = 1.0
    betas = [1e-2*i for i in range(46, 85, 1)]
    Cs_expect = [0.627, 0.627, 0.627, 0.627, 0.627, 0.627, 0.627, 0.627, 0.627, 0.628, 0.628, 0.628, 0.628, 0.629, 0.629, 0.629, 0.629, 0.629, 0.629, 0.629, 0.629, 0.629, 0.628, 0.628, 0.627, 0.626, 0.625, 0.624, 0.623, 0.621, 0.620, 0.618, 0.616, 0.613, 0.611, 0.608, 0.605, 0.601, 0.597]
    Cs_calc = [C_eccentric_orifice_ISO_15377_1998(D=D, Do=beta_i) for beta_i in betas]
    for Ci, Cj in zip(Cs_expect, Cs_calc):
        assert isclose(Ci, Cj, rel_tol=1.02e-3)
예제 #3
0
def test_control_valve_size_g():
    # From [1]_, matching example 3 for non-choked gas flow with attached
    # fittings  and a rotary, eccentric plug, flow-to-open control valve:

    Kv = size_control_valve_g(T=433.,
                              MW=44.01,
                              mu=1.4665E-4,
                              gamma=1.30,
                              Z=0.988,
                              P1=680E3,
                              P2=310E3,
                              Q=38 / 36.,
                              D1=0.08,
                              D2=0.1,
                              d=0.05,
                              FL=0.85,
                              Fd=0.42,
                              xT=0.60)
    assert_close(Kv, 72.58664545391052)

    # From [1]_, roughly matching example 4 for a small flow trim sized tapered
    # needle plug valve. Difference is 3% and explained by the difference in
    # algorithms used.

    Kv = size_control_valve_g(T=320.,
                              MW=39.95,
                              mu=5.625E-5,
                              gamma=1.67,
                              Z=1.0,
                              P1=2.8E5,
                              P2=1.3E5,
                              Q=0.46 / 3600.,
                              D1=0.015,
                              D2=0.015,
                              d=0.015,
                              FL=0.98,
                              Fd=0.07,
                              xT=0.8)
    assert_close(Kv, 0.016498765335995726)

    # Diameters removed
    Kv = size_control_valve_g(T=320.,
                              MW=39.95,
                              mu=5.625E-5,
                              gamma=1.67,
                              Z=1.0,
                              P1=2.8E5,
                              P2=1.3E5,
                              Q=0.46 / 3600.,
                              xT=0.8)
    assert_close(Kv, 0.012691357950765944)
    ans = size_control_valve_g(T=320.,
                               MW=39.95,
                               mu=5.625E-5,
                               gamma=1.67,
                               Z=1.0,
                               P1=2.8E5,
                               P2=1.3E5,
                               Q=0.46 / 3600.,
                               xT=0.8,
                               full_output=True)
    assert ans['laminar'] == False
    assert ans['choked'] == False
    assert ans['FP'] is None
    assert ans['FR'] is None
    assert ans['xTP'] is None
    assert ans['Rev'] is None

    # Choked custom example
    Kv = size_control_valve_g(T=433.,
                              MW=44.01,
                              mu=1.4665E-4,
                              gamma=1.30,
                              Z=0.988,
                              P1=680E3,
                              P2=30E3,
                              Q=38 / 36.,
                              D1=0.08,
                              D2=0.1,
                              d=0.05,
                              FL=0.85,
                              Fd=0.42,
                              xT=0.60)
    assert_close(Kv, 70.67468803987839)

    # Laminar custom example
    Kv = size_control_valve_g(T=320.,
                              MW=39.95,
                              mu=5.625E-5,
                              gamma=1.67,
                              Z=1.0,
                              P1=2.8E5,
                              P2=1.3E5,
                              Q=0.46 / 3600.,
                              D1=0.015,
                              D2=0.015,
                              d=0.001,
                              FL=0.98,
                              Fd=0.07,
                              xT=0.8)
    assert_close(Kv, 0.016498765335995726)

    # Laminar custom example with iteration
    Kv = size_control_valve_g(T=320.,
                              MW=39.95,
                              mu=5.625E-5,
                              gamma=1.67,
                              Z=1.0,
                              P1=2.8E5,
                              P2=2.7E5,
                              Q=0.1 / 3600.,
                              D1=0.015,
                              D2=0.015,
                              d=0.001,
                              FL=0.98,
                              Fd=0.07,
                              xT=0.8)
    assert_close(Kv, 0.989125783445497)

    # test not allowing chokes
    ans_choked = size_control_valve_g(T=320.,
                                      MW=39.95,
                                      mu=5.625E-5,
                                      gamma=1.67,
                                      Z=1.0,
                                      P1=2.8E5,
                                      P2=1e4,
                                      Q=0.46 / 3600.,
                                      D1=0.015,
                                      D2=0.015,
                                      d=0.015,
                                      FL=0.98,
                                      Fd=0.07,
                                      xT=0.8,
                                      full_output=True,
                                      allow_choked=True)
    ans = size_control_valve_g(T=320.,
                               MW=39.95,
                               mu=5.625E-5,
                               gamma=1.67,
                               Z=1.0,
                               P1=2.8E5,
                               P2=1e4,
                               Q=0.46 / 3600.,
                               D1=0.015,
                               D2=0.015,
                               d=0.015,
                               FL=0.98,
                               Fd=0.07,
                               xT=0.8,
                               full_output=True,
                               allow_choked=False)
    assert not isclose(ans_choked['Kv'], ans['Kv'], rel_tol=1E-4)

    # Test not allowing laminar
    for Kv, boolean in zip((0.001179609179354541, 0.00090739167642657),
                           (True, False)):
        ans = size_control_valve_g(T=320.,
                                   MW=39.95,
                                   mu=5.625E-5,
                                   gamma=1.67,
                                   Z=1.0,
                                   P1=2.8E5,
                                   P2=1e4,
                                   Q=1e-5,
                                   D1=0.015,
                                   D2=0.015,
                                   d=0.015,
                                   FL=0.98,
                                   Fd=0.07,
                                   xT=0.8,
                                   full_output=True,
                                   allow_laminar=boolean)
        assert_close(Kv, ans['Kv'])

    assert ans['choked']  # Still true even though the choke is ignored
    assert ans['xTP'] is None
    assert ans['Y']
    assert ans['FP'] is None
    assert ans['FR'] is None
    assert ans['Rev']

    # Test a warning is issued and a solution is still returned when in an unending loop
    # Ends with C ratio converged to 0.907207790871228

    args = {
        'P1': 680000.0,
        'full_output': True,
        'allow_choked': True,
        'Q': 0.24873053149856303,
        'T': 433.0,
        'Z': 0.9908749375670418,
        'FL': 0.85,
        'allow_laminar': True,
        'd': 0.05,
        'mu': 2.119519588834806e-05,
        'MW': 44.0095,
        'Fd': 0.42,
        'gamma': 1.2431389717945152,
        'D2': 0.1,
        'xT': 0.6,
        'D1': 0.08
    }
    ans = size_control_valve_g(P2=678000., **args)
    assert ans['warning']

    # Test Kv does not reach infinity
    kwargs = {
        'P2': 310000.0028935982,
        'P1': 680000.0,
        'full_output': True,
        'allow_choked': True,
        'T': 433.0,
        'Z': 0.9896087377962123,
        'FL': 0.85,
        'allow_laminar': True,
        'd': 0.05,
        'mu': 2.119519588834806e-05,
        'MW': 44.0095,
        'Fd': 0.42,
        'gamma': 1.2431389717945152,
        'D2': 0.1,
        'xT': 0.6,
        'D1': 0.08
    }
    size_control_valve_g(Q=1000000000.0, **kwargs)