-
Notifications
You must be signed in to change notification settings - Fork 0
/
final_project.m
191 lines (165 loc) · 5.34 KB
/
final_project.m
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
%% Initialize
clear;
clc;
close all;
rng(12);
%% Get Constants
const = Constants;
%% Adjustable parameters
m = 100; % number of blade elements
fs = 16;
fp = ['.' filesep 'figures' filesep];
fig_x = 1000;
fig_y = 500;
%% Calculated values
% Calculate radius
dr = (const.r_t - const.r_r)/(m); % Width of each blade element
r = linspace(const.r_r, const.r_t, m+1)';
r = r(1:end-1) + dr/2; % Distance to 'midpoint' of each blade element
% Calculate relative velocities and angles
V_t = const.omega * r;
V_r = sqrt(V_t.^2 + const.V_h^2);
phi = atan(const.V_h./V_t);
% Calculate dynamic pressure q
q = (1/2)*const.rho.*V_r.^2;
%% Optimize for angle of attack, alpha
% Define an arbitrary chord function
%c_func = @(x) ((0.8 - 2.5)/9).*x + (2.5 - (0.8 - 2.5)/9);
%c_func = @(x) ((0.5 - 1.5)/9).*x + (1.5 - (0.5 - 1.5)/9);
c_func = @(x) exp(-(2).*(x - 1)) + 0.5;
c = c_func(r);
% Get local drag coefficients
c_f = drag_coeffs(V_r, c, const);
% Define problem and variables
prob = optimproblem("ObjectiveSense","minimize");
order_a = 9; % Should be <= 3
afs = optimvar('afs', order_a + 1);
w_torque = 10;
w_bending = 0;
w_uniform = 1;
a_func = @(x) build_polynomial(afs, x);
% Uniform loading:
T_s = const.T_B/m;
% Define objective function
expr = optimexpr;
for i = 1:m
c_l = 2*pi*(a_func(r(i)) - const.a_L0); % Sectional coefficient of lift
c_n = c_l .* cos(phi(i)); % Sectional coefficient of force, normal
c_t = c_l .* sin(phi(i)); % Sectional coefficient of force, tangential
C_T = c_t .* dr; % Coefficient of force, tangential
C_N = c_n .* dr; % Coefficient of force, normal
D = C_T .* q(i) .* c(i); % Induced drag
c_t_visc = 2 * c_f(i) .* cos(phi(i)); % Sectional coeff of visc force, tan
C_T_visc = c_t_visc .* dr; % Coefficient of viscous force, tangential
D_visc = (C_T_visc .* q(i) .* c(i)); % Drag due to viscous force
dQ = (D + D_visc).* r(i);
T = C_N .* q(i) .* c(i);
dM_bending = T .* r(i);
% Any deviation from uniform loading is also penalized
diff_uniform = (T - T_s)^2;
expr = expr + (w_torque * dQ) + (w_uniform * diff_uniform); % + (w_bending * dM_bending)
end
prob.Objective = expr;
% Define Thrust constraint
constr1 = sum(2*pi*(a_func(r) - const.a_L0) .* cos(phi) .* q .* c .* dr) >= const.T_B;
prob.Constraints.constr1 = constr1;
% Define angle of attack constraints
constr2 = a_func(r) >= const.a_L0;
constr3 = a_func(r) <= const.a_stall - deg2rad(1);
constr4 = a_func(1) >= const.a_L0;
constr5 = a_func(1) <= const.a_stall - deg2rad(1);
constr6 = a_func(10) >= const.a_L0;
constr7 = a_func(10) <= const.a_stall - deg2rad(1);
prob.Constraints.constr2 = constr2;
prob.Constraints.constr3 = constr3;
prob.Constraints.constr4 = constr4;
prob.Constraints.constr5 = constr5;
prob.Constraints.constr6 = constr6;
prob.Constraints.constr7 = constr7;
% Define initial solution
clear('x0');
x0.afs = rand(size(afs));
% Solve problem
options = optimoptions('quadprog','Display','final', 'ConstraintTolerance',9e-9);
[sol,fval,EXITFLAG,OUTPUT,LAMBDA] = solve(prob,'Solver','quadprog','Options',options);
a_func = @(x) build_polynomial(sol.afs, x);
%% Analyze results
a = a_func(r);
disp(sol.afs);
analyze_blade(a, c, c_f, const, fs);
%% Plot
r_plot = linspace(1, 10, 101);
V_t_plot = const.omega * r_plot;
phi_plot = atan(const.V_h./V_t_plot);
% Plot angle of attack
f1 = figure;
f1.Position = [100 300 1200 500];
tl1 = tiledlayout(1,2,'Padding','compact');
nexttile;
plot(r_plot, rad2deg(a_func(r_plot)), 'LineWidth', 1);
hold on;
plot(r_plot, rad2deg(const.a_stall)*ones(size(r_plot)), '--r', 'LineWidth', 1)
plot(r_plot, rad2deg(const.a_L0)*ones(size(r_plot)), '-.b', 'LineWidth', 1)
legend("\alpha","\alpha_{stall}","\alpha_{L0}",'Location','east','FontSize', fs);
hold off;
ylabel("\alpha",'FontSize', fs)
xlabel("Blade Length [m]", 'FontSize', fs)
ylim([-5, 9]);
xlim([0, 10]);
yticks(-5:1:9);
yt=get(gca,'ytick');
yt1 = cell(numel(yt),1);
for k=1:numel(yt)
yt1{k}=sprintf('%d°',yt(k));
end
set(gca,'yticklabel',yt1);
set(gca,'FontSize',fs)
grid on;
title("Angle of Attack \alpha", 'FontSize', fs);
% Plot section angle
nexttile;
plot(r_plot, rad2deg(a_func(r_plot) + phi_plot), 'LineWidth', 1);
hold on;
plot(r_plot, rad2deg(phi_plot), '--r', 'LineWidth', 1);
hold off;
legend("\beta","\phi", 'location','east', 'FontSize', fs);
ylabel("\beta, \phi",'FontSize', fs)
xlabel("Blade Length [m]", 'FontSize', fs)
ylim([-5, 30]);
xlim([0, 10]);
yt=get(gca,'ytick');
yt1 = cell(numel(yt),1);
for k=1:numel(yt)
yt1{k}=sprintf('%d°',yt(k));
end
set(gca,'yticklabel',yt1);
set(gca,'FontSize',fs)
grid on;
title("Section Angle \beta and Induced Angle \phi", 'FontSize', fs);
exportgraphics(f1, strcat(fp,'angle.eps'));
% Plot chord variation
f2 = figure;
f2.Position = [100 300 600 500];
plot(r_plot, c_func(r_plot), 'LineWidth', 1);
grid on;
ylabel("c [m]");
xlim([0, 10]);
ylim([0.4, 1.6]);
xlabel("Blade Length [m]", 'FontSize', fs)
title("Chord",'FontSize', fs);
set(gca,'FontSize',fs)
exportgraphics(f2, strcat(fp,'chord.eps'));
blade3D(a, c, const);
function output = build_polynomial(coeffs, x)
output = 0;
order = numel(coeffs) - 1;
for i = 0:order
output = output + coeffs(i+1)*x.^i;
end
end
function c_f = drag_coeffs(V_r, c, const)
Re_L = (V_r .* c)./const.nu;
c_f = zeros(size(c));
c_f(Re_L <= 5 * 10^5) = 1.328 .* Re_L(Re_L <= 5*10^5).^(-1/2);
c_f(Re_L > 5 * 10^5) = 0.074 .* Re_L(Re_L > 5 * 10^5).^(-1/5);
end