-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconnect_1D.m
52 lines (42 loc) · 1.47 KB
/
connect_1D.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
function Con=connect_1D(Lev)
%=============================================================
% construct 1D connectivity
% output: the nonzero parts for matrices
% we consider the most numbers for connected case
% (ignoring Deg)
%=============================================================
Con=sparse(2^Lev,2^Lev);
for Lx=0:Lev
for Px=0:2^max(0,Lx-1)-1
I=lev_cell_to_1D_index(Lx,Px);
J=lev_cell_to_1D_index(Lx,[max(Px-1,0):min(Px+1,2^max(0,Lx-1)-1)]);
% diagnal is connected
Con(I,J)=1;
Con(J,I)=1;
% periodic boundary is connected
if Px==0
tmp_end=lev_cell_to_1D_index(Lx,2^max(0,Lx-1)-1);
Con(I,tmp_end)=1;
Con(tmp_end,I)=1;
elseif Px==2^max(0,Lx-1)-1
tmp_begin=lev_cell_to_1D_index(Lx,0);
Con(I,tmp_begin)=1;
Con(tmp_begin,I)=1;
end
for Ly=Lx+1:Lev
nL=Ly-Lx;
% the overlapping part, one cell Left, and one cell Right
if Lx>0
Py=[max(2^(nL)*Px-1,0):min(2^(nL)*Px+2^(nL),2^(Ly-1)-1)];
elseif Lx==0
Py=[max(2^(nL-1)*Px-1,0):min(2^(nL-1)*Px+2^(nL-1),2^(Ly-1)-1)];
end
% periodic boundary is connected
Py=[0,Py,2^max(0,Ly-1)-1];
J=lev_cell_to_1D_index(Ly,Py);
Con(I,J)=1;
Con(J,I)=1;
end
end
end
end