1 function y=prolongation_3d(x)
6 % y bilinear interpolation wrapped by zeros
9 % x=magic(2); prolongation_3d(x)
11 % map vector to 3d grid with zero boundary
14 xx(2:nn(1)+1,2:nn(2)+1,2:nn(3)+1)=reshape(x,nn);
17 % copy values on coarse points
18 y(2:2:end-1,2:2:end-1,2:2:end-1)=xx(2:end-1,2:end-1,2:end-1);
20 % averages to coarse edge midpoints in direction 1
21 y(1:2:end,2:2:end-1,2:2:end-1)=0.5*(xx(1:end-1,2:end-1,2:end-1)+xx(2:end,2:end-1,2:end-1));
22 % averages to coarse edge midpoints in direction 2
23 y(2:2:end-1,1:2:end,2:2:end-1)=0.5*(xx(2:end-1,1:end-1,2:end-1)+xx(2:end-1,2:end,2:end-1));
24 % averages to coarse edge midpoints in direction 3
25 y(2:2:end-1,2:2:end-1,1:2:end)=0.5*(xx(2:end-1,2:end-1,1:end-1)+xx(2:end-1,2:end-1,2:end));
27 % averages to coarse cell face centers in directions 1 and 2
28 y(1:2:end,1:2:end,2:2:end-1)=0.25*(xx(1:end-1,1:end-1,2:end-1)+xx(2:end,1:end-1,2:end-1)+...
29 xx(1:end-1,2:end,2:end-1) + xx(2:end,2:end,2:end-1));
30 % averages to coarse cell face centers in directions 2 and 3
31 y(1:2:end,2:2:end-1,1:2:end)=0.25*(xx(1:end-1,2:end-1,1:end-1)+xx(2:end,2:end-1,1:end-1)+...
32 xx(1:end-1,2:end-1,2:end) + xx(2:end,2:end-1,2:end));
33 % averages to coarse cell face centers in directions 2 and 3
34 y(2:2:end-1,1:2:end,1:2:end)=0.25*(xx(2:end-1,1:end-1,1:end-1)+xx(2:end-1,2:end,1:end-1)+...
35 xx(2:end-1,1:end-1,2:end) + xx(2:end-1,2:end,2:end));
37 % averages to coarse cell centers
38 y(1:2:end,1:2:end,1:2:end)=0.125*(xx(1:end-1,1:end-1,1:end-1)+xx(2:end,1:end-1,1:end-1)+...
39 xx(1:end-1,2:end,1:end-1) + xx(1:end-1,1:end-1,2:end)+...
40 xx(2:end,2:end,1:end-1) + xx(2:end,1:end-1,2:end)+...
41 xx(1:end-1,2:end,2:end) + xx(2:end,2:end,2:end));