Example #1
0
def test_UNIFAC_numpy_output():
    from thermo.unifac import DOUFIP2006, DOUFSG

    UNIFACnp = thermo.numba.unifac.UNIFAC
    N = 4
    T = 373.15
    xs = [0.2, 0.3, 0.1, 0.4]
    chemgroups = [{9: 6}, {78: 6}, {1: 1, 18: 1}, {1: 1, 2: 1, 14: 1}]
    model = thermo.unifac.UNIFAC.from_subgroups(T=T,
                                                xs=xs,
                                                chemgroups=chemgroups,
                                                version=1,
                                                interaction_data=DOUFIP2006,
                                                subgroups=DOUFSG)

    modelnp = UNIFACnp.from_subgroups(T=T,
                                      xs=np.array(xs),
                                      chemgroups=chemgroups,
                                      version=1,
                                      interaction_data=DOUFIP2006,
                                      subgroups=DOUFSG)
    modelnp2 = modelnp.to_T_xs(T=T, xs=np.array(xs))

    check_np_output_activity(model, modelnp, modelnp2)

    json_string = modelnp.as_json()
    new = UNIFACnp.from_json(json_string)
    assert new == modelnp
Example #2
0
def test_NRTL_numpy_output():
    NRTLnp = thermo.numba.nrtl.NRTL
    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]
    model = NRTL(T, xs, taus, alphas)
    modelnp = NRTLnp(T=T,
                     xs=np.array(xs),
                     tau_coeffs=np.array(taus),
                     alpha_coeffs=np.array(alphas))
    modelnp2 = modelnp.to_T_xs(T=T, xs=np.array(xs))

    check_np_output_activity(model, modelnp, modelnp2)
Example #3
0
def test_UNIQUAC_numpy_output():
    UNIQUACnp = thermo.numba.uniquac.UNIQUAC

    N = 3
    T = 331.42
    xs = [0.229, 0.175, 0.596]
    rs = [2.5735, 2.87, 1.4311]
    qs = [2.336, 2.41, 1.432]
    # madeup numbers to match Wilson example roughly
    tausA = [[0.0, -1.05e-4, -2.5e-4], [3.9e-4, 0.0, 1.6e-4],
             [-1.123e-4, 6.5e-4, 0]]
    tausB = [[0.0, 235.0, -169.0], [-160, 0.0, -715.0], [11.2, 144.0, 0.0]]
    tausC = [[0.0, -4.23e-4, 2.9e-4], [6.1e-4, 0.0, 8.2e-5],
             [-7.8e-4, 1.11e-4, 0]]
    tausD = [[0.0, -3.94e-5, 2.22e-5], [8.5e-5, 0.0, 4.4e-5],
             [-7.9e-5, 3.22e-5, 0]]
    tausE = [[0.0, -4.2e2, 8.32e2], [2.7e2, 0.0, 6.8e2], [3.7e2, 7.43e2, 0]]
    tausF = [[0.0, 9.64e-8, 8.94e-8], [1.53e-7, 0.0, 1.11e-7],
             [7.9e-8, 2.276e-8, 0]]
    ABCDEF = (tausA, tausB, tausC, tausD, tausE, tausF)
    ABCDEFnp = tuple(np.array(v) for v in ABCDEF)

    model = UNIQUAC(T=T, xs=xs, rs=rs, qs=qs, ABCDEF=ABCDEF)
    modelnp = UNIQUACnp(T=T,
                        xs=np.array(xs),
                        rs=np.array(rs),
                        qs=np.array(qs),
                        ABCDEF=ABCDEFnp)
    modelnp2 = modelnp.to_T_xs(T=T, xs=np.array(xs))

    check_np_output_activity(model, modelnp, modelnp2)
Example #4
0
def test_numpy_inputs():
    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]]

    model = RegularSolution(T, xs, Vs, SPs, lambda_coeffs)
    modelnp = RegularSolution(T, np.array(xs), np.array(Vs), np.array(SPs),
                              np.array(lambda_coeffs))
    modelnp2 = modelnp.to_T_xs(T=model.T * (1.0 - 1e-16), xs=np.array(xs))
    check_np_output_activity(model, modelnp, modelnp2)

    json_string = modelnp.as_json()
    new = RegularSolution.from_json(json_string)
    assert new == modelnp

    assert model.model_hash() == modelnp.model_hash()
    assert new.model_hash() == modelnp.model_hash()
    assert new.model_hash() == modelnp2.model_hash()

    # Pickle checks
    modelnp_pickle = pickle.loads(pickle.dumps(modelnp))
    assert modelnp_pickle == modelnp
    model_pickle = pickle.loads(pickle.dumps(model))
    assert model_pickle == model
Example #5
0
def test_Wilson_numpy_output():
    T = 331.42
    N = 3

    from thermo.numba import Wilson as Wilsonnp
    A = [[0.0, 3.870101271243586, 0.07939943395502425],
         [-6.491263271243587, 0.0, -3.276991837288562],
         [0.8542855660449756, 6.906801837288562, 0.0]]
    B = [[0.0, -375.2835, -31.1208], [1722.58, 0.0, 1140.79],
         [-747.217, -3596.17, -0.0]]
    D = [[-0.0, -0.00791073, -0.000868371], [0.00747788, -0.0, -3.1e-05],
         [0.00124796, -3e-05, -0.0]]

    C = E = F = [[0.0] * N for _ in range(N)]

    xs = [0.229, 0.175, 0.596]

    model = thermo.wilson.Wilson(T=T, xs=xs, ABCDEF=(A, B, C, D, E, F))
    modelnp = Wilsonnp(T=T,
                       xs=np.array(xs),
                       ABCDEF=(np.array(A), np.array(B), np.array(C),
                               np.array(D), np.array(E), np.array(F)))
    modelnp2 = modelnp.to_T_xs(T=T, xs=np.array(xs))

    check_np_output_activity(model, modelnp, modelnp2)
Example #6
0
def test_IdealSolution_np_out():
    from thermo import IdealSolution
    from thermo.numba import IdealSolution as IdealSolutionnp
    model = IdealSolution(T=300.0, xs=[.1, .2, .3, .4])
    modelnp = IdealSolutionnp(T=300.0, xs=np.array([.1, .2, .3, .4]))
    modelnp2 = modelnp.to_T_xs(T=310.0, xs=np.array([.2, .2, .2, .4]))

    check_np_output_activity(model, modelnp, modelnp2)
Example #7
0
def test_NRTL_numpy_output():
    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]
    model = NRTL(T, xs, taus, alphas)
    modelnp = NRTL(T=T,
                   xs=np.array(xs),
                   tau_coeffs=np.array(taus),
                   alpha_coeffs=np.array(alphas))
    modelnp2 = modelnp.to_T_xs(T=T, xs=np.array(xs))

    check_np_output_activity(model, modelnp, modelnp2)

    json_string = modelnp.as_json()
    new = NRTL.from_json(json_string)
    assert new == modelnp

    assert model.model_hash() == modelnp.model_hash()
    assert new.model_hash() == modelnp.model_hash()
    assert new.model_hash() == modelnp2.model_hash()

    # Pickle checks
    modelnp_pickle = pickle.loads(pickle.dumps(modelnp))
    assert modelnp_pickle == modelnp
    model_pickle = pickle.loads(pickle.dumps(model))
    assert model_pickle == model
Example #8
0
def test_UNIQUAC_numpy_inputs():

    N = 3
    T = 331.42
    xs = [0.229, 0.175, 0.596]
    rs = [2.5735, 2.87, 1.4311]
    qs = [2.336, 2.41, 1.432]
    # madeup numbers to match Wilson example roughly
    tausA = [[0.0, -1.05e-4, -2.5e-4], [3.9e-4, 0.0, 1.6e-4],
             [-1.123e-4, 6.5e-4, 0]]
    tausB = [[0.0, 235.0, -169.0], [-160, 0.0, -715.0], [11.2, 144.0, 0.0]]
    tausC = [[0.0, -4.23e-4, 2.9e-4], [6.1e-4, 0.0, 8.2e-5],
             [-7.8e-4, 1.11e-4, 0]]
    tausD = [[0.0, -3.94e-5, 2.22e-5], [8.5e-5, 0.0, 4.4e-5],
             [-7.9e-5, 3.22e-5, 0]]
    tausE = [[0.0, -4.2e2, 8.32e2], [2.7e2, 0.0, 6.8e2], [3.7e2, 7.43e2, 0]]
    tausF = [[0.0, 9.64e-8, 8.94e-8], [1.53e-7, 0.0, 1.11e-7],
             [7.9e-8, 2.276e-8, 0]]
    ABCDEF = (tausA, tausB, tausC, tausD, tausE, tausF)
    ABCDEFnp = tuple(np.array(v) for v in ABCDEF)

    model = UNIQUAC(T=T, xs=xs, rs=rs, qs=qs, ABCDEF=ABCDEF)
    modelnp = UNIQUAC(T=T,
                      xs=np.array(xs),
                      rs=np.array(rs),
                      qs=np.array(qs),
                      ABCDEF=ABCDEFnp)
    modelnp2 = modelnp.to_T_xs(T=T, xs=np.array(xs))

    check_np_output_activity(model, modelnp, modelnp2)

    json_string = modelnp.as_json()
    new = UNIQUAC.from_json(json_string)
    assert new == modelnp

    # Pickle checks
    modelnp_pickle = pickle.loads(pickle.dumps(modelnp))
    assert modelnp_pickle == modelnp
    model_pickle = pickle.loads(pickle.dumps(model))
    assert model_pickle == model
Example #9
0
def test_wilson_np_output_and_hash():
    T = 331.42
    N = 3

    A = [[0.0, 3.870101271243586, 0.07939943395502425],
         [-6.491263271243587, 0.0, -3.276991837288562],
         [0.8542855660449756, 6.906801837288562, 0.0]]
    B = [[0.0, -375.2835, -31.1208], [1722.58, 0.0, 1140.79],
         [-747.217, -3596.17, -0.0]]
    D = [[-0.0, -0.00791073, -0.000868371], [0.00747788, -0.0, -3.1e-05],
         [0.00124796, -3e-05, -0.0]]

    C = E = F = [[0.0] * N for _ in range(N)]

    xs = [0.229, 0.175, 0.596]

    model = Wilson(T=T, xs=xs, ABCDEF=(A, B, C, D, E, F))
    modelnp = Wilson(T=T,
                     xs=np.array(xs),
                     ABCDEF=(np.array(A), np.array(B), np.array(C),
                             np.array(D), np.array(E), np.array(F)))
    modelnp2 = modelnp.to_T_xs(T=T, xs=np.array(xs))

    check_np_output_activity(model, modelnp, modelnp2)

    json_string = modelnp.as_json()
    new = Wilson.from_json(json_string)
    assert new == modelnp

    assert model.model_hash() == modelnp.model_hash()
    assert new.model_hash() == modelnp.model_hash()
    assert new.model_hash() == modelnp2.model_hash()

    # Pickle checks
    modelnp_pickle = pickle.loads(pickle.dumps(modelnp))
    assert modelnp_pickle == modelnp
    model_pickle = pickle.loads(pickle.dumps(model))
    assert model_pickle == model
Example #10
0
def test_IdealSolution_numpy_output():
    model = IdealSolution(T=300.0, xs=[.1, .2, .3, .4])
    modelnp = IdealSolution(T=300.0, xs=np.array([.1, .2, .3, .4]))
    modelnp2 = modelnp.to_T_xs(T=model.T * (1.0 - 1e-16),
                               xs=np.array([.1, .2, .3, .4]))
    check_np_output_activity(model, modelnp, modelnp2)

    json_string = modelnp.as_json()
    new = IdealSolution.from_json(json_string)
    assert new == modelnp

    new = IdealSolution.from_json(json.loads(json.dumps(modelnp.as_json())))
    assert new == modelnp

    assert model.model_hash() == modelnp.model_hash()
    assert new.model_hash() == modelnp.model_hash()
    assert new.model_hash() == modelnp2.model_hash()

    # Pickle checks
    modelnp_pickle = pickle.loads(pickle.dumps(modelnp))
    assert modelnp_pickle == modelnp
    model_pickle = pickle.loads(pickle.dumps(model))
    assert model_pickle == model