Week 6 - Data analysis
Aim:
- 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.

CODE:
#importing the required modules for the function to understand the input modules
import math
import matplotlib.pyplot as plt
import numpy as np
#importing the trapz module from numpy
from numpy import trapz
#file name is defined so it takes in the data for the function
file_name = input('please enter the file name with .out at the end : ')
#checking the file name input if it is right or wrong, if right code proceed further else stops
try:
#the data is made as the variable for the input file and is read with the 'r'.if the input name of the file is true then the code runs for the other stage.
data = open(file_name,'r')
print('\ndata file is found!')
except:
#if file name is wrong then this output is shown as below
print('\nFile not recognized, please provide a valid CONVERGE output file')
#the iteration is done with the help of lc
lc = 1
#for line in the read file if the iteration is at 3, then print the line with the variable name parameter.
for line in data:
if lc == 3:
parameters = line.split()
#columns are but the length of the parameters
columns = len(parameters)
#the parameters and columns help in making a chart that contains the input parameters units for users to use as input.
print('\nThis contain the whole ic engine datas that we extracted from the directory : ')
#the column is made -1 since python takes the index to start from 0 and we are making no errors in the system
print('this table below contains %d data columns' %(columns-1))
#when the iteration reaches the fourth line of the data where units are, the values in it are made to save in unit.
for line in data:
if lc ==4:
Unit =line.split()
break
#the column numbers are stored in a variable called cn
for cn in range(1,columns):
print(cn,parameters[cn],line.split()[cn])
break
lc = lc+1
#the input values of x and y are taken in.they are but the parameters that which are needed to be plotted and compared.
print('\nChoose two parameters from above')
print('\nEnter the number corresponds to the parameter from 1 to 17')
x = int(input('please print xaxis parameter : '))
y = int(input('please print yaxis parameter : '))
print('')
#the x and y values contains the values of the two inputs.
x_values = []
y_values = []
#iterations are done to take out the values of parameters, x and y labels for the plot.
lc = 1
for line in open(file_name,'r'):
#when iteration reach line 3, the parameters names are made to be stored in the x and y label for plotting.
if lc == 3:
x_label = line.split()[x]
y_label = line.split()[y]
#when # sign is not at the line, then the parameters values are stored as x and y
if '#' not in line:
#-1 is done so we can get the right column values since python starts from 0
x_values.append(float(line.split()[x-1]))
y_values.append(float(line.split()[y-1]))
lc = lc+1
#file name is charted from the variables extracted
file_name = y_label + ' vs ' + x_label + '.png'
#plotting of the parameters re done as asked.
plt.plot(x_values,y_values)
plt.xlabel(x_label)
plt.ylabel(y_label)
plt.title(y_label + ' vs ' + x_label)
plt.savefig(file_name)
plt.show()
#the values of engine outputs are asked for which we are using the formulas to providr the output
#revolution per minute is set to 1500 as given
RPM = 1500
#area traced by the parameters is found with the help of trapz command
Area = np.trapz(y_values,x_values)
#workdone by the engine is but the area / 1000
workdone = Area*1000
#power formula is m.2.pi.n/60
power = 2*math.pi*RPM*workdone/60
#fuel per stroke value is given below and it is taken for 20 micro grams of fuel as asked
fpst = 20*1e-6
#fuel per second
fpse = fpst*RPM*(0.5/60)
#value of fuel consumption per hour
fph = fpse*3600
#brake specific fuel consumption. it is but the fuel per hour/power.
bsfc = fph/power
print('')
#the values of the formula are printed with their own respective variable
print('area under the pv diagram(workdone) : ',workdone,'kJ')
print('Power output of this engine : ',power,'KW')
print('specific fuel consumption : ',bsfc,'g/kwh')
print('')
OUTPUT:
Volume and pressure plot generated

Output:
Input the value to calculate the area under p v plot, power output of the engine and specific fuel consumption.
Taking rpm as 1500 and engine consumed 20 microgram of fuel(per 1 stroke )

Conclusion:
Code is written to create the visualizer tool using python which will extract data from a converge output file, which plot to generate as per the user peference
And also calculate the area under the PV diagram, power output this engine and specific fuel consumption