How to use the fluids.numerics.assert_close1d function in fluids

To help you get started, we’ve selected a few fluids examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CalebBell / fluids / tests / test_flow_meter.py View on Github external
from sympy import *
    C, beta, K = symbols('C, beta, K')
    
    expr = Eq(K, (sqrt(1 - beta**4*(1 - C*C))/(C*beta**2) - 1)**2)
    print(latex(solve(expr, C)[3]))
    '''
    
    Ds = logspace(log10(1-1E-9), log10(1E-9), 8)
    for D_ratio in Ds:
        Ks = logspace(log10(1E-9), log10(50000), 8)
        Ks_recalc = []
        for K in Ks:
            C = K_to_discharge_coefficient(D=1.0, Do=D_ratio, K=K)
            K_calc = discharge_coefficient_to_K(D=1.0, Do=D_ratio, C=C)
            Ks_recalc.append(K_calc)
        assert_close1d(Ks, Ks_recalc)
github CalebBell / fluids / tests / test_geometry.py View on Github external
SA3 = SA_tank(D=1., L=5, sideA='conical', sideA_a=2, sideB='conical', sideB_a=2)[0]
    SA4 = SA_tank(D=1., L=5, sideA='spherical', sideA_a=0.5, sideB='spherical', sideB_a=0.5)[0]
    SAs = [18.84955592153876, 10.124375616183064, 22.18452243965656, 18.84955592153876]
    assert_close1d([SA1, SA2, SA3, SA4], SAs)

    SA1, SA2, SA3, SA4 = SA_tank(D=2.54, L=5, sideA='torispherical', sideB='torispherical', sideA_f=1.039370079, sideA_k=0.062362205, sideB_f=1.039370079, sideB_k=0.062362205)
    SAs = [51.90611237013163, 6.00394283477063, 6.00394283477063, 39.89822670059037]
    assert_close1d([SA1, SA2, SA3, SA4], SAs)

    SA1 = SA_tank(D=1., L=5, sideA='guppy', sideA_a=0.5, sideB='guppy', sideB_a=0.5)[0]
    assert_close(SA1, 19.034963277504044)

    a1 = a_torispherical(D=96., f=0.9, k=0.2)
    a2 = a_torispherical(D=108., f=1., k=0.06)
    ais = [25.684268924767125, 18.288462280484797]
    assert_close1d([a1, a2], ais)

    # Horizontal configurations, compared with TankCalc - Ellipsoidal*2,
    # Ellipsoidal/None, spherical/conical, None/None. Final test is guppy/torispherical,
    # no checks available.

    Vs_calc = [V_from_h(h=h, D=10., L=25., horizontal=True, sideA='ellipsoidal', sideB='ellipsoidal', sideA_a=2, sideB_a=2) for h in [1, 2.5, 5, 7.5, 10]]
    Vs = [108.05249928250362, 416.5904542901302, 1086.4674593664702, 1756.34446444281, 2172.9349187329403]
    assert_close1d(Vs_calc, Vs)
    Vs_calc =[V_from_h(h=h, D=10., L=25., horizontal=True, sideA='ellipsoidal', sideA_a=2) for h in [1, 2.5, 5, 7.5, 10]]
    Vs = [105.12034613915314, 400.22799255268336, 1034.1075818066402, 1667.9871710605971, 2068.2151636132803]
    assert_close1d(Vs_calc, Vs)

    Vs_calc = [V_from_h(h=h, D=10., L=25., horizontal=True, sideA='spherical', sideB='conical', sideA_a=2, sideB_a=2) for h in [1, 2.5, 5, 7.5, 10]]
    Vs = [104.20408244287965, 400.47607362329063, 1049.291946298991, 1698.107818974691, 2098.583892597982]
    assert_close1d(Vs_calc, Vs)
    Vs_calc = [V_from_h(h=h, D=10., L=25., horizontal=True, sideB='spherical', sideA='conical', sideB_a=2, sideA_a=2) for h in [1, 2.5, 5, 7.5, 10]]
github CalebBell / fluids / tests / test_saltation.py View on Github external
def test_Weber_saltation():
    V1 = Weber_saltation(mp=1.0, rhop=1000., dp=1E-3, rhog=1.2, D=0.1, Vterminal=4.0)
    V2 = Weber_saltation(mp=1.0, rhop=1000., dp=1E-3, rhog=1.2, D=0.1, Vterminal=2.0)
    assert_close1d([V1, V2], [15.227445436331474, 13.020222930460088])
github CalebBell / fluids / tests / test_fittings.py View on Github external
Ks = [0.12301652230915454, 0.8081340270019336, 0.32533470783539786, 0.812308728765127, 0.3282650135070033, 0.12300865396254032]
    assert_close1d([K1, K2, K3, K4, K5, K6], Ks)
    with pytest.raises(Exception):
        diffuser_conical(Di1=.1, Di2=0.1, angle=1800., fd=0.020)
    with pytest.raises(Exception):
        diffuser_conical(Di1=.1, Di2=0.1, fd=0.020)

    K1 = diffuser_conical_staged(Di1=1., Di2=10., DEs=[2.0,3,4,5,6,7,8,9], ls=[1.0,1.0,1,1,1,1,1,1,1], fd=0.01)
    K2 = diffuser_conical(Di1=1., Di2=10.,l=9, fd=0.01)
    Ks = [1.7681854713484308, 0.973137914861591]
    assert_close1d([K1, K2], Ks)
    
    # Idelchilk
    Ks_Idelchik = [diffuser_conical(Di1=.1**0.5, Di2=1, l=l,  method='Idelchik') for l in [.1, .5, 1, 2, 3, 4, 5, 20]]
    Ks_Idelchik_expect = [0.8617385829640242, 0.9283647028367953, 0.7082429168951839, 0.291016580744589, 0.18504484868875992, 0.147705693811332, 0.12911637682462676, 0.17]
    assert_close1d(Ks_Idelchik, Ks_Idelchik_expect, rtol=1e-2)

    K = diffuser_conical(Di1=1/3., Di2=1.0, angle=50.0, Re=1E6, method='Hooper')
    assert_close(K, 0.79748427282836)

    K = diffuser_conical(Di1=1/3., Di2=1.0, angle=15.0, Re=1E6, method='Hooper')
    assert_close(K, 0.2706407222679227)
    
    K = diffuser_conical(Di1=1/3., Di2=1.0, angle=15.0, Re=1E6, method='Hooper', fd=0.0)
    assert_close(K, 0.26814269611625413)
    
    K = diffuser_conical(Di1=1/3., Di2=1.0, angle=15.0, Re=100, method='Hooper')
    assert_close(K, 1.9753086419753085)
    
    with pytest.raises(Exception):
        diffuser_conical(Di1=1/3., Di2=1.0, angle=15.0, method='Hooper')
github CalebBell / fluids / tests / test_filters.py View on Github external
def test_grills_rounded():
    from scipy.interpolate import splrep
    from fluids.filters import grills_rounded_tck, grills_rounded_alphas, grills_rounded_Ks
    tck_recalc = splrep(grills_rounded_alphas, grills_rounded_Ks, s=0, k=2)
    [assert_close1d(i, j) for i, j in zip(grills_rounded_tck[:-1], tck_recalc[:-1])]
github CalebBell / fluids / tests / test_geometry.py View on Github external
def test_V_vertical_spherical_concave():
    # Three examples from [1]_, and at empty and with h=D.
    Vs_calc = [V_vertical_spherical_concave(113., -33.0, i)/231 for i in [15., 25., 50., 0, 113]]
    Vs = [112.81405437348528, 341.7056403375114, 1372.9286894955042, 0.0, 4108.042093610599]
    assert_close1d(Vs_calc, Vs)
    assert 0.0 == V_vertical_spherical_concave(113., -33, 0.0)
github CalebBell / fluids / tests / test_atmosphere.py View on Github external
assert_close1d(MER_CALC, DAY_PROFILE_MER)
    assert_close1d(ZON_CALC, DAY_PROFILE_ZON)
    
    # Magnetic strength profile 
    APS = [0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260]
    AP_PROFILE_MER = [18.63, 11.026, -0.395, -9.121, -13.965, -16.868, -18.476, -19.38, -19.82, -19.887, -19.685, -19.558, -19.558, -19.558]
    AP_PROFILE_ZON = [-71.801, -69.031, -83.49, -96.899, -104.811, -109.891, -112.984, -114.991, -116.293, -116.99, -117.22, -117.212, -117.212, -117.212]
    
    winds = [hwm14(350E3, latitude=38, longitude=125, day=280, seconds=21*3600, geomagnetic_disturbance_index=AP) for AP in APS]
    
    winds = [[round(i, 3) for i in j] for j in winds]
    
    MER_CALC = [i[0] for i in winds]
    ZON_CALC = [i[1] for i in winds]
    
    assert_close1d(MER_CALC, AP_PROFILE_MER)
    assert_close1d(ZON_CALC, AP_PROFILE_ZON)
github CalebBell / fluids / tests / test_particle_size_distribution.py View on Github external
def test_PSDLognormal_ds_discrete():
    # Test the cdf discrete
    dist = PSDLognormal(s=0.5, d_characteristic=5E-6)
    ds = dist.ds_discrete(d_min=1e-7, d_max=1e-6, pts=8)
    ans = dist.fractions_discrete(ds)
    fractions_expect = [2.55351295663786e-15, 3.831379657981415e-13, 3.762157252396037e-11, 2.41392961175535e-09, 1.01281244724305e-07, 2.7813750147487326e-06, 5.004382447515443e-05, 0.00059054208024234]
    assert_close1d(fractions_expect, ans, rtol=1e-3)
github CalebBell / fluids / tests / test_particle_size_distribution.py View on Github external
'''For this test, ds is the same length as fractions, and we begin the series with the zero point.
    
    Half the test is spend on the `dn` solver tests, and the other half is just
    that these tests are slow.
    '''
    import numpy as np
    ds = [360, 450, 562.5, 703, 878, 1097, 1371, 1713, 2141, 2676, 3345, 4181, 5226, 6532]
    ds = np.array(ds)/1e6
    numbers = [65, 119, 232, 410, 629, 849, 990, 981, 825, 579, 297, 111, 21, 1]
    dist = ParticleSizeDistribution(ds=ds, fractions=numbers, order=0)
    psd = PSDInterpolated(dist.Dis, dist.fractions)
    
    assert len(psd.fractions) == len(psd.ds)
    assert len(psd.fractions) == 15
    # test fractions_discrete vs input
    assert_close1d(psd.fractions_discrete(ds), dist.fractions)
    
    # test cdf_discrete
    assert_close1d(psd.cdf_discrete(ds), psd.fraction_cdf[1:])
    
    # test that dn solves backwards for exactly the right value - slow
    cumulative_fractions = np.cumsum(dist.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)
github CalebBell / fluids / tests / test_atmosphere.py View on Github external
assert_close1d(ZON_CALC, TIME_PROFILER_ZON)

    # Longitude profile
    LONGS = [-180, -160, -140, -120, -100, -80, -60, -40, -20, 0, 20, 40, 60, 80, 100, 120, 140, 160, 180]
    LONG_PROFILE_MER = [-0.757, -0.592, 0.033, 0.885, 1.507, 1.545, 1.041, 0.421, 0.172, 0.463, 1.049, 1.502, 1.552, 1.232, 0.757, 0.288, -0.146, -0.538, -0.757]
    LONG_PROFILE_ZON = [-16.835, -18.073, -20.107, -22.166, -22.9, -21.649, -19.089, -16.596, -14.992, -13.909, -12.395, -10.129, -7.991, -7.369, -8.869, -11.701, -14.359, -15.945, -16.835]
    
    winds = [hwm14(40E3, latitude=-5, longitude=LONG, day=330, seconds=6*3600, geomagnetic_disturbance_index=4) for LONG in LONGS]
    
    winds = [[round(i, 3) for i in j] for j in winds]
    
    MER_CALC = [i[0] for i in winds]
    ZON_CALC = [i[1] for i in winds]
    
    assert_close1d(MER_CALC, LONG_PROFILE_MER)
    assert_close1d(ZON_CALC, LONG_PROFILE_ZON)
    
    # Day of year profile
    DAYS = [0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300, 320, 340, 360]
    DAY_PROFILE_MER = [1.57, -5.43, -13.908, -22.489, -30.844, -39.415, -48.717, -58.582, -67.762, -74.124, -75.371, -70.021, -58.19, -41.813, -24.159, -8.838, 1.319, 5.064, 2.908]
    DAY_PROFILE_ZON = [-42.143, -36.947, -29.927, -23.077, -17.698, -14.016, -11.35, -8.72, -5.53, -2.039, 0.608, 0.85, -2.529, -9.733, -19.666, -30.164, -38.684, -43.208, -42.951]
    
    winds = [hwm14(200E3, latitude=-65, longitude=-135, day=DAY, seconds=21*3600, geomagnetic_disturbance_index=15) for DAY in DAYS]
    
    winds = [[round(i, 3) for i in j] for j in winds]
    
    MER_CALC = [i[0] for i in winds]
    ZON_CALC = [i[1] for i in winds]
    
    assert_close1d(MER_CALC, DAY_PROFILE_MER)
    assert_close1d(ZON_CALC, DAY_PROFILE_ZON)