Challenge

Week 6 - Data analysis

Objective: To write a code to extract the data from the converge output file & to calculate specific fuel consumption & Power of the engine.

Code: In order to understand the code, let us split the code into 3 parts i.e. Data visualizer, Basic performance calculation & Compatibility check

Data Visualizer:

First, we have imported all the necessary library which we will need in the code.

Using for loop we have stored all the data into line and then using an array of the name of the variable we stored all the data to the respective variable using column indexing

Also, we have defined the empty array of the name of the variable.

The code is written in such a way that it will ask the input & plot the relation with respect to that meaning if I want a crank vs pressure plot I will enter that respective column number. Also, we have extracted the label & unit data from the engine file so, that it should print labels & units on the plot.

Basic performance calculation

In this part, we will calculate the power, specific fuel consumption & Area under the PV plot. In order to calculate the above parameter, the code has written in such a way that it will ask engine rpm & mass of fuel.

The above calculations will be done only when the input is asked for PV plot.

import numpy as np
import math
import matplotlib.pyplot as plt 

#Empty array for all engine parameters
Crank=[]
Pressure=[]
Max_pressure=[]
Min_pressure=[]
Mean_Temperature=[]
Max_Temperature=[]
Min_Temperature=[]
Volume=[]
Mass=[]
Density=[]
Integrate_HR=[]
HR_Rate=[]
C_p=[]
C_v=[]
gamma=[]
Kinematic_viscosity=[]
Dynamic_viscosity=[]
label=[]
unit=[]
line_count=1


file_name=input('Enter file name=')
if file_name=='engine.out':
    for line in open('engine_data.out'): #For loop for extracting the engine data 
        
         
        if line_count==3:
            for k in range(1,18):
                    label.append((line.split()[k]))
        if line_count==4:
            for j in range(1,18):
                    unit.append((line.split()[j]))

        line_count=line_count+1
      
    
        if '#' not in line:
                    Crank.append(float(line.split()[0]))
                    Pressure.append(float(line.split()[1]))
                    Max_pressure.append(float(line.split()[2]))
                    Min_pressure.append(float(line.split()[3]))
                    Mean_Temperature.append(float(line.split()[4]))
                    Max_Temperature.append(float(line.split()[5]))
                    Min_Temperature.append(float(line.split()[6]))
                    Volume.append(float(line.split()[7]))
                    Mass.append(float(line.split()[8]))
                    Density.append(float(line.split()[9]))
                    Integrate_HR.append(float(line.split()[10]))
                    HR_Rate.append(float(line.split()[11]))
                    C_p.append(float(line.split()[12]))
                    C_v.append(float(line.split()[13]))
                    gamma.append(float(line.split()[14]))
                    Kinematic_viscosity.append(float(line.split()[15]))
                    Dynamic_viscosity.append(float(line.split()[16]))
                    line_count=line_count+1

 
    Inp = np.array([Crank,Pressure,Max_pressure,Min_pressure,Mean_Temperature,Max_Temperature,
	            Min_Temperature,Volume,Mass,Density,Integrate_HR,HR_Rate,C_p,C_v,gamma,Kinematic_viscosity,Dynamic_viscosity])
    
    print('List of Parameters:'
            '\nCrank=0'
            '\nPressure=1'
            '\nMax_pressure=2'
            '\nMin_pressure=3'
            '\nMean_Temperature=4'
            '\nMax_Temperature=5'
            '\nMin_Temperature=6'
            '\nVolume=7'
            '\nMass=8'
            '\nDensity=9'
            '\nIntegrate_HR=10'
            '\nHR_Rate=11'
            '\nC_p=12'
            '\nC_v=13'
            '\ngamma=14'
            '\nKinematic_viscosity=15'
            '\nDynamic_viscosity=16')

    #Plotting          
    x=int(input('Enter the parameter which you want on x-axis='))
    y=int(input('Enter the parameter which you want on y-axis='))
    plt.plot(Inp[x],Inp[y])
    plt.xlabel((label[x])+(unit[x]))
    plt.ylabel((label[y])+(unit[y]))
    plt.title(' Plot for '+label[x]+  ' versus '  +label[y])
    plt.savefig(label[x]+ 'vs' +label[y])
    plt.show()

    #Calculating area under P-V diagram
    if x==1 and y==7:
        W=np.trapz(Inp[x],Inp[y]) #Work done per cycle is equal to area under the curve
        print('Area under P-V diagram=',W,'Nm')
        N=float(input('Enter the value of engine rpm=')) #Engine rpm
        P=(2*N*math.pi*W*1000)/(60) #Power
        print('Power of the engine=',P,'KJ/s')
        M=float(input('Enter engine fuel consumption in microgram per sec='))
        SFC=(M*pow(10,-6)*3600*1000)/P
        print('Specific fuel consumption=',SFC,'Kg/Kwhr')
           
else:
    print('File not recognized. Please provide a valid CONVERGE output file')

Output:


From the above image, its quite clear that the data inputted such that we should get a P-V plot, the below image, is the evidence that the code is working fine.

P-V Plot:

Basic performance calculation

As we discuss in the code explanation that performance calculation should be done only with input data is asked for P-V Plot and the above image is the evidence for that.

Compatibility check

The code is written in such a way that if the enter file name is not equal to the converge file name then it through an error which has shown below:











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.