How to plot the temperature vs.time and the updated contour through time in this CFD transient conduction heat transfer MATLAB code?
1 次查看(过去 30 天)
显示 更早的评论
Hello I have hear a code written in Matlab but the plot and the contours are not updated. What should we do? I need to see the contours updated and the same for the plot from time 0 to 8.5. The simulation should stop after 8.5 seconds due to steady state.
Thanks
clc
L = 0.05;
H = 0.05;
dx = 0.0025;
dy = 0.0025;
tmax = 50.;
dt =0.01;
epsilon = 0.0001;
alp= 1.11e-4;
r_x = (alp*dt)/dx^(2);
r_y = (alp*dt)/dy^(2);
fo = r_x + r_y;
% create the x, y meshgrid based on dx, dy
nx = uint32(L/dx + 1);
ny = uint32(H/dy + 1);
[X,Y] = meshgrid(linspace(0,L,nx),linspace(0,H,ny));
% take the center point of the domain
ic = uint32((nx-1)/2+1);
jc = uint32((ny-1)/2+1);
% set initial and boundary conditions
T = 25.0*ones(ny,nx);
T(:,1) = 100.0;
T(:,end) =0.0;
T(1,:) = 0.0;
T(end,:) = 0.0;
Tmin = min(min(T));
Tmax = max(max(T));
% iteration, march in time
n = 0;
nmax = uint32(tmax/dt);
while n < nmax
n = n + 1;
T_n = T;
for j = 2:ny-1
for i = 2:nx-1
T(j,i) = T_n(j,i) + r_x*(T_n(j,i+1)-2*T_n(j,i)+T_n(j,i-1))...
+ r_y*(T_n(j+1,i)-2*T_n(j,i)+T_n(j-1,i));
end
end
if uint16(n/50) == n/50 % refresh the plot every 50 time steps to save time
plot(n*dt,T(jc,ic),'r.')
contourf(X,Y,T,20)
cb=colorbar;
end
% check for convergence
err = max(max(abs((T-T_n))));
if err <= epsilon
break
end
end
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Mathematics and Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!