OTTO cycle p-v diagram visualizer with Thermal efficiency
clear all
close all
clc
% inputs
gama = 1.4;
t3 = 2300;
%state variable at point 1
p1 = 101325;
t1 = 500;
%engine geometric parameters
bore = 0.1;
stroke = 0.1;
con_rod = 0.15;
cr = 12;
%caliculating the swept volume and clearence volume
v_swept = (pi/4)*bore^2*stroke;
v_clearence = v_swept/(cr-1);
v1 = v_swept+v_clearence;
v2 = v_clearence;
% state variable at point 2
%p2v2^gama=p1v1^gama
%p2 = p1*(v1/v2)^gama = p1*cr^gama
p2 = p1*cr^gama;
%p1v1/t1=p2v2/t2
t2 = p2*v2*t1/(p1*v1);
constant_c = p1*v1^gama;
v_compression = engine_kinematics(bore,stroke,con_rod,cr,0,180);
p_compression = constant_c./v_compression.^gama;
%state variable at poinnt 3
v3 = v2;
%p3v3/t3=p2v2/t2
p3 = p2*t3/t2;
constant_c = p3*v3^gama;
v_expansion = engine_kinematics(bore,stroke,con_rod,cr,180,0);
p_expansion = constant_c./v_expansion.^gama;
%state variable at point 4
v4 = v1;
%p3v3^gama=p4v4^gama
p4 = p3*(v3/v4)^gama;
figure(1)
hold on
plot(v1,p1,\'*\',\'color\',\'r\');
plot(v_compression,p_compression,\'color\',\'g\');
plot(v2,p2,\'*\',\'color\',\'r\');
plot(v3,p3,\'*\',\'color\',\'r\');
plot(v_expansion,p_expansion,\'color\',\'g\');
plot(v4,p4,\'*\',\'color\',\'r\');
plot([v2,v3],[p2,p3],\'color\',\'b\');
plot([v4,v1],[p4,p1],\'color\',\'b\');
xlabel(\'PRESSURE\');
ylabel(\'VOLUME\');
%thermal efficiency of otto cycle= 1-1/r^(gama-1)
%where r=v4/v3
r = v4/v3;
term1 = 1/r^(gama-1);
thermalefficiency = ([1 - term1]*100)
Function of this program
fuction [v] = engine_kinematics(bore,stroke,con_rod,cr,startcrankangle,endcrankangle)
a = stroke/2;
R = con_rod/a;
v_s = pi/4*bore^2*stroke;
v_c = v_s/(cr-1);
theta = linspace(startcrankangle,endcrankangle,100);
term1 = 0.5*(cr-1);
term2 = R+1-cosd(theta);
term3 = (R^2-sind(theta).^2).^0.5;
v = (1+term1*(term2-term3))*v_c;
end