Week 6 - Data analysis
Compatability check
- You code should exit gracefully, if a non-compatible file is provided as an input. It should say something like "File not recognized. Please provide a valid CONVERGE output fill.
Data visualizer
- Your script should take column numbers as the input and plot the respective columns as separate images
- Each file should be saved by the name of the column
- The plot labels should be extracted from the file. If, I request for a plot between column 1 (crank angle) and column 8(volume), then the label information should automatically be extracted and must appear as labels in the plots. THIS SHOULD NOT BE DONE MANUALLY
Basic performance calculation
- Calculate the area under the P-V diagram. P is in column 2 and V is in column 8.
- Calculate the power output of this engine. Assume that RPM is 1500
- This engine consumed 20 micro grams of fuel (per 1 stroke cycle). Calculate its specific fuel consumption.
Introduction
When large simulation are performed , enormous data is generated. In such cases, searching for required data manually become tedious. To simplify this, programs are written to analyse and visualize data.
In this project the data file provided by CONVERGE analysis of an engine and retrieve the required information, the file consist 17 parameters.
The data file and program file must be in the same folder.
import matplotlib.pyplot as plt
import math
import numpy as np
from numpy import trapz
FILE = []
for line in open('engine_data.out','r'):
if '#' in line:
FILE.append(line.split())
#Compatibility Check
if 'CONVERGE' in (FILE[0]):
print("Compatibilty check successful")
print('File consisit of datas given below')
else:
print("File not recognize. Please provide a valid CONVERGE output file")
exit()
noc = len(FILE[1])
head = len(FILE[2])
col_no = []
col_val = []
col_units = []
z = FILE[1].index('column')
for i in range(z,noc-1):
col_no.append(i)
for j in FILE[2]:
if j is not '#':
col_val.append(j)
for k in FILE[3]:
if k is not '#':
col_units.append(k)
print('data available are:')
for a in range(0,len(col_no)):
print(col_no[a],col_val[a],col_units[a])
xaxis = int(input('Enter xaxis column no:'))-1
yaxis = int(input('Enter yaxis column no:'))-1
x = []
y = []
for data in open('engine_data.out','r'):
if '#' not in line:
x.append(float(data.split()[xaxis]))
y.append(float(data.split()[yaxis]))
plt.plot(x,y,linewidth=1.5)
plt.xlabel(col_val[xaxis])
plt.ylabel(col_val[yaxis])
plt.show()
line_count = 1
pressure = []
Volume = []
for value in open('engine_data.out'):
if '#' not in value:
pressure.append(float(value.split()[1]))
Volume.append(float(value.split()[7]))
line_count = line_count + 1
#Calculate area under the Pressure and Volume curve
P = 1000000*np.array(pressure)
V = np.array(Volume)
AREA = np.trapz(P,V)
print('Wrkdone(area under P-V diagram)=',AREA,'joules')
#Calculate power output from the engine at 1500 rpm
power =(AREA*1500)/60000
print('power output of the engine =',power,'KW')
#Calculate power output from the engine at 1500 rpm
sfc = 20*pow(10,-6)*3600/power
print('specific fuel consumption =',sfc,'Kg/KWh')
The result obtained are
Compatibilty check successful
File consisit of datas given below
data available are:
1 Crank (DEG)
2 Pressure (MPa)
3 Max_Pres (MPa)
4 Min_Pres (MPa)
5 Mean_Temp (K)
6 Max_Temp (K)
7 Min_Temp (K)
8 Volume (m^3)
9 Mass (kg)
10 Density (kg/m^3)
11 Integrated_HR (J)
12 HR_Rate (J/time)
13 C_p (J/kg-K)
14 C_v (J/kg-K)
15 Gamma (none)
16 Kin_Visc (m^2/s)
17 Dyn_Visc (N*s/m^2)
Enter xaxis column no:
The PV plot obtained is

Wrkdone(area under P-V diagram)= 500.5866274680076 joules
power output of the engine = 12.514665686700189 KW
specific fuel consumption = 0.005753249971073309 Kg/KWh