AIM:
Write code for the provided data output file as a challenge parsing data analysis.
OBJECTIVE
1) The script should be written to obtain the plot for the data input provide.
2) Checking the compatibility of the code with graceful exit, if non- compatibility file provided write code " file not recognized. please provide a valid CONVERGE output file".
3) Calculate the performance for the area under the P_V diagram, P is in column 2 and V is in column 8, the power output of the engine assumes rpm is 1500 and calculate specific fuel consumption.
Theory :
Data analysis (data analysis) is the process of exploring, cleaning, transforming, and modeling data with the goal of discovering useful information, drawing conclusions, and supporting decision-making. There are multiple aspects and approaches to data analysis, including various techniques with different names, used in business, science, and social sciences. In today's business world, data analytics play a role in helping organizations make more scientific decisions and operate more effectively.
Data analysis process:
Data requirements - Data collection - Data processing - Data cleansing - Exploratory data analysis.
We need to calculate some steps using the governing equations, so it looks like this:
1) Area Under the PV Plot Get results for the data you provided showing that the area under the process curve in the PV plot is equal to the work done by the gas during the process.
2) Engine power assuming rpm is 1500: power_output = n*area*stroke_cycle/(1000)
3) Fuel consumption rate: SFC = (Fuel_consumption*pow(10, -6)*stroke_cycle*3600)/(power_output*1000).
PROCEDURE:
To write the code using data parsing:
1. Importing math, matplotlib, numpy, and scipy for simps and trapz.
2. first input the file which carriers data that to be analysis and checking their compatibility by using try option
try:
file = open('engine_data.out')
line_count = 1.
3. The file which is not recognized ned to provide a CONVERGE output file.
4.
Creating the null array for pressure and volume, for plotting PV diagram from a data file which is in line 2 and 8 respectively, code for it and plotting them:
data = []
for line in open('engine_data.out'):
if '#' not in line:
data.append(line.split())
if line_count >= 6:
Pressure.append(float(line.split() [P-1]))
Volume.append(float(line.split() [V-1]))
line_count = line_count + 1
# Ploting P-V diagram
plt.plot(Volume, Pressure, color = 'green', linewidth = 3)
plt.xlabel('Volume (m^3)')
plt.ylabel('Pressure (MPa)')
plt.title('P-V Diagram of Engine')
plt.grid()
plt.show()
5. For calculating the area under PV diagram to be written as : area = simps(Pressure, Volume)
print('Area under the curve using simpson rule: ' +str(area) + 'units')
print('work done by the engine:' +str(area) + 'MJ')
area = area*1e6
print('work done by the engine: ' +str(area) + 'J')
6. For calculating the power output and specific fuel consumption (SFC), Inputing the value of rpm = 1500, rps = = 1500/60, fuel consumption = 20, n = 1: power_output = n*area*stroke_cycle/(1000)
print('power output from engine: ' +str(power_output) + 'KW')
SFC = (Fuel_consumption*pow(10, -6)*stroke_cycle*3600)/(power_output*1000)
print('specific Fuel consumption, SFC =' +str(SFC) + '(kg/hr)/(KW)')
print('t')
7. And calculating the sfc and power output by the simpson rules and trapezodial rule: Area = np.trapz(Pressure, Volume)
print('Area under the curve using trapezoidal rule :' + str(Area) +'units')
print('work done by the engine :' + str(Area) + 'MJ')
Area = Area* 1e6
print('work done by the engine :' + str(Area) + 'J')
power_output = n*Area*stroke_cycle/(1000)
print('power output from engine :' + str(power_output) + 'KW')
SFC = (Fuel_consumption*pow(10,-6)*stroke_cycle*3600)/(power_output*1000)
print('specific Fuel consumption, SFC = ' + str(SFC) + '(kg/hr)/KW')
print('t')
8. Transposing th columns into in raw matrix and converting into float type and string type: transpose = np.transpose(data)
float_f = transpose.astype(np.float)
9. And plotting the other graph by command:
#Array for header and their units
parameters = ['Crank', 'Pressure', 'Maximum Pressure', 'Minimum Pressure', 'Mean Temperature', 'Maximum Temperature', 'Minimum Temperature', 'Volume', 'Mass', 'Density', 'Integrated HR', 'HR Rate', 'Cp', 'Cv', 'Gamma', 'Kinematic viscosity' 'Dyanmic viscosity']
units = ['(DEG)', '(MPa)', '(MPa)', '(MPa)', '(K)', '(K)', '(K)', '(m^3)', '(kg)', '(kg/m^3)', 'J', '(J/time)','(J/kgK)', '(J/kgK)', '(m^2/s)', '(Ns/m^2)']
# Providing user choice of picking using two parameters for plotting
print('choose from the following options and press enter key')
print(' 1 Crank n 2 Pressure n 3 Maximum Pressure n 4 Minimum Pressure n 5 Mean Temperature n 6 Maximum Temperature n 7 Minimum Temperature n 8 Volume n 9 Mass n 10 Density n 11 Integrated HR n 12 HR Rate n 13 Cp n 14 Cv n 15 Gamma n 16 Kinematic viscosity n 17 Dyanmic viscosity')
X = int(input('Enter your choice on X-axis n'))
Y = int(input('Enter your choice on Y-axis n'))
# Ploting the graph beased on your choice
plt.figure(1)
plt.plot(float_f [X-1], float_f[Y-1], linewidth =4, color = 'yellow')
plt.title(' Plot for ' + parameters [X-1]+ 'versus' + parameters [Y-1], color = 'green')
plt.xlabel(parameters [X-1] + ' ' + units[X-1])
plt.ylabel(parameters [Y-1] + ' ' + units[Y-1])
plt.grid()
plt.show().
Results :
The output of Simpson's law results for work done by the engine, engine power, and fuel consumption rate.
Area under the curve by Simpson's Law: 0.0005005864474262364 units
Engine work: 0.0005005864474262364MJ
Engine work: 500.58644742623636J
Motor power: 6.257330592827954KW
Fuel consumption rate, SFC =0.00014383130100742395 (kg/h)/(KW)
Performance of work done by the engine, engine power, and trapezoidal result of fuel consumption rate.
Area under curve using trapezoidal rule: 0.0005005866274680075 units
Engine work: 0.0005005866274680075MJ
The work the engine does: 500.58662746800746J
Power output from engine: 6.257332843350094KW
Fuel consumption rate, SFC = 0.00014383124927683276 (kg/h)/KW
MAIN CODE :
'''
A program to calculate engine parameters and to plot a graph between two quantities according to user input
By Sahil Maniyar
'''
import math
import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import simps as simps, trapz as trapz
#file input
file = 'engine_data.out'
#Compatability check
try:
file = open('engine_data.out')
line_count = 1
except:
print('file not recognized. please provide a valid CONVERGE output file')
# Creating of the empty array to store the value of pressure and volume
Pressure = []
Volume = []
#Pressure and volume in the data file is present in column 2 and 8 respectively. calling them and storing their data into arrays
P = 2
V = 8
# Getting a null array and storing all data values of the data file into it
data = []
for line in open('engine_data.out'):
if '#' not in line:
data.append(line.split())
if line_count >= 6:
Pressure.append(float(line.split() [P-1]))
Volume.append(float(line.split() [V-1]))
line_count = line_count + 1
# Ploting P-V diagram
plt.plot(Volume, Pressure, color = 'green', linewidth = 3)
plt.xlabel('Volume (m^3)')
plt.ylabel('Pressure (MPa)')
plt.title('P-V Diagram of Engine')
plt.grid()
plt.show()
# Calculating the area P-V daigram, p is in column in 2 and v is in volume 8
area = simps(Pressure, Volume)
print('Area under the curve using simpson rule: ' +str(area) + 'units')
print('work done by the engine:' +str(area) + 'MJ')
area = area*1e6
print('work done by the engine: ' +str(area) + 'J')
#Inputs
#Speed of the engine (RPM)
rpm = 1500
rps = 1500/60
stroke_cycle = rps/2
#Fuel consumption in micrograms per 1 stroke cycle
Fuel_consumption = 20
# The sepcification of engine
# No of cylinder
n = 1
# 4 stroke engine
# Calculations of power output and specific fuel consumption
power_output = n*area*stroke_cycle/(1000)
print('power output from engine: ' +str(power_output) + 'KW')
SFC = (Fuel_consumption*pow(10, -6)*stroke_cycle*3600)/(power_output*1000)
print('specific Fuel consumption, SFC =' +str(SFC) + '(kg/hr)/(KW)')
print('t')
# Calculation of area under PV daigram using the trapezoidal rule and work done power, sfc
Area = np.trapz(Pressure, Volume)
print('Area under the curve using trapezoidal rule :' + str(Area) +'units')
print('work done by the engine :' + str(Area) + 'MJ')
Area = Area* 1e6
print('work done by the engine :' + str(Area) + 'J')
power_output = n*Area*stroke_cycle/(1000)
print('power output from engine :' + str(power_output) + 'KW')
SFC = (Fuel_consumption*pow(10,-6)*stroke_cycle*3600)/(power_output*1000)
print('specific Fuel consumption, SFC = ' + str(SFC) + '(kg/hr)/KW')
print('t')
#Transposing coulmns into raw matrix and converting them into float type from string type
transpose = np.transpose(data)
float_f = transpose.astype(np.float)
#Array for header and their units
parameters = ['Crank', 'Pressure', 'Maximum Pressure', 'Minimum Pressure', 'Mean Temperature', 'Maximum Temperature', 'Minimum Temperature', 'Volume', 'Mass', 'Density', 'Integrated HR', 'HR Rate', 'Cp', 'Cv', 'Gamma', 'Kinematic viscosity' 'Dyanmic viscosity']
units = ['(DEG)', '(MPa)', '(MPa)', '(MPa)', '(K)', '(K)', '(K)', '(m^3)', '(kg)', '(kg/m^3)', 'J', '(J/time)','(J/kgK)', '(J/kgK)', '(m^2/s)', '(Ns/m^2)']
# Providing user choice of picking using two parameters for plotting
print('choose from the following options and press enter key')
print(' 1 Crank n 2 Pressure n 3 Maximum Pressure n 4 Minimum Pressure n 5 Mean Temperature n 6 Maximum Temperature n 7 Minimum Temperature n 8 Volume n 9 Mass n 10 Density n 11 Integrated HR n 12 HR Rate n 13 Cp n 14 Cv n 15 Gamma n 16 Kinematic viscosity n 17 Dynamic viscosity')
X = int(input('Enter your choice on X-axis n'))
Y = int(input('Enter your choice on Y-axis n'))
# Ploting the graph beased on your choice
plt.figure(1)
plt.plot(float_f [X-1], float_f[Y-1], linewidth =4, color = 'yellow')
plt.title(' Plot for ' + parameters [X-1]+ 'versus' + parameters [Y-1], color = 'green')
plt.xlabel(parameters [X-1] + ' ' + units[X-1])
plt.ylabel(parameters [Y-1] + ' ' + units[Y-1])
plt.grid()
plt.show()