0% found this document useful (0 votes)
16 views4 pages

NACA 0012.m

VPM code

Uploaded by

tutoringaimers
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

NACA 0012.m

VPM code

Uploaded by

tutoringaimers
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

% NACA 0012 Airfoil

clear; close all; clc;

% Airfoil parameters
name = '0012';
N = 200; % Number of boundary points
spacing = 2; % Cosine spacing

% NACA 4-DIGIT GEOMETRY


[xu, yu, xl, yl] = naca4(name, N, spacing);
% Plot the airfoil
figure;
plot(xu, yu, xl, yl, 0.5*(xl+xu), 0.5*(yl+yu));
title(['NACA ', name]);
xlabel('X');
ylabel('Y');
xlim([0 1]);
ylim([-0.2 0.2]);
grid on;

% Defining Panel Geometry


% Airfoil will be divided into N panels
if xu(1) == xl(1)
xu = xu(2:end);
yu = yu(2:end);
end

XB = [flip(xl);xu]; % Boundary Point - X


YB = [flip(yl);yu]; % Boundary Point - Y

% Initialize
XC = zeros(1, max(size(XB)-1));
YC = XC;
S = XC;
phi = XC;

% Calculate the Control Points


for k = 1:max(size(XB))-1
XC(k) = 0.5*(XB(k) + XB(k+1));
YC(k) = 0.5*(YB(k) + YB(k+1));
deltaX = XB(k+1) - XB(k);
deltaY = YB(k+1) - YB(k);
S(k) = sqrt(deltaX^2 + deltaY^2); % Length of Panel
phi(k) = atan2d(deltaY,deltaX); % Panel Angle
if phi(k) < 0
phi(k) = phi(k)+360;
end
end

delta = phi+90;

% Plot panels and control points


figure;
hold on
plot(XB,YB);
fill(XB,YB,'b')
arrow_size = zeros(1,max(size(XC)));
Xarrow = arrow_size;
Yarrow = arrow_size;
for i=1:max(size(XC))
arrow_size(i) = S(i)*N/10;
Xarrow(i) = XC(i) + cosd(delta(i))*arrow_size(i);
Yarrow(i) = YC(i) + sind(delta(i))*arrow_size(i);
plot([XC(i) Xarrow(i)],[YC(i) Yarrow(i)],'k')
end
plot(XC,YC,'ro'); % Control points plot
title(['Panels Control point with Normal Vectors of NACA ', name]);
xlabel('X');
ylabel('Y');
xlim([-0.1 1.1]);
ylim([-0.5 0.5]);
grid on;
hold off

% Add Coefficient of Lift and Pressure calculations


AOA = 0:5:10; % Angle of attack range
U_inf = 57.23; % Freestream velocity

% Calculate beta for each AOA


for i = 1:length(AOA)
beta{i} = delta - AOA(i);
beta{i}(beta{i}>360) = beta{i}(beta{i}>360) - 360;
end

% Calculate Normal and Tangential Coefficients


[CN1,CN2,CT1,CT2] = NORM_TANG_lin(XC,YC,XB,YB,phi,S);

% Set up A matrix
A_MATRIX_N = zeros(size(CN1,1)+1, size(CN1,1)+1);
A_MATRIX_T = zeros(size(CT1,1), size(CT1,1)+1);

for k = 1:size(CN1,1)
A_MATRIX_N(k,1) = CN1(k,1);
A_MATRIX_N(k,size(CN1,1)+1) = CN2(k,size(CN1,1));
A_MATRIX_T(k,1) = CT1(k,1);
A_MATRIX_T(k,size(CT1,1)+1) = CT2(k,size(CT1,1));
for l = 2:size(CN1,1)
A_MATRIX_N(k,l) = CN1(k,l) + CN2(k,l-1);
A_MATRIX_T(k,l) = CT1(k,l) + CT2(k,l-1);
end
end
A_MATRIX_N(size(CN1,1)+1,:) = [1 zeros(1,size(CN1,1)-1) 1];

% Calculate B matrix, GAMMA, and Cp for each AOA


for i = 1:length(AOA)
B_MATRIX{i} = [-U_inf * cosd(beta{i}) 0]';
GAMMA{i} = A_MATRIX_N \ B_MATRIX{i};

for k = 1:size(CN1,1)
vt{i}(k) = U_inf * sind(beta{i}(k));
for l = 1:size(CN1,1)+1
vt{i}(k) = vt{i}(k) + GAMMA{i}(l) * A_MATRIX_T(k,l);
end
Cp{i}(k) = 1 - (vt{i}(k)/U_inf)^2;
end
end
% Plot Cp distribution
for i = 1:length(AOA)
figure;
hold on;
plot(XC, Cp{i});
plot(XC((end/2+1):end)', Cp{i}((end/2+1):end), 'ro-','LineWidth', 1.5,
'MarkerSize', 4, 'DisplayName', 'Upper Surface');
plot(XC(1:(end/2))', Cp{i}(1:(end/2)), 'bo-','LineWidth', 1.5,
'MarkerSize', 4, 'DisplayName', 'Lower Surface');
xlabel('x/c');
ylabel('C_p');
set(gca, 'YDir', 'reverse');
title(['C_p Distribution for NACA ', name, ' at \alpha = ',
num2str(AOA(i)), '°']);
legend('Location', 'best');
grid on;
hold off;
end

% Calculate and store CL


CL_values = zeros(size(AOA));
for i = 1:length(AOA)
CN{i} = -Cp{i} .* S .* sind(delta);
CA{i} = -Cp{i} .* S .* cosd(delta);
CL_values(i) = sum(CN{i} .* cosd(AOA(i))) - sum(CA{i} .* sind(AOA(i)));
end

% Plot CL vs AOA
figure;
plot(AOA, CL_values, '-o', 'LineWidth', 1.5);
grid on;
xlabel('Angle of Attack (AOA) [°]');
ylabel('Lift Coefficient (C_L)');
title(['Lift Coefficient (C_L) vs. Angle of Attack for NACA ', name]);
legend(['NACA ', name], 'Location', 'best');

% Calculating the Normal and Tangential Coefficients (NORM, TANG)

function [CN1,CN2,CT1,CT2] = NORM_TANG_lin(XC,YC,XB,YB,phi,S)


phi = phi*pi/180;
CN1 = zeros(max(size(XC)),max(size(XC)));
CN2 = CN1;
CT2 = CN1;
CT1 = CN1;

for i = 1:max(size(XC))
for j = 1:max(size(XC))
if j ~= i
C1 = -cos(phi(i)-phi(j));
C2 = (XC(i)-XB(j))*cos(phi(i))+(YC(i)-YB(j))*sin(phi(i));
C3 = -cos(phi(j))*(XC(i)-XB(j)) - sin(phi(j))*(YC(i)-YB(j));
C4 = (XC(i)-XB(j))^2 + (YC(i)-YB(j))^2;
C5 = sqrt(C4-(C3^2));
C6 = sin(phi(j)-phi(i));
C7 = (XC(i)-XB(j))*sin(phi(i))-(YC(i)-YB(j))*cos(phi(i));
A = 0.5*(C2-2*C1*C3);
B = log((S(j)^2+2*C3*S(j)+C4)/C4);
C = (C1*(C4-2*C3^2)+C2*C3)/C5;
D = atan2((C3+S(j)),C5)-atan2(C3,C5);
E = 0.5*(C7-2*C6*C3);
F = (C6*(C4-2*C3^2)+C7*C3)/C5;
CN2(i,j) = -C1 - A*B/S(j) + C*D/S(j);
CN1(i,j) = -0.5*C1*B - ((C2-C1*C3)/C5)*D-CN2(i,j);
CT2(i,j) = -C6 - E*B/S(j) + F*D/S(j);
CT1(i,j) = -0.5*C6*B - ((C7-C6*C3)/C5)*D-CT2(i,j);
else
CN2(i,j) = 1;
CN1(i,j) = -1;
CT2(i,j) = 0.5*pi;
CT1(i,j) = 0.5*pi;
end
end
end
end

% Load literature data


data = readtable('NACA 0012 CL.csv');
AOA_lit = data.AoA;
CL_lit = data.CL;

% Create the plot


figure;
plot(AOA_lit, CL_lit, '-o', 'LineWidth', 1.5, 'MarkerSize', 6, 'DisplayName',
'Literature Data');
hold on;
plot(AOA, CL_values, '-s', 'LineWidth', 1.5, 'MarkerSize', 8, 'DisplayName', 'Panel
Method');

% Customize the plot


xlabel('Angle of Attack (AOA) [°]');
ylabel('Lift Coefficient (C_L)');
title('Lift Coefficient (C_L) vs. Angle of Attack for NACA 0012');
grid on;
legend('Location', 'best');

hold off;

You might also like