예제 #1
0
    def test_formic_acid(self):
        rxns = [
            'HCHO + 0.5*O2 -> HCOOH', '        HCOOH -> CO + H2O',
            '       2*HCHO -> HCOOCH3', '      HCOOCH3 -> CH3OH + HCOOH'
        ]

        A_ref = sp.array([[-1., 0., -2., 0.], [-0.5, 0., 0., 0.],
                          [1., -1., 0., 1.], [0., 1., 0.,
                                              0.], [0., 1., 0., 0.],
                          [0., 0., 1., -1.], [0., 0., 0., 1.]])

        d_ref = {
            'HCHO': 0,
            'O2': 1,
            'HCOOH': 2,
            'CO': 3,
            'H2O': 4,
            'HCOOCH3': 5,
            'CH3OH': 6
        }

        A, d = genStoichMat(rxns)

        assert (sameRows(A, A_ref)
                and equivalentDictionaries(d, d_ref) is True)
예제 #2
0
    def test_6(self):
        # A -> B

        # binary system
        Cf0 = sp.array([1., 0])

        stoich_mat = sp.array([[-1., 1]]).T

        Cs, Es = stoich_S_1D(Cf0, stoich_mat)

        Cs_ref = sp.array([[1., 0], [0, 1]])

        Es_ref = sp.array([[0., 1]]).T

        assert (sameRows(Cs, Cs_ref))
        assert (sameRows(Es, Es_ref))
예제 #3
0
    def test_UCG_1(self):
        rxns = [
            'C + O2 -> CO2', 'C + CO2 -> 2*CO', 'CO + 0.5*O2 -> CO2',
            'C + H2O -> CO + H2', 'CO + H2O -> CO2 + H2',
            'CO2 + H2 -> CO + H2O', 'C + 2*H2 -> CH4',
            'CH4 + H2O -> CO + 3*H2', 'CO + 3*H2 -> CH4 + H2O'
        ]

        A_ref = sp.array([[-1., -1, 0, -1, 0, 0, -1, 0, 0],
                          [-1, 0, -0.5, 0, 0, 0, 0, 0, 0],
                          [1, -1, 1, 0, 1, -1, 0, 0, 0],
                          [0, 2, -1, 1, -1, 1, 0, 1, -1],
                          [0, 0, 0, -1, -1, 1, 0, -1, 1],
                          [0, 0, 0, 1, 1, -1, -2, 3, -3],
                          [0, 0, 0, 0, 0, 0, 1, -1, 1]])
        d_ref = {
            'C': 0,
            'O2': 1,
            'CO2': 2,
            'CO': 3,
            'H2O': 4,
            'H2': 5,
            'CH4': 6
        }
        A, d = genStoichMat(rxns)

        assert (sameRows(A, A_ref)
                and equivalentDictionaries(d, d_ref) is True)
예제 #4
0
    def test_1(self):
        Xs = sp.array([[1.0, 2.0, 3.0], [2.0, -1.0, 3.0]])

        bounds_ref = sp.array([[1.0, -1.0, 3.0], [2.0, 2.0, 3.0]])

        bounds = getExtrema(Xs)

        assert (sameRows(bounds, bounds_ref) is True)
예제 #5
0
    def test_1(self):
        # A + B -> C

        # 0-D array feed
        Cf0 = sp.array([1., 1, 0])

        # column vector stoich matrix
        stoich_mat = sp.array([[-1., -1, 1]]).T

        Cs, Es = stoich_S_1D(Cf0, stoich_mat)

        Cs_ref = sp.array([[1., 1, 0], [0, 0, 1]])

        Es_ref = sp.array([[0., 1]]).T

        assert (sameRows(Cs, Cs_ref))
        assert (sameRows(Es, Es_ref))
예제 #6
0
    def test_1(self):
        # 2-D system
        # A -> B -> C

        # 0-D array feed
        Cf0 = sp.array([1., 0, 0])

        stoich_mat = sp.array([[-1., 0], [1, -1], [0, 1]])

        Cs, Es = stoich_S_nD(Cf0, stoich_mat)

        Cs_ref = sp.array([[1., 0, 0], [0, 1, 0], [0, 0, 1]])

        Es_ref = sp.array([[0., 0], [1, 0], [1, 1]])

        assert (sameRows(Es, Es_ref))
        assert (sameRows(Cs, Cs_ref))
예제 #7
0
    def test_1(self):
        # 2-D nullspace
        A = sp.array([[1., 0, 0]])

        N = nullspace(A)
        N_ref = sp.array([[0., 0], [1, 0], [0, 1]])

        assert (sameRows(N, N_ref) is True)
예제 #8
0
    def test_2(self):
        # 2-D system
        # A -> B -> C

        # Test negative zero
        Cf0 = sp.array([1., -0, -0])

        stoich_mat = sp.array([[-1., 0], [1, -1], [0, 1]])

        Cs, Es = stoich_S_nD(Cf0, stoich_mat)

        Cs_ref = sp.array([[1., 0, 0], [0, 1, 0], [0, 0, 1]])

        Es_ref = sp.array([[0., 0], [1, 0], [1, 1]])

        assert (sameRows(Es, Es_ref))
        assert (sameRows(Cs, Cs_ref))
예제 #9
0
    def test_3(self):
        rxns = ["A + B -> 2*B", "B + C -> 3*C"]
        A, d = genStoichMat(rxns)

        A_ref = sp.array([[-1., 0.], [1., -1.], [0., 2.]])
        d_ref = {'A': 0, 'B': 1, 'C': 2}

        assert (sameRows(A, A_ref) is True)
        assert (equivalentDictionaries(d, d_ref) is True)
예제 #10
0
    def test_1(self):
        r = "A + B -> 2*B"
        A, d = genStoichMat([r])

        A_ref = sp.array([[-1.0, 1.0]]).T
        d_ref = {'A': 0, 'B': 1}

        assert (sameRows(A, A_ref) is True)
        assert (equivalentDictionaries(d, d_ref) is True)
예제 #11
0
    def test_1(self):
        xs = gridPts(2, [0., 1., 2., 3.5])

        xs_ref = sp.array([[ 0. ,  2. ],
                           [ 0. ,  3.5],
                           [ 1. ,  2. ],
                           [ 1. ,  3.5]])

        assert sameRows(xs, xs_ref) == True
예제 #12
0
    def test_NH3_1(self):
        rxn = ["N2 + 3*H2 -> 2*NH3"]

        A_ref = sp.array([[-1.0, -3.0, 2.0]]).T
        d_ref = {'N2': 0, 'H2': 1, 'NH3': 2}
        A, d = genStoichMat(rxn)

        assert (sameRows(A, A_ref)
                and equivalentDictionaries(d, d_ref) is True)
예제 #13
0
    def test_2(self):
        # 1-D subspace in 5-D
        A = sp.array([[1., 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0],
                      [0, 0, 0, 1, 0]])

        N = nullspace(A)
        N_ref = sp.array([[0., 0, 0, 0, 1]]).T

        assert (sameRows(N, N_ref) is True)
예제 #14
0
    def test_3D_2(self):
        # single feed, as a 0-D array, in packed into a one-element list

        # A -> B -> C
        # 2A -> D
        Cf = sp.array([1., 0, 0, 0])
        stoich_mat = sp.array([[-1., 0, -2], [1, -1, 0], [0, 1, 0], [0, 0, 1]])

        S = stoichSubspace([Cf], stoich_mat)
        Cs = S["all_Cs"]
        Es = S["all_Es"]

        Cs_ref = sp.array([[1., 0, 0, 0], [0, 0, 0, 0.5], [0, 1, 0, 0],
                           [0, 0, 1, 0]])

        Es_ref = sp.array([[0, 0, 0], [0, 0, 0.5], [1, 0, 0], [1, 1, 0]])

        assert (sameRows(Cs, Cs_ref) is True)
        assert (sameRows(Es, Es_ref) is True)
예제 #15
0
    def test_3D_1(self):
        # single feed, as a 0-D array

        # A -> B -> C
        # 2A -> D
        Cf = sp.array([1., 0, 0, 0])
        stoich_mat = sp.array([[-1., 0, -2], [1, -1, 0], [0, 1, 0], [0, 0, 1]])

        S = stoichSubspace(Cf, stoich_mat)
        Cs = S["all_Cs"]
        Es = S["all_Es"]

        Cs_ref = sp.array([[1., 0, 0, 0], [0, 0, 0, 0.5], [0, 1, 0, 0],
                           [0, 0, 1, 0]])

        Es_ref = sp.array([[0, 0, 0], [0, 0, 0.5], [1, 0, 0], [1, 1, 0]])

        assert (sameRows(Cs, Cs_ref) is True)
        assert (sameRows(Es, Es_ref) is True)
예제 #16
0
    def test_1(self):

        rxn_str = ["A -> B"]

        A, d = genStoichMat(rxn_str)
        A_ref = sp.array([[-1.0], [1.0]])
        d_ref = {'A': 0, 'B': 1}

        assert (sameRows(A, A_ref)
                and equivalentDictionaries(d, d_ref) is True)
예제 #17
0
    def test_CH4_reform(self):
        rxns = ['CH4 + H2O -> CO + 3*H2', 'CO + H2O -> CO2 + H2']

        A_ref = sp.array([[-1.0, 0.0], [-1.0, -1.0], [1.0, -1.0], [3.0, 1.0],
                          [0.0, 1.0]])
        d_ref = {'CH4': 0, 'H2O': 1, 'CO': 2, 'H2': 3, 'CO2': 4}
        A, d = genStoichMat(rxns)

        assert (sameRows(A, A_ref)
                and equivalentDictionaries(d, d_ref) is True)
예제 #18
0
    def test_3(self):
        # test along rows instead of columns

        Xs = sp.array([[1.0, 2.0, 3.0], [2.0, -1.0, 3.0]])

        bounds_ref = sp.array([[1.0, -1.0], [3.0, 3.0]])

        bounds = getExtrema(Xs, axis=1)

        assert (sameRows(bounds, bounds_ref) is True)
예제 #19
0
    def test_vdv3D(self):

        rxn_str = ["A -> B", "B -> C", "2*A -> D"]

        A, d = genStoichMat(rxn_str)
        A_ref = sp.array([[-1., 0, -2], [1, -1, 0], [0, 1, 0], [0, 0, 1]])
        d_ref = {'A': 0, 'B': 1, 'C': 2, 'D': 3}

        assert (sameRows(A, A_ref)
                and equivalentDictionaries(d, d_ref) is True)
예제 #20
0
    def test_4(self):
        # 3-D van de Vusse system
        # A -> B -> C
        # 2A -> D

        # column vector feed
        Cf0 = sp.array([[1., 0, 0, 0]]).T

        stoich_mat = sp.array([[-1., 0, -2], [1, -1, 0], [0, 1, 0], [0, 0, 1]])

        Cs, Es = stoich_S_nD(Cf0, stoich_mat)

        Cs_ref = sp.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0],
                           [0, 0, 0, 0.5]])

        Es_ref = sp.array([[0, 0, 0.5], [1, 1, 0], [0, 0, 0], [1, 0, 0]])

        assert (sameRows(Es, Es_ref))
        assert (sameRows(Cs, Cs_ref))
예제 #21
0
    def test_2(self):
        Cs = sp.array([[0.1, 0], [0.1, 0], [0.1, 0]], dtype=sp.float64)

        Cs_ref = sp.array([[0.1, 0]], dtype=sp.float64)

        axis_lims = sp.array([0, 1, 0, 1], dtype=sp.float64)

        Cs_ans = cullPts(Cs, min_dist=0.0, axis_lims=axis_lims)

        assert (sameRows(Cs_ref, Cs_ans) is True)
예제 #22
0
def test_steam_reforming_singleFeed_1():
    # methane steam reforming + water-gas shift
    # CH4 + H2O -> CO + 3H2
    # CO + H2O -> CO2 + H2

    Cf0 = sp.array([1., 1, 1, 0, 0])

    stoich_mat = sp.array([[-1., 0], [-1, -1], [1, -1], [3, 1], [0, 1]])

    S = stoichSubspace(Cf0, stoich_mat)
    Cs = S["all_Cs"]
    Es = S["all_Es"]

    Cs_ref = sp.array([[0, 0, 2, 3, 0], [1.25, 0.5, 0, 0, 0.75],
                       [1, 1, 1, 0, 0], [1, 0, 0, 1, 1]])

    Es_ref = sp.array([[1, 0], [-0.25, 0.75], [0, 0], [0, 1]])

    assert (sameRows(Cs, Cs_ref) is True)
    assert (sameRows(Es, Es_ref) is True)
예제 #23
0
    def test_1(self):

        # reactions written in tuple format
        rxn_str = ("A -> B", )

        A, d = genStoichMat(rxn_str)
        A_ref = sp.array([[-1.0], [1.0]])
        d_ref = {'A': 0, 'B': 1}

        assert (sameRows(A, A_ref)
                and equivalentDictionaries(d, d_ref) is True)
예제 #24
0
    def test_2(self):
        Xs_1 = sp.array([[1.0, 2.0, 3.0], [2.0, -1.0, 3.0]])

        Xs_2 = sp.array([[-1.0, -4.5, 6.5], [0.0, 1.0, -10.0]])

        Xs_list = [Xs_1, Xs_2, Xs_2]

        bounds_ref = sp.array([[-1.0, -4.5, -10.0], [2.0, 2.0, 6.5]])

        bounds = getExtrema(Xs_list)

        assert (sameRows(bounds, bounds_ref) is True)
예제 #25
0
    def test_1(self):
        # 2-D mass balance triangle
        A = sp.array([[-1., 0],
                      [0, -1],
                      [1, 1]])

        b = sp.array([[0., 0, 1]]).T

        vs = con2vert(A, b)
        vs_ref = sp.array([[0., 1], [0, 0], [1, 0]])

        assert (sameRows(vs, vs_ref) is True)
예제 #26
0
    def test_BTX(self):
        rxns = ['B + 0.5*E -> T', 'T + 0.5*E -> X', '2*B -> D + H']

        A_ref = sp.array([[-1.0, 0.0, -2.0], [-0.5, -0.5, 0.0],
                          [1.0, -1.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0],
                          [0.0, 0.0, 1.0]])
        d_ref = {'B': 0, 'E': 1, 'T': 2, 'X': 3, 'D': 4, 'H': 5}

        A, d = genStoichMat(rxns)

        assert (sameRows(A, A_ref)
                and equivalentDictionaries(d, d_ref) is True)
예제 #27
0
    def test_1D_1(self):
        # A + B -> C

        # two feeds
        Cf1 = sp.array([1., 1, 0])
        Cf2 = sp.array([1, 0.5, 0.1])

        feeds = [Cf1, Cf2]

        stoich_mat = sp.array([[-1., -1, 1]]).T

        S = stoichSubspace(feeds, stoich_mat)

        Cs1 = S["all_Cs"][0]
        Cs2 = S["all_Cs"][1]
        Es1 = S["all_Es"][0]
        Es2 = S["all_Es"][1]
        Es_bounds = S["bounds_Es"]
        Cs_bounds = S["bounds_Cs"]

        Cs1_ref = sp.array([[1., 1, 0], [0, 0, 1]])
        Cs2_ref = sp.array([[1., 0.5, 0.1], [0.5, 0, 0.6]])

        Es1_ref = sp.array([[0., 1]]).T
        Es2_ref = sp.array([[0., 0.5]]).T

        Es_bounds_ref = sp.array([[0., 1]]).T
        Cs_bounds_ref = sp.array([[0., 0, 0], [1, 1, 1]])

        assert (sameRows(Cs1, Cs1_ref) is True)
        assert (sameRows(Es1, Es1_ref) is True)
        assert (sameRows(Cs2, Cs2_ref) is True)
        assert (sameRows(Es2, Es2_ref) is True)
        assert (sameRows(Es_bounds, Es_bounds_ref) is True)
        assert (sameRows(Cs_bounds, Cs_bounds_ref) is True)
예제 #28
0
    def test_3(self):

        rxn_str = [
            'A + 2*B -> 1.5*C', 'A + C -> 0.5*D', 'C + 3.2*D -> E + 0.1*F'
        ]

        A, d = genStoichMat(rxn_str)
        A_ref = sp.array([[-1., -1, 0], [-2, 0, 0], [1.5, -1, -1],
                          [0, 0.5, -3.2], [0, 0, 1], [0, 0, 0.1]])
        d_ref = {'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4, 'F': 5}

        assert (sameRows(A, A_ref)
                and equivalentDictionaries(d, d_ref) is True)
예제 #29
0
    def test_3(self):
        # test along rows instead of columns

        Xs_1 = sp.array([[1.0, 2.0, 3.0], [2.0, -1.0, 3.0]])

        Xs_2 = sp.array([[-1.0, -4.5, 6.5], [0.0, 1.0, -10.0]])

        Xs_list = [Xs_1, Xs_2, Xs_2]

        bounds_ref = sp.array([[1.0, -1.0, -4.5, -10.0, -4.5, -10.0],
                               [3.0, 3.0, 6.5, 1.0, 6.5, 1.0]])

        bounds = getExtrema(Xs_list, axis=1)

        assert (sameRows(bounds, bounds_ref) is True)
예제 #30
0
    def test_3(self):
        # mass balance triangle cut at y = 0.5
        A = sp.array([[-1., 0],
                      [0, -1],
                      [1, 1],
                      [0, 1]])

        b = sp.array([[0., 0, 1, 0.5]]).T

        vs = con2vert(A, b)
        vs_ref = sp.array([[0, 0.5],
                           [0, 0],
                           [1, 0],
                           [0.5, 0.5]])

        assert (sameRows(vs, vs_ref) is True)