-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.txt
95 lines (83 loc) · 2.4 KB
/
code.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
%% 2D heat transfer
% =======================================================
% inputs
ro = 7600; %density (kg/m3)
vod = 47; %heat conductivity (W/m/K)
Cp = 480; %heat capacity (J/kg)
T0 = 400; %initial temperature (K)
TH = 800; %Top edge temperature (K)
TD = 300; %Bottom edge temperature (K)
TP = 200; %Left edge temperature (K)
TL = 500; %Right edge temperature (K)
L = 1; %Modul
M = 5; %Edge length (m)
N = 50; %Number of points
tkon = 500; %Final time (s)
% ===================================================
% calculation
a = vod/ro/Cp;
% length step
dx = L/(N-1);
% time step
dt =((dx)^2)/M/a;
t = dt;
% =======================================================
% initialy temperatures
Tpoc = zeros(N,N);
for i=1:1:N
for j=1:1:N
Tpoc(i,j) = T0;
end
end
h = figure(1);
h_ax = axes(h);
while t < tkon
% ============================================================
j=1;
i=1;
Tpoc(i,j)=(Tpoc(i+1,j)+TL+TD+Tpoc(i,j+1)+(M-4)*Tpoc(i,j))/M;
j=N;
i=1;
Tpoc(i,j)=(Tpoc(i+1,j)+TD+Tpoc(i,j-1)+TP+(M-4)*Tpoc(i,j))/M;
j=1;
i=N;
Tpoc(i,j)=(TH+Tpoc(i-1,j)+TL+Tpoc(i,j+1)+(M-4)*Tpoc(i,j))/M;
j=N;
i=N;
Tpoc(i,j)=(TP+Tpoc(i-1,j)+Tpoc(i,j-1)+TP+(M-4)*Tpoc(i,j))/M;
% ==========================================================
i=1;
for j=2:1:N-1
Tpoc(i,j)=(Tpoc(i+1,j)+TD+Tpoc(i,j-1)+Tpoc(i,j+1)+(M-4)*Tpoc(i,j))/M;
end
i=N;
for j=2:1:N-1
Tpoc(i,j)=(TH+Tpoc(i-1,j)+Tpoc(i,j-1)+Tpoc(i,j+1)+(M-4)*Tpoc(i,j))/M;
end
j=1;
for i=2:1:N-1
Tpoc(i,j)=(Tpoc(i+1,j)+Tpoc(i-1,j)+TL+Tpoc(i,j+1)+(M-4)*Tpoc(i,j))/M;
end
j=N;
for i=2:1:N-1
Tpoc(i,j)=(Tpoc(i+1,j)+Tpoc(i-1,j)+Tpoc(i,j-1)+TP+(M-4)*Tpoc(i,j))/M;
end
% ===========================================================
for i=2:1:N-1
for j=2:1:N-1
Tpoc(i,j)=(Tpoc(i+1,j)+Tpoc(i-1,j)+Tpoc(i,j-1)+Tpoc(i,j+1)+(M-4)*Tpoc(i,j))/M;
end
end
% ===========================================================
% graph
c = jet;
pause(0.02)
pcolor(h_ax, Tpoc)
retazec = sprintf('Time=%g s',t);
title(retazec);
colormap(c);
colorbar;
shading interp;
% --------
t=t+dt;
end