Challenge

Week 6 - Data analysis using PYTHON

OBJECTIVE

To write the program in python and analysis the given engine Data.

To calculate the area under the PV diagram curve.

To calculate the power output of the engine (Assume that RPM is 1500).

To calculate the Specific Fuel Consumption (SFC). (This engine consumed 20 micro grams of fuel (per 1 stroke cycle).

Data link- https://drive.google.com/open?id=1L8GY56d-M8mB1KfceM-xVhGNvnCIqxjm

THEORY

Pressure-Volume (PV) diagrams are a primary visualization tool for the study of heat engines. Since the engines usually involve a gas as a working substance, the ideal gas law relates the PV diagram to the temperature so that the three essential state variables for the gas can be tracked through the engine cycle. Since work is done only when the volume of the gas changes, the diagram gives a visual interpretation of work done. Since the internal energy of an ideal gas depends upon its temperature, the PV diagram along with the temperatures calculated from the ideal gas law determine the changes in the internal energy of the gas so that the amount of heat added can be evaluated from the first law of thermodynamics. In summary, the PV diagram provides the framework for the analysis of any heat engine which uses a gas as a working substance.

AREA UNDER PV DIAGRAM

The various processes seen above can be combined to create cycles found in most internal and external combustion engines. These diagrams are showing how pistons in engines (powered by fuel) or the various processes in a power plant, change the volume and pressure of a working fluid (ex. steam water for turbines, fuel-air mixture for engines) to create work. Then this work can be used to create electricity or move a vehicle. The work done would be calculated by finding the area inside the closed cycle (ex. the yellow shaded area of the Rankine cycle below).

Formulae

WORKDONE=area under the curve of PV diagram

`Power =area*n*`10^6` W`

where,

n=speed of the engine`=(N/(2*60))` for 4-stroke engine

n=`=(N/(60))` for 2-stroke engine

Specific Fuel Consumption(SFC)=`(Fuel consmed kg/hr)/(power output kW)`

PROCEDURE

  • Initially we are going to import the “matplotlib.pyplot” and “numpy” libraries to plot the graph and calculate the values.
  • First we save the program and then data file and program file is in the same folder.
  • The “try and except” command used to check the data file is in the same folder or it has name mistake.
  • Then we are going to open the file using the “for loop” command and then we read the data line by line. And using some counting line, if and else commands to separate the heading and numerical data.
  • Using “line.split” command to split all the data present in the data file.
  • For easy to calculate we creating some input commands to plot the graphs. The data input in the x-axis and y-axis.
  • Then we create two empty arrays for the x input and the y input and then we read the data again. The data created then using the float, the values float and append all the values for the x and y input arrays.
  • We create the plot command for the x and y input arrays and then we make all the labels and the title of the graph.
  • After that we calculate the area under the curve of a PV diagram and we know that the area under the curve is work done.
  • Then we calculate the power output the engine and Specific Fuel Consumption and then we print the values.

PROGRAM

#program for data anaylsis
#by Sallavodiin
"""
Demonstrating the engine data analysis

"""

import matplotlib.pyplot as plt
import math
import numpy as np
#import numpy as np


try:
	file=open('engine_data.out')
	print('data is found successfully! Now you can proceed to the next Calculations\n')
except:
	print('unfortunately the data is not found.Please check the file or filename\n')
file.close()


print('Information about input parameters')


pressure=[]
temperature=[]
volume=[]
column_name=[]
column_units=[]

#data parsing
count_data=1
for line in open('engine_data.out'):

	if '#' not in line:
		
		count_data=count_data+1	

		
	else:
		count_data=count_data+1
		if count_data == 4:

			column_name=line.split()
			print(column_name)
		elif count_data==5:
			coulumn_units=line.split()


#inputs
nx = int(input("Please enter the x-axis data of column(1-17) 1.Crank to 17.Dynamic Viscosity"))
print(nx-1)

ny = int(input("Please enter the y-axis data of column(1-17) 1.Crank to 17.Dynamic Viscosity"))
print(ny-1)

print('the plot is',column_name[ny],"vs",column_name[nx])
data_array_x=[]
data_array_y=[]




for line in open('engine_data.out'):

	if '#' not in line:
		
		data_array_x.append(float(line.split()[nx-1])) 
#print(data_array_x)
			

for line in open('engine_data.out'):

	if '#' not in line:
		
		data_array_y.append(float(line.split()[ny-1])) 
#print(data_array_y)


#plotting the data
plt.plot(data_array_x,data_array_y)
plt.xlabel(column_name[nx]+coulumn_units[nx])
plt.ylabel(column_name[ny]+coulumn_units[ny])
plt.title(column_name[nx]+column_name[ny]+'Diagram')
plt.savefig(column_name[nx]+'VS'+column_name[ny]+'.png')
plt.show()



for line in open('engine_data.out'):

	if '#' not in line:
		
		pressure.append(float(line.split()[1]))
		volume.append(float(line.split()[7]))  

#calculating area under the pv curve
work=[]
for i in range(0,8664):
	work.append((volume[i+1]-volume[i])*(pressure[i+1]+pressure[i])*0.5)

work_done=0
for j in range(0,len(work)):
	work_done=work_done+work[j]
	work_done1=work_done*1*1e6
print('Workdone is',work_done1,'j')


area=np.trapz(pressure,volume)
#print('the total area under the curve is',area,'m^2')

#calculating power output of the engine
rpm=1500
power=area*1e+06*rpm/9550
print('The power output of the engine is',power,'KW')

#calculating Specific fuel consumption
fps=20*1e-06
mass_flow_rate=2.99*1e-10
SFC=mass_flow_rate*36000/power
print('The specific Fuel Consumption is',SFC,'g/KW hr')

OUTPUT

Result window

PLOTS

PV diagram

crank pressure diagram

crank volume diagram

crank mean temp diagram

CONCLUSIONS

  • The area under the PV Diagram curve is calculated. We know that the area under pv diagram is workdone.
  • The specific Fuel Consumption(SFC) and power output of the engine also calculated.
  • The data visualization is shown in the output window.
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.