AIR STANDARD CYCLE (OTTO CYCLE) USING MATLAB
PROJECT NAME – AIR STANDARD CYCLE (OTTO CYCLE) USING MATLAB
AIM-
To calculate thermal efficiency of the engine by writing a code for PV diagram of an air standard cycle (Otto cycle).
OBJECTIVE-
- To understand the difference between ideal Otto cycle and actual Otto cycle.
- How changes in volume and pressure of the working fluid change due to combustion process which creates the heat and force motion of the piston results in movement of the bike.
PROCEDURE-
P-V Diagram of otto cycle-
Fig – Ideal P-V Diagram of Otto cycle
Ideal Otto cycle has -
1-2 = Reversible Isentropic Compression.
2-3 = Constant volume heat addition.
3-4 = Reversible isentropic expansion.
4-1 = Constant volume heat rejection.
Inputs –
V1 = Volume at point 1
T1 = Temperature at point 1.
P1 = Pressure at point 1.
Cr = Compression ratio.
V2 = Volume at point 2.
P2 = pressure at point 2.
T2 = Temperature at point 2.
T3 = Temperature at point 3.
V3 = Volume at point 3.
P3 = Pressure at point 3.
In order to complete P-V Diagram we should know that volume changes from state 1 to state 2.and this actually depends on engine kinematics and in this particular problem one should start with the engine geometric parameters i.e.
i)Bore.
ii) Stroke.
iii) Connecting rod.
iv) Compression Ratio.
Once one should have all these parameters one can solve kinematics equation for piston and can compute volume trace and sequentially able to compute swept volume and clearance volume which is the information that is required to calculate swept volume and clearance volume and eventually we will be able to calculate V1 & V2.
- Swept volume is basically the volume of cylinder that is defined by the bore and stroke and that’s equal to
Vswept = π/4 * bore2 * stroke;
- Clearance volume is nothing but - Swept volume/ (CR -1).
Now if u see workspace you will see that p3 > p2 which gives indication that values are correct because combustion process takes place-
clear all
close all
clc
%inputs
gamma = 1.4
t3 = 1000
%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 variables at state point 2
%p2v2^gamma = p1v1^gamma
%p2 = p1*(v1/v2)^gamma = p1*cr^gamma
p2 = p1*cr^gamma;
%p1v1/t1 = p2v2/t2 | t2 = p2*v2*t1/(p1*v1)
t2 = p2*v2*t1/(p1*v1);
%state variables at state point 3
v3 = v2
%p3v3/t3 = p2v2/t2 | p3 = p2*t3/t2
p3 = p2*t3/t2
%state variables at state point 4
v4 = v1
%p3v3^gamma = p4v4^gamma | p4 = p3(v3/v4)^gamma
p4 = p3*(v3/v4)^gamma
% plotting
figure(1)
hold on
plot(v1,p1, '*', 'color', 'b')
plot(v2, p2, '*', 'color', 'r')
plot(v3, p3, '*', 'color', 'b')
plot(v4, p4, '*', 'color', 'y')
plot ([v1, v2, v3, v4, v1], [p1, p2, p3, p4, p1,], 'color', 'b')
Fig – Workspace having calculation of values
After using plot command to plot out the points (1,2,3,4) you will see a plot of star shaped pointed plots which are the required position of the points of Otto cycle now to join that plot we will again use plot command and after running that plot command you will see 4 points joined out by straight line.
Fig – location of pressure and volume points(p1,v1, p2,v2, p3,v3, p4,v4)
Fig – Points connected by straight lines
The above plot is completely incorrect only the constant volume process is right but the compression and expansion process have been represented by wrong path curves in ordor to this correctly we should know two things
- Thermodynamic relationship during compression process &
- Piston kinematics to find change in the volume from Top Dead Centre to Bottom Dead Centre.
In ordor to read more information one should solve piston kinematics which basically tells us how the piston actually moves from TDC to BDC and during this process how does the combustion volume chamber changes as the function of the crank angle and to do this – write simple programme in MATLAB.
And hence we will use the formula which will tell us how the volume inside the combustion chamber will going to change
……………………………………..(1)
start with the engine geometric parameters i.e.
i)Bore.
ii) Stroke.
iii) Connecting rod.
iv) Compression Ratio.
Now let us think that crank angle Θ = 0
Which means that it is your TDC and now we will code a relationship for particular value of Θ and we can also see that the equation is pretty long we have to break it up in several terms i.e – term 1, term 2, term 3 and also after running a programme a simple test you can do to recheck the correctness of the programme is that, when Θ = 0 then volume should correspond clearance volume and you can check that thing by tying in command window and the whole idea of using the formula …(1) is that it provides a lot of advantages.
If we edit linspace command as linspace(0,180,180)and if we are using this matrix we have to use element wise operator in term 3 and in the formula of v & when you run this command you will see values in command window and now in command window if you type plot(theta,v) there will be a graph –
Fig – Volume inside the engine going to vary
Now if you were assuming that your volume from TDC to BDC changes linearly then you are wrong this is how [(graph)] profile changes and our code is generated and now if you edit
Θ = linspace(0,720,720) and plot(theta, v, ‘linewidth’, 3) you will get following graph –
Fig - Volume traces for two cycles
So we will be going to use this information for volume compression and expansion stroke once we do that we will complete our PV diagram now what you can do is to copy the entire code & paste it in previous code of Otto cycle but it will make whole coding cumbersome so what we will do we will convert it into the function.
Functions are nothing but piece of code that you can reuse by just calling its name and passing in the right parameters so we will start coding in editor window and save the script by the name engine kinematics and we are just creating a coding template and whenever we want to substitute different values we will just call that function and will pass the right values and also as we are writing function we will delete bore, stroke, con_rod because when we will be adding/inputing these values, when I call the function also we will remove that plot command and type end there.
Now in command window we will be calling a function by assigning it to a variable v_compression i.e. v_compression = [0.1, 0.1, 0.15, 12, 0, 180]………………..(2)
And when you will run the command (press enter) in command window you will see different values and if you pot v_compression you will see same graph [Fig – Volume inside the engine going to vary].
MATLAB knows function [v] is an array which contains our volume trace and MATLAB knows [v] is output because because we are calculating v = (1 + term1 * term2 – term3).*v_c
If you name this as volume_trace & in command window if you run the code (2) you will see error saying output argument v is not assigned so you have to edit the function as volume_trace or simply place [v] in both the places and now it will run this is called as function definition because you are defining what the function is and function [v] = engine_kinematics is the name of the function and always remember the name of the function and the name of the file should exactly be the same and (bore, stroke, input) are input functions & in command window as we are typing v_compression = [0.1, 0.1, 0.15, …] called as calling a function means using a function (using template with appropriate values & you need to focus on order in which you pass the input) you need to make sure that numbr of inputs you provide and & called inputs should always match.
If you type in command window v_compression you will get same old wrong plot but in command window you can see its values are getting printed so If you remember pv^ˠ = constant and since v_compression is an array we need to use element wise operator.
function used for actual otto cycle -
function [v] = engine_kinematics_otto(bore, stroke, con_rod, cr, start_crank, end_crank)
a = stroke/2
R = con_rod/a
v_s = pi/4*bore^2*stroke;
v_c = v_s/(cr-1);
theta = linspace(start_crank, end_crank,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
Actual code for otto cycle -
clear all
close all
clc
%inputs
gamma = 1.4
t3 = 1000
%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 variables at state point 2
%p2v2^gamma = p1v1^gamma
%p2 = p1*(v1/v2)^gamma = p1*cr^gamma
p2 = p1*cr^gamma;
constant_c = p1*v1^gamma;
V_compression = engine_kinematics_otto(bore, stroke, con_rod, cr, 180,0);
P_compression = constant_c./V_compression.^gamma;
%p1v1/t1 = p2v2/t2 | t2 = p2*v2*t1/(p1*v1)
t2 = p2*v2*t1/(p1*v1);
%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_otto(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
% plotting
figure(1)
hold on
plot( V_compression, P_compression)
plot( V_expansion, P_expansion)
plot([v2 v3], [p2 p3], 'color', 'b')
plot([v4 v1], [p4 p1], 'color', 'r')
xlabel('volume')
ylabel('pressure')
legend('isentropic comp.', 'constant vol heat addition','isentropic exp.','constant volume heat rejection')
% thermal efficiency of otto cycle
Thermal_effe = (1-(1/cr^(gamma-1)))*100
Graph is shown in figure below –
Fig – Actual area under the curve for Otto cycle
Thermal efficiency of otto cycle is -
Fig - Thermal efficiency of otto cycle
Thermal efficiency = 62.9893 ...........................(Answer)