Challenge

Week 6 - Data analysis

INTRODUCTION

File parsing and data processing are very important in the industry. In this challenge, we are implementing the file parsing and data processing of the output file from a simulation using Converge CFD.

AIM

In this challenge, file parsing and data processing are implemented using python.

RESULTS AND CODE

The stepwise explanation of code is given below:

'''
Compatability Check 
'''
try:
    data =open('engine_data.out','r')
except FileNotFoundError:
    print('File not found, provide  valid .out file.')

In the above snippet of code, the file is checked if it is a .out file. If the file is not compatible with the program terminates.

"""
DATA Visualiser
"""


import matplotlib.pyplot as plt
import numpy as np

parameters = ['Crank_Angle ', 'Pressure' ,'Max_Pres', 'Min_Pres', 'Mean_Temp','Max_Temp','Min_Temp' ,'Volume', 'Mass' , 'Density', 'Integrated_HR' ,'HR_Rate', 'C_p',' C_v',' Gamma ' ,'Kin_Visc','Dyn_Visc']

Number = ['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', 'Integrated_HR = 10' ,'HR_Rate = 11', 'C_p = 12',' C_v = 13',' Gamma = 14 ' ,'Kin_Visc =15','Dyn_Visc =16']
print(Number)

print("Enter the parameter to be the independent co-ordinate :")

x = int(input())

print("Enter the parameter to be the dependent co-ordinate :")

y = int(input())

value_x = []
value_y = []

for line in open('engine_data.out'):
      if '#' not in line:
        value_x.append(float(line.split()[x]))
        value_y.append(float(line.split()[y]))
        
fname = parameters[y] +"vs"+ parameters[x]

plt.figure()
plt.plot(value_x,value_y, linewidth = 3)
plt.xlabel(parameters[x])
plt.ylabel(parameters[y])
plt.title(fname)
plt.savefig(fname+'.png', format = 'png')
plt.show()

In the above snippet of code, the libraries such as matplotlib and numpy are imported. Parameters are defined and the two inputs are taken using the input function which is used to specifically access the locations which are needed for the user. By getting the specific columns of data the data is stored in two different arrays and it is plotted using the matplotlib library.

The plots generated using the above code is shown below:

Different figures can be generated by applying different ordinate and abscissa.

The performance calculation is done using the above piece of code.


"""
Program to find the work done
"""
from scipy.integrate import simps



pressure = []
volume = []

for line in open('engine_data.out'):
      if '#' not in line:
        pressure.append(float(line.split()[1])*1e6)
        volume.append(float(line.split()[7]))

Work_done = simps(pressure,volume)
print('The work done per cycle:', Work_done,'J')


"""
Performance Calculations

"""
# Power = Work done per unit time or in case of an ic engine no. of cycles in unit time times work done
# For a four stroke engine running at 1500 rpm, no of revolutions per second = 1500/60
# No of working strokes will be half of the no of revolutions per second i.e 1500/120
N = 1500 #rpm given

n = 2 # for four stroke engine

cycles = N/(60*n)

Power = (Work_done * cycles)/1000

# Brake specific fuel consumption 

m_f = 20*pow(10,-9) #micro gram is converted to kg

bsfc = (m_f* 3600)/Power


print('Power:', Power,'kW')

print('Brake Specific Fuel Consumption:',bsfc,'kg/kWhr')

The Simpsons rule integration function is used to calculate the work done from the values of pressure and volume. The simps() function is imported from the integrate module of scipy library. The values of pressure and volume are taken from the file and stored in two separate arrays pressure and volume.

The power and specific fuel consumption are calculated assuming a four-stroke engine running at 1500 rpm. The output of the program is shown below:

CONCLUSION

The code is implemented in python and the outputs are presented.

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.