PYTHON PROGRAM TO READ AN ENGINE DATA FILE AND CREATE A DATA VISUALIZER
PYTHON PROGRAM TO READ AN ENGINE DATA FILE AND CREATE A DATA VISUALIZER
Objective:
To write a Python program that would read the file containing an engine's data and create a data visualizer. Also to plot the P-V diagram of the engine and calculate its power output and specific fuel consumption.
Data analysis:
Python is an increasingly popular tool for data analysis.
In this task, a file containing data of an automotive engine obtained from CONVERGE CFD software, is used to create data visualization using Python.
The column numbers are used to give input from the user and the plots between respective column numbers are stored in the name of corresponding column terms.
The program is written in such a way that the plot labels are extracted from the engine.out file automatically.The column terms are appeared as the plot labels accordingly.
Compatibility check:
The program is written using Exceptional file handling function.
If the file opens up, the console displays as 'File opened successfully'.
If the file fails to open up,then the console displays as 'File not recognized. Please provide a valid CONVERGE output file'
Libraries used:
Here, matplotlib.pyplot function is used to plot graphs between various engine parameters.
Also, numpy library is used in calculating area under the P-V diagram.
Engine parameters:
A jagged array(array of arrays) is used to define the arrays of each parameters into an array.
After the engine data file is read,the parameters' names,units and values corresponding to the column numbers are added to each array stored in specific names using 'append' command.
Data visualization:
For any input of column numbers in x-axis and y-axis, a plot is created with plot labels fetched from the engine data file and saved the image with the plot names accordingly.
Output:
1. Area under P-V diagram:
A plot between volume in x-axis and pressure in y-axis is created using the values stored in volume and pressure arrays respectively.
The plot labels are extracted automatically from the engine data file with the names and units.
The area under the P-V curve is calculated using the np.trap() command which computes the area using trapezoidal integration method.
The area under the P-V curve is found to be 0.00050058 m^2
2. Power output of the engine:
We know that,
Workdone = Pressure * Volume
Power = Workdone / time
Using the above two relations,the power output of the engine is calculated as
Power = Workdone * Speed in rps
Therefore, the power output of the engine is calculated as 4733.44 W
3. Specific fuel consumption:
We know that the specific fuel consumption of an engine is the amount of fuel consumed per hour for each unit of power output.
Hence,
SFC = mass flow rate of fuel / power output
Therefore,
Specific fuel consumption of the engine for burning 20 micro grams of fuel per hour is found to be 1.5210 e-05 kg/kW hr
Program:
# file parsing
# importing required libraries
import matplotlib.pyplot as plt
import numpy as np
# exceptional file handling
try:
f = open('engine_data.out', 'r')
print('File opened successfully')
crank = []
pressure = []
max_pressure = []
min_pressure = []
mean_temp = []
max_temp = []
min_temp = []
volume = []
mass = []
density = []
integrated_hr = []
hr_rate = []
cp = []
cv = []
gamma = []
kin_visc = []
dyn_visc = []
parameters = [[crank], [pressure], [max_pressure], [min_pressure], [mean_temp], [max_temp], [min_temp], [volume],
[mass], [density], [integrated_hr], [hr_rate], [cp], [cv], [gamma], [kin_visc], [dyn_visc]]
for line in f:
# storing parameter names in respective arrays
if 'Crank' in line:
crank.append(line.split()[1])
pressure.append(line.split()[2])
max_pressure.append(line.split()[3])
min_pressure.append(line.split()[4])
mean_temp.append(line.split()[5])
max_temp.append(line.split()[6])
min_temp.append(line.split()[7])
volume.append(line.split()[8])
mass.append(line.split()[9])
density.append(line.split()[10])
integrated_hr.append(line.split()[11])
hr_rate.append(line.split()[12])
cp.append(line.split()[13])
cv.append(line.split()[14])
gamma.append(line.split()[15])
kin_visc.append(line.split()[16])
dyn_visc.append(line.split()[17])
# storing units of parameters in respective arrays
if '(DEG)' in line:
crank.append(line.split()[1])
pressure.append(line.split()[2])
max_pressure.append(line.split()[3])
min_pressure.append(line.split()[4])
mean_temp.append(line.split()[5])
max_temp.append(line.split()[6])
min_temp.append(line.split()[7])
volume.append(line.split()[8])
mass.append(line.split()[9])
density.append(line.split()[10])
integrated_hr.append(line.split()[11])
hr_rate.append(line.split()[12])
cp.append(line.split()[13])
cv.append(line.split()[14])
gamma.append(line.split()[15])
kin_visc.append(line.split()[16])
dyn_visc.append(line.split()[17])
# storing values of parameters in respective arrays
if '#' not in line:
crank.append(float(line.split()[0]))
pressure.append(float(line.split()[1]))
max_pressure.append(float(line.split()[2]))
min_pressure.append(float(line.split()[3]))
mean_temp.append(float(line.split()[4]))
max_temp.append(float(line.split()[5]))
min_temp.append(float(line.split()[6]))
volume.append(float(line.split()[7]))
mass.append(float(line.split()[8]))
density.append(float(line.split()[9]))
integrated_hr.append(float(line.split()[10]))
hr_rate.append(float(line.split()[11]))
cp.append(float(line.split()[12]))
cv.append(float(line.split()[13]))
gamma.append(float(line.split()[14]))
kin_visc.append(float(line.split()[15]))
dyn_visc.append(float(line.split()[16]))
# reading x data
x_data = int(input('Enter the column number to be in x_axis = '))
for i in parameters:
if parameters.index(i) + 1 == x_data:
x_axis = parameters[x_data - 1]
# reading y data
y_data = int(input('Enter the column number to be in y_axis = '))
print('\n')
for j in parameters:
if parameters.index(j) + 1 == y_data:
y_axis = parameters[y_data - 1]
# saving filename
filename = str(y_axis[0][0]) + ' vs ' + str(x_axis[0][0])
plt.plot((x_axis[0][2:]), (y_axis[0][2:]))
plt.xlabel(x_axis[0][0] + x_axis[0][1])
plt.ylabel(y_axis[0][0] + y_axis[0][1])
plt.title(filename)
plt.savefig(filename)
plt.show()
# Calculating area
area = np.trapz(pressure[2:], volume[2:])
print('Area under P-V curve in m^2 =', area)
print('\n')
# Calculating power output of the engine
Power = []
for i in range(2, len(pressure)):
WD = pressure[i] * pow(10, 6) * volume[i] # (converting pressure from MPa to Pa)
pwr = (WD * 1500) / 60 # (workdone = pressure * volume)(power = workdone * speed in rps )
Power.append(pwr)
print('Max.Power in W =', max(Power))
print('\n')
print('Min.Power in W =', min(Power))
print('\n')
print('Average power in W =', (max(Power) + min(Power)) / 2)
print('\n')
# Calculating SFC of the engine
mass_flow_rate = 20 * pow(10, -6) * 3600 # (fuel amount per hour)
power = (max(Power) + min(Power)) / 2
sfc = (mass_flow_rate / power)
print('SFC in kg/kW hr =', sfc)
except Exception:
print('File not recognized. Please provide a valid CONVERGE output file')
- Lesitte Lesigueshello, i have some questions regarding this project. can you contact me thru email? [email protected]