All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
AIM: From the given file “engine_data.out”, All the data inside the file has to be read and some task to be performed by using thadata inside the file, with PYTHON programming language. OBJECTIVE: Task -1: The PYTHON code should exit gracefully if a non-compatible file is provided as an input. It should say somethinglike…
Jayesh Keche
updated on 24 Jul 2021
AIM: From the given file “engine_data.out”, All the data inside the file has to be read and some task to be performed by using tha
data inside the file, with PYTHON programming language.
OBJECTIVE:
Task -1: The PYTHON 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"
Task-2: The PYTHON code should take column numbers as the input and plot the respective columns as separate images
and each file should be saved by the name of the column. This should not be done manually.
Task-3: The PYTHON code to calculate the area under the P-V diagram. P is in column 2 and V is in column 8
Task-4: Calculate the power output of this engine. Assume that RPM is 1500
Task-5: This engine consumed 20 micrograms of fuel (per 1 stroke cycle). Calculate its specific fuel consumption.
Program:-
import math
import numpy as np
import matplotlib.pyplot as plt
colomData_1= []
colomData_2=[]
Units=[]
properties = []
A= input('Input a file name: ')
if A == 'engine_data.out':
print('Ok, valid file')
else:
print('File not recognized. Please provide a valid CONVERGE output file')
exit()
a = input ("Enter the first column index value: ")
b = input ("Enter the second column index value: ")
a= int(a)
b= int(b)
line_count =1
for line in open(A):
line_count = line_count + 1
if line_count == 4:
properties.append(line.split())
P1 = (line.split()[a])
P2 = (line.split()[b])
if line_count == 5:
Units.append(line.split())
U1 = (line.split()[a])
U2 = (line.split()[b])
if '#' not in line:
colomData_1.append(float(line.split()[a-1]))
colomData_2.append(float(line.split()[b-1]))
# filename = 'property%04d.png' % line_count
plt.figure(line_count)
plt.plot(colomData_1, colomData_2, linewidth =3)
plt.xlabel(P1 + U1)
plt.ylabel(P2 + U2)
plt.savefig((P1 + U1)+' VS '+(P2 + U2)+'.PNG')
plt.show()
# Calculate the area under the P-V diagram
pressure= []
volume=[]
for line in open('engine_data.out'):
if '#' not in line:
pressure.append(float(line.split()[1]))
volume.append(float(line.split()[7]))
Area= np.trapz(pressure,volume)* pow(10,6)
print(Area)
# Calculate the power output of this engine
RPM = 1500
Power = Area * (RPM/60)
Fuel_mass = 20 * pow(10,-6)
# Calculate its specific fuel consumption
Specific_fuel_cons= Fuel_mass/ Power
print('Workdone in Joules = ', Area)
print('Power in Watt = ', Power)
print('Specific fuel consumption in gm/w hr= ',Specific_fuel_cons)
Explanation:-
1)For Compatability check, the file should match with the main file so we take that input as a string and match it with the if else
loop
2)The a and b as integer inputs to use later.
3)We start reading file A after opening it in for loop.
4)In this, we use 3 if conditions in which we save the line of unit and properties in an array and append them into an empty
array.
5)when we split the line it comes in form of an array.
6)from this, I can get any column data of that row/line just by indexing the required value
7)As the crank angle has 1 indexing, pressure has 2 like this we can get any data we want.
8)convert that data into floating-point numbers as it might be a string.
9)Add this to my crank array.
10)Now, save the file name and plot figure.
11)We calculated the below area, power, etc by simply defining the formula in python.
12)At last, we print all of them.
Output:-
Error throw for Invalid file
To change the compability
CONCLUSION:
Hence, the large amount of data stored in a file, can easily studied, compared and analysed, using PYTHON programming
language.
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...
Roof challenge
Design of Roof Objectives- 1. For the Given Roof styling, Develop the essential flanges and reinforcements, provide appropriate dimensions and check forDraft analysis and also submit your section modulus report on the 0-Y section.2. Start with the creation of a roof ditch area the tool opening angle is only 3 degrees.3.…
30 Jul 2021 04:51 PM IST
Section Modulus calculation and optimization
AIM: Section modulus calculation and optimization OBJECTIVE: Use section of the Hood and calculate the section modulus.Vary the section in such a way that new section is an improved version of previous section. THEORY:Section modulus is to find the geometric property for a given cross-section used in the design.Calculate…
30 Jul 2021 04:51 PM IST
Fender Design Challenge
FENDER: The fender is the car body part that frames the wheel. Its purpose is to prevent sand, dirt, rocks, and other roads spray from beinthrown into the air by the rotating tire and close the engine component. When a vehicle is moving, tires pick up stones and otherand hurl them in all directions. Fenders are basically…
30 Jul 2021 04:51 PM IST
Hood design-Week 2
DESIGNING OF HOOD ASSEMBLY Objective To understand and study the design methodology and mechanisms that goes under designing and developing an AutomotivHood to achieve maximum safety for everyone in and around vehicle. HOOD DESIGN- CHALLANGE Introduction:- Hood is main component of a car at the front portion. It is used…
30 Jul 2021 04:50 PM 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.