Week 6 - Data analysis
In data analysis our prime interest is to read the data from the suitable file format and analyse the data,plot the graphs,calculate area under the given curve,power and specific fuel consuption.
- for opening and reading the file "open" command is used.
- 'try' & 'except' command is used to display the error prompt if suitable file format is not provided.
- transpose-The transpose method returns a transposed view of the passed multi-dimensional matrix.
- astype-Copy of the array, cast to a specified type,here we have used astype to cast into float.
- Then corresponding codes for the parameters as well as parameters is printed on the screen and program asks for user input as independent and dependent variable and gives the plot between the dependent vs independent variables and also save the plot as in name"dependent vs independent"
- Then for area under pv diagram following reference is used:-#ref=https://www.google.co.in/search?q=integrating+discrete+function+using+trapezidal+rule+numericalmethodsguy&rlz=1C1CHBD_enIN738IN738&oq=integrating+discrete+function+using+trapezidal+rule+numericalmethodsguy&aqs=chrome..69i57.9196j0j7&sourceid=chrome&ie=UTF-8#kpvalbx=1
- After calculating the area under curve (work),Power and specific fuel consumption is calculated as per the given data.
import matplotlib.pyplot as plt
import math
import numpy as np
try:
data=open('engine_data.out','r')
except FileNotFoundError:
print(' "File not recognized. Please provide a valid CONVERGE output file"')
value=[]
for line in data:
if '#' not in line:
value.append(line.split())
column=np.transpose(value)
column=column.astype(float)
parameter=['Crank Angle','Pressure','Maximum Pressure','Minimum Pressure','Mean Temperature','Maximum Temperature','Minimum Temperature','Volume','Mass','Density','Heat Rejection','Heat Rejection Rate','C_p','C_v','gamma','Kinematic Viscosity','Dynamic Viscosity']
print(parameter)
print('Followings are the codes for corresponding parameters,Please follow the instructions')
corresponding_num=['crank_angle=0','pressure=1','max_pres=2','min_pres=3','mean_temp=4','max_temp=5','min_temp=6','volume=7','mass=8','density=9','Heat Rejection=10','Heat Rejection Rate=11','C_p=12','C_v=13','gamma=14','Kin Vis=15','Dyn Vis=16']
print(corresponding_num)
print("please enter the code for independent variable then press enter: \n")
x=int(input())
print("please enter the code for dependent variable then press enter: \n")
y=int(input())
plt.plot(column[x,:],column[y,:],linewidth=3,color='red')
plt.xlabel(parameter[x],color='green',fontsize=12)
plt.ylabel(parameter[y],color='green',fontsize=12)
plt.title(parameter[y]+' VS '+parameter[x],color='b',fontsize=15)
plt.savefig(parameter[y]+'VS'+parameter[x]+'.png')
plt.show()
vol=column[7,:]
press=column[1,:]*pow(10,6) #converting the pressure into Pascal
#area under curve
#ref=https://www.google.co.in/search?q=integrating+discrete+function+using+trapezidal+rule+numericalmethodsguy&rlz=1C1CHBD_enIN738IN738&oq=integrating+discrete+function+using+trapezidal+rule+numericalmethodsguy&aqs=chrome..69i57.9196j0j7&sourceid=chrome&ie=UTF-8#kpvalbx=1
work=[]
for i in range(0,8664):
work.append((vol[i+1]-vol[i])*(press[i+1]+press[i])*0.5)
work_done=0
for j in range(0,len(work)):
work_done=work_done+work[j]
print('Work Done :',work_done,'J')
#power calculations
speed=1500/60 #in rev per sec
power=work_done*speed
print('Power:',power/1000,'KW')
#bsfc
m_f=20*pow(10,-6) #since mass of fuel consumed is 20 micrograms
bsfc=(m_f*3600)/power
print('Specific Fuel Consumption:',bsfc,'gm/KWhr')
Output screen is attached:-