Hello,
I am trying to predict the timing of HCCI combustion using methane fuel at different pressure range.. Here's my python code. I keep getting this error, not sure what i'm doing wrong.
Python Code:
import numpy as np
import cantera as ct
import matplotlib.pyplot as plt
gas = ct.Solution("gri30.xml")
T = 1250 #K
P = [1,2,3,4,5] #Pa
autoignition_time = []
j=0
for j in range(5):
gas.TPX = T,P[j]*101325,{'CH4':1,'O2':2,'N2':7.52}
r = ct.IdealGasReactor(gas)
sim = ct.ReactorNet([r])
time = 0.0
states = ct.SolutionArray(gas, extra = ['time_in_ms', 't'])
for n in range(10000):
time += 1e-3
sim.advance(time)
states.append(r.thermo.state, time_in_ms = time*1e3, t =time)
for i in range(len(states.T)):
if states[i].T >= (1250+400):
autoignition_time.append(states.time_in_ms[i])
break
fig, ax = plt.subplots()
ax.plot(P, autoignition_time)
plt.show()
Error:
C:\Users\jopad\.conda\envs\ct-env\python.exe C:/Users/jopad/PycharmProjects/pythonProject1/auto_timing.py
Traceback (most recent call last):
File "C:\Users\jopad\PycharmProjects\pythonProject1\auto_timing.py", line 33, in <module>
ax.plot(P, autoignition_time)
File "C:\Users\jopad\.conda\envs\ct-env\lib\site-packages\matplotlib\axes\_axes.py", line 1605, in plot
lines = [*self._get_lines(*args, data=data, **kwargs)]
File "C:\Users\jopad\.conda\envs\ct-env\lib\site-packages\matplotlib\axes\_base.py", line 315, in __call__
yield from self._plot_args(this, kwargs)
File "C:\Users\jopad\.conda\envs\ct-env\lib\site-packages\matplotlib\axes\_base.py", line 501, in _plot_args
raise ValueError(f"x and y must have same first dimension, but "
ValueError: x and y must have same first dimension, but have shapes (5,) and (9996,)