All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
AIM :TO WRITE A PYTHON PROGRAM WHICH READS THE ENGINE OUTPUT PARAMETER DATA FILE AND PERFORM THE REQUIRED OBJECTIVES The programming language used is Python 2.OBJECTIVE : To read the data from a given data file. To take the file name as an input from the user and check whether the file is present or not. To plot a graph…
Ayush Kumar
updated on 16 Aug 2021
AIM :TO WRITE A PYTHON PROGRAM WHICH READS THE ENGINE OUTPUT PARAMETER DATA FILE AND PERFORM THE REQUIRED OBJECTIVES
The programming language used is Python
2.OBJECTIVE :
3.PROBLEM STATEMENT :
Read the data from a given file named 'engine_data.out' using python program, plot a curve between 2 engine parameters (parameters to be given by the user as an input) and perform basic performance calculation by calculating the area under the P-V diagram, the power output of this engine(Assume that RPM is 1500) and specific fuel consumption (engine consumed 20 micrograms of fuel (per 1 stroke cycle))
4.PROCEDURE
To solve the above-given problem statement, the following procedure is followed:
Python Code
#DATA ANALYSIS OF ENGINE DATA
#Importing the modules
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import simps
filename = input("Enter the name of CONVERGE output filename with extension(.out):")
#COMPATIBILITY CHECK
#Checking if the file is a valid CONVERGE output file
try:
f = open(filename)
f.close()
except FileNotFoundError:
print('File not recognized. Please provide a valid CONVERGE output file')
exit()
#Checking if data is present in the CONVERGE output file
i=0
for line in open(filename):
if '#' not in line:
break
i = i+1
j=0
for line in open(filename):
j=j+1
if j>i:
break
if j==i:
print('No data present in the CONVERGE output file')
exit()
#DATA EXTRACTION
i=0
for line in open(filename):
if i==2:
c = line.split() #Storing unit of variables in list c
i=0
break
if i==1:
b=line.split() #Storing names of variables in list b
i = i+1
if 'column' in line.split():
a = line.split() #Storing column numbers of variables in list a
i=1
a.remove("column") #Removing column from list a
a.remove("#") #Removing # from list a
a = np.array(a,dtype=np.int) #Converting data to integer
b.remove("#") #Removing # from list b
c.remove("#") #Removing # from list c
num_col = len(a) #Number of columns/number of variables
#GETTING THE DATA
data_counter = 0 #Initializing number of data points counter variable
data = np.arange(0,num_col)
for line in open(filename):
if '#' not in line:
d = line.split() #Storing current data line as in d
d = np.array(d,dtype=np.float32) #Converting list data to float array
data = np.vstack([data,d]) #Stacking the float array d in data matrix
data_counter = data_counter + 1
data = np.delete(data,0,0) #Deleting the first row used to initialize the array
#DATA VISUALIZER
print('Type -')
for i in a:
print('{} for {}'.format(i,b[i-1]))
print(' ')
x = input("Do you want a plot between any two variables? (y/n): ")
while(x.lower()=='y'):
cn1 = input("Enter the clumn number of the variable along X-axis (Refer input map above):")
cn2 = input("Enter the clumn number of the variable along Y-axis (Refer input map above):")
cn1 = int(cn1)
cn2 = int(cn2)
plt.figure()
plt.plot(data[:,cn1-1],data[:,cn2-2])
plt.xlabel('{} {}' .format(b[cn1-1],c[cn1-1]))
plt.ylabel('{} {}' .format(b[cn2-1],c[cn2-1]))
plt.title('{} {} vs {} {}' .format(b[cn2-1],c[cn2-1],b[cn1-1],c[cn1-1]))
z = "n"
z = input("Do you want to save the plot? (y/n):")
if(z.lower()=='y'):
plt.savefig("{}-{}.png".format(b[cn2-1],b[cn1-1]))
plt.show()
print(' ')
x = input("Do you want to plot any other two variables? (y/n):")
print(' ')
x = input("Do you want a single variable plot? (y/n): ")
while(x.lower()=='y'):
cn = input("Enter the column number of the variable (Refer input map above): ")
cn = int(cn)
plt.figure()
plt.plot(np.arange(0,data_counter),data[:,cn-1])
plt.xlabel('Data point number')
plt.ylabel('{} {} '.format(b[cn-1],c[cn-1]))
z = "n"
z = input("Do you want to save the plot? (y/n): ")
if(z.lower()=='y'):
plt.savefig("{}.png".format(b[cn-1]))
plt.show()
print(' ')
x = input("Do you want any other single variable plot? (y/n): ")
print(' ')
#CALCULATIONS
print('PERFORMANCE OF THE ENGINE')
#Work done
b1 = [i.lower() for i in b]
pressure_column = b1.index('pressure')
volume_column = b1.index('volume')
pressure = data[:,pressure_column]
volume = data[:,volume_column]
A = 0 #Area under the P-V curve
A = simps(pressure,volume,even='first')*np.power(10,6) #Work per cycle(J)
#Power output
rpm = float(input('Enter the rpm of the engine at which data was collected: ')) #Rotation per min
f = float(input('Enter the value of the fuel consumed per cycle (in micrograms): ')) #Fuel consumption per cycle (Microgram)
n = rpm/(2*60) #Number of cycle per second for 4-stroke engine
P = A*n #Power output(W) at speed N (rad/s)
#Specific fuel consumption
f = (f*n*3600)/np.power(10,9) #Fuel consumption (Kg/hr)
sfc = (f*1000)/P #Specific fuel consumption(Kg/hr.KW)
#Results
print('Area under the P-V curve (i.e. the Work done per cycle) = {} J'.format(A))
print('Power output at {} rpm = {} W'.format(rpm,P))
print('Specific fuel consumption = {} Kg/KW.hr'.format(sfc))
RESULTS
PLOTS
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Week 6 - Data analysis
AIM :TO WRITE A PYTHON PROGRAM WHICH READS THE ENGINE OUTPUT PARAMETER DATA FILE AND PERFORM THE REQUIRED OBJECTIVES The programming language used is Python 2.OBJECTIVE : To read the data from a given data file. To take the file name as an input from the user and check whether the file is present or not. To plot a graph…
16 Aug 2021 10:01 AM IST
Week 3 - Solving second order ODEs
Aim: To write a program to simulate the transient behavior of a simple pendulum.(Simulate the motion between 0-20 sec, for angular displacement=0,angular velocity=3 rad/sec at time t=0) To create an animation of its motion. Theory: A pendulum is a weight suspended from a pivot so that it can swing freely. When…
14 Jul 2021 08:05 AM IST
Week 5 - Curve fitting
AIM- To write a PYTHON code that performs curve-fitting on the relationship between cp and Temperature and finding the PERFECT FIT for the following. THEORY- Curve fitting is the process of constructing a curve, or mathematical functions, which possess the closest proximity to the real series of…
14 Jul 2021 06:10 AM IST
Week 2 Air standard Cycle
AIM:To generate the PV diagram and to determine the thermal efficiency of the engine. The programming language used is Python THEORY: Otto Cycle is an idealized thermodynamic cycle that describes the working of a spark-ignition engine. The cycle consists of 4 processes as illustrated in the figure below: it consists…
12 Jul 2021 09:38 AM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.