import matplotlib.pyplot as plt
import numpy as np
import sys
import math
#Opening the file
try:
f=open(\'engine_data.out\',\'r\')
except FileNotFoundError:
print(\'File not recognized. Please provide a valid CONVERGE output file!\')
sys.exit(1)
value=[]
#reading from file and assigning values to arrays
for line in f:
if \'#\' not in line :
values=line.split()
value.append(values)
col1=np.transpose(value)
col1=col1.astype(np.float)
#Area under PV Diagram using Trapezoidal rule
xvar=col1[1]
yvar=col1[7]
dx=[]
k=0
while k < 8664 :
dif=xvar[k+1]-xvar[k]
dx.append(dif)
k=k+1
W=[]
Work=0
t=0
while t < 8664 :
W.append(((dx[t])/2)*(yvar[0]+2*(yvar[t+1])+yvar[8664]))
t=t+1
for n in range(0,len(W)):
Work=Work+W[n]
#Work,Power and Specific fuel consumption calculation and output
Work=Work*1000000
print(\'Work Output in Joules is :\')
print(abs(Work))
print(\'Power Output in Watts is :\')
power=(Work*2*1500*math.pi*0.001)/60
print(abs(power))
print(\'Specific fuel consumption in gram/Joule is :\')
bsfc=0.02/abs(power)
print(bsfc)
name=[\'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\']
print(\'Press \\n 1 for Crank \\n 2 for Pressure \\n 3 for Max_Pres \\n 4 for Min_Pres \\n 5 for Mean_Temp \\n 6 for Max_Temp \\n 7 for Min_Temp \\n 8 for Volume \\n 9 for Mass \\n 10 for Density \\n 11 for Integrated_HR \\n 12 for HR_Rate \\n 13 for C_p \\n 14 for C_v \\n 15 for Gamma \\n 16 for Kin_Visc \\n 17 for Dyn_Visc\')
x=int(input(\'Enter number corresponding to value you want to plot on X-axis & then press enter \\n\'))
y=int(input(\'Enter number corresponding to value you want to plot on Y-axis & then press enter \\n\'))
#PLOTTING the Inputs provided by the user
plt.figure(1)
plt.plot(col1[x-1],col1[y-1])
plt.title(name[y-1]+\' & \'+name[x-1]+\' Plot\',fontsize=20,color=\'red\')
plt.xlabel(name[x-1],fontsize=12)
plt.ylabel(name[y-1],fontsize=12)
plt.savefig(name[x-1] + \' vs \' + name[y-1] + \'.png\')
plt.show()
#PLOTTING P-V diagram
plt.figure(2)
plt.plot(col1[7],col1[1])
plt.title(\'P-V diagram\',fontsize=20,color=\'red\')
plt.xlabel(\'Volume\',fontsize=12)
plt.ylabel(\'Pressure\',fontsize=12)
plt.show()