importnumpyasnpimportcanteraasctimportPyCSP.FunctionsascspFimportPyCSP.SolverascspS#create an instance of the CanteraCSP classgas=cspF.CanteraCSP('hydrogen.yaml')#set the gas state using Cantera's methods (as an alternative to set_stateYT())T=1000P=ct.one_atmgas.TP=T,Pgas.set_equivalence_ratio(1.0,'H2','O2:1, N2:3.76')#push densityrho=gas.densitygas.constRho=rho#initial conditiony0=np.hstack((gas.Y,gas.T))t0=0.0t_end=1e-2#create an instance of CSPsolversolver=cspS.CSPsolver(gas)solver.set_integrator(cspRtol=1e-2,cspAtol=1e-8,factor=0.2,jacobiantype='full')solver.set_initial_value(y0,t0)states=ct.SolutionArray(gas,1,extra={'t':[0.0],'M':0})#integrate ODE with CSP solverwhilesolver.t<t_end:solver.integrate()states.append(gas.state,t=solver.t,M=solver.M)print('%10.3e%10.3f%10.3e%10.3e%10.3e%2i'%(solver.t,solver.y[-1],solver.dt,gas.P,gas.density,solver.M))
Figure 7: Example outcomes: temperature, OH, H, number of exhausted modes, density and pressure in a constant-volume reactor integrated with the CSP solver.