Data Analysis
Aim:
To read the data from the suitable file format and analyse the data,plot the graphs,calculate area under the given curve,power and specific fuel consuption.
Theory:
Code:
# Data Analysis
# By : Anubrat Padhee
# Importing libraries
import matplotlib.pyplot as plt
import ast
# To check if file is present or not
try:
file=open('engine_data.out')
print('File opened suceesfully')
except FileNotFoundError:
print('"File not recognized. Please provide a valid CONVERGE output file"')
# General information
parameter=['Crank Angle','Pressure','Maximum Pressure','Minimum Pressure','Mean Temperature','Maximum Temperature','Minimum Temperature','Volume','Mass','Density','Heat Rejection','Heat Rejection Rate','C_p','C_v','gamma','Kinematic Viscosity','Dynamic Viscosity']
print(parameter)
print('\n')
print('Followings are the codes for corresponding parameters,Please follow the instructions')
print('\n')
corresponding_num=['crank_angle=0','pressure=1','max_pres=2','min_pres=3','mean_temp=4','max_temp=5','min_temp=6','volume=7','mass=8','density=9','Heat Rejection=10','Heat Rejection Rate=11','C_p=12','C_v=13','gamma=14','Kin Vis=15','Dyn Vis=16']
print(corresponding_num)
print('\n')
str=input("Enter first independent variable then separarted by a comma enter dependent variable: ")
list=ast.literal_eval(str)
x=int(list[0])
y=int(list[1])
independent=[]
dependent=[]
pressure=[]
volume=[]
# File parsing
for line in open('engine_data.out'):
if '#' not in line:
independent.append(float(line.split()[x]))
dependent.append(float(line.split()[y]))
plt.figure()
plt.plot(independent,dependent,linewidth=3)
plt.xlabel(parameter[x])
plt.ylabel(parameter[y])
plt.title(parameter[x]+" Vs. "+parameter[y])
# Saving the image file
plt.savefig(parameter[x]+" Vs. "+parameter[y]+'.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]))
# Work done that is area under P-V diagram
work=[]
for i in range(8664):
work.append((pressure[i+1]-pressure[i])*(volume[i+1]-volume[i])*0.5)
work_done=0
for i in work:
work_done=work_done+i
work_done=abs(work_done*pow(10,6))
print("Work done i.e area under P-V graph",work_done,"KJ")
# Inputs
RPM=1500
speed=RPM/60
power=work_done*speed
print("Power output of the engine for 1500 RPM is :",power,"kw")
# Calculating specific fuel consumption
mass_of_fuel=20*pow(10,-6)
specific_fuel_consumption=mass_of_fuel/power
print("specific fuel consumption is",specific_fuel_consumption,"gm/Kwhr")
Procedure:
- For opening and reading the file "open" command is used.
- 'try' & 'except' command is used to display the error prompt if suitable file format is not provided.
- Then corresponding codes for the parameters as well as parameters is printed on the screen and program asks for user input as independent and dependent variable and gives the plot between the dependent vs independent variables and also save the plot as in name"dependent vs independent"
- Then proper codes were written for calculating work done, power and specific fuel consumption were written.
Error encountered:
Input() function do not work in sublime text so we add package called as sublimeREPL so, that we can take input from user.
Outputs: