Beispiel #1
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)
Beispiel #2
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)
Beispiel #3
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)
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)
    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
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
Beispiel #7
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)
Beispiel #8
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')
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')
Beispiel #10
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())