-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunSim.m
39 lines (32 loc) · 1.01 KB
/
runSim.m
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
function T = runSim(k_geom, T_geom, geom_temp, boundary_T)
% grid points
disp('running simulation');
NX = length(k_geom);
K1 = k_geom;
T = T_geom;
Tnew = T;
% plotting stuff
count = 0;
while (count < 1000)
for i = 2:NX-1
for j = 2:NX-1
for k = 2:NX-1
% calculate y and z terms from heat equation
Tnew(i,j,k) = (1/(3*K1(i,j,k) + K1(i-1,j,k) + K1(i,j-1,k) + K1(i,j,k-1))) * ...
((K1(i,j,k) * (T(i+1,j,k) + T(i,j+1,k) + T(i,j,k+1))) + ...
K1(i-1,j,k)*T(i-1,j,k) + K1(i,j-1,k)*T(i,j-1,k) + K1(i,j,k-1)*T(i,j,k-1));
end
end
end
T = Tnew;
T(T_geom == 1) = geom_temp;
count = count + 1;
% boundarys
T(:,:,end) = boundary_T;
T(:,:,1) = boundary_T;
T(:,end,:) = boundary_T;
T(:,:,end) = boundary_T;
T(end,:,:) = boundary_T;
T(1,:,:) = boundary_T;
end
end