您现在的位置:首页 >> ★免费资源 >> 源码下载 >> 内容

基于MATLAB的有限元SOR算法的仿真程序

时间:2019-1-22 2:58:48 点击:

  核心提示:基于MATLAB的有限元SOR算法的仿真程序...
% Twodimensional heat conduction
% Finite Volume Method
% SOR
clear all;
x=[];y=[];T=[];Told=[];Su=[];Sp=[];ap=[];ae=[];aw=[];as=[];an=[];
great = 1.e20;
lambda = 10; % thermal conductivity
alfa = 10; % heat transfer coefficient
dt = great; % Time step. If great stedy state
density = 6000;% density
cp = 500;% heat capacity
Lx = 0.12; % length x-direction
Ly = 0.12; % length y -direction
Tfluid = 20; % Fluid temperature
Tinit = 50; % Initial guess and top- and bottom tempearature
%cv_x = input('Number of CVs in x-direction = ')
%cv_y = input('Number of CVs in y-direction = ')
cv_x=10;cv_y=10;
ni = cv_x+2; % grid points x-direction
nj = cv_y+2; % grid points y-direction
dx = Lx/cv_x;
dy = Ly/cv_y;
x(1) = 0;
x(2)=dx/2;
for i = 3:ni-1
   x(i)=x(i-1)+dx;
end;
x(ni)=Lx;
y(1) = 0;
y(2)=dy/2;
for j = 3:nj-1
   y(j)=y(j-1)+dy;
end
y(nj)=Ly;
% Initial values and coefficients
for i = 1:ni
  for j = 1:nj
    T(i,j) = Tinit;  %Initial temperature
    Told(i,j) = Tinit;
    T(i,1) = 50;
    T(i,nj) = 50;
    Su(i,j)=0;       %Initial indendendent source term
    Sp(i,j)=0;       %Initial dependent source term
    ae(i,j) = lambda*dy/dx;
    aw(i,j) = lambda*dy/dx;
    an(i,j) = lambda*dx/dy;
    as(i,j) = lambda*dx/dy;
    dV = dx*dy;
    ap0 = density*cp*dV/dt;
    if i==2  % convective heat transfer boundary
       Su(i,j) = Tfluid/(1/alfa+dx/(2*lambda))*dy/dV;
       Sp(i,j) = -1/(1/alfa+dx/(2*lambda))*dy/dV;
       aw(i,j) = 0;
    end;
    if i==ni-1 % insulated boundary
       ae(i,j) = 0;
    end
    if j==2 % bottom boundary, given temperature
       as(i,j)=2*lambda*dx/dy;
    end   
    if j==nj-1 % top boundary, given temperature
       an(i,j)=2*lambda*dx/dy;
    end   
    ap(i,j) = ae(i,j)+aw(i,j)+an(i,j)+as(i,j)-Sp(i,j)*dV+ap0;
  end;
end;
%%%%%%%%%%%
maxres = 1.0e-6;
maxit = 100;
time=0;
maxtime=100;
s=(cos(pi/cv_x)+(dx/dy)^2*cos(pi/cv_y))/(1+(dx/dy)^2);
omega =2/(1+sqrt(1-s^2));omega=1;
while (time < (maxtime+dt/2))
 Told=T;  
 sumres = 1;
 counter = 0;
 while (sumres>maxres&counter<maxit)
  sumres = 0;
  for i = 2:ni-1
   for j = 2:nj-1
    T(i,j)=omega*(ae(i,j)*T(i+1,j)+aw(i,j)*T(i-1,j)+an(i,j)*T(i,j+1)...
       +as(i,j)*T(i,j-1)+Su(i,j)*dV+ap0*Told(i,j))/ap(i,j)+(1-omega)*T(i,j);
    res =  abs(ap(i,j)*T(i,j)-(ae(i,j)*T(i+1,j)+aw(i,j)*T(i-1,j)+...
      an(i,j)*T(i,j+1)+as(i,j)*T(i,j-1)+Su(i,j)*dV+ap0*Told(i,j)));
    sumres=sumres+res;
   end;
  end;
  for i = 2:ni-1
   for j = 2:nj-1
    res =  abs(ap(i,j)*T(i,j)-(ae(i,j)*T(i+1,j)+aw(i,j)*T(i-1,j)+...
      an(i,j)*T(i,j+1)+as(i,j)*T(i,j-1)+Su(i,j)*dV+ap0*Told(i,j)));
    sumres=sumres+res;
   end;
  end

  sumerr=sumres
  counter = counter + 1
 end;
 time = time +dt;
end; 
% Calculate boundary values
 for j = 2:nj-1
   T(1,j)=(alfa*Tfluid+lambda/(dx/2)*T(2,j))/(alfa+lambda/(dx/2));
   T(ni,j) = T(ni-1,j);
end;   
%
pcolor(x,y,T');shading interp;xlabel('x');ylabel('y');title('Temperature distribution');colorbar;
%

联系:highspeedlogic

QQ :1224848052

微信:HuangL1121

邮箱:1224848052@qq.com

网站:http://www.mat7lab.com/

网站:http://www.hslogic.com/

微信扫一扫:

Tags:SOR算法 
作者:SOR算法 来源:SOR算法
  • 您是如何找到本站的?
  • 百度搜索
  • Google搜索
  • 查阅资料过程中
  • 论坛发现
  • 百度贴吧发现
  • 朋友介绍
本站最新成功开发工程项目案例
相关文章
  • 没有相关文章
相关评论
发表我的评论
  • 大名:
  • 内容:
  • matlab代做|matlab专业代做|matlab淘宝代做(www.hslogic.com) © 2019 版权所有 All Rights Reserved.
  • Email:highspeed_logic@163.com 站长QQ: 1224848052

    专业代做/代写/承接、MATLAB、SIMULINK、FPGA项目、博士/硕士/本科毕业设计、课题设计、论文,毕业论文,Coursework、Eassy、Assignment