fdm之二维静态热传导

function heat_2d

% Geol 5200, Humphrey 2013

% 2D, steady state temperature.  Simplest approach
% full (not sparse) matrices, with BCnodes included in matrix
clear
% solve temperature field in crust with a constant temperatures
BCtop = 0;
BCbottom = 5;
BCright = 3;
BCleft  = 4;


nodes_x = 36;       %width
nodes_y = 25;       %depth


nodes   = nodes_y*nodes_x;


% all BCs at boundaries are fixed
% steady state and constant K
% values of the diagonal and off diagonal coeff
alpha = -4;
beta  =  1;


% make a diagonal matrix of correct size, with '1's on diagonal
v(1:nodes)=1;
A = diag(v);
% better would be to use sparse matrices as follows
% A = speye(nodes,nodes)


% construct the non-trivial bands in the matrix, using a 5 point FD kernel
for i=nodes_x+1:nodes-nodes_x;
    % check if we are at a boundary node, if not then do:
    if((mod(i-1,nodes_x)~=0) && (mod(i,nodes_x)~=0))    %leave BC nodes as '1's  
        A(i,i)=alpha;
        A(i,i-1)=beta;
        A(i,i+1)=beta;
        A(i,i-nodes_x)=beta;
        A(i,i+nodes_x)=beta;
    end
end


% make the known vector, with BC's in correct locations
B = zeros(nodes,1);
B(1:nodes_x)                         =BCtop;     %
B(nodes-nodes_x:nodes)               =BCbottom;    
B(nodes_x+1:nodes_x:nodes-nodes_x-1) =BCleft;     
B(2*nodes_x:nodes_x:nodes-1)         =BCright;     %bottom BC


%solve
T = A\B;


%Plot a contour plot of the solution, note the solution is a vector, and needs to be 
% reshaped into a matrix to plot
B = reshape(T,nodes_x,nodes_y);
%[C, h]=contour(B,[ 1.25 1.5 1.75 2 2.25 2.5 2.75 3 3.25 3.5 3.75]);
[C, h]=contour(B');
clabel(C,h);
axis ij;
xlabel('Bottom');
ylabel('Left');
title('Steady Temperature field, contoured');


% make a new figure and make a surface plot of the temperature field
figure;
surf(B);
axis ij;
title('Temperature as a surface, note upside down');
view(140,30)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值