IntakeDesign Multi Shock.m
IntakeDesign Multi Shock.m
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %%%%%%%%%%%%% %%%%%%%%%%%%%
3 %%%%%%%%%%%%% Sarah Scott - 22nd April 2018 %%%%%%%%%%%%%
4 %%%%%%%%%%%%% Supersonic Intake Design %%%%%%%%%%%%%
5 %%%%%%%%%%%%% %%%%%%%%%%%%%
6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8 % Notes!! (Read me)
9 % Set number of shocks, Mach number, inlet height, and ramp angles in the
10 % section "Design Specs".
11 %
12 % Code could be tidied up a lot and split into functions, but I'm currently
13 % writing a script to model the performance for the whole engine so will
14 % update in due course, however please modify as you see fit.
15 %
16 % There are some calculations producing total pressure ratio, Mach numbers
17 % post shock etc that I haven't explicity used yet but will be included in
18 % the total engine simulation.
19 %
20 % The ramp co-ordinates can be found from the variables [rampx,rampy]
21 %
22 % If output is complex, shock is dettached!!!! Try reducing ramp angles.
23 %
24 % If spurious plots are generated, it's usually due to excessive shock
25 % angles created by large ramp angles and/or low Mach number.
26 clc;
27 clear all;
28 close all;
29 %% Design Specs
30 Mfs = 3; % Design freestream Mach number
31 del_1 = 5; % First Ramp angle
32 del_inc = 5; % Ramp Increment angle
33 h = 18; % Inlet height between cowl and centrebody
34 n = 3; % Number of shocks
35 %% Constants
36 gamma = 1.4; % Gas constant
37 itr = 25; % Number of iterations
38 %% Pre-allocate variable arrays
39 y2 = zeros(itr,1);
40 Pti_Pte = zeros(n,1);
41 Pi_Pe = zeros(n,1);
42 Me = zeros(n,1);
43 theta = zeros(n,1);
44 Mi = zeros(n,1);
45 del = zeros(n,1);
46 alpha = zeros(n,1);
47 eta = zeros(n,1);
48 a = zeros(n,1);
49 b = zeros(n,1);
50 ramp_x = zeros(n+1,1);
51 ramp_y = zeros(n+1,1);
52 Mi(1) = Mfs; % Initial freestream Mach number for first value
53 del(1) = del_1; % Initial ramp angle for first value
54 %% Find theta (Shock angle)
55 for j = 1:1:n % Loop for each shock
56 for i = 2:1:itr % Loop iteration to find y
57 y2(1) = 1/Mi(j)^2; % Initial guess for y
58 y2(i) = (1/(Mi(j)^2))+(((1/Mi(j)^2)+((gamma+1)/2)-y2(i-1))*((y2(i-1)/(1-y2(i-1))))^0.5)*tand(del(j));
59 if abs(y2(i) - y2(i-1)) < 0.00005 % Check for convergence
60 break
61 end
62 end
63 if j+1 <= n
64 del(j+1) = del(j)+del_inc; % Increment ramp angle after each shock
65 end
66 Pti_Pte(j) = (((gamma+1)/((2*gamma*y2(i)*Mi(j)^2)-(gamma-1)))^(1/(gamma-1)))*((((gamma+1)*(y2(i)*Mi(j)^2))/(2+((gamma-1)*(y2(i)*Mi(j)^2))))^(gamma/(ga
67 Pi_Pe(j) = ((2*gamma*y2(i)*Mi(j)^2)-(gamma-1))/(gamma+1); % Static pressure across shock
68 Me(j) = ((4+(4*(gamma-1)*y2(i)*Mi(j)^2)+(y2(i)*(Mi(j)^4)*(gamma+1)^2)-(4*gamma*(y2(i)^2)*Mi(j)^4))/(((2*gamma*y2(i)*Mi(j)^2)-gamma+1)*(2+((gamma
69 theta(j) = asind(sqrt(y2(i))); % Shockwave angle
70 Mi(j+1) = Me(j); % Set Mach number for next shock calculations
71 end
72 %% Find lengths of shock to ramp
73 alpha(n) = theta(n)+ del(n); % Three internal angles of shock,ramp,vector triangle
74 psi(n) = 90 + del(n);
75 beta(n) = 90 - alpha(n);
76 eta(n) = 90;
77 a(n) = h;
78 c(n) = (a(n)*sind(eta(n)))/sind(alpha(n));
79 x(n+1) = 0; % Add 0,0 datum location, end of last ramp (normal shock intersection on centrebody)
80 y(n+1) = 0;
81 x_L = a(n)*cosd(psi(n));
82 y_L = a(n)*sind(psi(n));
83 s(n) = (a(n)*sind(beta(n)))/sind(alpha(n));
84 x(n) = 0 - s(n)*cosd(del(n));
85 y(n) = 0 - s(n)*sind(del(n));
86 %% Loop for other shocks
87 if n > 1 % If number of shocks is more than one, loop for other ramps
88 for j = 1:1:n-1
89 ind = n-1:-1:1; % Indices to allow starting at last shock and work forwards
90 alpha(ind(j)) = theta(ind(j)) - del(ind(j)); % Find internal angles that form triangles between shocks and ramp
91 eta(ind(j)) = 180 - theta(ind(j)+1) + del(ind(j));
92 beta(ind(j)) = 180 - eta(ind(j)) - alpha(ind(j));
93 c(ind(j)) = (c(ind(j)+1)*sind(eta(ind(j))))/sind(alpha(ind(j))); % Find sides of triangles between shocks and ramp
94 s(ind(j)) = (c(ind(j)+1)*sind(beta(ind(j))))/sind(alpha(ind(j))); % Find length of side s
95 x(ind(j)) = x(ind(j)+1) - s(ind(j))*cosd(del(ind(j))); % Find positions from previous x_3 locations
96 y(ind(j)) = y(ind(j)+1) - s(ind(j))*sind(del(ind(j)));
97 end
98 end
99 %% Find lengths and heights of each ramp
100 for i = 1:1:n+1 % In x_3 & y_3, ramp starts at (0,0) and progresses negatively from n to 1
101 rampx(i) = x(i) + abs(x(1)); % Translate all x coords (so they start at x = 0 for first ramp)
102 rampy(i) = y(i) + abs(y(1)); % Translate all y coords (so they start at y = 0 for first ramp)
103 end
104 %% Plotting and formatting
105 inletx = [rampx(n+1); (x_L+rampx(n+1))]; % Normal shock vector across inlet
106 inlety = [rampy(n+1); (y_L+rampy(n+1))]; % Normal shock vector across inlet
107 basex = [0; rampx(n+1)]; % In x_3, ramp starts at inlet (n) [0,0] plus three ramp coords to define full length!!
108 basey = [0;0]; % Set base to zero
109 lip = [(x_L+rampx(n+1)),(y_L+rampy(n+1))]; % Lip position in space
110 hold on
111 fig1 = figure(1);
112 for i = 1:1:n % Loop to plot n number of shocks
113 plot([rampx(i),lip(1)],[rampy(i),lip(2)],'m','LineWidth',2)
114 end
115 plot(rampx,rampy,'-k',basex,basey,'--k','LineWidth',2) % Plot the ramp geometry
116 plot(inletx,inlety,':m','LineWidth',1.5) % Plot normal shock across inlet
117 %% formatting
118 axis equal
119 ylim([-0.25 (lip(2)*1.1)]) % 10% margin around max/min values for nice plot
https://www.dropbox.com/s/68mq8pcety6g0h4/IntakeDesign_multi_shock.m?dl=0 1/2
11/15/2018 IntakeDesign_multi_shock.m
120 xlim([-0.25 (rampx(n+1)*1.1)])
121 set(gca,'fontSize',22,'FontWeight','bold','LineWidth',1.5');
122 ylabel('Ramp Profile Height [mm]','fontsize',22,'FontWeight','bold');
123 xlabel('Ramp Profile Length [mm]','Fontsize',22,'FontWeight','bold');
124 title('Ramp Profile and Shockwaves','fontsize',30,'Fontweight','bold');
125 % set(fig1,'Color','w','Position',[350 100 900 900],'Toolbar','none','MenuBar','none','IntegerHandle','off');
126 %% Look up which ramp and show data on plot
127 str1 = sprintf('Freestream Mach Number %2.2f M',Mfs);
128 str2 = sprintf('Number of Shocks %2.0f ',n);
129 str3 = sprintf('Inlet Height %2.0f mm',h);
130 First = 1;
131 Second = 2;
132 Third = 3;
133 Fourth = 4;
134 Fifth = 5;
135 TableItr = [First Second Third Fourth Fifth];
136 Table = ["First Ramp Angle ","Second Ramp Angle ","Third Ramp Angle ","Fourth Ramp Angle ","Fifth Ramp Angle "]; % Strings spaced to gi
137 for i = 1:1:n
138 deg = "°";
139 r_angle = num2str(del(i));
140 Value = abs(TableItr-i); %Find closest match
141 [~, idx] = min(Value); %index of closest value
142 class = Table(idx); %closest value
143 str(i,:) = strcat(class,r_angle,deg); % Concatonate strings
144 end
145 if n == 1
146 string = {str1,str2,str3,str(1)};
147 elseif n == 2
148 string = {str1,str2,str3,str(1),str(2)};
149 elseif n ==3
150 string = {str1,str2,str3,str(1),str(2),str(3)};
151 elseif n==4
152 string = {str1,str2,str3,str(1),str(2),str(3),str(4)};
153 elseif n==5
154 string = {str1,str2,str3,str(1),str(2),str(3),str(4),str(5)};
155 end
156 dim = [0.2 0 0 0.8];
157 annotation('textbox',dim,'String',string,'FitBoxToText','on','LineStyle','none','fontsize',15,'fontweight','bold');
158 (set(gcf,'PaperPositionMode','auto')); %Reset figures PaperPositionMode to auto to stop cropping of image during save
159 print(gcf, '-dpng','Intake-1-shock-proposed-design.png') %Save image of output figure
https://www.dropbox.com/s/68mq8pcety6g0h4/IntakeDesign_multi_shock.m?dl=0 2/2