Project

Plotting PV diagram for otto cycle and Calculating thermal efficiency of Otto cycle using Octave:

This code is used to plot PV diagram and Calculate Thermal Efficiency for otto cycle by taking intial conditions (t1, p1), t3 and engine parameters (bore, stroke length,connection rod length, compression ratio) as inputs.

Code:

close all
clear all
clc

%Inputs

    Gamma = 1.4;
    t3 = 2300;
    
    % Variables
    p1 = 101325;
    t1 =500;
    
    %Engine Parameters
    bore = 0.1;
    stroke = 0.1;
    con_rod = 0.15;
    cr = 12;

%Calculate Swept Volume and Clearance Volume
    
    v_swept = (pi/4)* bore* 2 * stroke
    v_clearance = v_swept/(cr-1)
    
%Calculating Variables    
    
    v1 = v_swept + v_clearance
    v2 = v_clearance
    
    %p1*(v1^gamma) = p2*(v2^gamma)
    p2 = p1*((v1/v2)^Gamma)
    
    %(p1*v1)/t1 = (p2*v2)/t2;
    t2 = (p2*v2*t1)/(p1*v1)
    
    %variavbles for ploting isentropic compression curve 
    contant_c = p1*v1^Gamma;
    v_compression = engine_kinematics(bore, stroke, con_rod, cr, 180, 0);
    p_compression = contant_c./(v_compression.^Gamma)
    
    %Constant Volume process
    v3 = v2;
    v4 = v1;
    
    %(p3*v3)/t3 = (p2*v2)/t2;
    p3 = (p2*t3)/t2;
    
    %variavbles for ploting isentropic expansion curve
    contant_c = p3*v3^Gamma;
    v_expansion = engine_kinematics(bore, stroke, con_rod, cr, 0, 180);
    p_expansion = contant_c./(v_expansion.^Gamma)
    
    %p3*(v3^gamma) = p4*(v4^gamma)
    p4 = p3 *((v3/v4)^Gamma);
    
%Calcualting Thermal Efficiency

    Thermal_Efficiency = 1- (1/cr^(Gamma - 1))
    
%Plotting

    figure(1);
    hold on;
    title("Otto Cycle")
    xlabel("Volume")
    ylabel("Pressure")
    plot(v1, p1, '*', 'color', 'r')    
    plot(v2, p2, '*', 'color', 'r')    
    plot(v_compression, p_compression, 'color', 'b')
    plot(v3, p3, '*', 'color', 'r')
    plot(v_expansion, p_expansion, 'color', 'b')
    plot(v4, p4, '*', 'color', 'r')
    
    plot([v2 v3], [p2 p3], 'color', 'b')
    plot([v4 v1], [p4 p1], 'color', 'b')

Procedure:

Following steps used to plot PV diagram and Calculate Efficiency of Otto cycle in Octave

1. After creating new file, inputs are initialized.

p1 = 101325 | t1 =500 | t3 = 2300 | `gamma` = 1.4 | cr = 12

2. Swept volume and clearance volume are calculated by using following formulas

v_swept = (`pi`/4)* bore* 2 * stroke
v_clearance = v_swept/(cr-1)

3. Remaining variables are calculated based on following relations:

v2 =v3 | v4=v1 for constant volume process

p1*(v1^ `gamma`)= p2*(v2^ `gamma`) for isentropic compression

p3*(v3^ `gamma`)= p4*(v4^ `gamma`) for isentropic expansion

pv/t = constant

4. plot command is used to plot (v1 p1), (v2 p2), (v3 p3), (v4 p4) points on graph.

5. same plot command can be used to plot stright lines in the graph using points, but to create curves vector points are needed.

6. To create vector points a funtion is created

function [v] = engine_kinematics(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;

 
endfunction

7. This function takes engine parameters (bore, stroke, conecting rod length, compression ratio), initial and final piston angles as input and gives a vector variable as output.

8. Funtion output is saved as compresion volume vector variable and compression pressure is calculated using equation

p*(v^ `gamma`)=constant

9. This creates array of volume and pressure points along compression curve, to plot compression curve

10. Same will be repeated for isentropic expansion curve.

11. Thermal efficiency is calculated by using formula

Efficiency = 1- (1/cr^(`gamma` - 1)).

Output:

Thermal Efficiency output

Plot figure

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.