예제 #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)
예제 #2
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())
예제 #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)
예제 #4
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)
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')