quasi mat lab

Upload: manch-supreo

Post on 20-Feb-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/24/2019 Quasi Mat Lab

    1/5

    %Generalized Quasi-One-Dimensional (QOD) Flow Analyzer%by Adam J. Resler

    %This program designed for subsonic flow only (0 < M < 1).

    %Clear variables and screen for clean run of programclcclear

    %Fluid informationga = 1.4; %input(' Input heat capacity ratio, gamma: ');gm = 0.5 * (ga - 1);gi = ga / (ga - 1);

    %Gather initial information

    %Data from test cases%case1%case2%case3

    %case4

    %Data from project caseme560p1case

    %Set tolerance for convergenceelim = 0.005; %input('Tolerance, eps_lim: ');

    %Perform initial calculationsto1 = t1 * (1 + gm * m1^2);po1 = p1 * ((1 + gm * m1^2)^gi);a1 = 3.1415926535897932 * (d1^2) / 4;dx = l / (n - 1);

    %Initialize variablesx(1) = 0;m(1) = m1;mtest(1) = m1;p(1) = p1;po(1) = po1;t(1) = t1;to(1) = to1;a(1) = a1;d(1) = d1;i = 1;j = 1;eps = 1;

    sonic = 0;stag = 0;slow = 0;dad = -0.0000084667;dexit = d1 + ad * l;

    %Begin looptic

    % Optional exit diameter loop for choked conditions

  • 7/24/2019 Quasi Mat Lab

    2/5

    % To disable diameter finding loop, place a '%' figure in front of lines% 71, 73, 161, 162, and 164 in this code.%while sonic == 0

    %eps = 1;

    while eps >= elim

    i = 1;

    while i < n;% Solve for lagging variablesdadx(i) = 1.5707963267948966 * d(i) * (ad + 2 * bd * x(i));dtdx(i) = ae + 2 * be * x(i);g(i) = (-2 * dadx(i) / a(i)) + ((ga * (m(i)^2) + 1) * dtdx(i) /

    to(i)) + (ga * (m(i)^2) * f * 4 / d(i));dmdx(i) = (m(i)^2) * (((1 + gm * (m(i)^2)) * g(i)) / (1 -

    (m(i)^2)));

    % Solve for new variables

    m(i+1) = ((m(i)^2) + dmdx(i) * dx)^0.5;

    % Test for sonic conditions from subsonicif m1 < 1 && m(i+1) >= 0.9999

    m(i+1) = 0.9999;

    if sonic == 0xson = x(i-1);dson = d(i-1);

    end

    sonic = 1;

    end

    %Test for sonic conditions from supersonicif m1 > 1 && m(i+1)

  • 7/24/2019 Quasi Mat Lab

    3/5

    stag = 1;

    end

    x(i+1) = x(i) + dx;to(i+1) = to(1) + ae * x(i+1) + be * (x(i+1)^2);d(i+1) = d(1) + ad * x(i+1) + bd * (x(i+1)^2);a(i+1) = 3.1415926535897932 * (d(i+1)^2) / 4;t(i+1) = t(i) * (((1 + gm * (m(i)^2)) * (to(i+1))) / ((1 + gm *

    (m(i+1)^2)) * to(i)));p(i+1) = (p(i) * m(i) * a(i) / (m(i+1) * a(i+1))) *

    ((t(i+1)/t(i))^0.5);i = i + 1;

    end

    mtest(j) = m(i);dmdxt(j) = dmdx(i-1);ttest(j) = t(i);

    ptest(j) = p(i);

    % Test convergence of Mach numberif j > 1

    eps = abs((mtest(j) - mtest(j-1))/mtest(j));e(j) = eps;

    if eps > elimdx = l / (n - 1);

    end

    end

    j = j + 1;n = n + 1;

    end

    %ad = ad + dad;%dexit = d1 + (ad * l);

    %end

    % Negate fencepost problemj = j - 1;n = n - 1;

    % Analysis and screen printue = m(n-1) * sqrt(ga * 287 * t(n-1));

    % Plotting resultssubplot(3,1,1); plot(x,m,'LineWidth',1.5),xlabel('Duct Position(m)'),ylabel('Mach Number'),grid on,xlim([0 l]);set(gca,'xtick',[0:l/20:l]);subplot(3,1,2); plot(x,t,'LineWidth',1.5),xlabel('Duct Position(m)'),ylabel('Static Temperature (K)'),grid on,xlim([0 l]);

  • 7/24/2019 Quasi Mat Lab

    4/5

    hold onplot(x,to,'r--','LineWidth',2.25),legend('Static Temperature','StagnationTemperature','Location',[0.132833333333323 0.539854166666662 0.240.0729694444444444]);hold offset(gca,'xtick',[0:l/20:l]);subplot(3,1,3); plot(x,p,'LineWidth',1.5),xlabel('Duct Position(m)'),ylabel('Static Pressure (Pa)'),grid on,xlim([0 l]);set(gca,'xtick',[0:l/20:l]);

    % Print results

    % Transition test resultsif sonic > 0

    fprintf('Flow became CHOKED at approximately% 4.4f m in theduct.\n\n',xson);end

    if slow > 0fprintf('Flow SLOWED TO SONIC at approximately% 4.4f m in the

    duct.\n\n',xslo);end

    if stag > 0fprintf('Flow became STAGNANT at approximately% 4.4f m in the

    duct.\n\n',xstag);end

    % Program resultsfprintf(' Exit Mach number: % 12.4f\n',m(n));fprintf(' Exit velocity: % 12.4f m/s \t or % 12.4f mph\n',ue,ue *2.23693629);fprintf(' Exit temperature: % 12.4f K \t\t or % 12.4f degF\n',t(n),(t(n)+273)*1.8 + 32);

    % Pressure results and unit check (Pa, kPa, MPa); P > 0if p(n) >= 0 && p(n) < 1000

    fprintf(' Exit pressure: % 12.4f Pa \t or % 12.4fpsi\n\n',p(n),p(n)*0.0001450377380072);elseif p(n) >= 1000 && p(n) < 1000000

    p(n) = p(n)/1000;fprintf(' Exit pressure: % 12.4f kPa \t or % 12.4f

    psi\n\n',p(n),p(n)*0.0001450377380072*1000);else

    p(n) = p(n)/1000000;fprintf(' Exit pressure: % 12.4f MPa \t or % 12.4f

    psi\n\n',p(n),p(n)*0.0001450377380072*1000000);

    end

    % Print inlet/exhaust diametersfprintf(' Inlet Diameter: % 12.2f mm \t or % 12.4f in.\n',d1 *1000,(d1*1000)*0.03937007874);fprintf(' Exhaust Diameter: % 12.2f mm \t or % 12.4f in.\n',dexit *1000,(dexit*1000)*0.03937007874);fprintf('\n');

    % Program Analysis Time and Data

  • 7/24/2019 Quasi Mat Lab

    5/5

    fprintf('------------------------------------------------------------------\n');fprintf(' ********** PROGRAM ANALYSIS DATA **********\n');fprintf('\n');fprintf(' CPU Analysis Time: \t % 12.4f seconds\n',toc);fprintf(' Initial No. Iterations: \t % 12i\n',n1);fprintf(' Final No. Iterations: \t % 12i\n',n);fprintf(' Final tolerance: \t % 12.4E {limit % 12.4E}\n',eps,elim);fprintf('------------------------------------------------------------------\n');