import numpy as np
velocity = np.diff(volume) / np.diff(time)
def velocity_function(sim_t):
"""Compute the velocity of the piston at the simulation time, sim_t"""
if t > self.time[-1]:
# Return 0 if the simulation time is greater than a velocity we've computed
return 0
else:
# prev_time_point is the previous value in the time array
# after the current simulation time
prev_time_point = self.time[self.time <= t][-1]
# index is the index of the time array where
# prev_time_point occurs
index = np.where(self.time == prev_time_point)[0][0]
return velocity[index]
gas = ct.Solution(input_file, transport_model=None)
gas.TPX = 325, 101325, YOUR_COMPOSITION
env = ct.Reservoir(ct.Solution("air.xml", transport_model=None))
reac = ct.IdealGasReactor(gas)
ct.Wall(reac, env, velocity=velocity_function)
netw = ct.ReactorNet([reac])
while netw.time < end_time:
netw.step()
--
You received this message because you are subscribed to the Google Groups "Cantera Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cantera-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cantera-users/a4b5301d-368b-4788-a13d-d341ba4d4592%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Cantera Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cantera-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cantera-users/28d900f5-e041-425a-8dcd-6a0fddf270bc%40googlegroups.com.
time = 0.0
dt = 1.0e-6
tsteps = 1000
times = np.zeros(tsteps)
for n in range(tsteps):
time = time + dt
netw.advance(time)
times[n] = netw.time
To unsubscribe from this group and stop receiving emails from it, send an email to cantera-users+unsubscribe@googlegroups.com.
Hi Shirin,
To unsubscribe from this group and stop receiving emails from it, send an email to canter...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Cantera Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cantera-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cantera-users/169d4265-bab4-4eb3-82c0-fc8e3915e397%40googlegroups.com.
On Sat, Jan 11, 2020 at 8:49 PM Bryan W. Weber <bryan...@gmail.com> wrote:
--Hi Shirin,You didn't show how you loaded the volume trace. You have to have time be a NumPy array, it can't be a plain Python list.Best,Bryan
You received this message because you are subscribed to the Google Groups "Cantera Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to canter...@googlegroups.com.
import cantera as ct
import numpy as np
import sys
import xlrd
# Give the location of the file
loc = ("vol_time_engine_.xlsx")
# To open Workbook
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
#gas = ct.Solution('mech_DME_2000.xml')
gas = ct.Solution('gri30.xml')
# print(gas.species_names)
T_in = 300 #K
P_in = 1e5 #pa
# to set the composition of the gas
fuel_species = 'ch4'
ifuel = gas.species_index(fuel_species)
# print(ifuel)
io2 = gas.species_index('o2')
#print(io2 )
in2 = gas.species_index('n2')
#print(in2)
#air_N2_O2_molar_ratio = 3.76
nu=2
phi=1
#X[ifuel] =1
#X[io2] =nu/phi
#X[in2] = X[io2]*air_N2_O2_molar_ratio
#gas.X={'CH4':1, 'O2':2/phi, 'N2':2*3.76/phi}
#gas.TPX = T_in, P_in, {'ch4':1, 'o2':2/phi, 'n2':2*3.76/phi}
gas.TPX = T_in, P_in, {'CH4':0.5, 'O2':nu/phi, 'N2':nu*3.76/phi}
#gas.TPX = T_in, P_in, {'ch4':0.5, 'o2':nu/phi, 'n2':nu*3.76/phi}
#gas()
print("GasTPX: ", gas.TPX)
#print("gas.n_species: ",gas.n_species)
reac = ct.IdealGasReactor(gas)
env = ct.Reservoir(ct.Solution('air.xml'))
Exp_time = []
Exp_vol = []
# keywords={}
for i in range(0,sheet.nrows,1):
Exp_vol.append(sheet.cell_value(i, 0))
Exp_time.append(sheet.cell_value(i, 1))
keywords = {'Time': Exp_time, 'Vol': Exp_vol}
#print("Volume: ", Exp_vol)
#print("Time: ", len(Exp_time))
#print("keywords: ", keywords)
class VolumeProfile():
def __init__(self, keywords):
self.time = np.array(keywords['Time'])
#print("self.time :",self.time)
self.volume = np.array(keywords['Vol'])/keywords['Vol'][0]
#print("self.volume: ", self.volume)
self.velocity = np.diff(self.volume)/np.diff(self.time)
# print("self.velocity: ",self.velocity )
self.velocity = np.append(self.velocity, 0)
def __call__(self, t): #Return the velocity when called during a time step.
if t < self.time[-1]:
prev_time_point = self.time[self.time <= t][-1] #prev_time_point is the previous value in the time array after the current simulation time
index = np.where(self.time == prev_time_point)[0][0] #index is the index of the time array where prev_time_point occurs
return self.velocity[index]
else:
return 0
vp = VolumeProfile(keywords)
net=ct.Wall(reac, env, velocity=vp)
print(np.min(np.diff(vp.time)))
netw = ct.ReactorNet([reac])
netw.set_max_time_step(np.min(np.diff(vp.time)))
time = []
temperature = []
pressure = []
volume = []
while netw.time < 0.08:
time.append(netw.time)
temperature.append(reac.T)
pressure.append(reac.thermo.P)
volume.append(reac.volume)
netw.step()
#print (time)
#print (pressure)
import matplotlib.pyplot as plt
plt.figure()
plt.plot(time, pressure)
plt.ylabel('Pressure [Pa]')
plt.xlabel('Time [s]')
plt.figure()
plt.plot(Exp_time, Exp_vol, label='Experimental Volume', color='k', linestyle=':')
plt.plot(time, volume, label='Simulated Volume',linestyle='-', markersize=15)
plt.legend()
plt.ylabel('Volume [cm^3]')
plt.xlabel('Time [s]')
plt.figure()
plt.plot(time, temperature)
plt.ylabel('temperature [K]')
plt.savefig('temperature.png')
vp = VolumeProfile(keywords)
net=ct.Wall(reac, env, velocity=vp)
print(np.min(np.diff(vp.time)))
netw = ct.ReactorNet([reac])
netw.set_max_time_step(np.min(np.diff(vp.time)))
Hi Shirin,
plt.plot(Exp_time,<span
--
You received this message because you are subscribed to the Google Groups "Cantera Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cantera-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cantera-users/014280c1-bd2e-4ba1-a34b-b63533649701%40googlegroups.com.
Hi Shirin,There is currently a problem with PyKED and one of the libraries it uses called Cerberus. You need to install version 1.1 or lower of Cerberus. This should be automatically handled by the installer, but it doesn't work sometimes for some reason. Since this isn't really about Cantera, I'll reply to you off the list to do some more troubleshooting.Best,Bryan
On Friday, November 15, 2019 at 2:53:27 AM UTC-5, Shirin wrote:
Hello,
I am trying to run your code in rcm-example.ipynb to see if I can get the same plot as you did. But I am getting this below error. I have installed Pyked and pyyaml.
Traceback (most recent call last):