Week 6 - Data analysis
1. OBJECTIVES
Write a script that does the following.Link to data file
1. Data visualizer
Write a script that should take column numbers as the input and plot the respective columns as
separate images.
Each file should be saved by the name of the column
The plot labels should be extracted from the file.If, I request for a plot between column 1 (crank
angle) and column 8 (volume), then the label information should automatically be extracted and must appear as labels in the plots. THIS SHOULD NOT BE DONE MANUALLY
2. Compatability check
Code should exit gracefully, if a non-compatible file is provided as an input. It should say
something like 'File not recognized. Please provide a valid CONVERGE output file"
3. Basic performance calculation Calculate the area under the -V diagram. P is in column 2 and V is in column 8.
Calculate the power output of this engine.Assume that RPM is 1500
THEORY
Thermodynamic data collected from simulation of a port fuel injected engine is extracted and
analyzed from a data file using a Python program. This data file consists of 17 columns of different thermodynamic properties for which more than 8000 values have been recorded. From the data file we can understand that it a 4-Stroke otto cycle. So, we will apply the following formula for to calculate the Work done, Power output and Specific fuel consumption
A-Area under the P_V curve=-Work done per cycle (MJ)
Power output =A -n - 10° W
n=Number of cycles per second
N
" for 4-stroke engine
2 . 60
N
on for 2-stroke engine
N = Rotations per min.
SFC(Specific Fuel consumption)
Fuel consumed in kg/hr
Power output in kW
#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))
EXPLANATION OF THE PYTHON CODE
1.Import the necessary modules.
2.Take filename as an input and assign to ‘filename’ variable.
3.Perform compatibility test
Checking if the file is a valid CONVERGE output file
Checking if data is present in the CONVERGE output file
4.Data extraction
Extracting data along with the column name and column number from the CONVERGE output file. Complete data from the file stored in two 2D array ‘data’. The columns of the data matrix contains the data for each individual parameters.
5.Getting the data
Provide an instruction to the user so that he/she can use the numbers as an input to designate the variables to be plotted.
Ask users of plot between any two variables is required. If input is ‘y’ then ask for the numbers representing the variables to be plotted.
Ask the user if the plot is to be saved or not.
Then show the plot.
Above steps run in a while loop until user gives an input ‘n’ to the question “Do you want a plot between any two variables? (y/n): “
6.Calculation
Extract volume and pressure data from matrix ‘data’ and store in the ‘volume’ and ‘pressure’ respectively.Then, Numerically integrate pressure and volume data using simps() function from scipy.integrate library. It is the work done by the engine.
Take the value of engine speed (in rpm) and fuel consumption (in microgram) form user. Calculate the Power produced and Specific fuel consumption using the derived formulas.