-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfoil.m
More file actions
196 lines (160 loc) · 5.73 KB
/
foil.m
File metadata and controls
196 lines (160 loc) · 5.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
% foil.m
%
% Script to analyse an aerofoil section using potential flow calculation
% and boundary layer solver.
%
clear all
addpath('../')
global Re
% Read in the parameter file
caseref = input('Enter case reference: ','s');
parfile = ['Parfiles/' caseref '.txt'];
fprintf(1, '%s\n\n', ['Reading in parameter file: ' parfile])
[section np Re alpha] = par_read(parfile);
% Read in the section geometry
secfile = ['Geometry/' section '.surf'];
[xk yk] = textread ( secfile, '%f%f' );
% Generate high-resolution surface description via cubic splines
nphr = 5*np;
[xshr yshr] = splinefit ( xk, yk, nphr );
% Resize section so that it lies between (0,0) and (1,0)
[xsin ysin] = resyze ( xshr, yshr );
% Interpolate to required number of panels (uniform size)
[xs ys] = make_upanels ( xsin, ysin, np );
% Assemble the lhs of the equations for the potential flow calculation
A = build_lhswk3 ( xs, ys );
Am1 = inv(A);
% Loop over alpha values
for nalpha = 1:length(alpha)
% rhs of equations
alfrad = pi * alpha(nalpha)/180;
b = build_rhs ( xs, ys, alfrad );
% solve for surface vortex sheet strength
gam = Am1 * b;
% calculate cp distribution and overall circulation
[cp circ] = potential_op ( xs, ys, gam );
% locate stagnation point and calculate stagnation panel length
[ipstag fracstag] = find_stag(gam);
dsstag = sqrt((xs(ipstag+1)-xs(ipstag))^2 + (ys(ipstag+1)-ys(ipstag))^2);
% upper surface boundary layer calc
% first assemble pressure distribution along bl
clear su cpu
su(1) = fracstag*dsstag;
cpu(1) = cp(ipstag);
for is = ipstag-1:-1:1
iu = ipstag - is + 1;
su(iu) = su(iu-1) + sqrt((xs(is+1)-xs(is))^2 + (ys(is+1)-ys(is))^2);
cpu(iu) = cp(is);
end
% check for stagnation point at end of stagnation panel
if fracstag < 1e-6
su(1) = 0.01*su(2); % go just downstream of stagnation
uejds = 0.01 * sqrt(1-cpu(2));
cpu(1) = 1 - uejds^2;
end
% boundary layer solver
[iunt iuls iutr iuts delstaru thetau] = bl_solv ( su, cpu );
% lower surface boundary layer calc
% first assemble pressure distribution along bl
clear sl cpl
sl(1) = (1-fracstag) * dsstag;
cpl(1) = cp(ipstag+1);
for is = ipstag+2:np+1
il = is - ipstag;
sl(il) = sl(il-1) + sqrt((xs(is-1)-xs(is))^2 + (ys(is-1)-ys(is))^2);
cpl(il) = cp(is);
end
% check for stagnation point at end of stagnation panel
if fracstag > 0.999999
sl(1) = 0.01*sl(2); % go just downstream of stagnation
uejds = 0.01 * sqrt(1-cpl(2));
cpl(1) = 1 - uejds^2;
end
% boundary layer solver
[ilnt ills iltr ilts delstarl thetal] = bl_solv ( sl, cpl );
% lift and drag coefficients
[Cl Cd] = forces ( circ, cp, delstarl, thetal, delstaru, thetau );
% copy Cl and Cd into arrays for alpha sweep plots
clswp(nalpha) = Cl;
cdswp(nalpha) = Cd;
lovdswp(nalpha) = Cl/Cd;
% screen output
disp ( sprintf ( '\n%s%5.3f%s', ...
'Results for alpha = ', alpha(nalpha), ' degrees' ) )
disp ( sprintf ( '\n%s%5.3f', ' Lift coefficient: ', Cl ) )
disp ( sprintf ( '%s%7.5f', ' Drag coefficient: ', Cd ) )
disp ( sprintf ( '%s%5.3f\n', ' Lift-to-drag ratio: ', Cl/Cd ) )
upperbl = sprintf ( '%s', ' Upper surface boundary layer:' );
if iunt~=0
is = ipstag + 1 - iunt;
upperbl = sprintf ( '%s\n%s%5.3f', upperbl, ...
' Natural transition at x = ', xs(is) );
end
if iuls~=0
is = ipstag + 1 - iuls;
upperbl = sprintf ( '%s\n%s%5.3f', upperbl, ...
' Laminar separation at x = ', xs(is) );
if iutr~=0
is = ipstag + 1 - iutr;
upperbl = sprintf ( '%s\n%s%5.3f', upperbl, ...
' Turbulent reattachment at x = ', xs(is) );
end
end
if iuts~=0
is = ipstag + 1 - iuts;
upperbl = sprintf ( '%s\n%s%5.3f', upperbl, ...
' Turbulent separation at x = ', xs(is) );
end
upperbl = sprintf ( '%s\n', upperbl );
disp(upperbl)
lowerbl = sprintf ( '%s', ' Lower surface boundary layer:' );
if ilnt~=0
is = ipstag + ilnt;
lowerbl = sprintf ( '%s\n%s%5.3f', lowerbl, ...
' Natural transition at x = ', xs(is) );
end
if ills~=0
is = ipstag + ills;
lowerbl = sprintf ( '%s\n%s%5.3f', lowerbl, ...
' Laminar separation at x = ', xs(is) );
if iltr~=0
is = ipstag + iltr;
lowerbl = sprintf ( '%s\n%s%5.3f', lowerbl, ...
' Turbulent reattachment at x = ', xs(is) );
end
end
if ilts~=0
is = ipstag + ilts;
lowerbl = sprintf ( '%s\n%s%5.3f', lowerbl, ...
' Turbulent separation at x = ', xs(is) );
end
lowerbl = sprintf ( '%s\n', lowerbl );
disp(lowerbl)
% save data for this alpha
fname = ['Data/' caseref '_' num2str(alpha(nalpha)) '.mat'];
save ( fname, 'Cl', 'Cd', 'xs', 'cp', ...
'sl', 'delstarl', 'thetal', 'lowerbl', ...
'su', 'delstaru', 'thetau', 'upperbl' )
end
% save alpha sweep data in summary file
fname = ['Data/' caseref '.mat'];
save ( fname, 'xs', 'ys', 'alpha', 'clswp', 'cdswp', 'lovdswp' )
set(0,'DefaultAxesTitleFontWeight','normal');
figure(1)
plot(alpha,clswp)
title(['Cl vs \alpha (',section,' at Re ',num2str(Re,'%.2g'),')'])
xlabel("\alpha")
ylabel("Cl")
grid on;
figure(2)
plot(alpha,cdswp)
title(['Cd vs \alpha (',section,' at Re ',num2str(Re,'%.2g'),')'])
xlabel("\alpha")
ylabel("Cd")
grid on;
figure(3)
plot(alpha,clswp./cdswp)
title(['^{Cl}/_{Cd} vs \alpha (',section,' at Re ',num2str(Re,'%.2g'),')'])
xlabel("\alpha")
ylabel('^{Cl}/_{Cd}')
grid on;