You are on page 1of 19

Panel Method (2-D) for NACA four,five,six-digit-airfoil series

Kıvanç Ali ANIL


1.5
1.4
1.3
1.2
1.1
1
0.9
0.8
0.7 N = 80
0.6
0.5
0.4
0.3
0.2
0.1
0
-0.1
-0.2
-0.3
-0.4
-0.5
-0.6
-0.7
-0.8
-0.9
-1
0 0.2 0.4 0.6 0.8 1

(Reference: LEE, Jin-Tae, A Potential Based Panel Method for the Analysis of Marine Propellers in
Steady Flow,Thesis (Ph. D.), Massachusetts Institute of Technology, Dept. of Ocean Engineering,
1987, http://hdl.handle.net/1721.1/14641)
panel_naca_2D.m
% Kivanc Ali ANIL (10.12.2012)
%
% NACA four,five,six-digit-airfoil series
% PANEL METHODS
% Combined Source and Doublet Method
% Constant Strength Source Method (optional if alpha = 0
% and if foil is symmetric)
%
% This program uses following functions and subroutines:
% naca4dig.m (function)
% naca5dig.m (function)
% naca6dig.m (function)
% naca66a08.m (function)
% panelmet1.m
% panelmet2.m (option if alpha = 0 and if foil is symmetric)
clear,clc,close all
% ---------------------------------------------
% default values

def0 = {'66, a=0.8, t/c=0.04, f/c=0.02','1','1.5','1','80'};


def1 = {'0.04','0.02'};

% def0 = {'0012','1','8','1','20'};
% def0 = {'6418','1','-30:30','1','60'};
% def0 = {'6418','1','0','1','60'};
% def0 = {'4412','1','1.875','1','60'};
% def0 = {'0021','1','1.875','1','60'};
% def0 = {'21018','1','0','1','60'};
% def0 = {'63A018','1','0','1','60'};
% ---------------------------------------------
dlgTitle= 'NACA four,five,six-digit-airfoil series ';
prompt = {['Enter the NACA four-digit-airfoil number [6412, 0012, 0016, etc] OR ',...
'Enter the NACA five-digit-airfoil number [210XX, 220XX, 230XX, 240XX 250XX] OR ',...
'Enter the NACA 63A or 64A six-digit-airfoil number [63A0XX, 64A0XX] OR ',...
'Enter the NACA 66 (Mod) & a =.8 Camber'],...
'Enter the airfoil chord c',...
'Enter the flow angle of attack (alpha in degrees)',...
'Free stream velocity (U)',...
'Number of Panels (N) - ENTER AN EVEN NUMBER!'};
data = inputdlg(prompt,dlgTitle,1,def0);
if isempty(data)==1
clear
return
end
Nname = char(data(1)); % NACA airfoil number
c = str2num(char(data(2))); % chord (length of airfoil's chord line)
alphaarray = str2num(char(data(3))); %#ok<ST2NM>
U = str2num(char(data(4)));
N = str2num(char(data(5)));
% ---------------------------------------------
x = linspace(0,c,200);
x = x';
xtilda = 0:2*pi/N:pi;
xgc = (c/2)*(1-cos(xtilda)); % 0 - c
x2 = xgc; %2010
% ---------------------------------------------
if length(Nname) == 4
[Xu, Yu, Xl, Yl, Y] = naca4dig(Nname,x,c);
[xgcu, ygcu, xgcl, ygcl, Y2]= naca4dig(Nname,xgc,c);
elseif length(Nname) == 5
[Xu, Yu, Xl, Yl, Y] = naca5dig(Nname,x,c);
[xgcu, ygcu, xgcl, ygcl, Y2]= naca5dig(Nname,xgc,c);
elseif length(Nname) == 6
[Xu, Yu, Xl, Yl, Y] = naca6dig(Nname,x,c);
[xgcu, ygcu, xgcl, ygcl, Y2]= naca6dig(Nname,xgc,c);
else
dlgTitle= 'NACA 66, a=0.8 ';
prompt = { 'Thickness ratio (tmax/c)(maximim thickness/chord)',...
'Maximum camber ratio (f/c) (maximim camber/chord)'};
data2 = inputdlg(prompt,dlgTitle,1,def1);
if isempty(data2)==1
clear
return
end
tau = str2num(char(data2(1)));% thickness ratio (tmax/c)
e = str2num(char(data2(2)));% maximum camber ratio (f/c)
[Xu, Yu, Xl, Yl, Y] = naca66a08(tau,e,x,c);
[xgcu, ygcu, xgcl, ygcl, Y2]= naca66a08(tau,e,xgc,c);
end

xgc = [fliplr(xgcu), xgcl(1,2:length(xgc))];


ygc = [fliplr(ygcu), ygcl(1,2:length(ygcl))];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The global coordinates for panels
GCO = [xgc' ygc'];
%convert paneling to clockwise
GCO = flipud(GCO);
% GCO(1,2) = 0; %2010
% GCO(N+1,2) = 0; %2010
% ---------------------------------------------
% The global mid points of the panels
GMP = zeros(N,2);
for i = 1:N
GMP(i,:) = [(GCO(i,1)+GCO(i+1,1))/2,...
(GCO(i,2)+GCO(i+1,2))/2];
end
% ---------------------------------------------
L = zeros(1,N);
thetaMP = zeros(1,N);
nx = zeros(1,N);
ny = zeros(1,N);
tx = zeros(1,N);
ty = zeros(1,N);
for i = 1:N
% Panel lengths
L(i) = ((GCO(i+1,1)-GCO(i,1))^2+(GCO(i+1,2)-GCO(i,2))^2)^.5;
% The normal vectors of midpoints
thetaMP(i) = atan2((GCO(i+1,2)-GCO(i,2)),(GCO(i+1,1)-GCO(i,1)));
nx(i) = -sin(thetaMP(i));
ny(i) = cos(thetaMP(i));
tx(i) = cos(thetaMP(i));
ty(i) = sin(thetaMP(i));
end
% ---------------------------------------------
XG = GMP(:,1);
YG = GMP(:,2);
% ---------------------------------------------
% Constant Strength Source Method (optional if alpha = 0
% and if foil is symmetric) 2010
panmet = 1;
symmet = 0; %2010
if length(Nname) == 6 %2010 Simetri kontrol
symmet = 1; %2010
elseif length(Nname) == 4 %2010
if str2num(Nname(1)) == 0 && str2num(Nname(1)) == 0 %2010
symmet = 1; %2010
end %2010
end %2010
if symmet == 1
if length(alphaarray)==1 && alphaarray == 0
panmet = menu('Select Method!',...
'Combined Source and Doublet Method',...
'Constant Strength Source Method',...
'CANCEL');
if panmet == 3 % CANCEL, IPTAL
clear, close all
return
end
end
end
if panmet == 1 % Combined Source and Doublet Method
panelmet1
elseif panmet == 2 % Constant Strength Source Method
panelmet2
end
% [alphaarray' CLpanel CDpanel CMpanel]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1)
set(gcf,'Position',[52 45 1183 590])
subplot(211),
plot(x,Y)
hold on
plot(Xu,Yu,'r')
plot(Xl,Yl,'r')
axis equal
%axis off
for ix = 1:length(x)
line([Xu(ix) Xl(ix)],[Yu(ix) Yl(ix)])
end
title(['\fontsize{20}\bf{NACA }',Nname]);
grid on
xlabel('\fontsize{20}\bf{x}');
ylabel('\fontsize{20}\bf{y}');
hold off
subplot(212),
plot(GCO(:,1)/c,GCO(:,2)/c,'-xr','linewidth',1)
hold on
plot(x2/c,Y2/c,'.') %2010
quiver(GMP(:,1)/c,GMP(:,2)/c,nx',ny',0.1,'color',[1, 0 ,1])
axis equal
title(['\fontsize{20}\bf{Number of Panels: }',num2str(N)]);
xlabel('\fontsize{20}\bf{x/c}');
ylabel('\fontsize{20}\bf{y/c}');
hold off
% ---------------------------------------------
if panmet == 1
figure(11) %2010
set(gcf,'Position',[52 45 1183 590])
subplot(211),
hold on
plot(GCO(1:1+N/2,1)/c,GCO(1:1+N/2,2)/c,'-xr','linewidth',1)
plot(GCO(1+N/2:N+1,1)/c,GCO(1+N/2:N+1,2)/c,'-xb','linewidth',1)
plot(x2/c,Y2/c,'.') %2010
quiver(GMP(:,1)/c,GMP(:,2)/c,nx',ny',0.1,'color',[0, 0 ,0])
quiver(GMP(:,1)/c,GMP(:,2)/c,tx',ty',0.1,'color',[0, 0 ,0])
quiver(-.11,0,U*cos(alpha),U*sin(alpha),0.1,'color',[0, 0 ,0])% free stream
axis equal
text(.4,1.2*min(GMP(:,2))/c,'\fontsize{15}\bf{FACE}');
text(.4,1.2*max(GMP(:,2))/c,'\fontsize{15}\bf{BACK}');
title(['\fontsize{20}\bf{Number of Panels: }',num2str(N)]);
xlabel('\fontsize{20}\bf{x/c}');
ylabel('\fontsize{20}\bf{y/c}');
hold off
subplot(212),
quiver([XN';-U/20],[GCO(2:N,2);0],...
[VN'.*txalpha'; U*cos(alpha)],...
[VN'.*tyalpha'; U*sin(alpha)],...
0.5,'color',[0, 0 ,0])
axis equal
title('\fontsize{20}\bf{Velocity Distribution}');
end
% ---------------------------------------------
if length(alphaarray) == 1
figure(2)
set(gcf,'Position',[52 45 1183 590]);
hold on
plot(XN(1:N/2)/c,-CpN(1:N/2),'-+r') % FACE
plot(XN(N/2:length(XN))/c,-CpN(N/2:length(XN)),'-+b') % BACK
ylabel('\fontsize{20}\bf{Negative Pressure Coefficient, - C_P}');
xlabel('\fontsize{20}\bf{x/c}');
%title(['\fontsize{20}\bf{Pressure Distribution (C_L = }',num2str(CLpanel),')']);
title(['\fontsize{20}\bf{NACA }',Nname,...
' Pressure Distribution (\alpha = ',num2str(alpha*180/pi),')']);
legend('\fontsize{15}\bf{FACE}','\fontsize{15}\bf{BACK}');
grid on
xlim([min(GCO(:,1))/c 1]); % 2010
YLimDATA = get(gca,'Ylim');
YTickDATA = get(gca,'YTick');
hold off
figure(3)
set(gcf,'Position',[52 45 1183 590]);
[AX,H1,H2] = plotyy(XN/c,-CpN,GCO(:,1)/c,GCO(:,2)/c);
legend(['\fontsize{15}\bf{Panel Method, Number of Panels: }',num2str(N)]);
set(get(AX(1),'Ylabel'),'String','\fontsize{20}\bf{Negative Pressure Coefficient, - C_P}')
set(get(AX(2),'Ylabel'),'String','\fontsize{20}\bf{y/c}')
xlabel('\fontsize{20}\bf{x/c}');
title(['\fontsize{20}\bf{NACA }',Nname,...
' Pressure Distribution (\alpha = ',num2str(alpha*180/pi),')']);
set(H1,'Marker','+')
set(H1,'LineStyle','-')
set(H2,'Marker','x')
set(H2,'LineStyle','-')
axis(AX(2),'equal')
set(AX(1),'XLim', [min(GCO(:,1))/c, 1])
set(AX(1),'YLim', YLimDATA)
set(AX(1),'YTick', YTickDATA)
set(AX(2),'XLim', [min(GCO(:,1))/c, 1])
grid on
else
figure(2)
set(gcf,'Position',[52 45 1183 590])
axis([min(alphaarray) max(alphaarray) min(min(-CpN)) max(max(-CpN))])
view([90 -90])
for M = 1 : length(XN)
if M < N/2 % 2010
plot(alphaarray, -CpN(:,M),'r') % FACE
elseif M == N/2
plot(alphaarray, -CpN(:,M),'g','linewidth',1.5) % LEADING EDGE
else
plot(alphaarray, -CpN(:,M),'b') % BACK
end
axis([min(alphaarray) max(alphaarray) min(min(-CpN)) max(max(-CpN))])
view([90 -90])
grid on
hold on
% pause(.1) % 2010
end
title(['\fontsize{20}\bf{NACA }',Nname,...
' Cavitation Bucket Diagram - Panel Method, Number of Panels: ',...
num2str(N)]);
ylabel('\fontsize{20}\bf{Negative Pressure Coefficient, - C_P}');
xlabel('\fontsize{20}\bf{Angle of Attack, \alpha}');
view([90 -90])
figure(2) %2012
plot(alphaarray',max(-CpN')','k','linewidth',1.5) % minimum pressure envelope %2012
figure(3)
set(gcf,'Position',[52 45 1183 590])
plot(alphaarray,CLpanel(:,2),...
alphaarray,CLpanel(:,1),...
alphaarray,CDpanel,'LineWidth',4)
title(['\fontsize{20}\bf{NACA }',Nname,...
' Lift and Drag Coefficient - Panel Method, Number of Panels: ',...
num2str(N)]);
ylabel('\fontsize{20}\bf{Lift and Drag Coefficient, C_L and C_D}');
xlabel('\fontsize{20}\bf{Angle of Attack, \alpha}');
legend('\fontsize{15}\bf{C_L}',...
'\fontsize{15}\bf{C_L = -2*(PHI1(N)-PHI1(1))/(U*c)}',...
'\fontsize{15}\bf{C_D}',4);
grid on
figure(4)
set(gcf,'Position',[52 45 1183 590])
plot(alphaarray,CDpanel,'LineWidth',4,'Color', [1 0 0])
title(['\fontsize{20}\bf{NACA }',Nname,...
' Drag Coefficient - Panel Method, Number of Panels: ',...
num2str(N)]);
ylabel('\fontsize{20}\bf{Drag Coefficient, C_D}');
xlabel('\fontsize{20}\bf{Angle of Attack, \alpha}');
grid on
figure(5)
set(gcf,'Position',[52 45 1183 590])
plot(alphaarray,CMpanel,'LineWidth',4,'Color', [1 0 0])
title(['\fontsize{20}\bf{NACA }',Nname,...
' Moment Coefficient - Panel Method, Number of Panels: ',...
num2str(N)]);
ylabel('\fontsize{20}\bf{Moment Coefficient, C_M}');
xlabel('\fontsize{20}\bf{Angle of Attack, \alpha}');
grid on
end

naca4dig.m
function [XuG, YuG, XlG, YlG, YG] = naca4dig(NnameG,xG,cG)
% Kivanc Ali ANIL (08 Oct.2009)
% Function for NACA four-digit-airfoil number [6412, 0012, 0016, etc]
tau = str2num([NnameG(3) NnameG(4)])/100; % thickness ratio (maximim thickness/chord)
e = str2num(NnameG(1))/100; % maximum camber ratio (maximim camber/chord)
p = str2num(NnameG(2))/10 ;
YG = zeros(size(xG)); % camber line
theta = zeros(size(xG)); %
for i = 1:length(xG)
if xG(i)/cG < p
YG(i) = (e*xG(i)/p^2)*(2*p-xG(i)/cG);
theta(i) = atan(2*e*(p-xG(i)/cG)/p^2);
else
YG(i) = (e*(cG-xG(i))/(1-p)^2)*(1+xG(i)/cG-2*p);
theta(i) = atan(2*e*(p-xG(i)/cG)/(1-p)^2);
end
end
% ---------------------------------------------
% thickness distribution
ZZZ = 0.3537; % An Introduction to Theoretical and
% Computational Aerodynamics, Jack MORAN
% ZZZ = 0.3516; % Theory of Wing Sections
T = 10*tau*cG*(0.2969*sqrt(xG./cG)-0.126*(xG./cG)-...
ZZZ*(xG./cG).^2+0.2843*(xG./cG).^3-0.1015*(xG./cG).^4);
% ---------------------------------------------
XuG = xG-(T/2).*sin(theta);
YuG = YG+(T/2).*cos(theta);
XlG = xG+(T/2).*sin(theta);
YlG = YG-(T/2).*cos(theta);
naca5dig.m
function [XuG, YuG, XlG, YlG, YG] = naca5dig(NnameG,xG,cG)
% Kivanc Ali ANIL (08 Oct.2009)
% Function for NACA five-digit-airfoil number [210XX, 220XX, 230XX, 240XX 250XX]
dsg = str2num([NnameG(1) NnameG(2) NnameG(3)]); % Mean-Line Designation
if dsg == 210
m = 0.0580; k1 = 361.4;
elseif dsg == 220
m = 0.1260; k1 = 51.64;
elseif dsg == 230
m = 0.2025; k1 = 15.957;
elseif dsg == 240
m = 0.2900; k1 = 6.643;
elseif dsg == 250
m = 0.3910; k1 = 3.230;
else
wtxt = ['THIS PROGRAM IS NOT ABLE TO FIND A SOLUTION',...
' FOR THIS NACA FIVE-DIGIT AIRFOIL NUMBER'];
warn = warndlg(wtxt ,' WARNING');
uiwait(warn)
clear
return
end
% ---------------------------------------------
tau = str2num([NnameG(4) NnameG(5)])/100; % thickness ratio (maximim thickness/chord)
% p = str2num([NnameG(2) NnameG(3)])/200; % maximum camber location ratio
% CLD = str2num(NnameG(1))*3/20; % Design lift coefficient
% ---------------------------------------------
YG = zeros(size(xG)); % camber line
theta = zeros(size(xG)); %
for i = 1:length(xG)
if xG(i)/cG <= m
YG(i) = cG*(k1/6)*((xG(i)/cG)^3 - 3*m*(xG(i)/cG)^2 + (3*m^2-m^3)*(xG(i)/cG));
theta(i) = atan((k1/6)*(3*(xG(i)/cG)^2 - 6*m*(xG(i)/cG) + (3*m^2-m^3)));
else
YG(i) = cG*(k1/6)*m^3*(1-(xG(i)/cG));
theta(i) = atan(-(k1/6)*m^3);
end
end
% ---------------------------------------------
% thickness distribution
ZZZ = 0.3537; % An Introduction to Theoretical and
% Computational Aerodynamics, Jack MORAN
% ZZZ = 0.3516; % Theory of Wing Sections
T = 10*tau*cG*(0.2969*sqrt(xG./cG)-0.126*(xG./cG)-...
ZZZ*(xG./cG).^2+0.2843*(xG./cG).^3-0.1015*(xG./cG).^4);
% ---------------------------------------------
XuG = xG-(T/2).*sin(theta);
YuG = YG+(T/2).*cos(theta);
XlG = xG+(T/2).*sin(theta);
YlG = YG-(T/2).*cos(theta);

naca6dig.m
function [XuG, YuG, XlG, YlG, YG] = naca6dig(NnameG,xG,cG)
% Kivanc Ali ANIL (07 Jul.2009)
% Function for NACA 63A or 64A six-digit-airfoil number [63A0XX, 64A0XX]
tau = str2num([NnameG(5) NnameG(6)])/100; % thickness ratio (maximim thickness/chord)
d6X = str2num([NnameG(1) NnameG(2)]);
data63A010 = [ ...
0.000000 0.0000000
0.005000 0.0081600
0.007500 0.0098300
0.012500 0.0125000
0.025000 0.0173700
0.050000 0.0241200
0.075000 0.0291700
0.100000 0.0332400
0.150000 0.0395000
0.200000 0.0440000
0.250000 0.0471400
0.300000 0.0491300
0.350000 0.0499500
0.400000 0.0496800
0.450000 0.0483700
0.500000 0.0461300
0.550000 0.0431100
0.600000 0.0394300
0.650000 0.0351700
0.700000 0.0304400
0.750000 0.0254500
0.800000 0.0204000
0.850000 0.0153500
0.900000 0.0103000
0.950000 0.0052500
1.000000 0.0000000];
data64A010 = [ ...
0.000000 0.0000000
0.005000 0.0080400
0.007500 0.0096900
0.012500 0.0122500
0.025000 0.0166800
0.050000 0.0232700
0.075000 0.0281000
0.100000 0.0319900
0.150000 0.0381300
0.200000 0.0427200
0.250000 0.0460600
0.300000 0.0483700
0.350000 0.0496800
0.400000 0.0499500
0.450000 0.0489400
0.500000 0.0468400
0.550000 0.0438800
0.600000 0.0402100
0.650000 0.0359700
0.700000 0.0312700
0.750000 0.0262300
0.800000 0.0210300
0.850000 0.0158200
0.900000 0.0106200
0.950000 0.0054100
1.000000 0.0000000];
if d6X == 63
data6XA010 = data63A010;
elseif d6X == 64
data6XA010 = data64A010;
end
YG = zeros(size(xG));
XuG1 = data6XA010(:,1)*cG;
YuG1 = +(tau/.10)*data6XA010(:,2)*cG;
XlG1 = data6XA010(:,1)*cG;
YlG1 = -(tau/.10)*data6XA010(:,2)*cG;
YuG = interp1(XuG1,YuG1,xG,'spline');
YlG = interp1(XlG1,YlG1,xG,'spline');
XuG = xG;
XlG = xG;

naca66a08.m
function [XuG, YuG, XlG, YlG, YG] = naca66a08(tauG,eG, xG,cG)
% Kivanc Ali ANIL (02.12.2012)
% Function for Section mean line: NACA a = 0.8
% Section thickness distribution: NACA 66 (modified)

% tauG : thickness ratio (tmax/c)(maximim thickness/chord)


% eG : maximum camber ratio (f/c) (maximim camber/chord)

tmax = tauG*cG; % c = cG
f = eG*cG; % c = cG

% "MINIMUM PRESSURE ENVELOPES FOR MODIFIED NACA-66 SECTIONS WITH NACA


% a=0.8 CAMBER AND BUSHIPS TYPE 1 AND TYPE 2 SECTIONS" BY TERRY BROCKETT
% TABLE 3
% Foil Geometry at Conventional Stations
% NACA 66 (Mod) & a =. 8 Camber
%
% NACA 66 (mod) a=0.8 mean line a=0.8 mean line
% Thickness Ordinate Camber Ordinate Camber Slope
% x/c T/tmax yc/f dyc/f
data66a08 = [ ...
0.0000 0.0000 0.0000 7.6300 % it is actually infinite
0.0050 0.0665 0.0423 7.1490
0.0075 0.0812 0.0595 6.6170
0.0125 0.1044 0.0907 5.9440
0.0250 0.1466 0.1586 5.0230
0.0500 0.2066 0.2712 4.0830
0.0750 0.2525 0.3657 3.5150
0.1000 0.2907 0.4482 3.1000
0.1500 0.3521 0.5869 2.4880
0.2000 0.4000 0.6993 2.0230
0.2500 0.4363 0.7905 1.6350
0.3000 0.4637 0.8635 1.2920
0.3500 0.4832 0.9202 0.9330
0.4000 0.4952 0.9615 0.6780
0.4500 0.5000 0.9881 0.3850
0.5000 0.4962 1.0000 0.0910
0.5500 0.4846 0.9971 -0.2110
0.6000 0.4653 0.9786 -0.5320
0.6500 0.4383 0.9434 -0.8850
0.7000 0.4035 0.8892 -1.2950
0.7500 0.3612 0.8121 -1.8130
0.8000 0.3110 0.7027 -2.7120
0.8500 0.2532 0.5425 -3.5230
0.9000 0.1877 0.3586 -3.7680
0.9500 0.1143 0.1713 -3.6680
0.9750 0.0748 0.0823 -3.4410
1.0000 0.0000 0.0000 -3.0030];%T/tmax is actually 0.0333
% ---------------------------------------------
% thickness distribution
xtemp = data66a08(:,1)*cG; % c = cG
Ttemp = data66a08(:,2)*tmax;
T = 2*interp1(xtemp,Ttemp,xG,'spline');
% ---------------------------------------------
% mean line (camber)
Ytemp = data66a08(:,3)*f;
YG = interp1(xtemp,Ytemp,xG,'spline');
dYtemp = data66a08(:,4)*f;
dY = interp1(xtemp,dYtemp,xG,'spline');
theta = atan(dY);
theta(1) = pi/2; % tan(pi/2) = inf
theta(length(xG))= pi/2;
% ---------------------------------------------
XuG = xG-(T/2).*sin(theta);
YuG = YG+(T/2).*cos(theta);
XlG = xG+(T/2).*sin(theta);
YlG = YG-(T/2).*cos(theta);

panelmet1.m
% Kivanc Ali ANIL (12 JAN.2011)
% Subroutine for the Combined Source and Doublet Method
CLpanel = zeros(length(alphaarray),2);
CDpanel = zeros(length(alphaarray),1);
CMpanel = zeros(length(alphaarray),1);
CpN = zeros(length(alphaarray),N-1);%%%%%%%%%%
for k = 1 : length(alphaarray)
alpha = alphaarray(k)*pi/180;
Un = zeros(1,N);
aw = zeros(1,N);
xiL = zeros(N,N);
yiL = zeros(N,N);
xjL1 = zeros(N,N);
xjL2 = zeros(N,N);
r1 = zeros(N,N);
r2 = zeros(N,N);
theta1 = zeros(N,N);
theta2 = zeros(N,N);
Asource = zeros(N,N);
Adouble = zeros(N,N);
for i = 1:N % Collocation Points
% U*n for each panel (n is pointing outward)
Un(i) = -(U*cos(alpha)*nx(i)+U*sin(alpha)*ny(i));
% Two dimensional point vortex (unit strength) for wake
aw(i) = +(0.5/pi)*atan((YG(i)-GCO(N+1,2))/(XG(i)-GCO(N+1,1))); %2011
for j = 1:N
% Transformation from Global to Local Coordinates
% xiL(i,j) = (XG(i)-XG(j))*cos(thetaMP(j))+(YG(i)-YG(j))*sin(thetaMP(j));
% yiL(i,j) = (YG(i)-YG(j))*cos(thetaMP(j))-(XG(i)-XG(j))*sin(thetaMP(j));
xiL(i,j) = (XG(i)-XG(j))*tx(j)+(YG(i)-YG(j))*ty(j); % 2011
yiL(i,j) = (XG(i)-XG(j))*nx(j)+(YG(i)-YG(j))*ny(j); % 2011
xjL1(i,j) = -L(j)/2;
xjL2(i,j) = +L(j)/2;
r1(i,j) = ((xiL(i,j)-xjL1(i,j))^2+yiL(i,j)^2)^.5;
r2(i,j) = ((xiL(i,j)-xjL2(i,j))^2+yiL(i,j)^2)^.5;
theta1(i,j) = atan2(yiL(i,j),(xiL(i,j)-xjL1(i,j)));
theta2(i,j) = atan2(yiL(i,j),(xiL(i,j)-xjL2(i,j)));
% a unit source strength distribution
Asource(i,j)= (0.5/pi)* ((xiL(i,j)-xjL1(i,j))*log(r1(i,j))-...
(xiL(i,j)-xjL2(i,j))*log(r2(i,j))+yiL(i,j)*(theta2(i,j)-theta1(i,j)));
% if j == i
% Asource(i,j)= (0.5/pi)*(xjL2(i,j)-xjL1(i,j))*log((xjL2(i,j)-xjL1(i,j))/2);
% end
% a unit doublet strength distribution
Adouble(i,j)= -(0.5/pi)*(theta2(i,j)-theta1(i,j));
if j == i
Adouble(i,j)= 0.5;
end
% wake correction
if j == 1
Adouble(i,j) = Adouble(i,j)-aw(i);
elseif j == N
Adouble(i,j) = Adouble(i,j)+aw(i);
end
end
end
amatrix = Adouble;
bmatrix = -Asource*Un';
PHI1 = amatrix\bmatrix; % = mldivide(amatrix,bmatrix);
% = inv(amatrix)*bmatrix
% = (amatrix\eye(size(amatrix)))*bmatrix
% = pinv(amatrix)*bmatrix
PHIuf = zeros(1,N);
PHI = zeros(1,N);
for i = 1:N
PHIuf(i) = U*(GMP(i,1)*cos(alpha)+GMP(i,2)*sin(alpha));% uniformflow
PHI(i) = -PHI1(i)+PHIuf(i);
end
R = zeros(1,N-1);
VN = zeros(1,N-1);
XN = zeros(1,N-1);
for i = 1:N-1
kk = i+1;
R(i) = (L(kk)+L(i))/2;
VN(i) = (PHI(kk)-PHI(i))/R(i);
XN(i) = GCO(kk,1);
end
CpN(k,:) = 1-(VN/U).^2;
if alpha < 0
nyalpha = [ny(1:.5*N-1),ny(.5*N+1:N)];
nxalpha = [nx(1:.5*N-1),nx(.5*N+1:N)];
tyalpha = [ty(1:.5*N-1),ty(.5*N+1:N)]; %2010
txalpha = [tx(1:.5*N-1),tx(.5*N+1:N)]; %2010
else
nyalpha = [ny(1:.5*N) ,ny(.5*N+2:N)];
nxalpha = [nx(1:.5*N) ,nx(.5*N+2:N)];
tyalpha = [ty(1:.5*N) ,ty(.5*N+2:N)]; %2010
txalpha = [tx(1:.5*N) ,tx(.5*N+2:N)]; %2010
end
Cypanel = sum(-(CpN(k,:)).*R.*nyalpha/c); %2011
Cxpanel = sum(-(CpN(k,:)).*R.*nxalpha/c); %2011
% CLpanel(k,:) = [-2*(PHI1(N)-PHI1(1))/(U*c) ,Cypanel]; %2011
% CDpanel(k,:) = Cxpanel; %2011
CLpanel(k,:) = [-2*(PHI1(N)-PHI1(1))/(U*c) ,...
-Cxpanel*sin(alpha)+...
Cypanel*cos(alpha)]; %2011
CDpanel(k,:) = Cxpanel*cos(alpha)+...
Cypanel*sin(alpha); %2011
CyMpanel = sum(-(CpN(k,:)).*R.*nyalpha.*XN*cos(alpha)/c^2); %2011
CxMpanel = sum(-(CpN(k,:)).*R.*nxalpha.*XN*cos(alpha)/c^2); %2011
CMpanel(k,:) = -CxMpanel*sin(alpha)+...
CyMpanel*cos(alpha); %2011
% or:
% CMpanel(k,:) = -sum(-(CpN(k,:)).*R.*nxalpha*sin(alpha).*XN*cos(alpha)/c^2)+...
% sum(-(CpN(k,:)).*R.*nyalpha*cos(alpha).*XN*cos(alpha)/c^2); %2011
end

Panelmet2.m
% Kivanc Ali ANIL (12 JAN.2011)
% Subroutine for Constant Strength Source Method (optional if alpha = 0
% and if foil is symmetric)
CpN = zeros(length(alphaarray),N);
for k = 1 : length(alphaarray)
alpha = alphaarray(k)*pi/180;
aw = zeros(1,N);
xiL = zeros(N,N);
yiL = zeros(N,N);
xjL1 = zeros(N,N);
xjL2 = zeros(N,N);
r1 = zeros(N,N);
r2 = zeros(N,N);
theta1 = zeros(N,N);
theta2 = zeros(N,N);
UL = zeros(N,N);
WL = zeros(N,N);
UG = zeros(N,N);
WG = zeros(N,N);
A = zeros(N,N);
B = zeros(N,N);
Bmat = zeros(N,1);
for i = 1:N % Collocation Points
for j = 1:N
% Transformation from Global to Local Coordinates
% xiL(i,j) = (XG(i)-XG(j))*cos(thetaMP(j))+(YG(i)-YG(j))*sin(thetaMP(j));
% yiL(i,j) = (YG(i)-YG(j))*cos(thetaMP(j))-(XG(i)-XG(j))*sin(thetaMP(j));
xiL(i,j) = (XG(i)-XG(j))*tx(j)+(YG(i)-YG(j))*ty(j); % 2011
yiL(i,j) = (XG(i)-XG(j))*nx(j)+(YG(i)-YG(j))*ny(j); % 2011
xjL1(i,j) = -L(j)/2;
xjL2(i,j) = +L(j)/2;
r1(i,j) = ((xiL(i,j)-xjL1(i,j))^2+yiL(i,j)^2)^.5;
r2(i,j) = ((xiL(i,j)-xjL2(i,j))^2+yiL(i,j)^2)^.5;
theta1(i,j) = atan2(yiL(i,j),(xiL(i,j)-xjL1(i,j)));
theta2(i,j) = atan2(yiL(i,j),(xiL(i,j)-xjL2(i,j)));
% COMPUTE VELOCITY IN LOCAL REF. FRAME
if j == i
UL(i,j) = 0;
WL(i,j) = .5;
else
UL(i,j) = (0.5/pi)*log(r1(i,j)/r2(i,j));
WL(i,j) = (0.5/pi)*(theta2(i,j)-theta1(i,j));
end
% RETURN VELOCITY TO GLOBAL REF. FRAME
% UG(i,j) = UL(i,j)*cos(-thetaMP(j))+WL(i,j)*sin(-thetaMP(j));
% WG(i,j) = -UL(i,j)*sin(-thetaMP(j))+WL(i,j)*cos(-thetaMP(j));
% UG(i,j) = UL(i,j)*cos(thetaMP(j))-WL(i,j)*sin(thetaMP(j));
% WG(i,j) = UL(i,j)*sin(thetaMP(j))+WL(i,j)*cos(thetaMP(j));
UG(i,j) = UL(i,j)*tx(j)+WL(i,j)*nx(j);
WG(i,j) = UL(i,j)*ty(j)+WL(i,j)*ny(j);
% A(I,J) IS THE INFLUENCE COEFF. DEFINED BY THE TANGENCY CONDITION.
% B(I,J) IS THE INDUCED LOCAL TANGENTIAL VELOCITY TO BE USED IN CP CALCULATION.
% A(i,j) =-UG(i,j)*sin(thetaMP(i))+WG(i,j)*cos(thetaMP(i));
% B(i,j) = UG(i,j)*cos(thetaMP(i))+WG(i,j)*sin(thetaMP(i));
A(i,j) = UG(i,j)*nx(i)+WG(i,j)*ny(i); % 2011
B(i,j) = UG(i,j)*tx(i)+WG(i,j)*ty(i); % 2011
end
% Bmat(i,1) = sin(thetaMP(i));
Bmat(i,1) = -(U*cos(alpha)*nx(i)+U*sin(alpha)*ny(i)); % 2011
end
amatrix = A;
bmatrix = Bmat;
Sigma = amatrix\bmatrix;
XN = GMP(:,1)';
% for i = 1:N
% VN(i) = 0;
% for j = 1:N
% VN(i) = VN(i)+B(i,j)*Sigma(j);
% end
% end
VN = B*Sigma; % 2011
VN = VN'; % 2011
CpN(k,:) = 1-(VN+cos(thetaMP)).^2;
end

You might also like