-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexplicit_sor.m
45 lines (39 loc) · 1.13 KB
/
explicit_sor.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
40
41
42
43
44
45
function [ out ] = explicit_sor( nx, ny, x, y, dx, dy, T, t, dt, tol, k, k1, k2 )
% Explicit Successive Over-Relaxation Method for Transient State
lambda = 1.3; % Over Relaxation factor
meshgrid(x,y);
T_old = T;
To = T;
nt = t/dt;
sor_iter = 1;
tic
for m = 1:nt
error = 9e9;
while (error > tol)
for i = 2:nx-1
for j = 2:ny-1
term1 = T(i-1, j) + T_old(i+1, j);
term2 = T(i, j-1) + T_old(i, j+1);
T(i,j) = (1-lambda)*T_old(i,j) + (lambda*((To(i,j)*(1 - 2*k1 - 2*k2)) + (k1*term1) + (k2*term2)));
end
end
error = max(max(abs(T_old - T)));
T_old = T;
sor_iter = sor_iter + 1;
end
To = T;
end
iter_time = toc;
figure(9)
[a, b] = contourf(x, y, T);
colormap(jet)
clabel(a, b);
xlabel('X Length Domain');
ylabel('Y Length Domain');
txt1 = sprintf('Explicit Successive Over-Relaxation Method Iterations = %d', sor_iter);
txt2 = sprintf('Explicit Successive Over-Relaxation Method Simulation Time = %f s', iter_time);
txt3 = sprintf('Final error = %f', error);
colorbar
title({'Transient State';txt1;txt2;txt3});
out = iter_time;
end