Write code that can solve an otto cycle and make plots for it.
AIM : To write a code that can solve an otto cycle and make plots for it
EXPLANATION :

PROCESS :
0 - 1 CONSTANT PRESSURE INTAKE
1 - 2 ISENTROPIC COMPRSSION
2 - 3 CONSTANT VOLUME HEAT ADDITION
3 - 4 ISENTROPIC EXPANSION
4 - 1 CONSTANT VOLUME HEAT REJECTION
1 - 0 MASS OF AIR RELEASED
- With the input of volume 1 (v1) and temperature1 (t1) then pressure 1(p1) is calculated.
- If the compression ratio is known then volume 2 (v2) is calculated.
- And then need to know about the engine parameters instead of starting from v1 can start from engine parameters.
ENGINE GEOMETRIC PARAMETERS
- Bore.
- Stroke.
- Connecting rod length.
- CR(copression ratio).
Calculating the sewpt volume & clearance volume
swept volume = (pi/4)*bore^2*stroke.
clearance volume = (swept volume/CR-1).
volume v1 = swept volume + clearance volume.
volume v2 = clearance volume.
- Swept volume is nothing but the volume of the cylinder through which a piston or plunger moves as it makes a stroke.
- clearance volume is the ratio of this volume to the swept volume determines the compression ratio of the engine.
state variable at state point 1 is computed.
now state variable at state point 2 has to be determined by the
p2v2^gamma = p1v1^gamma which refers the isentropic compression.
so p2 = p1*(v1/v2)^gamma. v1/v2 is nothing but the compression ratio(CR).
To compute the temperature2 (t2) at state point 2 using ideal gas law.
since pv/t is constant. so p1v1/t1 = p2v2/t2.
therefore t2 = p2v2t1/p1v1.
let's determined the state variable at state point 3.
state point 3 represents end point of constant volume compression process.
v3 = v2
At the end of the compression process the temperature hs be assumed in order to determined p3.
p3v3/t3 = p2v2/t2.
therefore p3 = p2t3/t2.
Determined the state variable at state point 3.
volume at state 4 = volume ate state 1.
To compute the pressure p4.
p3v3^gamma = 04v4^gamma.
therefore p4 = p3(v3/v4)^gamma.
Function to be compute volume and pressure that has to be change the adiabatic process in the above function.
Volume trace function that input the function of bore,stroke,con-rod,start-crank angle,end-crank angle using the formula of
v/vc = 1+0.5(cr-1)[R+1-cosdtheta - (R^2-sin^2theta)^0.5].
This forumla is divied into three term
term1 = 0.5*(cr-1).
term2 = r+1-cosd(theta).
term3 = (r^2-sind(theta).^2).^0.5.
NOTE : THE NAME OF THE FUNCTION & NAME OF THE SAVE FILE SHOULD BE SAME.
Compression:
constant c = p1v1^gamma
V compression = engine kinematics(bore,stroke,con_rod,cr,180,0)
P compression = (constant c./V compression.^gamma)
Expansion:
constant c = p3v3^gamma
V expansion = engine kinematics(bore,stroke,con_rod,cr,0,180)
P expansion = (constant c./V expansion.^gamma)
thermal efficiency = 1-(1/(cr^gamma-1))
CODE : 1
function [V] = engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank)
a=stroke/2;
r=con_rod/a;
v_swept = (pi/4)*bore^2*stroke;
v_clearance = (v_swept/(cr-1));
theta = linspace(start_crank,end_crank,180);
term1 = 0.5*(cr-1);
term2 = r+1-cosd(theta);
term3 = (r^2-sind(theta).^2).^0.5;
V = (1+term1*(term2-term3))*v_clearance;
end
CODE : 2
close all
clear all
clc
%input
gamma = 1.4
t3 = 2300
%state variables
p1 = 101325
t1 = 500
%Engine geometric parameters
bore = 0.1;
stroke = 0.1;
con_rod =0.15;
cr = 12;
%calculating the swept volume and the clearance volume
v_swept = (pi/4)*bore^2*stroke;
v_clearance = (v_swept/(cr-1));
v1 = v_swept+v_clearance;
v2 = v_clearance;
%state variable at state point 2
%p2v2^gamma = p1v1^gamma | p2 = p1*(v1/2)^gamma = p1*cr^gamma;
p2 = p1*cr^gamma;
%p1v1/t1 = p2v2/t2 | t2 = (p2*v2*t1/(p1*v1));
t2 = (p2*v2*t1/(p1*v1));
constant_c = p1*v1^gamma;
V_compression = engine_kinematics(bore,stroke,con_rod,cr,180,0)
P_compression = (constant_c./V_compression.^gamma);
%state variables at state point 3
v3 = v2
%p3v3/t3 = p2v2/t2 | p3 = (p2*t3/t2);
p3 = (p2*t3/t2)
constant_c = p3*v3^gamma;
V_expansion = engine_kinematics(bore,stroke,con_rod,cr,0,180)
P_expansion = (constant_c./V_expansion.^gamma);
%state variables at state point 4
v4 = v1
%p3v3^gamma = p4v4^gamma | p4 =p3*(v3/v4)^gamma;
p4 =p3*(v3/v4)^gamma
%thermal efficiency
thermal_efficiency = 1-(1/(cr^gamma-1))
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')
xlabel('volume')
ylabel('pressure')
title('Correct plot')
figure (2)
plot([v1 v2 v3 v4],[p1 p2 p3 p4],'color','b')
xlabel('volume')
ylabel('pressure')
title('Incorrect plot')


THERMAL EFFICIENCY:

Thermal efficiency is calculated by
thermal efficiency = 1-(1/(cr^gamma-1)).
ERROR :

V_compression .capital 'V' is to be use. corrected in the above code 2.