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
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)
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())
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)
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')