forked from garyptchoi/kirigami-control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDoF_NCC_vs_link_density_kagome.m
158 lines (130 loc) · 4.61 KB
/
DoF_NCC_vs_link_density_kagome.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
% The codes below calculate the Degree of Freedom (DoF) and NCC (number of
% connected components in a kagome kirigami structure, with varying number
% of links added
%
% Reference:
% S. Chen, G. P. T. Choi, L. Mahadevan,
% ``Deterministic and stochastic control of kirigami topology.''
% Proceedings of the National Academy of Sciences, 117(9), 4511-4517, 2020.
%%
M = 30; %width
N = 30; %height
ntri = M*N; %Number of quads
nlink = rigidity_bound(M,N);% theoretical lower bound for number of links
Linkpairs = [];
% horizontal links
for n = 0:N-1
for m = 0:M-2
i = M*n + m + 1;
if mod(n,2) == mod(m,2)
Linkpairs = [Linkpairs;
3*i-1, 3*(i+1)-2;
3*i, 3*(i+1)];
else
Linkpairs = [Linkpairs;
3*i-2, 3*(i+1)-2;
3*i-1, 3*(i+1)];
end
end
end
% vertical links
for n = 0:N-2
for m = 0:M-1
i = M*n + m + 1;
if mod(n,2) == mod(m,2)
Linkpairs = [Linkpairs;
3*i, 3*(i+M)-2];
else
Linkpairs = [Linkpairs;
3*i-1, 3*(i+M)-1;
3*i, 3*(i+M)-2];
end
end
end
%%
n_simu=100;
n_bin=20;
n_maxlink=round((3*M*floor((N-1)/2))+(1.5*M-0.5*rem(M,2))*rem(N-1,2)+2*(M-1)*N);%Number of links
% combinations = combnk(1:length(Linkpairs),nlink);
link_list = round(linspace(0,n_maxlink,n_bin+1));
dof_all = zeros(n_bin+1,n_simu);
num_conncomp = zeros(n_bin+1,n_simu);
size_conncomp = zeros(n_bin+1,n_simu);
dof_rot = zeros(n_bin+1,n_simu);
tic;
for link_i = 1:length(link_list)
n_link = link_list(link_i);
mat=zeros(ntri*10+n_link*4,3);
% Edge length constraints
for n = 0:N-1
for m = 0:M-1
i = M*n + m + 1;
if mod(n,2) == mod(m,2)
mat(i*10-9,:)=[i*3-2,i*6-5,-1];
mat(i*10-8,:)=[i*3-2,i*6-3,1];
mat(i*10-7,:)=[i*3-1,i*6-5,-1];
mat(i*10-6,:)=[i*3-1,i*6-1,1];
mat(i*10-5,:)=[i*3-1,i*6-4,-sqrt(3)];
mat(i*10-4,:)=[i*3-1,i*6-0,sqrt(3)];
mat(i*10-3,:)=[i*3, i*6-0,sqrt(3)];
mat(i*10-2,:)=[i*3, i*6-2,-sqrt(3)];
mat(i*10-1,:)=[i*3, i*6-1,-1];
mat(i*10-0,:)=[i*3, i*6-3,1];
else
mat(i*10-9,:)=[i*3-2,i*6-1,-1];
mat(i*10-8,:)=[i*3-2,i*6-3,1];
mat(i*10-7,:)=[i*3-1,i*6-5,-1];
mat(i*10-6,:)=[i*3-1,i*6-3,1];
mat(i*10-5,:)=[i*3-1,i*6-4,-sqrt(3)];
mat(i*10-4,:)=[i*3-1,i*6-2,sqrt(3)];
mat(i*10-3,:)=[i*3 ,i*6-1,-1];
mat(i*10-2,:)=[i*3 ,i*6-5,1];
mat(i*10-1,:)=[i*3 ,i*6-4,-sqrt(3)];
mat(i*10-0,:)=[i*3 ,i*6-0,sqrt(3)];
end
end
end
for jjj=1:n_simu
linkpairs = Linkpairs(randsample(size(Linkpairs,1),n_link),:);
disp([num2str(M),' ',num2str(n_link),' ',num2str(jjj)]);
rown=0;
newmat=mat;
% Add link constraints
for t=1:size(linkpairs,1)
[newmat,rown]=constrain(newmat,rown,linkpairs(t,1),linkpairs(t,2),ntri);
end
% Calculate DoF
[r,rgd_Matrix]=calc_rank(newmat,ntri,n_link,M);%%% if M=N
dof=ntri*6-r;
dof_all(link_i,jjj) = dof;
% Calculate the NCC and the size of the largest connected component
linkpairs_adj=ceil(linkpairs/3);
adjacencyMatrix = sparse([linkpairs_adj(:,1); linkpairs_adj(:,2)], [linkpairs_adj(:,2); linkpairs_adj(:,1)], ones(size(linkpairs,1)*2,1), ntri, ntri);
G = graph(adjacencyMatrix);
bins = conncomp(G);
num_conncomp(link_i,jjj)=max(bins);
[MM,FF]=mode(bins);
size_conncomp(link_i,jjj)=FF;
% Calculate the number of internal rotational DoF
dof_rot(link_i,jjj)=dof-3*max(bins);
end
end
toc;
save(['DoF_and_ConnComp_Kagome_rect_L',num2str(M),'_',datestr(datetime('now'),'yyyymmdd'),'.mat'],...
'dof_all','dof_rot','num_conncomp','size_conncomp');
%%
function [mat, rown] = constrain(mat,rown,i,j,ntri)
mat(10*ntri+rown*2+1,:)=[3*ntri+rown+1,i*2-1,1];
mat(10*ntri+rown*2+2,:)=[3*ntri+rown+1,j*2-1,-1];
mat(10*ntri+rown*2+3,:)=[3*ntri+rown+2,i*2,1];
mat(10*ntri+rown*2+4,:)=[3*ntri+rown+2,j*2,-1];
rown = rown+2;
end
%%
function n = rigidity_bound(M,N)
if nargin == 1
n = ceil((3*M^2-3)/2);
else
n = ceil((3*M*N-3)/2);
end
end