Ejemplo n.º 1
0
def test_NRTL():
    # P05.01b VLE Behavior of Ethanol - Water Using NRTL
    gammas = NRTL_gammas([0.252, 0.748], [[0, -0.178], [1.963, 0]],
                         [[0, 0.2974], [.2974, 0]])
    assert_close1d(gammas, [1.9363183763514304, 1.1537609663170014])

    # Test the general form against the simpler binary form
    def NRTL2(xs, taus, alpha):
        x1, x2 = xs
        tau12, tau21 = taus
        G12 = exp(-alpha * tau12)
        G21 = exp(-alpha * tau21)
        gamma1 = exp(x2**2 * (tau21 * (G21 /
                                       (x1 + x2 * G21))**2 + G12 * tau12 /
                              (x2 + x1 * G12)**2))
        gamma2 = exp(x1**2 * (tau12 * (G12 /
                                       (x2 + x1 * G12))**2 + G21 * tau21 /
                              (x1 + x2 * G21)**2))
        return gamma1, gamma2

    gammas = NRTL2(xs=[0.252, 0.748], taus=[-0.178, 1.963], alpha=0.2974)
    assert_close1d(gammas, [1.9363183763514304, 1.1537609663170014])

    # Example by
    # https://github.com/iurisegtovich/PyTherm-applied-thermodynamics/blob/master/contents/main-lectures/GE1-NRTL-graphically.ipynb
    tau = [[0.0, 2.291653777670652, 0.5166949715946564],
           [4.308652420938829, 0.0, 1.6753963198550983],
           [0.5527434579849811, 0.15106032392136134, 0.0]]
    alpha = [[0.0, 0.4, 0.3], [0.4, 0.0, 0.3], [0.3, 0.3, 0.0]]
    xs = [.1, .3, .6]
    gammas = NRTL_gammas(xs, tau, alpha)
    assert_close1d(gammas,
                   [2.7175098659360413, 2.1373006474468697, 1.085133765593844])

    # Test the values which give activity coefficients of 1:
    gammas = NRTL_gammas([0.252, 0.748], [[0, 0], [0, 0]], [[0, 0.5], [.9, 0]])
    assert_close1d(gammas, [1, 1])
    # alpha does not matter

    a = b = np.zeros((6, 6)).tolist()
    gammas = NRTL_gammas([0., 1, 0, 0, 0, 0], a, b)
    assert_close1d(gammas, [1, 1, 1, 1, 1, 1])

    # Test vs chemsep parameters, same water ethanol T and P
    T = 343.15
    b12 = -57.9601 * calorie
    b21 = 1241.7396 * calorie
    tau12 = b12 / (R * T)
    tau21 = b21 / (R * T)

    gammas = NRTL_gammas(xs=[0.252, 0.748],
                         taus=[[0, tau12], [tau21, 0]],
                         alphas=[[0, 0.2937], [.2937, 0]])
    assert_close1d(gammas, [1.9853834856640085, 1.146380779201308])

    # Random bad example
    alphas = [[0.0, 0.35, 0.35, 0.35, 0.35], [0.35, 0.0, 0.35, 0.35, 0.35],
              [0.35, 0.35, 0.0, 0.35, 0.35], [0.35, 0.35, 0.35, 0.0, 0.35],
              [0.35, 0.35, 0.35, 0.35, 0.0]]
    taus = [[0.0, 0.651, 2.965, 1.738,
             0.761], [1.832, 0.0, 2.783, 1.35, 0.629],
            [0.528, 1.288, 0.0, 0.419,
             2.395], [1.115, 1.838, 2.16, 0.0, 0.692],
            [1.821, 2.466, 1.587, 1.101, 0.0]]

    xs = [
        0.18736982702111407, 0.2154173017033719, 0.2717319464745698,
        0.11018333572613222, 0.215297589074812
    ]
    gammas = NRTL_gammas(xs, taus, alphas)
    gammas_expect = [
        2.503204848288857, 2.910723989902569, 2.2547951278295497,
        2.9933258413917154, 2.694165187439594
    ]
    assert_close1d(gammas, gammas_expect)
Ejemplo n.º 2
0
def test_Kawahara():
    alphas_calc = [Kawahara(.4, 800, 2.5, D) for D in [0.001, 100E-6, 1E-7]]
    alphas_exp = [0.8291135303265941, 0.9276148194410238, 0.8952146812696503]
    assert_close1d(alphas_calc, alphas_exp)
Ejemplo n.º 3
0
def test_4_components():
    #    m = Mixture(['acetone', 'chloroform', 'methanol', 'water'], zs=xs, T=300)
    xs = [.4, .3, .2, .1]
    SPs = [19570.2, 18864.7, 29261.4, 47863.5]
    Vs = [7.421e-05, 8.068e-05, 4.083e-05, 1.808e-05]
    N = 4
    T = 300.0
    # Made up asymmetric parameters
    lambda_coeffs = [[0.0, 0.01811, 0.01736, 0.02111],
                     [0.00662, 0.0, 0.00774, 0.01966],
                     [0.01601, 0.01022, 0.0, 0.00698],
                     [0.0152, 0.00544, 0.02579, 0.0]]

    GE = RegularSolution(T, xs, Vs, SPs, lambda_coeffs)
    assert eval(str(GE)).GE() == GE.GE()

    GE2 = RegularSolution.from_json(GE.as_json())
    assert GE2.__dict__ == GE.__dict__

    # Test with no interaction parameters
    GE3 = RegularSolution(T, xs, Vs, SPs)
    GE4 = eval(str(GE3))
    assert GE3 == GE4
    assert GE4.GE() == GE3.GE()
    GE5 = RegularSolution.from_json(GE4.as_json())
    assert GE4.__dict__ == GE3.__dict__
    assert GE5.__dict__ == GE3.__dict__
    assert GE5 == GE3
    assert hash(GE5) == hash(GE3)
    GE6 = eval(str(GE4))
    assert GE5.model_hash() == GE6.model_hash()
    assert GE5.state_hash() == GE6.state_hash()

    dT = 1e-7 * T
    gammas_expect = [
        1.1928784349228994, 1.3043087978251762, 3.2795596493820955,
        197.92137114651274
    ]
    assert_close1d(GE.gammas(), gammas_expect, rtol=1e-12)
    assert_close1d(GibbsExcess.gammas(GE), gammas_expect)

    # Gammas
    assert_close(GE.GE(), 2286.257263714889, rtol=1e-12)
    gammas = GE.gammas()
    GE_from_gammas = R * T * sum(xi * log(gamma)
                                 for xi, gamma in zip(xs, gammas))
    assert_close(GE_from_gammas, GE.GE(), rtol=1e-12)

    # Gamma direct call
    assert_close1d(GE.gammas(),
                   regular_solution_gammas(T=T,
                                           xs=xs,
                                           Vs=Vs,
                                           SPs=SPs,
                                           lambda_coeffs=lambda_coeffs,
                                           N=N),
                   rtol=1e-12)

    # dGE dT
    dGE_dT_numerical = (
        (np.array(GE.to_T_xs(T + dT, xs).GE()) - np.array(GE.GE())) / dT)
    dGE_dT_analytical = GE.dGE_dT()
    assert_close(dGE_dT_analytical, 0, rtol=1e-12, atol=1e-9)
    assert_close(dGE_dT_numerical, dGE_dT_analytical)

    # d2GE dT2
    d2GE_dT2_numerical = (
        (np.array(GE.to_T_xs(T + dT, xs).dGE_dT()) - np.array(GE.dGE_dT())) /
        dT)
    d2GE_dT2_analytical = GE.d2GE_dT2()
    assert_close(d2GE_dT2_analytical, 0, rtol=1e-12, atol=1e-9)
    assert_close(d2GE_dT2_analytical, d2GE_dT2_numerical, rtol=1e-8)

    # d3GE dT3
    d3GE_dT3_numerical = ((np.array(GE.to_T_xs(T + dT, xs).d2GE_dT2()) -
                           np.array(GE.d2GE_dT2())) / dT)
    d3GE_dT3_analytical = GE.d3GE_dT3()
    assert_close(d3GE_dT3_analytical, 0, rtol=1e-12, atol=1e-9)
    assert_close(d3GE_dT3_numerical, d3GE_dT3_analytical, rtol=1e-7)

    # d2GE_dTdxs
    def dGE_dT_diff(xs):
        return GE.to_T_xs(T, xs).dGE_dT()

    d2GE_dTdxs_numerical = jacobian(dGE_dT_diff, xs, perturbation=1e-7)
    d2GE_dTdxs_analytical = GE.d2GE_dTdxs()
    d2GE_dTdxs_expect = [0] * 4
    assert_close1d(d2GE_dTdxs_analytical, d2GE_dTdxs_expect, rtol=1e-12)
    assert_close1d(d2GE_dTdxs_numerical, d2GE_dTdxs_analytical, rtol=1e-7)

    # dGE_dxs
    def dGE_dx_diff(xs):
        return GE.to_T_xs(T, xs).GE()

    dGE_dxs_numerical = jacobian(dGE_dx_diff, xs, perturbation=1e-7)
    dGE_dxs_analytical = GE.dGE_dxs()
    dGE_dxs_expect = [
        439.92463410596037, 662.6790758115604, 2962.5490239819123,
        13189.738825326536
    ]
    assert_close1d(dGE_dxs_analytical, dGE_dxs_expect, rtol=1e-12)
    assert_close1d(dGE_dxs_analytical, dGE_dxs_numerical, rtol=1e-7)

    # d2GE_dxixjs
    d2GE_dxixjs_numerical = hessian(dGE_dx_diff, xs, perturbation=1e-5)
    d2GE_dxixjs_analytical = GE.d2GE_dxixjs()
    d2GE_dxixjs_expect = [[
        -1022.4173091041094, -423.20895951381453, 1638.9017092099375,
        2081.4926965380164
    ],
                          [
                              -423.20895951381453, -1674.3900233778054,
                              1920.6043029143648, 2874.797302359955
                          ],
                          [
                              1638.901709209937, 1920.6043029143648,
                              -3788.1956922483323, -4741.028361086175
                          ],
                          [
                              2081.4926965380164, 2874.797302359955,
                              -4741.028361086175, -7468.305971059591
                          ]]
    d2GE_dxixjs_sympy = [[
        -1022.4173091041112, -423.208959513817, 1638.9017092099352,
        2081.492696538016
    ],
                         [
                             -423.208959513817, -1674.3900233778083,
                             1920.6043029143652, 2874.7973023599534
                         ],
                         [
                             1638.9017092099352, 1920.6043029143652,
                             -3788.1956922483323, -4741.028361086176
                         ],
                         [
                             2081.492696538016, 2874.7973023599534,
                             -4741.028361086176, -7468.305971059591
                         ]]
    assert_close2d(d2GE_dxixjs_analytical, d2GE_dxixjs_sympy, rtol=1e-12)
    assert_close2d(d2GE_dxixjs_analytical, d2GE_dxixjs_expect, rtol=1e-12)
    assert_close2d(d2GE_dxixjs_analytical, d2GE_dxixjs_numerical, rtol=2.5e-4)

    d3GE_dxixjxks_analytical = GE.d3GE_dxixjxks()
    d3GE_dxixjxks_sympy = [[[
        3564.2598967437325, 2275.2388316927168, -3155.248707372427,
        -4548.085576267108
    ],
                            [
                                2275.2388316927168, 3015.024292098843,
                                -4031.740524903445, -5850.4575581223535
                            ],
                            [
                                -3155.248707372427, -4031.740524903445,
                                2306.3682432066844, 3714.462825687298
                            ],
                            [
                                -4548.085576267108, -5850.4575581223535,
                                3714.462825687298, 7499.862362680743
                            ]],
                           [[
                               2275.2388316927168, 3015.024292098843,
                               -4031.740524903445, -5850.4575581223535
                           ],
                            [
                                3015.024292098843, 6346.017369615182,
                                -3782.270609497761, -6789.70782446731
                            ],
                            [
                                -4031.740524903445, -3782.270609497761,
                                2329.947090204009, 3607.836718555389
                            ],
                            [
                                -5850.4575581223535, -6789.70782446731,
                                3607.836718555389, 7807.307245181044
                            ]],
                           [[
                               -3155.248707372427, -4031.740524903445,
                               2306.3682432066844, 3714.462825687298
                           ],
                            [
                                -4031.740524903445, -3782.270609497761,
                                2329.947090204009, 3607.836718555389
                            ],
                            [
                                2306.3682432066844, 2329.947090204009,
                                7265.918548487337, 7134.805582069884
                            ],
                            [
                                3714.462825687298, 3607.836718555389,
                                7134.805582069884, 7459.310988306651
                            ]],
                           [[
                               -4548.085576267108, -5850.4575581223535,
                               3714.462825687298, 7499.862362680743
                           ],
                            [
                                -5850.4575581223535, -6789.70782446731,
                                3607.836718555389, 7807.307245181044
                            ],
                            [
                                3714.462825687298, 3607.836718555389,
                                7134.805582069884, 7459.310988306651
                            ],
                            [
                                7499.862362680743, 7807.307245181044,
                                7459.310988306651, 6343.066547716518
                            ]]]
    assert_close3d(d3GE_dxixjxks_analytical, d3GE_dxixjxks_sympy, rtol=1e-12)

    # Test with some stored results
    GE2 = RegularSolution.from_json(GE.as_json())
    assert GE2.__dict__ == GE.__dict__
Ejemplo n.º 4
0
def test_helical_turbulent_Nu_Schmidt():
    Nu = helical_turbulent_Nu_Schmidt(2E5, 0.7, 0.01, .2)
    assert_close(Nu, 466.2569996832083)
    Nus = [helical_turbulent_Nu_Schmidt(i, 0.7, 0.01, .2) for i in [2.2E4, 2.2E4+1E-9]]
    assert_close1d(Nus, [80.1111786843, 79.75161984693375])
Ejemplo n.º 5
0
def test_C_long_radius_nozzle_full():
    Cs = [[0.9673, 0.9759, 0.9834, 0.9873, 0.9900, 0.9924, 0.9936, 0.9952, 0.9956],
    [0.9659, 0.9748, 0.9828, 0.9868, 0.9897, 0.9922, 0.9934, 0.9951, 0.9955],
    [0.9645, 0.9739, 0.9822, 0.9864, 0.9893, 0.9920, 0.9933, 0.9951, 0.9955],
    [0.9632, 0.9730, 0.9816, 0.9860, 0.9891, 0.9918, 0.9932, 0.9950, 0.9954],
    [0.9619, 0.9721, 0.9810, 0.9856, 0.9888, 0.9916, 0.9930, 0.9950, 0.9954],
    [0.9607, 0.9712, 0.9805, 0.9852, 0.9885, 0.9914, 0.9929, 0.9949, 0.9954],
    [0.9596, 0.9704, 0.9800, 0.9848, 0.9882, 0.9913, 0.9928, 0.9948, 0.9953],
    [0.9584, 0.9696, 0.9795, 0.9845, 0.9880, 0.9911, 0.9927, 0.9948, 0.9953],
    [0.9573, 0.9688, 0.9790, 0.9841, 0.9877, 0.9910, 0.9926, 0.9947, 0.9953],
    [0.9562, 0.9680, 0.9785, 0.9838, 0.9875, 0.9908, 0.9925, 0.9947, 0.9952],
    [0.9552, 0.9673, 0.9780, 0.9834, 0.9873, 0.9907, 0.9924, 0.9947, 0.9952],
    [0.9542, 0.9666, 0.9776, 0.9831, 0.9870, 0.9905, 0.9923, 0.9946, 0.9952],
    [0.9532, 0.9659, 0.9771, 0.9828, 0.9868, 0.9904, 0.9922, 0.9946, 0.9951],
    [0.9523, 0.9652, 0.9767, 0.9825, 0.9866, 0.9902, 0.9921, 0.9945, 0.9951],
    [0.9513, 0.9645, 0.9763, 0.9822, 0.9864, 0.9901, 0.9920, 0.9945, 0.9951],
    [0.9503, 0.9639, 0.9759, 0.9819, 0.9862, 0.9900, 0.9919, 0.9944, 0.9950],
    [0.9499, 0.9635, 0.9756, 0.9818, 0.9861, 0.9899, 0.9918, 0.9944, 0.9950],
    [0.9494, 0.9632, 0.9754, 0.9816, 0.9860, 0.9898, 0.9918, 0.9944, 0.9950],
    [0.9490, 0.9629, 0.9752, 0.9815, 0.9859, 0.9898, 0.9917, 0.9944, 0.9950],
    [0.9485, 0.9626, 0.9750, 0.9813, 0.9858, 0.9897, 0.9917, 0.9944, 0.9950],
    [0.9481, 0.9623, 0.9748, 0.9812, 0.9857, 0.9897, 0.9917, 0.9943, 0.9950],
    [0.9476, 0.9619, 0.9746, 0.9810, 0.9856, 0.9896, 0.9916, 0.9943, 0.9950],
    [0.9472, 0.9616, 0.9745, 0.9809, 0.9855, 0.9895, 0.9916, 0.9943, 0.9949],
    [0.9468, 0.9613, 0.9743, 0.9808, 0.9854, 0.9895, 0.9915, 0.9943, 0.9949],
    [0.9463, 0.9610, 0.9741, 0.9806, 0.9853, 0.9894, 0.9915, 0.9943, 0.9949],
    [0.9459, 0.9607, 0.9739, 0.9805, 0.9852, 0.9893, 0.9914, 0.9942, 0.9949],
    [0.9455, 0.9604, 0.9737, 0.9804, 0.9851, 0.9893, 0.9914, 0.9942, 0.9949],
    [0.9451, 0.9601, 0.9735, 0.9802, 0.9850, 0.9892, 0.9914, 0.9942, 0.9949],
    [0.9447, 0.9599, 0.9733, 0.9801, 0.9849, 0.9892, 0.9913, 0.9942, 0.9949],
    [0.9443, 0.9596, 0.9731, 0.9800, 0.9848, 0.9891, 0.9913, 0.9942, 0.9948],
    [0.9439, 0.9593, 0.9730, 0.9799, 0.9847, 0.9891, 0.9912, 0.9941, 0.9948],
    [0.9435, 0.9590, 0.9728, 0.9797, 0.9846, 0.9890, 0.9912, 0.9941, 0.9948],
    [0.9430, 0.9587, 0.9726, 0.9796, 0.9845, 0.9889, 0.9912, 0.9941, 0.9948],
    [0.9427, 0.9584, 0.9724, 0.9795, 0.9845, 0.9889, 0.9911, 0.9941, 0.9948],
    [0.9423, 0.9581, 0.9722, 0.9793, 0.9844, 0.9888, 0.9911, 0.9941, 0.9948],
    [0.9419, 0.9579, 0.9721, 0.9792, 0.9843, 0.9888, 0.9910, 0.9941, 0.9948],
    [0.9415, 0.9576, 0.9719, 0.9791, 0.9842, 0.9887, 0.9910, 0.9940, 0.9948],
    [0.9411, 0.9573, 0.9717, 0.9790, 0.9841, 0.9887, 0.9910, 0.9940, 0.9947],
    [0.9407, 0.9570, 0.9715, 0.9789, 0.9840, 0.9886, 0.9909, 0.9940, 0.9947],
    [0.9403, 0.9568, 0.9714, 0.9787, 0.9839, 0.9886, 0.9909, 0.9940, 0.9947],
    [0.9399, 0.9565, 0.9712, 0.9786, 0.9839, 0.9885, 0.9908, 0.9940, 0.9947],
    [0.9396, 0.9562, 0.9710, 0.9785, 0.9838, 0.9884, 0.9908, 0.9940, 0.9947],
    [0.9392, 0.9560, 0.9709, 0.9784, 0.9837, 0.9884, 0.9908, 0.9939, 0.9947],
    [0.9388, 0.9557, 0.9707, 0.9783, 0.9836, 0.9883, 0.9907, 0.9939, 0.9947],
    [0.9385, 0.9555, 0.9705, 0.9781, 0.9835, 0.9883, 0.9907, 0.9939, 0.9947],
    [0.9381, 0.9552, 0.9704, 0.9780, 0.9834, 0.9882, 0.9907, 0.9939, 0.9947]]

    Rd_values = [1E4, 2E4, 5E4, 1E5, 2E5, 5E5, 1E6, 5E6, 1E7]
    betas = [i/100. for i in list(range(20, 51, 2)) + list(range(51, 81))]

    def C_long_radius_nozzle(D, Do, Re_D):
        beta = Do/D
        return 0.9965 - 0.00653*beta**0.5*(1E6/Re_D)**0.5


    for i in range(len(betas)):
        Cs_expect = Cs[i]
        beta = betas[i]
        Cs_calc = [round(C_long_radius_nozzle(D=1, Do=beta, Re_D=i), 4) for i in Rd_values]
        assert_close1d(Cs_expect, Cs_calc, atol=1E-4)
Ejemplo n.º 6
0
def test_HeatCapacityLiquid():
    tol = HeatCapacityLiquid(CASRN='108-88-3', MW=92.13842, Tc=591.75, omega=0.257, Cpgm=115.30398669098454, similarity_variable=0.16279853724428964)
#    Cpl_calc = []
#    for i in tol.all_methods:
#        tol.method = i
#        Cpl_calc.append(tol.T_dependent_property(330))

    tol.method = ROWLINSON_BONDI
    assert_close(tol.T_dependent_property(330.0), 165.45542037912406, rtol=1e-10)
    tol.method = ZABRANSKY_QUASIPOLYNOMIAL_C
    assert_close(tol.T_dependent_property(330.0), 165.472878778683, rtol=1e-10)
    tol.method = CRCSTD
    assert_close(tol.T_dependent_property(330.0), 157.3, rtol=1e-10)
    tol.method = ROWLINSON_POLING
    assert_close(tol.T_dependent_property(330.0), 167.33806248209527, rtol=1e-10)
    tol.method = POLING_CONST
    assert_close(tol.T_dependent_property(330.0), 157.29, rtol=1e-10)
    tol.method = ZABRANSKY_SPLINE_SAT
    assert_close(tol.T_dependent_property(330.0), 166.69813077891135, rtol=1e-10)
    tol.method = DADGOSTAR_SHAW
    assert_close(tol.T_dependent_property(330.0), 175.34392562391267, rtol=1e-10)
    tol.method = ZABRANSKY_SPLINE_C
    assert_close(tol.T_dependent_property(330.0), 166.7156677848114, rtol=1e-10)
    tol.method = VDI_TABULAR
    assert_close(tol.T_dependent_property(330.0), 166.52477714085708, rtol=1e-10)

    assert eval(str(tol)) == tol
    new = HeatCapacityLiquid.from_json(tol.as_json())
    assert new == tol
    tol.extrapolation = None
    for i in tol.all_methods:
        tol.method = i
        assert tol.T_dependent_property(2000) is None


    with pytest.raises(Exception):
        tol.test_method_validity('BADMETHOD', 300)

    assert False == tol.test_property_validity(-1)
    assert False == tol.test_property_validity(1.01E5)
    assert True == tol.test_property_validity(100)



    propylbenzene = HeatCapacityLiquid(MW=120.19158, CASRN='103-65-1', Tc=638.35)

    Cpl_calc = []
    for i in propylbenzene.all_methods:
        propylbenzene.method = i
        Cpl_calc.append(propylbenzene.T_dependent_property(298.15))

    Cpls = [214.6499551694668, 214.69679325320664, 214.7, 214.71]
    assert_close1d(sorted(Cpl_calc), sorted(Cpls))

    new = HeatCapacityLiquid.from_json(propylbenzene.as_json())
    assert new == propylbenzene

    ctp = HeatCapacityLiquid(MW=118.58462, CASRN='96-43-5')

    Cpl_calc = []
    for i in ctp.all_methods:
        ctp.method = i
        Cpl_calc.append(ctp.T_dependent_property(250))

    Cpls = [134.1186737739494, 134.1496585096233]
    assert_close1d(sorted(Cpl_calc), sorted(Cpls))
    new = HeatCapacityLiquid.from_json(ctp.as_json())
    assert new == ctp
Ejemplo n.º 7
0
def test_EnthalpyVaporization():
    EtOH = EnthalpyVaporization(Tb=351.39,
                                Tc=514.0,
                                Pc=6137000.0,
                                omega=0.635,
                                similarity_variable=0.1954,
                                Psat=7872.2,
                                Zg=0.9633,
                                Zl=0.0024,
                                CASRN='64-17-5')

    EtOH.method = COOLPROP
    assert_close(EtOH.T_dependent_property(305), 42062.9371631488)
    EtOH.method = VDI_PPDS
    assert_close(EtOH.T_dependent_property(305), 42099.23631527565)
    EtOH.method = CLAPEYRON
    assert_close(EtOH.T_dependent_property(305), 39904.512005771176)
    EtOH.method = LIU
    assert_close(EtOH.T_dependent_property(305), 40315.087291316195)
    EtOH.method = ALIBAKHSHI
    assert_close(EtOH.T_dependent_property(305), 39244.0137575973)
    EtOH.method = MORGAN_KOBAYASHI
    assert_close(EtOH.T_dependent_property(305), 42182.87752489718)
    EtOH.method = VELASCO
    assert_close(EtOH.T_dependent_property(305), 43056.23753606326)
    EtOH.method = PITZER
    assert_close(EtOH.T_dependent_property(305), 41716.88048400951)
    EtOH.method = RIEDEL
    assert_close(EtOH.T_dependent_property(305), 44258.89496024996)
    EtOH.method = SIVARAMAN_MAGEE_KOBAYASHI
    assert_close(EtOH.T_dependent_property(305), 42279.09568184713)
    EtOH.method = CHEN
    assert_close(EtOH.T_dependent_property(305), 42951.50714053451)
    EtOH.method = CRC_HVAP_TB
    assert_close(EtOH.T_dependent_property(305), 42423.58947282491)
    EtOH.method = DIPPR_PERRY_8E
    assert_close(EtOH.T_dependent_property(305), 42115.102057622214)
    EtOH.method = VETERE
    assert_close(EtOH.T_dependent_property(305), 41382.22039928848)
    EtOH.method = CRC_HVAP_298
    assert_close(EtOH.T_dependent_property(305), 41804.5417918726)
    EtOH.method = VDI_TABULAR
    assert_close(EtOH.T_dependent_property(305), 42119.6665416816)
    EtOH.method = GHARAGHEIZI_HVAP_298
    assert_close(EtOH.T_dependent_property(305), 41686.00339359697)

    EtOH.extrapolation = None
    for i in EtOH.all_methods:
        EtOH.method = i
        assert EtOH.T_dependent_property(5000) is None

    EtOH = EnthalpyVaporization(CASRN='64-17-5', Tc=514.0)
    Hvap_calc = []
    for i in [
            'GHARAGHEIZI_HVAP_298', 'CRC_HVAP_298', 'VDI_TABULAR', 'COOLPROP'
    ]:
        EtOH.method = i
        Hvap_calc.append(EtOH.T_dependent_property(310.0))
    Hvap_exp = [
        41304.19234346344, 41421.6450231131, 41857.962450207546,
        41796.56243049473
    ]
    assert_close1d(Hvap_calc, Hvap_exp)

    # Test Clapeyron, without Zl
    EtOH = EnthalpyVaporization(Tb=351.39,
                                Tc=514.0,
                                Pc=6137000.0,
                                omega=0.635,
                                similarity_variable=0.1954,
                                Psat=7872.2,
                                Zg=0.9633,
                                CASRN='64-17-5')
    assert_close(EtOH.calculate(298.15, 'CLAPEYRON'), 37864.70507798813)

    EtOH = EnthalpyVaporization(Tb=351.39,
                                Pc=6137000.0,
                                omega=0.635,
                                similarity_variable=0.1954,
                                Psat=7872.2,
                                Zg=0.9633,
                                CASRN='64-17-5')
    assert EtOH.test_method_validity(351.39, 'CRC_HVAP_TB')
    assert not EtOH.test_method_validity(351.39 + 10, 'CRC_HVAP_TB')
    assert not EtOH.test_method_validity(351.39, 'CRC_HVAP_298')

    Ts = [200, 250, 300, 400, 450]
    props = [
        46461.62768429649, 44543.08561867195, 42320.381894706225,
        34627.726535926406, 27634.46144486471
    ]
    EtOH.add_tabular_data(Ts=Ts, properties=props, name='CPdata')
    EtOH.forced = True
    assert_close(43499.47575887933, EtOH.T_dependent_property(275), rtol=1E-4)

    EtOH.tabular_extrapolation_permitted = False
    assert None == EtOH.T_dependent_property(5000)

    with pytest.raises(Exception):
        EtOH.test_method_validity('BADMETHOD', 300)
def test_cbrt_imag_dd():
    ans = cbrt_imag_dd(2.718281828459045, 1.4456468917292502e-16, 3.141592653589793, 1.2246467991473532e-16)
    assert_close1d(ans, (1.5423370526780396, 8.764992916723807e-17, 0.45326965450036827, 2.105896617565284e-17), rtol=1e-14)
def test_cbrt_dd():
    ans = cbrt_dd(3, 0.0)
    assert_close1d(ans, (1.4422495703074083, 8.054912676113696e-17), rtol=1e-13)

    ans = cbrt_dd(1.4422495703074083, 8.054912676113696e-17)
    assert_close1d(ans, (1.129830963909753, 1.601807086137469e-17), rtol=1e-13)
Ejemplo n.º 10
0
def test_div_imag_dd():
    ans = div_imag_dd(2.718281828459045, 1.4456468917292502e-16, 3.141592653589793, 1.2246467991473532e-16,
                      3.141592653589793, 1.2246467991473532e-16, 2.718281828459045, 1.4456468917292502e-16)
    assert_close1d(ans, (0.9896172675351794, -2.57625629153772e-17, 0.14372774191576643, 1.174077497180584e-17), rtol=1e-13)
Ejemplo n.º 11
0
def test_imag_inv_dd():
    ans = imag_inv_dd(2.718281828459045, 1.4456468917292502e-16, 3.141592653589793, 1.2246467991473532e-16)
    assert_close1d(ans, (0.15750247989731844, -3.9415361951446925e-18, -0.18202992367722576, -5.408691854671257e-18), rtol=1e-13)
Ejemplo n.º 12
0
def test_add_imag_dd():
    ans = add_imag_dd(2.718281828459045, 1.4456468917292502e-16, 3.141592653589793, 1.2246467991473532e-16,
                      3.141592653589793, 1.2246467991473532e-16, 2.718281828459045, 1.4456468917292502e-16)
    assert_close1d(ans, (5.859874482048839, -1.770598407624023e-16, 5.859874482048839, -1.770598407624023e-16))
Ejemplo n.º 13
0
def test_sqrt_imag_dd():
    ans = sqrt_imag_dd(2.718281828459045, 1.4456468917292502e-16, 3.141592653589793, 1.2246467991473532e-16)
    assert_close1d(ans, (1.853730863795006, 1.8197550334075816e-17, 0.8473702183385572, 4.942630438677856e-17))

    ans = sqrt_imag_dd(2.718281828459045, 1.4456468917292502e-16, 0, 0)
    assert_close1d(ans, (1.6487212707001282, -4.731568479435833e-17, 0.0, 0.0))
Ejemplo n.º 14
0
def test_mul_imag_noerrors_dd():
    ans = mul_imag_noerrors_dd(1.11, .027, -1.2, .2995)
    assert_close1d(ans, (-1.3400865, -1.0926552718171222e-16, 0.300045, 1.1863843241144421e-17), rtol=1e-14)
Ejemplo n.º 15
0
def test_square_dd():
    ans = square_dd(2.718281828459045, 1.4456468917292502e-16)
    assert_close1d(ans, (7.38905609893065, -1.7971139497839148e-16), rtol=1e-13)
Ejemplo n.º 16
0
def test_cube_dd():
    ans = cube_dd(2.718281828459045, 1.4456468917292502e-16)
    assert_close1d(ans, (20.085536923187668, -1.8275625525512858e-16), rtol=1e-14)
Ejemplo n.º 17
0
def check_np_output_activity(model, modelnp, modelnp2):
    # model is flat, scalar, list-based model
    # modelnp is numba model
    # modelnp2 is created from the numba model with to_T_xs at a different composition

    scalar_attrs = ['d3GE_dT3', 'd2GE_dT2', 'GE', 'dGE_dT']
    for attr in scalar_attrs:
        if hasattr(model, attr):
            #            print(attr)
            assert_close(getattr(model, attr)(),
                         getattr(modelnp, attr)(),
                         rtol=2e-13)
            assert_close(getattr(modelnp2, attr)(),
                         getattr(modelnp, attr)(),
                         rtol=2e-13)
            assert type(getattr(model, attr)()) is float
    #        assert type(getattr(modelnp, attr)()) is float
    #        assert type(getattr(modelnp2, attr)()) is float

    vec_attrs = [
        'dGE_dxs', 'gammas', '_gammas_dGE_dxs', 'd2GE_dTdxs', 'dHE_dxs',
        'gammas_infinite_dilution', 'dHE_dns', 'dnHE_dns', 'dSE_dxs',
        'dSE_dns', 'dnSE_dns', 'dGE_dns', 'dnGE_dns', 'd2GE_dTdns',
        'd2nGE_dTdns', 'dgammas_dT'
    ]

    for attr in vec_attrs:
        #        print(attr)
        assert_close1d(getattr(model, attr)(),
                       getattr(modelnp, attr)(),
                       rtol=2e-13)
        assert_close1d(getattr(modelnp2, attr)(),
                       getattr(modelnp, attr)(),
                       rtol=2e-13)
        assert type(getattr(model, attr)()) is list
        assert type(getattr(modelnp, attr)()) is np.ndarray
        assert type(getattr(modelnp2, attr)()) is np.ndarray

    mat_attrs = ['d2GE_dxixjs', 'd2nGE_dninjs', 'dgammas_dns']
    for attr in mat_attrs:
        #        print(attr)
        assert_close2d(getattr(model, attr)(),
                       getattr(modelnp, attr)(),
                       rtol=1e-12)
        assert_close2d(getattr(modelnp2, attr)(),
                       getattr(modelnp, attr)(),
                       rtol=1e-12)
        assert type(getattr(model, attr)()) is list
        assert type(getattr(modelnp, attr)()) is np.ndarray
        assert type(getattr(modelnp2, attr)()) is np.ndarray

    attrs_3d = ['d3GE_dxixjxks']
    for attr in attrs_3d:
        if hasattr(model, attr):
            #            print(attr)
            # some models do not have this implemented
            assert_close3d(getattr(model, attr)(),
                           getattr(modelnp, attr)(),
                           rtol=1e-13)
            assert_close3d(getattr(modelnp2, attr)(),
                           getattr(modelnp, attr)(),
                           rtol=1e-13)
            assert type(getattr(model, attr)()) is list
            assert type(getattr(modelnp, attr)()) is np.ndarray
            assert type(getattr(modelnp2, attr)()) is np.ndarray
Ejemplo n.º 18
0
def test_div_imag_dd():
    mp_ans = (-6221711.561975023 - 2.5074521914349666e-10j)/(1247.1686953729213 +2160.157819988352j)
    ans = div_imag_dd(-6221711.561975023, 0.0, - 2.5074521914349666e-10, 0.0,
                      1247.1686953729213, 0.0, 2160.157819988352, 0.0)
    assert_close1d(ans, (-1247.168695372921, -7.085386715133776e-14, 2160.1578199883515, -1.7404258749820416e-14), rtol=1e-13)
Ejemplo n.º 19
0
def test_friction_factor_curved():
    fd = friction_factor_curved(2E4, 0.01, .02)
    assert_close(fd, 0.050134646621603024)
    fd = friction_factor_curved(250, .02, .1)
    assert_close(fd, 0.47460725672835236)

    fd_transition = [
        friction_factor_curved(i, 0.01, .02) for i in [16779, 16780]
    ]
    assert_close1d(fd_transition, [0.03323676794260526, 0.057221855744623344])

    with pytest.raises(Exception):
        friction_factor_curved(16779, 0.01, .02, Method='BADMETHOD')
    with pytest.raises(Exception):
        friction_factor_curved(16779, 0.01, .02, Rec_method='BADMETHOD')

    fd_rough_false = friction_factor_curved(20000,
                                            0.01,
                                            .02,
                                            roughness=.0001,
                                            turbulent_method='Guo')
    assert_close(fd_rough_false, 0.1014240343662085)

    methods = friction_factor_curved(20000, 0.01, .02, AvailableMethods=True)
    assert sorted(methods) == sorted([
        'Guo', 'Ju', 'Schmidt turbulent', 'Prasad', 'Mandel Nigam',
        'Mori Nakayama turbulent', 'Czop', 'Srinivasan turbulent'
    ])
    methods = friction_factor_curved(2000, 0.01, .02, AvailableMethods=True)
    assert sorted(methods) == sorted(
        ['White', 'Schmidt laminar', 'Mori Nakayama laminar'])

    methods = friction_factor_curved_methods(20000,
                                             0.01,
                                             .02,
                                             check_ranges=True)
    assert sorted(methods) == sorted([
        'Guo', 'Ju', 'Schmidt turbulent', 'Prasad', 'Mandel Nigam',
        'Mori Nakayama turbulent', 'Czop', 'Srinivasan turbulent'
    ])
    methods = friction_factor_curved_methods(2000,
                                             0.01,
                                             .02,
                                             check_ranges=True)
    assert sorted(methods) == sorted(
        ['White', 'Schmidt laminar', 'Mori Nakayama laminar'])
    assert 'Schmidt turbulent' in friction_factor_curved_methods(Re=1E5,
                                                                 Di=0.02,
                                                                 Dc=0.5)
    assert 11 == len(
        friction_factor_curved_methods(Re=1E5,
                                       Di=0.02,
                                       Dc=0.5,
                                       check_ranges=False))

    for m in friction_factor_curved_methods(Re=1E5,
                                            Di=0.02,
                                            Dc=0.5,
                                            check_ranges=False):
        friction_factor_curved(2000, 0.01, .02, Method=m)

    # Test the Fanning case
    fd = friction_factor_curved(2E4, 0.01, .02, Darcy=False)
    assert_close(fd, 0.012533661655400756)

    for m in [
            'Seth Stahel', 'Ito', 'Kubair Kuloor', 'Kutateladze Borishanskii',
            'Schmidt', 'Srinivasan'
    ]:
        helical_Re_crit(Di=0.02, Dc=0.5, Method=m)
Ejemplo n.º 20
0
def test_add_dd():
    ans = add_dd(2.718281828459045, 1.4456468917292502e-16, -3.141592653589793, -1.2246467991473532e-16)
    assert_close1d(ans, (-0.423310825130748, 2.2100009258189695e-17), rtol=1e-13)
def test_k_IAPWS():
    rhos = [1., 122., 222., 272., 322., 372., 422., 750.]
    Cps = [
        2069.0812064568445, 11353.470032452065, 101243.30196479718,
        794916.0384979197, 5420611.2721776245, 500237.6519254826,
        62663.67284339393, 4570.624565173062
    ]
    Cvs = [
        1595.69907291979, 3243.791325724295, 4523.436913569467,
        5491.264195750903, 6188.749461187972, 5181.406642440796,
        3904.379773638152, 2833.6557941038973
    ]
    mus = [
        2.3377752122053447e-05, 2.5520676836476175e-05, 3.133758919727549e-05,
        3.622814313612717e-05, 4.296157881024315e-05, 4.5688204474708324e-05,
        4.943625601494995e-05, 9.401498317589303e-05
    ]
    d_rho_d_Ps = [
        3.3774067394654917e-06, 1.710930848910942e-05, 0.000175456980972237,
        0.0015082800389184703, 0.012136419490369314, 0.0012459172043680759,
        0.00013039353796524478, 1.0510776327652118e-06
    ]
    k_CP = [
        0.05192989239188059, 0.13092288520449896, 0.3677874588628728,
        0.7579597763651718, 1.4437555614266426, 0.6503194015489409,
        0.4488834872838822, 0.6009613455848507
    ]
    k_calc = [
        k_IAPWS(T=647.35,
                rho=rhos[i],
                Cp=Cps[i],
                Cv=Cvs[i],
                mu=mus[i],
                drho_dP=d_rho_d_Ps[i]) for i in range(len(rhos))
    ]
    assert_close1d(k_calc, k_CP, rtol=5e-6)

    #        Region 1, test 2, from IAPWS formulation, exact match:

    k = k_IAPWS(T=620.,
                rho=699.226043,
                Cp=5320.47725,
                Cv=2916.92653,
                mu=84.1527945E-6,
                drho_dP=1.84869007E-6)
    assert_close(k, 0.5450389394624772, rtol=1e-13)

    #    Region 2, test 1, from IAPWS formulation, exact match:

    k = k_IAPWS(T=650.,
                rho=1.00452141,
                Cp=2070.10035,
                Cv=1596.75313,
                mu=23.4877453E-6,
                drho_dP=3.36351419E-6)
    assert_close(k, 0.052231102436372065, rtol=1e-13)

    #    Region 3, test 1, from IAPWS formulation, exact match:

    k = k_IAPWS(T=647.35,
                rho=222.,
                Cp=101054.488,
                Cv=4374.66458,
                mu=31.2204749E-6,
                drho_dP=177.778595E-6)
    assert_close(k, 0.36687941154060383, rtol=1e-13)

    # Feed P: 8600000.0
    # Case where zero division was occuring
    kwargs = {
        'T': 400,
        'rho': 941.720097520186,
        'Cp': 4233.740244740559,
        'Cv': 3622.5838143014544,
        'mu': 0.00022080449914642125,
        'drho_dP': 4.996396679875349e-07,
        'drho_dP_Tr': 2.3158445867118744e-07
    }
    assert_close(k_IAPWS(**kwargs), .688018419964361, rtol=1e-11)
Ejemplo n.º 22
0
def test_mul_dd_mp():
    ans = mul_dd(2.718281828459045, 1.4456468917292502e-16, 3.141592653589793, 1.2246467991473532e-16)
    assert_close1d(ans, (8.539734222673568, -6.773815290502423e-16), rtol=1e-13)
    assert abs(mp.e*mp.pi - (mp.mpf(ans[0]) + mp.mpf(ans[1]))) < 1e-30
Ejemplo n.º 23
0
def test_ThermalConductivityLiquid():
    EtOH = ThermalConductivityLiquid(CASRN='64-17-5',
                                     MW=46.06844,
                                     Tm=159.05,
                                     Tb=351.39,
                                     Tc=514.0,
                                     Pc=6137000.0,
                                     omega=0.635,
                                     Hfus=4931.0)

    EtOH.T_dependent_property(305.)
    all_methods = EtOH.all_methods
    methods = list(all_methods)
    methods.remove(VDI_TABULAR)
    kl_calcs = []
    for i in methods:
        EtOH.method = i
        kl_calcs.append(EtOH.T_dependent_property(305.))

    kl_exp = [
        0.162183005823234, 0.16627999999999998, 0.166302, 0.20068212675966418,
        0.18526367184633258, 0.18846433785041306, 0.16837295487233528,
        0.16883011582627103, 0.09330268101157643, 0.028604363267557775
    ]
    assert_close1d(sorted(kl_calcs), sorted(kl_exp))

    assert_close(EtOH.calculate(305., VDI_TABULAR),
                 0.17417420086033197,
                 rtol=1E-4)

    # Test that methods return None
    EtOH.extrapolation = None
    kl_calcs = []
    for i in all_methods:
        EtOH.method = i
        kl_calcs.append(EtOH.T_dependent_property(5000))

    assert [None] * 11 == kl_calcs

    EtOH.method = VDI_TABULAR
    EtOH.extrapolation = 'interp1d'
    assert_close(EtOH.T_dependent_property(600.), 0.040117737789202995)
    EtOH.extrapolation = None
    assert None == EtOH.T_dependent_property(600.)

    with pytest.raises(Exception):
        EtOH.test_method_validity(300, 'BADMETHOD')

    assert ThermalConductivityLiquid.from_JSON(EtOH.as_JSON()) == EtOH

    # Ethanol compressed
    assert [False, True] == [
        EtOH.test_method_validity_P(300, P, COOLPROP) for P in (1E3, 1E5)
    ]
    assert [True, True] == [
        EtOH.test_method_validity_P(300, P, DIPPR_9G) for P in (1E3, 1E5)
    ]
    assert [True, True, False] == [
        EtOH.test_method_validity_P(300, P, MISSENARD)
        for P in (1E3, 1E5, 1E10)
    ]

    EtOH = ThermalConductivityLiquid(CASRN='64-17-5',
                                     MW=46.06844,
                                     Tm=159.05,
                                     Tb=351.39,
                                     Tc=514.0,
                                     Pc=6137000.0,
                                     omega=0.635,
                                     Hfus=4931.0)
    assert_close(EtOH.calculate_P(298.15, 1E6, COOLPROP), 0.1639626989794703)
    assert_close(EtOH.calculate_P(298.15, 1E6, DIPPR_9G), 0.1606146938795702)
    assert_close(EtOH.calculate_P(298.15, 1E6, MISSENARD), 0.1641582259181843)

    # Ethanol data, calculated from CoolProp
    Ts = [275, 300, 350]
    Ps = [1E5, 5E5, 1E6]
    TP_data = [[0.16848555706973622, 0.16313525757474362, 0.15458068887966378],
               [0.16868861153075654, 0.163343255114212, 0.1548036152853355],
               [0.16894182645698885, 0.1636025336196736, 0.15508116339039268]]
    EtOH.add_tabular_data_P(Ts, Ps, TP_data, name='CPdata')
    recalc_pts = [[EtOH.TP_dependent_property(T, P) for T in Ts] for P in Ps]
    assert_close1d(TP_data, recalc_pts)

    EtOH.forced_P = True
    assert_allclose(EtOH.TP_dependent_property(274, 9E4), 0.16848555706973622)
    EtOH.tabular_extrapolation_permitted = False
    assert None == EtOH.TP_dependent_property(300, 9E4)

    with pytest.raises(Exception):
        EtOH.test_method_validity_P(300, 1E5, 'BADMETHOD')

    assert False == EtOH.test_method_validity_P(-10, 1E5, DIPPR_9G)

    assert ThermalConductivityLiquid.from_JSON(EtOH.as_JSON()) == EtOH
Ejemplo n.º 24
0
def test_div_dd():
    ans = div_dd(2.718281828459045, 1.4456468917292502e-16, 3.141592653589793, 1.2246467991473532e-16)
    assert_close1d(ans, (0.8652559794322651, 2.1741459631779752e-17), rtol=1e-13)
Ejemplo n.º 25
0
def test_C_venturi_nozzle_full():
    # Many values do not match well, but the equation has been checked with both standards.
    betas = [0.32, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.40, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.50, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.60, 0.61, 0.62, 0.63, 0.64, 0.65, 0.66, 0.67, 0.68, 0.69, 0.70, 0.71, 0.72, 0.73, 0.74, 0.75, 0.76, 0.77, 0.78]
    Cs = [0.9847, 0.9846, 0.9845, 0.9843, 0.9841, 0.9838, 0.9836, 0.9833, 0.9830, 0.9826, 0.9823, 0.9818, 0.9814, 0.9809, 0.9804, 0.9798, 0.9792, 0.9786, 0.9779, 0.9771, 0.9763, 0.9755, 0.9745, 0.9736, 0.9725, 0.9714, 0.9702, 0.9689, 0.9676, 0.9661, 0.9646, 0.9630, 0.9613, 0.9595, 0.9576, 0.9556, 0.9535, 0.9512, 0.9489, 0.9464, 0.9438, 0.9411, 0.9382, 0.9352, 0.9321, 0.9288, 0.9253, 0.9236]
    Cs_calc = [C_venturi_nozzle(D=1, Do=beta) for beta in betas]
    assert_close1d(Cs, Cs_calc, rtol=5E-3)
Ejemplo n.º 26
0
def test_sqrt_dd():
    ans = sqrt_dd(2.718281828459045, 1.4456468917292502e-16)
    assert_close1d(ans, (1.6487212707001282, -4.731568479435833e-17), rtol=1e-13)
Ejemplo n.º 27
0
def test_Tandon_Varma_Gupta():
    alphas_calc = [Tandon_Varma_Gupta(.4, 800, 2.5, 1E-3, 1E-5, m, 0.3) for m in [1, .1]]
    assert_close1d(alphas_calc, [0.9228265670341428, 0.8799794756817589])
Ejemplo n.º 28
0
def test_mul_noerrors_dd():
    ans = mul_noerrors_dd(2.718281828, 3.1415926)
    assert_close1d(ans, (8.539734075559272, 6.111502792870851e-16), rtol=1e-13)
    assert_close1d(ans, mul_dd(2.718281828, 0.0, 3.1415926, 0.0), rtol=1e-13)
Ejemplo n.º 29
0
def test_LMTD_vect():
    dTlms = [ht.LMTD(T, 60., 30., 40.2) for T in [100, 101]]
    dTlms_vect = ht.vectorized.LMTD([100, 101], 60., 30., 40.2)
    assert_close1d(dTlms, dTlms_vect)
Ejemplo n.º 30
0
def test_water_ethanol_methanol_madeup():
    alphas = [[[0.0, 2e-05], [0.2937, 7e-05], [0.2999, 0.0001]],
              [[0.2937, 1e-05], [0.0, 4e-05], [0.3009, 8e-05]],
              [[0.2999, 1e-05], [0.3009, 3e-05], [0.0, 5e-05]]]

    taus = [[[6e-05, 0.0, 7e-05, 7e-05, 0.00788, 3.6e-07],
             [3e-05, 624.868, 9e-05, 7e-05, 0.00472, 8.5e-07],
             [3e-05, 398.953, 4e-05, 1e-05, 0.00279, 5.6e-07]],
            [[1e-05, -29.167, 8e-05, 9e-05, 0.00256, 1e-07],
             [2e-05, 0.0, 7e-05, 6e-05, 0.00587, 4.2e-07],
             [0.0, -35.482, 8e-05, 4e-05, 0.00889, 8.2e-07]],
            [[9e-05, -95.132, 6e-05, 1e-05, 0.00905, 5.2e-07],
             [9e-05, 33.862, 2e-05, 6e-05, 0.00517, 1.4e-07],
             [0.0001, 0.0, 6e-05, 2e-05, 0.00095, 7.4e-07]]]

    N = 3
    T = 273.15 + 70
    dT = T * 1e-8
    xs = [.2, .3, .5]
    GE = NRTL(T, xs, taus, alphas)
    assert eval(str(GE)).GE() == GE.GE()

    assert NRTL.from_JSON(GE.as_JSON()).__dict__ == GE.__dict__

    # gammas
    assert_close1d(
        GE.gammas(),
        [1.7795902383749216, 1.1495597830749005, 1.0736702352016942])

    ### Tau and derivatives
    taus_expected = [
        [0.06687993075720595, 1.9456413587531054, 1.2322559725492486],
        [-0.04186204696272491, 0.07047352903742096, 0.007348860249786843],
        [-0.21212866478360642, 0.13596095401379812, 0.0944497207779701]
    ]
    assert_close2d(taus_expected, GE.taus(), rtol=1e-14)

    # Tau temperature derivative
    dtaus_dT_numerical = (np.array(GE.to_T_xs(T + dT, xs).taus()) -
                          GE.taus()) / dT
    dtaus_dT_analytical = GE.dtaus_dT()
    dtaus_dT_expected = [[
        0.000317271602387579, -0.004653030923421638, -0.0029936361350323625
    ], [0.000406561723402744, 0.00034844970187634483, 0.0009043271077256468],
                         [
                             0.0011749522864265571, -0.00013143064874333648,
                             0.0005280368036263511
                         ]]
    assert_close2d(dtaus_dT_analytical, dtaus_dT_expected, rtol=1e-12)
    assert_close2d(dtaus_dT_numerical, dtaus_dT_analytical, rtol=4e-7)

    # tau second derivative
    d2taus_dT2_analytical = GE.d2taus_dT2()
    d2taus_dT2_expected = [[
        7.194089397742681e-07, 3.2628265646047626e-05, 2.0866597625703075e-05
    ], [
        -1.2443543228779117e-06, 8.394080699905074e-07, -1.169244972344292e-07
    ], [-3.669244570181493e-06, 1.955896362917401e-06, 1.4794908652710361e-06]]
    assert_close2d(d2taus_dT2_analytical, d2taus_dT2_expected, rtol=1e-12)
    d2taus_dT2_numerical = (np.array(GE.to_T_xs(T + dT, xs).dtaus_dT()) -
                            GE.dtaus_dT()) / dT
    assert_close2d(d2taus_dT2_analytical, d2taus_dT2_numerical, rtol=4e-7)

    # tau third derivative
    d3taus_dT3_analytical = GE.d3taus_dT3()
    d3taus_dT3_expected = [[
        3.425034691577827e-12, -2.703935984244539e-07, -1.7263626338812435e-07
    ], [1.2625331389834536e-08, 3.4351735085462344e-12, 1.535797829031479e-08],
                           [
                               4.116922701015044e-08, -1.4652079774338131e-08,
                               2.9650219270685846e-12
                           ]]

    # Not sure why precision of numerical test is so low, but confirmed with sympy.
    assert_close2d(d3taus_dT3_analytical, d3taus_dT3_expected, rtol=1e-12)
    d3taus_dT3_numerical = (np.array(GE.to_T_xs(T + dT, xs).d2taus_dT2()) -
                            GE.d2taus_dT2()) / dT
    assert_close2d(d3taus_dT3_numerical, d3taus_dT3_analytical, rtol=2e-5)

    # alphas
    alphas_expect = [[0.006863, 0.3177205, 0.334215],
                     [0.2971315, 0.013726, 0.328352],
                     [0.3033315, 0.3111945, 0.0171575]]
    assert_close2d(alphas_expect, GE.alphas(), rtol=1e-12)

    # dalphas_dT
    dalphas_dT_expect = [[2e-05, 7e-05, 0.0001], [1e-05, 4e-05, 8e-05],
                         [1e-05, 3e-05, 5e-05]]
    dalphas_dT_analytical = GE.dalphas_dT()
    assert_close2d(dalphas_dT_expect, dalphas_dT_analytical, rtol=1e-12)
    dalphas_dT_numerical = (np.array(GE.to_T_xs(T + 1e-4, xs).alphas()) -
                            GE.alphas()) / 1e-4
    assert_close2d(dalphas_dT_expect, dalphas_dT_numerical)

    # d2alphas_d2T
    d2alphas_d2T_numerical = (np.array(GE.to_T_xs(T + dT, xs).dalphas_dT()) -
                              GE.dalphas_dT()) / dT
    d2alphas_d2T_analytical = GE.d2alphas_dT2()
    assert_close2d(d2alphas_d2T_analytical, [[0] * N for _ in range(N)])
    assert_close2d(d2alphas_d2T_numerical, d2alphas_d2T_analytical, rtol=1e-12)

    # d3alphas_d3T
    d3alphas_d3T_numerical = (np.array(GE.to_T_xs(T + dT, xs).d2alphas_dT2()) -
                              GE.d2alphas_dT2()) / dT
    d3alphas_d3T_analytical = GE.d3alphas_dT3()
    assert_close2d(d3alphas_d3T_analytical, [[0] * N for _ in range(N)])
    assert_close2d(d3alphas_d3T_numerical, d3alphas_d3T_analytical, rtol=1e-12)

    # Gs
    Gs_expect = [[0.9995411083582052, 0.5389296989069797, 0.6624312965198783],
                 [1.0125162130984628, 0.999033148043276, 0.9975898960147673],
                 [1.0664605905163351, 0.9585722883795924, 0.9983807912510595]]
    assert_close2d(Gs_expect, GE.Gs())

    # dGs_dT
    dGs_dT_expect = [[
        -3.513420602780159e-06, 0.0007233344205287423, 0.000581146010596799
    ],
                     [
                         -0.00012189042196807427, -7.594411991210204e-06,
                         -0.00029680845584651057
                     ],
                     [
                         -0.000377824327942326, 3.529622902294454e-05,
                         -1.3759961112813966e-05
                     ]]
    dGs_dT_analytical = GE.dGs_dT()
    assert_close2d(dGs_dT_expect, dGs_dT_analytical, rtol=1e-12)
    dGs_dT_numerical = (np.array(GE.to_T_xs(T + 2.5e-5, xs).Gs()) -
                        GE.Gs()) / 2.5e-5
    assert_close2d(dGs_dT_numerical, dGs_dT_expect,
                   rtol=3e-7)  # Closest I could get

    # d2Gs_dT2
    d2Gs_dT2_expect = [[
        -1.7607728438831442e-08, -4.264997204215131e-06,
        -3.7132987505208185e-06
    ], [
        3.808051820202208e-07, -3.9301868673119065e-08, -1.773565965539868e-08
    ], [1.2957622532360591e-06, -5.745898135094948e-07, -7.78717985147786e-08]]
    d2Gs_dT2_analytical = GE.d2Gs_dT2()
    assert_close2d(d2Gs_dT2_expect, d2Gs_dT2_analytical, rtol=1e-12)
    d2Gs_dT2_numerical = (np.array(GE.to_T_xs(T + 4e-6, xs).dGs_dT()) -
                          GE.dGs_dT()) / 4e-6
    assert_close2d(d2Gs_dT2_numerical, d2Gs_dT2_analytical, rtol=2e-6)

    # d3Gs_dT3
    d3Gs_dT3_analytical = GE.d3Gs_dT3()
    d3Gs_dT3_expect = [[
        -4.298246167557067e-11, 2.282743128709054e-08, 2.3406412447900822e-08
    ], [
        -3.894534156411875e-09, -9.978151596051988e-11, -4.934296656436311e-09
    ], [
        -1.448282405010784e-08, 4.1384450135276364e-09, -2.1839009944794027e-10
    ]]
    d3Gs_dT3_numerical = (np.array(GE.to_T_xs(T + dT, xs).d2Gs_dT2()) -
                          GE.d2Gs_dT2()) / dT
    assert_close2d(d3Gs_dT3_analytical, d3Gs_dT3_numerical, rtol=1e-7)
    assert_close2d(d3Gs_dT3_expect, d3Gs_dT3_analytical, rtol=1e-12)

    # dGE_dT
    dGE_dT_expect = 2.258093406765717
    dGE_dT_analytical = GE.dGE_dT()
    assert_close(dGE_dT_expect, dGE_dT_analytical, rtol=1e-12)

    def to_diff(T):
        return GE.to_T_xs(T, xs).GE()

    dGE_dT_numerical = derivative(to_diff, T, dx=1, order=17)
    assert_close(dGE_dT_analytical, dGE_dT_numerical, rtol=1e-12)

    # d2GE_dT2
    def to_diff(T):
        return GE.to_T_xs(T, xs).dGE_dT()

    d2GE_dT2_numerical = derivative(to_diff, T, dx=5, order=17)
    d2GE_dT2_expected = 0.007412479461681191
    d2GE_dT2_analytical = GE.d2GE_dT2()
    assert_close(d2GE_dT2_expected, d2GE_dT2_analytical, rtol=1e-12)
    assert_close(d2GE_dT2_numerical, d2GE_dT2_analytical, rtol=1e-12)

    # dGE_dxs
    def to_jac(xs):
        return GE.to_T_xs(T, xs).GE()

    dGE_dxs_analytical = GE.dGE_dxs()
    dGE_dxs_expected = [
        1644.4832445701338, 397.6635234141318, 202.8071951151063
    ]
    assert_close1d(dGE_dxs_analytical, dGE_dxs_expected, rtol=1e-12)
    dGE_dxs_numerical = jacobian(to_jac, xs, perturbation=1e-8)
    assert_close1d(dGE_dxs_numerical, dGE_dxs_expected, rtol=1e-7)

    # d2GE_dxixjs - more decimals in numdifftools
    def to_hess(xs):
        return GE.to_T_xs(T, xs).GE()

    d2GE_dxixjs_expect = [
        [-1690.7876619180952, 1208.6126803238276, -48.852543427058286],
        [1208.6126803238276, -468.99032836115686, -202.0508751128366],
        [-48.852543427058606, -202.0508751128365, 140.77154243852513]
    ]
    d2GE_dxixjs_analytical = GE.d2GE_dxixjs()
    assert_close2d(d2GE_dxixjs_expect, d2GE_dxixjs_analytical, rtol=1e-12)
    d2GE_dxixjs_numerical = hessian(to_hess, xs, perturbation=5e-5)
    assert_close2d(d2GE_dxixjs_numerical, d2GE_dxixjs_analytical, rtol=3e-4)

    # d2GE_dTdxs - matched really well
    d2GE_dTdxs_expect = [
        3.053720836458414, 1.8759446742883084, 2.1691316743750826
    ]
    d2GE_dTdxs_analytical = GE.d2GE_dTdxs()
    assert_close1d(d2GE_dTdxs_expect, d2GE_dTdxs_analytical, rtol=1e-12)

    def to_jac(xs):
        return GE.to_T_xs(T, xs).dGE_dT()

    d2GE_dTdxs_numerical = jacobian(to_jac, xs, perturbation=3e-8)
    assert_close1d(d2GE_dTdxs_analytical, d2GE_dTdxs_numerical, rtol=1e-7)