XFOIL联合Matlab的翼型优化设计

1.软件介绍
XFOIL是亚音速隔离单段翼型的设计和分析的交互式程序。由麻省理工学院教授马克·德雷拉(Mark Drela)撰写。

2.Matlab运行XFOIL
下图为采用Matlab软件与XFOIL接口进行连接运行XFOIL软件在这里插入图片描述3.采用遗传算法进行翼型气动优化
在这里插入图片描述

%% Create a new instance of the XFOIL class, and set some properties
xf = XFOIL;
xf.KeepFiles = true; % Set it to true to keep all intermediate files created (Airfoil, Polars, ...)
xf.Visible = true;    % Set it to false to hide XFOIL plotting window

%% Create a NACA 5-series airfoil
% xf.Airfoil =  Airfoil.createNACA4('0012',150);
% xf.Airfoil =  Airfoil('oa212.dat');
xf.Airfoil =  Airfoil('oa209.dat');
% xf.Airfoil =  Airfoil('na0012.dat');
% To create a NACA 4-series, use   >> xf.Airfoil =  Airfoil.createNACA4('0012');
% To load an existing airfoil, use >> xf.Airfoil =  Airfoil('naca0012.dat');

%% Setup the action list

%Add five filtering steps to smooth the airfoil coordinates and help convergence
xf.addFiltering(5);

%Switch to OPER mode, and set Reynolds = 3E7, Mach = 0.1
xf.addOperation(3E7, 0.1);

%Set maximum number of iterations
xf.addIter(100)

%Initializate the calculations
xf.addAlpha(0,true);

%Create a new polar
xf.addPolarFile('Polar.txt');

% %Calculate a sequence of angle of attack, from 0 to 25 degrees, step size of 0.1 degrees
xf.addAlpha(0:0.1:25);

%Another option is to keep all the CP curves, replace the previous line with this:
%for alpha = 0:0.1:25
%    xf.addAlpha(alpha);
%    xf.addActions(sprintf('CPWR alpha_%f.txt',alpha));
%end

%Close the polar file
xf.addClosePolarFile;

%And finally add the action to quit XFOIL
xf.addQuit;

%% Now we're ready to run XFOIL
xf.run
disp('Running XFOIL, please wait...')

%% Wait up to 100 seconds for it to finish... 
%It is possible to run more than one XFOIL instance at the same time
finished = xf.wait(100); 

%% If successfull, read and plot the polar
if finished
    disp('XFOIL analysis finished.')
    xf.readPolars;
    figure
    xf.plotPolar(1);
else
    xf.kill;
end

创建dat文件:

clc
clear all
a = [0.0000000 0.0000000
 0.0002924 0.0028551
 0.0007810 0.0047471
 0.0017586 0.0072243
 0.0048866 0.0121590
 0.0070371 0.0145844
 0.0097746 0.0171549
 0.0156407 0.0216181
 0.0224839 0.0258454
 0.0293282 0.0294448
 0.0351946 0.0321729
 0.0391053 0.0338387
 0.0449719 0.0361378
 0.0537712 0.0391946
 0.0635487 0.0421315
 0.0733262 0.0446694
 0.0831038 0.0468743
 0.0928814 0.0487973
 0.1222146 0.0532210
 0.1466590 0.0557137
 0.1711047 0.0573865
 0.1955495 0.0584144
 0.2199944 0.0589332
 0.2444394 0.0590590
 0.2688844 0.0588899
 0.2933294 0.0585127
 0.3177745 0.0580034
 0.3422197 0.0574183
 0.3666649 0.0567851
 0.3911100 0.0560989
 0.4155561 0.0553337
 0.4400013 0.0544535
 0.4644465 0.0534314
 0.4888917 0.0522542
 0.5133371 0.0509200
 0.5377824 0.0494348
 0.5622277 0.0478067
 0.5866730 0.0460385
 0.6111183 0.0441303
 0.6355637 0.0420791
 0.6600091 0.0398820
 0.6844547 0.0375358
 0.7089013 0.0350436
 0.7333468 0.0324094
 0.7577922 0.0296382
 0.7822378 0.0267311
 0.8066834 0.0236749
 0.8311290 0.0204437
 0.8506855 0.0177115
 0.8702421 0.0148404
 0.8800204 0.0133593
 0.8995770 0.0103632
 0.9191335 0.0074690
 0.9386901 0.0049059
 0.9511083 0.0035814
 0.9778036 0.0019806
 1.0000000 0.0025150
 0.0000000 0.0000000
 0.0002934 -.0025969
 0.0007827 -.0040758
 0.0017611 -.0057866
 0.0048906 -.0086200
 0.0070419 -.0097936
 0.0097801 -.0109121
 0.0156475 -.0126099
 0.0224917 -.0140076
 0.0293369 -.0150912
 0.0352041 -.0158681
 0.0391152 -.0163313
 0.0449823 -.0169601
 0.0537825 -.0177994
 0.0635607 -.0186385
 0.0733388 -.0194185
 0.0831169 -.0201646
 0.0928951 -.0208907
 0.1222295 -.0229909
 0.1466749 -.0246691
 0.1711212 -.0262593
 0.1955665 -.0277175
 0.2200117 -.0289996
 0.2444569 -.0300718
 0.2689021 -.0309240
 0.2933472 -.0315792
 0.3177923 -.0320834
 0.3422375 -.0324905
 0.3666825 -.0328357
 0.3911275 -.0331239
 0.4155736 -.0333301
 0.4400187 -.0334213
 0.4644636 -.0333685
 0.4889086 -.0331596
 0.5133536 -.0327928
 0.5377985 -.0322740
 0.5622433 -.0316132
 0.5866882 -.0308134
 0.6111330 -.0298756
 0.6355777 -.0287947
 0.6600226 -.0275679
 0.6844673 -.0261931
 0.7089130 -.0246733
 0.7333577 -.0230135
 0.7578022 -.0212177
 0.7822468 -.0192799
 0.8066914 -.0171821
 0.8311360 -.0148962
 0.8506916 -.0129154
 0.8702472 -.0108045
 0.8800250 -.0097146
 0.8995805 -.0075468
 0.9191361 -.0055509
 0.9386918 -.0039291
 0.9511096 -.0031806
 0.9778045 -.0024304
 1.0000000 -.0025080]; 
for n = 1:57
 b(58-n,:) = a(n,:);
end
c = [b;a(58:end,:)]

function [F,elapsedTime] = fitnessfun(x)

    tic;
    airfoil = coordinates2file(cst2coordinates(x));
    polars = runXfoil(airfoil);
    
    if ~isempty(polars) && ~isempty(polars.CD)
        F = min(polars.CD);
        elapsedTime = toc;
    else
        F = 1;
    end

    %F=mean(x);
end
function filename = coordinates2file( data )
%COORDINATES2FILE Summary of this function goes here
%   Detailed explanation goes here

filename = 'oa209.txt';

fileID = fopen(filename,'wt');
name = 'Test-Profile \n';
fprintf(fileID,name);
for n=1:length(data)
    fprintf(fileID,'%1.5f %12.5f \n',data(n,1),data(n,2));
end

fclose(fileID);
end
function coord = cst2coordinates(x)
%CST2COORDINATES Summary of this function goes here
%   Detailed explanation goes here

    size = numel(x);
    coord = CST_airfoil(x(1:size/2),x(size/2+1:size),0,30);

end

function [coord] = CST_airfoil(wl,wu,dz,N)

% Description : Create a set of airfoil coordinates using CST parametrization method 
% Input  : wl = CST weight of lower surface
%          wu = CST weight of upper surface
%          dz = trailing edge thickness
% Output : coord = set of x-y coordinates of airfoil generated by CST


% Create x coordinate
x=ones(N+1,1);
y=zeros(N+1,1);
zeta=zeros(N+1,1);

for i=1:N+1
    zeta(i)=2*pi/N*(i-1);
    x(i)=0.5*(cos(zeta(i))+1);
end

% N1 and N2 parameters (N1 = 0.5 and N2 = 1 for airfoil shape)
N1 = 0.5;
N2 = 1;

[~,zerind] = min(x(:,1)); % Used to separate upper and lower surfaces

xl = x(1:zerind-1); % Lower surface x-coordinates
xu = x(zerind:end); % Upper surface x-coordinates

[yl] = ClassShape(wl,xl,N1,N2,-dz); % Call ClassShape function to determine lower surface y-coordinates
[yu] = ClassShape(wu,xu,N1,N2,dz);  % Call ClassShape function to determine upper surface y-coordinates

y = [yl;yu]; % Combine upper and lower y coordinates

coord = [x y]; % Combine x and y into single output

end

%% Function to calculate class and shape function
function [y] = ClassShape(w,x,N1,N2,dz)


% Class function; taking input of N1 and N2
C(:,1) = x(:).^N1.*((1-x(:)).^N2);


% Shape function; using Bernstein Polynomials
n = length(w)-1; % Order of Bernstein polynomials

K(n+1) = 0;
for i = 1:n+1
     K(i) = factorial(n)/(factorial(i-1)*(factorial((n)-(i-1))));
end

S(length(x),1) = 0;
for j = 1:n+1
        S(:,1) = S(:,1) + w(j)*K(j)*x(:).^(j-1).*((1-x(:)).^(n-(j-1)));
end

% Calculate y output
y(:,1) = C(:,1).*S(:,1) + x(:)*dz;


end

4.参考资料
XFOILinterface
airfoil_aerodynamic_optimization-master

  • 9
    点赞
  • 71
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 9
    评论
Matlab 中进行翼型优化可以使用多种方法,下面是一个常见的基于遗传法的翼型优化示例: 1. 定义翼型参数:可以使用参数化的方式定义翼型,例如使用贝塞尔曲线或NACA曲线。在 Matlab 中,可以使用控制点来定义贝塞尔曲线,并通过调整控制点的位置来修改翼型的形状。 2. 目标函数定义:确定一个评估翼型性能的目标函数。例如,可以使用计算流场的方法来评估翼型的升力、阻力等性能指标。在 Matlab 中,可以编写一个函数来计算目标函数值,该函数输入翼型参数,输出目标函数值。 3. 遗传算法优化:使用遗传算法来搜索最优的翼型参数。遗传算法是一种模拟自然选择和遗传机制的优化算法,在 Matlab 中有相关的函数可以直接调用,例如 ga 函数。 4. 循环迭代:在遗传算法中,需要设置迭代次数和种群大小等参数,并进行迭代优化。每次迭代,遗传算法会根据目标函数值选择优秀的翼型参数,并通过交叉、变异等操作产生新的种群。 5. 结果分析:在优化完成后,可以对得到的最优翼型参数进行分析,并绘制翼型形状、计算流场等。 需要注意的是,翼型优化是一个复杂的问题,除了遗传算法,还有其他方法可以尝试,例如粒子群算法、模拟退火算法等。此外,翼型优化还涉及到流场模拟、网格生成等其他领域的知识,需要综合考虑。以上只是一个简单的示例,具体的优化方法和步骤可以根据实际情况进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Quincy.Liu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值