G11-NAOE9101MSP-船舶推进大作业

该系列MATLAB代码实现了一种变稳方法(VortexLatticeMethod,VLM),用于计算机翼的气动特性。主要函数包括`VLM.m`、`mesh.m`、`VLMalphaList.m`等,涉及网格生成、涡旋分布计算、气动力计算等步骤。代码首先定义了不同角度攻角(alpha_deg)和网格数(nCells)的组合,然后对每个组合进行VLM计算并绘制结果,展示了不同攻角和网格数量对机翼升力和阻力的影响。

main.m
 

clearvars; clc; % main.m
f_max=0.08; % f_max=0.0;
alpha_deg_list = [-10;-5;0;5;10]; nCellsList = [8;16;32;64;128];
objVLMalphaList = VLMalphaList(f_max,alpha_deg_list,nCellsList);
solve_plot(objVLMalphaList);

mesh.m
 

% mesh.m
classdef mesh
    properties
        nCells
        f_max
    end
    methods
        function obj = mesh(nCells,f_max)
            obj.nCells = nCells;
            obj.f_max = f_max;
        end
        function y = get_y(obj,x)
            c = 1;
            y = obj.f_max*(1-(2*x/c-1)^2);
        end
        function xy_mat = mesh_points(obj)
            c = 1;
            delta_x = c / obj.nCells;
            x = zeros(obj.nCells+1,1);
            y = zeros(size(x,1),1);
            for i = 1 : size(x,1)
                x(i,1) = (i-1)*delta_x;
                y(i,1) = get_y(obj,x(i,1));
            end
            xy_mat = [x,y];
        end
        function xy_mat = mesh_slope(obj)
            xy_p = mesh_points(obj);
            x_p = xy_p(:,1);
            y_p = xy_p(:,2);
            y_k = zeros(obj.nCells,1);
            x_k = zeros(size(y_k,1),1);
            for i = 1 : size(x_k,1)
                y_k(i,1) = (y_p(i+1,1)-y_p(i,1))/(x_p(i+1,1)-x_p(i,1));
                x_k(i,1) = (x_p(i+1,1)+x_p(i,1))/2;
            end
            xy_mat = [x_k,y_k];
        end
        function xy_mat = mesh_linear_points(obj,fraction)
            xy_p = mesh_points(obj);
            xy_k = mesh_slope(obj);
            y_k = xy_k(:,2);
            x_p = xy_p(:,1);
            y_p = xy_p(:,2);
            x_line = zeros(obj.nCells,1);
            y_line = zeros(size(x_line,1),1);
            for i = 1 : size(y_line,1)
                delta_x = x_p(i+1,1) - x_p(i,1);
                delta_x = delta_x*fraction;
                x_line(i,1) = x_p(i,1) + delta_x;
                y_line(i,1) = y_p(i,1) + delta_x*y_k(i,1);
            end
            xy_mat = [x_line,y_line];
        end
        function xy_mat = mesh_vortex_points(obj)
            fraction = 0.25;
            xy_mat = mesh_linear_points(obj,fraction);
        end
        function xy_mat = mesh_middle_points(obj)
            fraction = 0.5;
            xy_mat = mesh_linear_points(obj,fraction);
        end
        function xy_mat = mesh_control_points(obj)
            fraction = 0.75;
            xy_mat = mesh_linear_points(obj,fraction);
        end
        function xyr_mat = mesh_vortex_xyr(obj,xp,yp)
            x_mat = zeros(obj.nCells,1);
            y_mat = zeros(size(x_mat,1),1);
            r_mat = zeros(size(y_mat,1),1);
            xy_v = mesh_vortex_points(obj);
            x_v = xy_v(:,1);
            y_v = xy_v(:,2);
            for i = 1 : size(r_mat,1)
                xx = xp - x_v(i,1);
                yy = yp - y_v(i,1);
                r_mat(i,1) = sqrt(xx^2+yy^2);
                x_mat(i,1) = yy;
                y_mat(i,1) = - xx;
            end
            xyr_mat = [x_mat,y_mat,r_mat];
        end
        function deltax = get_dx(obj)
            c = 1;
            deltax = c / obj.nCells;
        end
        function deltac = get_dc(obj,ii)
            xy_p = mesh_points(obj);
            x_p = xy_p(:,1);
            y_p = xy_p(:,2);
            dx = x_p(ii+1,1) - x_p(ii,1);
            dy = y_p(ii+1,1) - y_p(ii,1);
            deltac = sqrt(dx^2+dy^2);
        end
    end
end

VLM.m
 

% VLM.m
classdef VLM
    properties
        f_max
        alpha
        nCells
    end
    methods
        function obj = VLM(f_max,alpha_deg,nCells)
            obj.f_max = f_max;
            obj.alpha = alpha_deg / 180 * pi;
            obj.nCells = nCells;
        end
        function plot_mat(~,mat)
            x = mat(:,1);
            y = mat(:,2);
            plot(x,y);
        end
        function scatter_mat(~,mat)
            x = mat(:,1);
            y = mat(:,2);
            scatter(x,y);
        end
        function xy_bb = get_bb(obj)
            U = 1;
            y_b = zeros(obj.nCells,1);
            Uy = U * sin(obj.alpha);
            Ux = U * cos(obj.alpha);
            objMesh = mesh(obj.nCells,obj.f_max);
            xy_k = mesh_slope(objMesh);
            xy_c = mesh_control_points(objMesh);
            x_c = xy_c(:,1);
            y_k = xy_k(:,2);
            for i = 1 : size(y_b,1)
                y_b(i,1) = Uy - y_k(i,1)*Ux;
            end
            xy_bb = [x_c,y_b];
        end
        function A_mat = get_AA(obj)
            A_mat = zeros(obj.nCells,obj.nCells);
            objMesh = mesh(obj.nCells,obj.f_max);
            xy_c = mesh_control_points(objMesh);
            xy_k = mesh_slope(objMesh);
            y_k = xy_k(:,2);
            x_c = xy_c(:,1);
            y_c = xy_c(:,2);
            for ii = 1 : size(A_mat,1)
                xp = x_c(ii,1);
                yp = y_c(ii,1);
                xyr_v = mesh_vortex_xyr(objMesh,xp,yp);
                x_v = xyr_v(:,1);
                y_v = xyr_v(:,2);
                r_v = xyr_v(:,3);
                for jj = 1 : size(A_mat,2)
                    A_mat(ii,jj) = (y_k(ii,1)*x_v(jj,1)-y_v(jj,1))/(2*pi*r_v(jj,1)^2);
                end
            end
        end
        function xgamma_mat = solve(obj)
            xy_bb = get_bb(obj);
            b_mat = xy_bb(:,2);
            A_mat = get_AA(obj);
            gamma = A_mat\b_mat;
            objMesh = mesh(obj.nCells,obj.f_max);
            deltax = get_dx(objMesh);
            gamma = gamma ./ deltax;
            %for ii = 1 : size(gamma,1)
            %    deltac = get_dc(objMesh,ii);
            %    gamma(ii,1) = gamma(ii,1) ./ deltac;
            %end
            xy_m = mesh_vortex_points(objMesh);
            x_m = xy_m(:,1);
            xgamma_mat = [x_m,gamma];
        end
        function solve_plot(obj)
            xgamma_mat = solve(obj);
            figure(1);
            alpha_deg = obj.alpha * 180 / pi;
            objExt = vortex_ext(obj.f_max,alpha_deg);
            A_ext = ext_matrix(objExt);
            x_ext = A_ext(:,1);
            y_ext = A_ext(:,2);
            plot(x_ext,y_ext); hold on;
            x_num = xgamma_mat(:,1);
            y_num = xgamma_mat(:,2);
            scatter(x_num,y_num); hold on;
        end
    end
end

VLMalphaList.m
 

% VLMalphaList.m
classdef VLMalphaList
    properties
        f_max
        alpha_deg_list
        nCellsList
    end
    methods
        function obj = VLMalphaList(f_max,alpha_deg_list,nCellsList)
            obj.f_max = f_max;
            obj.alpha_deg_list = alpha_deg_list;
            obj.nCellsList = nCellsList;
        end
        function solve_plot(obj)
            for ii = 1 : size(obj.alpha_deg_list,1)
                objVLMList = VLMList(obj.f_max,obj.alpha_deg_list(ii,1),obj.nCellsList);
                solve_plot(objVLMList);
            end
        end
    end
end

VLMList.m
 

% VLMList.m
classdef VLMList
    properties
        f_max
        alpha
        nCellsList
    end
    methods
        function obj = VLMList(f_max,alpha_deg,nCellsList)
            obj.f_max = f_max;
            obj.alpha = alpha_deg / 180 * pi;
            obj.nCellsList = nCellsList;
        end
        function solve_plot(obj)
            alpha_deg = obj.alpha * 180 / pi;
            objExt = vortex_ext(obj.f_max,alpha_deg);
            xy_ext = ext_matrix(objExt);
            x_ext = xy_ext(:,1);
            y_ext = xy_ext(:,2);
            figure(1);
            plt0 = plot(x_ext,y_ext); hold on;
            plt0.Color = 'black';
            plt0.LineWidth = 1.5;
            nCellsListLength = size(obj.nCellsList,1);
            for ii = 1 : size(obj.nCellsList,1)
                objVLM = VLM(obj.f_max,alpha_deg,obj.nCellsList(ii,1));
                xgamma_mat = solve(objVLM);
                x_num = xgamma_mat(:,1);
                y_num = xgamma_mat(:,2);
                plt1=plot(x_num,y_num); hold on;
                plt1.Color = [0,0,0,(ii/nCellsListLength)];
                plt1.LineStyle = '--';
                plt1.LineWidth = 1.0;
                sc1=scatter(x_num,y_num); hold on;
                sc1.Marker = 'x
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

jmsyh

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

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

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

打赏作者

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

抵扣说明:

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

余额充值