Predicting Timing of HCCI combustion

31 views
Skip to first unread message

oluwapelumi adebowale

unread,
Nov 30, 2021, 2:02:45 PM11/30/21
to Cantera Users' Group
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,)

Ray Speth

unread,
Dec 10, 2021, 5:27:14 PM12/10/21
to Cantera Users' Group
Hi,

Can you provide a copy of your code where the indentation hasn't been removed, perhaps as an attachment? It's hard to tell what should be happening in your code without that.

Regards,
Ray
Reply all
Reply to author
Forward
0 new messages