import matplotlib.pyplot as plt
import numpy as np
import os
from numpy import trapz
from scipy.integrate import simpson
#Heading
crank=[]
Pressure=[]
Max_Pres=[]
Min_Pres=[]
Mean_Temp=[]
Max_Temp=[]
Min_Temp=[]
Volume=[]
Mass=[]
Density=[]
Integrated_HR=[]
HR_Rate=[]
C_p=[]
C_v=[]
Gamma=[]
Kin_Visc=[]
Dyn_Visc=[]
#internal variable
heading_number=[]
heading=[]
group=[]
Power_output=[]
counter = 0
#non-compactability check
check = os.path.splitext('filename.out') #the compactability can be verified by changing the extension.
file_name = check[0]
file_extension = check[1]
if not file_extension == ".out":
print ("File not recognized. Please provide a valid CONVERGE output file")
exit()
#Main Program
for line in open('engine_data.out'):
if 'CONVERGE' in line:
for line in open('engine_data.out'):
if 'column' in line:
for n in range (2,19):
heading_number.append(line.split()[n])
for line in open('engine_data.out'):
if 'Crank' in line:
for n in range (1,18):
heading.append(line.split()[n])
for line in open('engine_data.out'):
if '#' not in line:
crank.append(float(line.split()[0]))
Pressure.append(float(line.split()[1]))
Max_Pres.append(float(line.split()[2]))
Min_Pres.append(float(line.split()[3]))
Mean_Temp.append(float(line.split()[4]))
Max_Temp.append(float(line.split()[5]))
Min_Temp.append(float(line.split()[6]))
Volume.append(float(line.split()[7]))
Mass.append(float(line.split()[8]))
Density.append(float(line.split()[9]))
Integrated_HR.append(float(line.split()[10]))
HR_Rate.append(float(line.split()[11]))
C_p.append(float(line.split()[12]))
C_v.append(float(line.split()[13]))
Gamma.append(float(line.split()[14]))
Kin_Visc.append(float(line.split()[15]))
Dyn_Visc.append(float(line.split()[16]))
counter = counter+1
group=np.array([crank, Pressure, Max_Pres, Min_Pres, Mean_Temp, Max_Temp, Min_Temp, Volume, Mass, Density, Integrated_HR, HR_Rate, C_p, C_v, Gamma, Kin_Visc, Dyn_Visc])
x = int(input("enter the x-axis column data:"))-1
y = int(input("enter the y-axis column data:"))-1
plt.figure()
plt.plot((group[y]),(group[x]), color='red')
plt.xlabel(heading[y])
plt.ylabel(heading[x])
plt.savefig('Graph between ' + str(heading[x]) + ' Vs ' + str(heading[y]) )
#print(a[16])
#Area under P-V
area1 = trapz(Pressure, Volume)
area2 = simpson(Pressure, Volume)
print(max(area1,area2))
#Power output = Torque * rpm
#torque = pressure * volume
#Power output = pressure * volume * rpm
#rpm is given as 1500
rpm = 1500
for z in range (0,counter):
Power_output_1=Pressure[z]*Volume[z]*rpm
Power_output.append(Power_output_1)
print(Power_output)
#specific fuel consumption.
#SFC = fuel consumed / power in Wh
Fuel = 20*10^-6
Ph = (Power_output*60)
sfc = np.divide(Fuel,Ph)
print(sfc)