How to use the fluids.numerics.assert_close 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_friction.py View on Github external
def test_friction():
    assert_close(Moody(1E5, 1E-4), 0.01809185666808665)
    assert_close(Alshul_1952(1E5, 1E-4), 0.018382997825686878)
    assert_close(Wood_1966(1E5, 1E-4), 0.021587570560090762)
    assert_close(Churchill_1973(1E5, 1E-4), 0.01846708694482294)
    assert_close(Eck_1973(1E5, 1E-4), 0.01775666973488564)
    assert_close(Jain_1976(1E5, 1E-4), 0.018436560312693327)
    assert_close(Swamee_Jain_1976(1E5, 1E-4), 0.018452424431901808)
    assert_close(Churchill_1977(1E5, 1E-4), 0.018462624566280075)
    assert_close(Chen_1979(1E5, 1E-4), 0.018552817507472126)
    assert_close(Round_1980(1E5, 1E-4), 0.01831475391244354)
    assert_close(Shacham_1980(1E5, 1E-4), 0.01860641215097828)
    assert_close(Barr_1981(1E5, 1E-4), 0.01849836032779929)
    assert_close(Zigrang_Sylvester_1(1E5, 1E-4), 0.018646892425980794)
    assert_close(Zigrang_Sylvester_2(1E5, 1E-4), 0.01850021312358548)
    assert_close(Haaland(1E5, 1E-4), 0.018265053014793857)
    assert_close(Serghides_1(1E5, 1E-4), 0.01851358983180063)
    assert_close(Serghides_2(1E5, 1E-4), 0.018486377560664482)
    assert_close(Tsal_1989(1E5, 1E-4), 0.018382997825686878)
    assert_close(Tsal_1989(1E8, 1E-4), 0.012165854627780102)
    assert_close(Manadilli_1997(1E5, 1E-4), 0.01856964649724108)
    assert_close(Romeo_2002(1E5, 1E-4), 0.018530291219676177)
    assert_close(Sonnad_Goudar_2006(1E5, 1E-4), 0.0185971269898162)
    assert_close(Rao_Kumar_2007(1E5, 1E-4), 0.01197759334600925)
github CalebBell / fluids / tests / test_geometry.py View on Github external
# Torispherical tests
    T1 = TANK(L=120*inch, D=72*inch, horizontal=True,
              sideA='torispherical', sideA_f=1, sideA_k=.06, sideB='same')
    assert_close(T1.SA_from_h(2.28*inch)/foot**2, 22.74924, rtol=1e-7)
    assert_close(T1.SA_from_h(24*inch)/foot**2, 94.29092, rtol=1e-7)
    assert_close(T1.SA_from_h(36*inch)/foot**2, 127.74876, rtol=1e-7)
    assert_close(T1.SA_from_h(48*inch)/foot**2, 161.20660, rtol=1e-7)
    assert_close(T1.SA_from_h(69.72*inch)/foot**2, 232.74828, rtol=1e-7)
    assert 0.0 == T1.SA_from_h(0)
    assert_close(T1.SA_from_h(T1.h_max), T1.A, rtol=1e-12)
    
    T2 = TANK(L=120*inch, D=72*inch, horizontal=True,
              sideA='torispherical', sideA_f=.9, sideA_k=.1, sideB='same')
    assert_close(T2.SA_from_h(3*inch)/foot**2, 26.82339, rtol=2e-7)
    assert_close(T2.SA_from_h(24*inch)/foot**2, 96.18257, rtol=1e-7)
    assert_close(T2.SA_from_h(36*inch)/foot**2, 130.22802, rtol=1e-7)
    assert_close(T2.SA_from_h(48*inch)/foot**2, 164.27347, rtol=1e-7)
    assert_close(T2.SA_from_h(69*inch)/foot**2, 233.63265, rtol=1e-7)
    assert 0.0 == T2.SA_from_h(0)
    assert_close(T2.SA_from_h(T2.h_max), T2.A, rtol=1e-12)
github CalebBell / fluids / tests / test_compressible.py View on Github external
def test_IGT():
    D = 0.340
    mu = 1E-5
    P1 = 90E5
    P2 = 20E5
    L = 160E3
    SG=0.693
    Tavg = 277.15
    Q = 48.92351786788815
    assert_close(IGT(D=D, P1=P1, P2=P2, L=L, SG=SG, mu=mu, Tavg=Tavg), Q)
    assert_close(IGT(D=D, Q=Q, P2=P2, L=L, SG=SG, mu=mu, Tavg=Tavg), P1)
    assert_close(IGT(D=D, Q=Q, P1=P1, L=L, SG=SG, mu=mu, Tavg=Tavg), P2)
    assert_close(IGT(D=D, Q=Q, P1=P1, P2=P2, SG=SG, mu=mu, Tavg=Tavg), L)
    assert_close(IGT(L=L, Q=Q, P1=P1, P2=P2, SG=SG, mu=mu, Tavg=Tavg), D)

    with pytest.raises(Exception):
        IGT(D=D, P2=P2, L=L, SG=SG, mu=mu, Tavg=Tavg)
github CalebBell / fluids / tests / test_geometry.py View on Github external
def test_RectangularOffsetStripFinExchanger():
    ROSFE = RectangularOffsetStripFinExchanger(fin_length=.05, fin_height=.01, fin_thickness=.003, fin_spacing=.05)
    assert_close(ROSFE.fin_length, 0.05)
    assert_close(ROSFE.fin_height, 0.01)
    assert_close(ROSFE.fin_thickness, 0.003)
    assert_close(ROSFE.fin_spacing, 0.05)
    assert_close(ROSFE.blockage_ratio, 0.348)
    assert_close(ROSFE.blockage_ratio_Kim, 0.34199999999999997)
    assert_close(ROSFE.alpha, 5)
    assert_close(ROSFE.delta, 0.06)
    assert_close(ROSFE.gamma, 0.06)
    assert_close(ROSFE.A_channel, 0.000329)
#    assert_close(ROSFE.SA_fin, 0.005574)
    assert_close(ROSFE.Dh, 0.011804808037316112)
    assert_close(ROSFE.Dh_Kays_London, 0.012185185185185186)
    assert_close(ROSFE.Dh_Joshi_Webb, 0.011319367879456085)
github CalebBell / fluids / tests / test_units.py View on Github external
Cd = drag_sphere(200)
    assert_close(Cd.to_base_units().magnitude, 0.7682237950389874)
    assert dict(Cd.dimensionality) == {}

    V, D = integrate_drag_sphere(D=0.001*u.m, rhop=2200.*u.kg/u.m**3, rho=1.2*u.kg/u.m**3, mu=1.78E-5*u.Pa*u.s, t=0.5*u.s, V=30*u.m/u.s, distance=True)
    assert_close(V.to_base_units().magnitude, 9.686465044063436)
    assert dict(V.dimensionality) == {u'[length]': 1.0, u'[time]': -1.0}
    assert_close(D.to_base_units().magnitude, 7.829454643649386)
    assert dict(D.dimensionality) == {u'[length]': 1.0}
    
    Bo = Bond(1000*u.kg/u.m**3, 1.2*u.kg/u.m**3, .0589*u.N/u.m, 2*u.m)
    assert_close(Bo.to_base_units().magnitude, 665187.2339558573)
    assert dict(Bo.dimensionality) == {}
    
    head = head_from_P(P=98066.5*u.Pa, rho=1000*u.kg/u.m**3)
    assert_close(head.to_base_units().magnitude, 10.000000000000002)
    assert dict(head.dimensionality) == {u'[length]': 1.0}
    
    roughness = roughness_Farshad('Cr13, bare', 0.05*u.m)
    assert_close(roughness.to_base_units().magnitude, 5.3141677781137006e-05)
    assert dict(roughness.dimensionality) == {u'[length]': 1.0}
github CalebBell / ht / tests / test_numba.py View on Github external
def test_tube_bank():
    # not implemented - dP_Zukauskas
    
    kwargs = dict(Re=10263.37, Pr=.708, tube_rows=11, pitch_normal=.05, pitch_parallel=.05, Do=.025)
    assert_close(ht.numba.Nu_Grimison_tube_bank(**kwargs), ht.Nu_Grimison_tube_bank(**kwargs))
    
    assert_close(ht.numba.Zukauskas_tube_row_correction(4, staggered=True), 
                 ht.Zukauskas_tube_row_correction(4, staggered=True))

    kwargs = dict(Re=1E4, Pr=7., tube_rows=10, pitch_parallel=.05, pitch_normal=.05)
    assert_close(ht.numba.Nu_Zukauskas_Bejan(**kwargs), ht.Nu_Zukauskas_Bejan(**kwargs))

    kwargs = dict(Re=1.32E4, Pr=0.71, tube_rows=8, pitch_parallel=.09, pitch_normal=.05)
    assert_close(ht.numba.Nu_ESDU_73031(**kwargs), ht.Nu_ESDU_73031(**kwargs))

    kwargs = dict(Re=10263.37, Pr=.708, tube_rows=11, pitch_normal=.05, pitch_parallel=.05, Do=.025)
    assert_close(ht.numba.Nu_HEDH_tube_bank(**kwargs), ht.Nu_HEDH_tube_bank(**kwargs))
    kwargs = dict(Re=10263.37, Pr=.708, tube_rows=5, pitch_normal=.05, pitch_parallel=.05, Do=.025)
    assert_close(ht.numba.Nu_HEDH_tube_bank(**kwargs), ht.Nu_HEDH_tube_bank(**kwargs))

    kwargs = dict(m=11., rho=995., mu=0.000803, mu_w=0.000657, DShell=0.584, LSpacing=0.1524, pitch=0.0254, Do=.019, NBaffles=22)
github CalebBell / fluids / tests / test_geometry.py View on Github external
# Was a bug computing this
    SA_partial_horiz_torispherical_head(D=72., f=1, k=.06, h=1e-20)
    
    assert 0 == SA_partial_horiz_torispherical_head(D=72., f=1, k=.06, h=0)
    assert 0 == SA_partial_horiz_torispherical_head(D=72., f=1, k=.06, h=-1e-12)

    assert SA_partial_horiz_torispherical_head(D=72., f=1, k=.06, h=7200) == SA_partial_horiz_torispherical_head(D=72., f=1, k=.06, h=72)
    
    # Check G returns a real number
    assert_close(SA_partial_horiz_torispherical_head(D=72., f=1, k=.06, h=1e-13), 3.859157404406146e-12, rtol=.1)
    
    # Torispherical tests
    T1 = TANK(L=120*inch, D=72*inch, horizontal=True,
              sideA='torispherical', sideA_f=1, sideA_k=.06, sideB='same')
    assert_close(T1.SA_from_h(2.28*inch)/foot**2, 22.74924, rtol=1e-7)
    assert_close(T1.SA_from_h(24*inch)/foot**2, 94.29092, rtol=1e-7)
    assert_close(T1.SA_from_h(36*inch)/foot**2, 127.74876, rtol=1e-7)
    assert_close(T1.SA_from_h(48*inch)/foot**2, 161.20660, rtol=1e-7)
    assert_close(T1.SA_from_h(69.72*inch)/foot**2, 232.74828, rtol=1e-7)
    assert 0.0 == T1.SA_from_h(0)
    assert_close(T1.SA_from_h(T1.h_max), T1.A, rtol=1e-12)
    
    T2 = TANK(L=120*inch, D=72*inch, horizontal=True,
              sideA='torispherical', sideA_f=.9, sideA_k=.1, sideB='same')
    assert_close(T2.SA_from_h(3*inch)/foot**2, 26.82339, rtol=2e-7)
    assert_close(T2.SA_from_h(24*inch)/foot**2, 96.18257, rtol=1e-7)
    assert_close(T2.SA_from_h(36*inch)/foot**2, 130.22802, rtol=1e-7)
    assert_close(T2.SA_from_h(48*inch)/foot**2, 164.27347, rtol=1e-7)
    assert_close(T2.SA_from_h(69*inch)/foot**2, 233.63265, rtol=1e-7)
    assert 0.0 == T2.SA_from_h(0)
    assert_close(T2.SA_from_h(T2.h_max), T2.A, rtol=1e-12)
github CalebBell / fluids / tests / test_numba.py View on Github external
def test_misc_safety_valve():
    assert_close(fluids.numba.API520_round_size(1E-4),
                 fluids.API520_round_size(1E-4))
    assert_close(fluids.numba.API520_SH(593+273.15, 1066.325E3),
                fluids.API520_SH(593+273.15, 1066.325E3))
    assert_close(fluids.numba.API520_W(1E6, 3E5),
                fluids.API520_W(1E6, 3E5))
    
    assert_close(fluids.numba.API520_B(1E6, 5E5),
                 fluids.API520_B(1E6, 5E5))
    
    assert_close(fluids.numba.API520_A_g(m=24270/3600., T=348., Z=0.90, MW=51., k=1.11, P1=670E3, Kb=1, Kc=1),
                fluids.API520_A_g(m=24270/3600., T=348., Z=0.90, MW=51., k=1.11, P1=670E3, Kb=1, Kc=1))
    
    assert_close(fluids.numba.API520_A_steam(m=69615/3600., T=592.5, P1=12236E3, Kd=0.975, Kb=1, Kc=1),
                 fluids.API520_A_steam(m=69615/3600., T=592.5, P1=12236E3, Kd=0.975, Kb=1, Kc=1))
github CalebBell / fluids / tests / test_two_phase_voidage.py View on Github external
def test_Rouhani_2():
    assert_close(Rouhani_2(0.4, 800., 2.5, sigma=0.02, m=1, D=0.3), 0.44819733138968865)
github CalebBell / fluids / tests / test_pump.py View on Github external
def test_current_ideal():
    I = current_ideal(V=120.0, P=1E4, PF=1.0, phase=1)
    assert_close(I, 83.33333333333333)

    I = current_ideal(V=208, P=1E4, PF=1, phase=3)
    assert_close(I, 27.757224480270473)

    I = current_ideal(V=208, P=1E4, PF=0.95, phase=3)
    assert_close(I,29.218131031863656)

    with pytest.raises(Exception):
        current_ideal(V=208, P=1E4, PF=0.95, phase=5)