P-V Diagram visualizer for air standard cycle
Aim: To write a code that can solve an otto -cycle and make plots for it.
- To create a P- V diagram
- To compute the thermal efficiency of the engine.
Reference : Youtube
To write the program for otto cycle , we need to calculate value of state variables at all 4 points. Some initial parameters are known to us at the start of the problem are t1, p1, gamma, t3 temperature at the end heta supplied and geometric parameters of the engine.
Swept volume and clearance volume calculation:
`v_s = (pi/4)*(bore)^2*stroke;`
`v_c= v_s/ (r-1);`
`v1 = v_s + v_c`;
`v2= v_c`
Computing state variables at all state points using the relation of Ideal gas law and `p*v^gamma = constant.`
These 4 points are located using plot command on p-v diagram. Figure command along with ‘hold on‘ is used to open up new figure window.
Wrong way joining these 4 points is by using plot command.
To overcome we need to follow piston kinematics which will tell us volume changes from top dead -center to bottom dead -center.
Engine kinematics is to be understood by drawing graph between volume traced and crank angle theta. To calculate traced volume, following formulae is used:
Program that we wrote for engine -kinematics.
Corresponding plot :
Theta vs traced -volume plot for 2 cycles
To use above program in our otto cycle proram , a new program is written for engine kinematics and saved as function to call it as function in our original program. We are saving it as a function to make overall program more presentable. To call the function we have to delete some input parameters like engine-geometrics which will be called through saved fuction in matlab. Name of the function and saved matlab file is exactly identical.
function[V]= engine_kinematics( bore ,stroke,con_rod, r, start_crank, end_crank)
%Geometeric parameters of engine
% a is crank pin radius
a= stroke/2
R = con_rod/a
% computing swept volume and clearance
v_s = (pi/4)*bore^2*stroke
v_c= v_s/ (r-1)
theta = linspace(start_crank, end_crank , 100) ;
term1 = 0.5*(r-1);
term2 = R + 1 -cosd(theta);
term3 = (R^2 - sind(theta).^2).^0.5;
% V is traced volume
V= ( 1+ term1*(term2 - term3)).*v_c;
end
% This is not the main program.
Calling saved function in the command window. No. of inputs provided are in the same order in which they are mentioned while defining the function. Otherwise there will error stating that less no. of input provided.
This function is being called in our main program. We use it to calculate volume at the end of compression and expansion.
Thermal-efficiency = `1- (1/r)^(gamma-1)`
Main Code is mentioned below.
clear all
close all
clc
%To write a program to plot otto cycle and compute its thermal efficiency
%initial input
gamma = 1.4 ;
t3= 2300
%state points values
p1 = 101325
t1= 500
%Geometeric parameters of engine
bore = 0.1;
stroke= 0.1;
con_rod = 0.15;
r = 12;
% computing swept volume and clearance
v_s = (pi/4)*bore^2*stroke;
v_c= v_s/ (r-1);
v1 = v_s + v_c
v2= v_c
%state variables at at state point 2
% p2v2^gamma = p1v1^gamma
%p2 = p1*(v1/v2)^gamma= p1*r^gamma
p2 = p1*r^gamma
% using ideal gas law
t2= p2*v2*t1/ (p1*v1)
constant_c = p1*v1^gamma
V_compression = engine_kinematics( bore ,stroke,con_rod, r, 180, 0);
P_compression= constant_c./V_compression.^gamma;
%state variables at state point 3
v3=v2;
% again using Ideal gas law
p3 = p2*t3/t2
constant_c = p3*v3^gamma
V_expansion = engine_kinematics( bore ,stroke,con_rod, r, 0, 180);
P_expansion= constant_c./V_expansion.^gamma;
%state variable at state point 4
v4= v1
% p4*v4^gamma = p3*v3^gamma
p4= p3*(v3/v4)^gamma
figure(1)
hold on
plot(v1,p1, '*' , 'color', 'r')
plot(V_compression, P_compression)
plot(v2,p2, '*' , 'color', 'r')
plot(v3,p3, '*' , 'color', 'r')
plot(V_expansion, P_expansion)
plot(v4,p4, '*' , 'color', 'r')
%to join straight lines
plot([ v1 v4 ],[ p1 p4],[v2 v3],[p2 p3], 'color', 'b')
xlabel('volume');
ylabel('pressure');
Thermal_efficiency = 1- (1/r)^(gamma-1)
Output:
Corresponding plot of otto cycle after over-coming all errors mentioned above in the report.
Conclusion : Thermal efficiency of otto cycle come out to be 62.99%.