Week 6 - Data analysis
Aim: To read the le 'engine_data.out' and perform the following operations on the data.
Objective:
In data analysis, our prime interest is to read the data from the suitable file format and analyze the data, plot the graphs, calculate the area under the given curve, power and specific fuel consumption.
- Compatibility Check: The program will ask for the file name with a valid extension which if provided incorrect will terminate the program. In case the file name is correct it will further check whether it is a valid Converge output file. If the file is authentic then will proceed to data analysis else it would terminate
- Data Visualization: The program shall display the contents of data available in the file and ask the user for inputs to plot the results will corresponding units
- Performance Calculations: the program shall also perform basic performance calculations including area under the P-V curve, the power output of the engine (@1500RPM) and specific fuel consumption
Description:
Data analysis is a process for obtaining raw data and converting it into information useful for decision-making by users. Data is collected and analyzed to answer questions, test hypotheses, or disprove theories.
The basic concept is to read the le 'engine_data.out' perform several functions on it. As Sublime doesn't allow you to input the data, It is better to dene a
function Input(), to input the column numbers. I have taken the example of Column nos. 1 & 5. To perform compatibility check, the try and except block: is to be
used, as it used for python exceptions i.e. it will display the command 'File not recognized. Please provide a valid CONVERGE output le', if it fails to open. The
next task will be to calculate the engine's basic performance calculations i.e.
a) The area under a P-V diagram
used trapz() function from numpy library
area = np.trapz(Pressure,Volume)
b) The power output of the engine
Power output for the 4-stroke engine is given as,
Power = Work done * RPM/2 (Joules)
c) Specific Fuel Consumption
SFC = Area/ Work Done
Program:
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')
Explanation of the code
- For opening and reading the file "open" command is used.
- 'try' & 'except' command is used to display the error prompt if the 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 the float.
- Then corresponding codes for the parameters as well as parameters are printed on the screen and the program asks for user input as the independent and dependent variable and gives the plot between the dependent vs independent variables and also saves the plot.
- After calculating the area under the curve (work), Power and specific fuel consumption are calculated as per the given data.
Output:
Conclusion:
We have successfully accomplished our objectives.