Week 6 - Data analysis
AIM
To Calculate the area under the P-V diagram , power output of this engine and specific fuel consumption
INTRODUCTION
When large simulation are performed , enormous amount of data is generated. In case, programs are written to analyse and visualise data.
Convert data in a certain format into a more usable format.
the first step, with any parsing problem, is to understand the input data format. There will be documentation that describes the data format.
Once you understand the input data, the next step is to determine what would be a more usable format.
The file contains 17 parameters
Formulas used
PROGRAM
"""
demonstating file parsing in python
"""
import matplotlib.pyplot as plt
from numpy import trapz
try:
data=open('engine_data.out','r')
except :
print(' "File not recognized.Please provide a valid CONVERGE output file"')
value=[]
i=0
for line in data:
if '#' not in line:
value.append(line.split())
if i == 1 :
c = line.split()
if i ==2 :
d = line.split()
if i==3:
e =line.split()
i+=1 #incrementing the value
cinx = int(input('Enter the column number (xaxis) :')) #parameter1
ciny = int(input('Enter the column number (yaxis) :')) #parameter2
len(value) #length values for the parameter
X = [] #defining a empty array
Y = [] #defining a empty array
f = [] #defining a empty array
d.pop(0)
for i in range(0,len(value)):
X.append(float(value[i][cinx-1])) #storing the all the values of the parameter1
Y.append(float(value[i][ciny-1])) #storing the all the values of the parameter2
e.pop(0)
for i in range(0,len(d)) :
f.append(d[i] + ' ' + e[i])
plt.figure(1)
plt.plot(X,Y)
plt.xlabel(f[cinx-1])
plt.ylabel(f[ciny-1])
plt.savefig(f[cinx-1] +'VS'+ f[ciny-1]+'.png')
plt.show()
A=[]
B=[]
for i in range (0,len(value)):
A.append(float(value[i][7])) #volume parameter
B.append(float(value[i][1])) #pressure parameter
#Area under PV curve
area=trapz(B,A)
workdone=(area/1000)*pow(10,6)
print('area under curve=',workdone,'KJ')
RPM=1500
n=RPM/(2*60) #For 4 stroke engine
power=(workdone*0.001*n*pow(10,6))/1000
print('power=',power,'KW')
#calculating specific fuel consumption
#fuel consumption is given to be 20 micro grams of fuel(per one stroke)
#Specific fuel consumption (g/kwhr)
FC=20*pow(10,-6) #micrograms to gram
FCH=FC*3600 #fuel consumption per sec to hour
SFC=FCH/(power)
print('speciic fuel consumtion is :', SFC,'g/KWh')
EXPLANATION
- Intially we are importing math and mathplotlib
- Matplotlib is a plotting library for the Python programming language.
- trapz is imported from numpy python library.
- First try clause is executed i.e. the code between try and except clause.
- The file should be opened in read mode (General syntax :a=open('data','r')).
- If there is no exception, then only try clause will run, except clause is finished.
- If any exception occured, try clause will be skipped and except clause will run.
- If any exception occurs, but the except clause within the code doesn’t handle it, it is passed on to the outer try statements. If the exception left unhandled, then the execution stops.
- Then using for loop datas in file are splitted using line.split().and Input for the columns is given.
- pop() is an inbuilt function in Python that removes and returns last value from the list or the given index value.
- X and Y values are stored and using plt.plot the graph is plotted.
- Then area is found out by using trapezoidal rule syntax: np.trapz(Y,X) (integration of area is done P vs V)
- Then RPM and fuel consumption micrograms are given as input. using this power output of the engine is calculated and specific fuel consumption of the engine is calculated.
RESULTS:
Results of workdone , power and specific fuel consumption is shown below