Ejemplo n.º 1
0
def test_bad_reactant():
    """test that input parser correctly handles reactants not matching the species array"""
    try:
        reactions = chemkin('tests/test_xml/rxns_bad_reactants.xml')
    except ValueError as e:
        assert type(e) == ValueError
        print(e)
Ejemplo n.º 2
0
    def start(self):
        global myFileString
        print("start")
        T = 273.15
        x_init = np.array([100, 1, 1, 1])  #initial concentration
        t_max = 300  #integration end time in seconds
        dt = 0.01  #step size in seconds
        cs = ChemSolver(chemkin('TaskD.xml'))
        cs.solve(x_init, T, t_max, dt, algorithm='vode', nsteps=5000)

        #time_array, conc_array, rxnrate_array = cs.get_results()

        cs.save_results('SimulationData/TaskDSimulationData' + myFileString +
                        '.csv')

        cv = ChemViz(cs)
        cv.plot_time_series(
            'concentration',
            tmin=0,
            tmax=300,
            species=['a', 'b', 'c', 'd'],
            outputfile='ConcentrationGraphs/TaskDConcentrationSeries' +
            myFileString + '.png')
        #cv.html_report('HTMLReports/TaskDHTMLReport' + myFileString + '.html')

        self.iterate()
        return
Ejemplo n.º 3
0
def test_singlereversible():
    reactions = chemkin('tests/test_xml/rxns_singlereversible.xml')
    x = np.array([2., 1., 0.5, 1.])
    T = 1500
    expect = np.array(
        [2.97178272e+14, 2.97178272e+14, -2.97178272e+14, -2.97178272e+14])
    assert str(reactions.reaction_rate(x, T)) == str(expect)
Ejemplo n.º 4
0
def test_not_implement():
    """Test that input parser correctly handles reaction types and rate coefficients that are not implemented"""
    try:
        reactions = chemkin('tests/test_xml/rxns_bad_not_implement.xml')
    except NotImplementedError as e:
        assert type(e) == NotImplementedError
        print(e)
Ejemplo n.º 5
0
def run(myFileString):
    global file_name
    T = 273.15
    x_init = np.array([100, 0, 1, 1])  #initial concentration
    t_max = 300  #integration end time in seconds
    dt = 0.1  #step size in seconds
    #rxn_system = chemkin(filename)
    cs = ChemSolver(chemkin(file_name))
    cs.solve(x_init, T, t_max, dt, algorithm='lsoda')

    #time_array, conc_array, rxnrate_array = cs.get_results()

    cs.save_results('SimulationData/TaskDSimulationData' + myFileString +
                    '.csv')

    cv = ChemViz(cs)
    cv.plot_time_series(
        'concentration',
        tmin=0,
        tmax=300,
        species=['a', 'b', 'c', 'd'],
        outputfile='ConcentrationGraphs/TaskDConcentrationSeries' +
        myFileString + '.png')

    #cv.plot_time_series('reactionrate', tmin=1.e-13, tmax=300, outputfile='TaskDReactionRateSeries' + str(number) + '.png')
    #cv.html_report('HTMLReports/TaskDHTMLReport' + myFileString + '.html')
    # simpleIO('cs.pkl').to_pickle(cs)
    # cs2 = simpleIO('cs.pkl').read_pickle()
    return
Ejemplo n.º 6
0
def test_reversible():
    reactions = chemkin('tests/test_xml/rxns_reversible.xml')
    x = np.array([2., 1., 0.5, 1., 1., 0., 0., 0.25])
    T = 1500
    expect = np.array([
        3.77689350e+14, -3.81148508e+14, -4.18872924e+14, 6.96275658e+12,
        3.07172197e+13, 3.93416746e+14, 1.66470991e+13, -2.54117388e+13
    ])
    assert str(reactions.reaction_rate(x, T)) == str(expect)
Ejemplo n.º 7
0
def test_mixedreversible():
    reactions = chemkin('tests/test_xml/rxnset_mixedreversible_long.xml')
    x = np.array([2., 1., 0.5, 1., 1., 0., 0., 0.25])
    T = 1500
    expect = np.array([
        -1.51420660e+13, 1.22682375e+13, -2.60415020e+13, 6.37742014e+12,
        3.13025562e+13, 0.00000000e+00, 1.66470929e+13, -2.54117388e+13
    ])
    assert str(reactions.reaction_rate(x, T)) == str(expect)
Ejemplo n.º 8
0
def test_singlerxnxml():
    """testing that single reaction systems are handled correctly"""

    reactions = chemkin('tests/test_xml/rxns_single.xml')
    expect = np.array([-1.e4, -1.e4, 1.e4, 1.e4])
    assert all(
        reactions.reaction_rate([1, 1, 1, 1], 1000).astype(int) ==
        expect.astype(int))
    return reactions
Ejemplo n.º 9
0
def test_dimension_error():
    """
    check that inconsistencies in input params are handled correctly
    """
    try:
        reactions = chemkin('tests/test_xml/rxns_dimensionerror.xml')
    except ValueError as e:
        assert type(e) == ValueError
        print(e)
Ejemplo n.º 10
0
def test_long():
    reactions = chemkin('tests/test_xml/rxnset_long.xml')
    x = np.array([2., 1., 0.5, 1., 1., 0., 0., 0.25])
    T = 1500
    print(reactions.reaction_rate(x, T))
    expect = np.array([
        -7.10942556e+12, -1.58164670e+13, 2.20952666e+13, -1.65522031e+12,
        1.12504921e+13, 0.00000000e+00, 1.66470929e+13, -2.54117388e+13
    ])
    assert str(reactions.reaction_rate(x, T)) == str(expect)
Ejemplo n.º 11
0
def test_invalid_reversible():
    """
    test that chemkin object handles invalid reversible input as expected
    """

    try:
        reactions = chemkin('tests/test_xml/rxns_invalid_reversible.xml')
    except ValueError as e:
        assert type(e) == ValueError
        print(e)
Ejemplo n.º 12
0
def test_solve():
    chem = chemkin("tests/test_xml/rxns.xml")
    y0 = np.ones(len(chem.species))
    T = 300
    t1 = 0.003
    dt = 5e-4
    cs = ChemSolver(chem).solve(y0, T, t1, dt, algorithm='lsoda')
    t, y, rr = cs.get_results(return_reaction_rate=False)
    assert rr is None
    t, y, rr = cs.get_results()
    print(y)
Ejemplo n.º 13
0
def test_construct_nonelementary():
    """
    test that chemkin object handles non-elementary reactions as expected
    """

    try:
        reactions = chemkin('tests/test_xml/rxns_pseudononelementary.xml')
        reactions.reaction_rate_T(np.ones(1), 1000)
    except NotImplementedError as e:
        assert type(e) == NotImplementedError
        print(e)
Ejemplo n.º 14
0
def test_grid_search():
    chem = chemkin("tests/test_xml/rxns.xml")
    t1 = 0.003
    dt = 5e-4
    y0s = [np.ones(len(chem.species)) * i for i in range(1, 4)]
    Ts = [300, 400]
    gs = ChemSolver(chem).grid_solve(y0s, Ts, t1, dt, algorithm='lsoda')
    _y1 = gs.get_grid_results()[1][300][0][1]
    _y2 = ChemSolver(chem).solve(y0s[0], Ts[0], t1, dt,
                                 algorithm='lsoda').get_results()[1]
    assert str(_y1) == str(_y2)
    print(_y1)
    gs.save_grid_results('abc')
Ejemplo n.º 15
0
def test_from_xml():
    """
    testing normal reaction rate calculations from xml input
    """
    reactions = chemkin('tests/test_xml/rxns.xml')
    expect = np.array([
        -6.28889929e+06, 6.28989929e+06, 6.82761528e+06, -2.70357993e+05,
        1.00000000e+03, -6.55925729e+06
    ])
    assert all(
        reactions.reaction_rate([1, 1, 1, 1, 1, 1], 1000).astype(int) ==
        expect.astype(int))
    return reactions
Ejemplo n.º 16
0
def test_IO():
    chem = chemkin("tests/test_xml/rxns.xml")
    y0 = np.ones(len(chem.species))
    T = 300
    t1 = 0.003
    dt = 5e-4
    cs = ChemSolver(chem).solve(y0, T, t1, dt, algorithm='lsoda')
    cs.save_results('tests/test_data/test.csv')
    cs.save_results('tests/test_data/test.h5')
    cs1 = ChemSolver(chem).load_results('tests/test_data/test.csv')
    cs2 = ChemSolver(chem).load_results('tests/test_data/test.h5')
    assert str(cs.get_results()) == str(cs1.get_results())
    assert str(cs1.get_results()) == str(cs2.get_results())
Ejemplo n.º 17
0
def test_wrong_file_name():
    chem = chemkin("tests/test_xml/rxns.xml")
    cs = ChemSolver(chem)
    try:
        cs.save_results('test.pdf')
    except ValueError as e:
        assert type(e) == ValueError
        print(e)
    try:
        cs.load_results('test.pdf')
    except ValueError as e:
        assert type(e) == ValueError
        print(e)
Ejemplo n.º 18
0
def test_ODE_not_solved():
    chem = chemkin("tests/test_xml/rxns.xml")
    cs = ChemSolver(chem)
    try:
        t, y, rr = cs.get_results()
    except ValueError as e:
        assert type(e) == ValueError
        print(e)
    try:
        cs.save_results('tests/test_data/test.csv')
    except ValueError as e:
        assert type(e) == ValueError
        print(e)
Ejemplo n.º 19
0
def test_reversible():
    x_init = np.ones(8)
    T = 1000

    # integration end time
    t_max = 5.e-13

    # step size
    dt = 1.e-16

    cs = ChemSolver(chemkin('tests/test_xml/rxns_reversible.xml')).solve(
        x_init, T, t_max, dt)
    assert not cs.is_equilibrium()
    t, y, rr = cs.get_results(return_reaction_rate=False)
    assert rr is None
    t, y, rr = cs.get_results()
    assert rr is not None
    print(y)
Ejemplo n.º 20
0
def test_simpleIO():
    chem2 = chemkin("tests/test_xml/rxns_reversible.xml")
    # initial concentration
    x_init = np.ones(8)
    T = 2000
    t_final = 3.e-13
    t_step = 1.e-16
    cs = ChemSolver(chem2).solve(x_init, T, t_final, t_step, algorithm='lsoda')
    r1 = cs.get_results()

    simpleIO('tests/test_data/test.pkl').to_pickle(cs)
    cs2 = simpleIO('tests/test_data/test.pkl').read_pickle()
    r2 = cs2.get_results()

    for i in range(len(r1)):
        assert np.any(r1[i] == r2[i])

    assert repr(cs.chem) == repr(cs2.chem)
import pandas
import numpy as np
from pychemkin import chemkin, ChemSolver, ChemViz, simpleIO
T = 1000
x_init = np.ones(8)  #initial concentration
t_max = 5.e-13  #integration end time in seconds
dt = 1.e-16  #step size in seconds
cs = ChemSolver(chemkin('rxns_reversible.xml'))
cs.solve(x_init, T, t_max, dt, algorithm='vode', method='bdf', nsteps=500)

time_array, conc_array, rxnrate_array = cs.get_results()

df = cs.to_df()
cs.save_results('simulationdata.csv')

cv = ChemViz(cs)
cv.plot_time_series('concentration',
                    tmin=0,
                    tmax=4.5e-13,
                    species=['H', 'OH', 'O2', 'H2O'],
                    outputfile='modeldocfig1.png')

cv.plot_time_series('reactionrate',
                    tmin=1.e-13,
                    tmax=4.5e-13,
                    outputfile='modeldocfig2.png')

cv.plot_network([0, 1.5e-13, 3e-13],
                figsize=(8, 15),
                outputfile='modeldocfig3.png')