-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot_poisson.m
78 lines (66 loc) · 1.5 KB
/
plot_poisson.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
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
% Manuel Tsolakis, 2019
% reads and plots the file "result" generated by poisson_solver3d.c
close all
%edit according to your needs
m=100;
n=20;
q=10;
ax=0;
ay=0;
az=0;
h=0.1;
%read the result file and reshape/permute the 3d matrix so that it can be used
%note that the dimensions might seem wrong but Matlab needs it this way
fileID = fopen('results','r');
t=fread(fileID,'double');
fclose(fileID);
t=permute(reshape(t,[q n m]),[2 3 1]);
clear fileID
%calculate the end coordinates in each dimension
bx=ax+m*h;
by=ay+n*h;
bz=az+q*h;
%create mesh vectors
xv = zeros(m,1);
yv = zeros(n,1);
zv = zeros(q,1);
for i=1:m
xv(i)=ax+h*i;
end
for i=1:n
yv(i)=ay+h*i;
end
for i=1:q
zv(i)=az+h*i;
end
clear i
%plot results (using slices)
[x,y,z]=meshgrid(xv,yv,zv);
xslice = [(bx-(ax+h))/3,(bx-(ax+h))/3*2, bx];
yslice = by;
zslice = [az+h,(bz-(az+h))/3,(bz-(az+h))/3*2];
fig1=slice(x,y,z,t,xslice,yslice,zslice);
set(fig1,'edgecolor','none')
title('Approximate Solution')
xlabel('x')
ylabel('y')
zlabel('z')
%plot the analytical solution
figure
A=(1+x+z).*sin(x+y);
fig2=slice(x,y,z,A,xslice,yslice,zslice);
set(fig2,'edgecolor','none')
title('Analytical Solution')
xlabel('x')
ylabel('y')
zlabel('z')
%plot the relative difference (of course for A close to 0 this will be large)
figure
A=(A-t)./A;
fig3=slice(x,y,z,A,xslice,yslice,zslice);
set(fig3,'edgecolor','none')
title('Relative difference')
xlabel('x')
ylabel('y')
zlabel('z')
colorbar