Skip to content
This repository has been archived by the owner on Apr 23, 2022. It is now read-only.

Commit

Permalink
\tada
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavoquincy committed Nov 8, 2019
0 parents commit 0fa639e
Show file tree
Hide file tree
Showing 44 changed files with 1,352 additions and 0 deletions.
16 changes: 16 additions & 0 deletions EquidistantPacking.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
width = 10;
height = 5*sqrt(3);
r = 0.5;
[x,y] = meshgrid(1+0.5:2:19+0.5,sqrt(3)/3:2*sqrt(3):8*sqrt(3)+sqrt(3)/3);
[xx,yy] = meshgrid(0+0.5:2:18+0.5,sqrt(3)/3+sqrt(3):2*sqrt(3):9*sqrt(3)+sqrt(3)/3);
s1 = size(x);
s2 = size(xx);
X = zeros(s1(1)*s1(2)+s2(1)*s2(2),2);
for i = 1:s1(1)*s1(2)
X(i,:) = [x(i),y(i)];
end
for i = 1:s2(1)*s2(2)
X(i+s1(1)*s1(2),:) = [xx(i),yy(i)];
end
X = r.*X;
save('./RegularPackingData/HexagonalPacking10.mat','X','width','height')
33 changes: 33 additions & 0 deletions HardcorePacking.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
%seed control
rng('default')

width = 100;
height = 100;
max = width.*height;
inside_box = 1;
count = 0;
X = [width/2,height/2];
while inside_box <= max
count = count+1;
v = [width.*rand, height.*rand];
flag = true;
for i = 1:inside_box
%brutal here since it compare norm2 with all extant points in the
%box
if norm(v-X(i,:))<1
flag = false;
break
end
end
if flag == true
inside_box = inside_box+1;
X = [X;v];
end
if count >1e5
break
end
end
save('./HardcorePackingData/HardPacking100.mat','X','width','height')



Binary file added HardcorePackingData/HardPacking.mat
Binary file not shown.
Binary file added HardcorePackingData/HardPacking100.mat
Binary file not shown.
Binary file added HardcorePackingData/HardPacking2.mat
Binary file not shown.
Binary file added HardcorePackingData/HardPacking20*10.mat
Binary file not shown.
Binary file added HardcorePackingData/HardPacking20.mat
Binary file not shown.
Binary file added HardcorePackingData/HardPacking3.mat
Binary file not shown.
Binary file added HardcorePackingData/HardPacking30*10.mat
Binary file not shown.
Binary file added HardcorePackingData/HardPacking4.mat
Binary file not shown.
Binary file added HardcorePackingData/HardPacking5*5.mat
Binary file not shown.
Binary file added RegularPackingData/HexagonalPacking10.mat
Binary file not shown.
31 changes: 31 additions & 0 deletions Simplex.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
classdef Simplex
properties
Vertices
Vsize
Orientation
Area
Perimeter
Centroid
A0 = 1.5%Optimal Area
K = 0.12 %AreaElasticityParameter
Gamma = 1 %PerimeterContractilityParameter
CorsonCellState = 0 %CorsonCellState ccs will affect K Gamma Delta as reflected in related function
end
methods
function obj=Simplex(varargin)
if nargin>0
obj.Vertices=cell2mat(varargin);
end
end
function [r,l] = ver(obj)
r = horzcat(obj(:).Vertices);
l = horzcat(obj(:).Vsize);
end
function r = cen(obj)
r = vertcat(obj.Centroid);
end
function r = stateu(obj)
r = vertcat(obj.CorsonCellState);
end
end
end
62 changes: 62 additions & 0 deletions Vertex.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
classdef Vertex
properties
Loc %Location coordinate of vertex
Dual = []%Vertex that is topological equivalent assuming periodic boundary condition
N_Vertex = [] %neighboring vertex index
N_Face = []%neighboring face index
Edge = []%representative edge for energy calculation
Delta = 1*ones(1,3)%corresponding line tension parameter
%Energy %3*3 vector, row1,area contribution, neighbor_face 1, 2, 3 respectively,
%row 2 perimeter and row 3 cell junction, with edge vertex 1, 2, 3 respectively.
%UpdateFlag = false

end
methods
function obj = Vertex(valx,valy)
if nargin>0
obj.Loc=[valx,valy];
end
end
function obj = add_dual(obj,val)
obj.Dual = horzcat(obj.Dual, val);
end
function obj = add_n_vertex(obj,val)
obj.N_Vertex = horzcat(obj.N_Vertex,val);
end
function obj = add_n_face(obj,val)
obj.N_Face = unique(horzcat(obj.N_Face,val));
end
function obj = set_delta(obj,loc,val)
obj.Delta(loc) = val;
end
function sumU = sumU(obj)
l = length(obj);
if l == 1
sumU = sum(obj.Energy,'all');
else
sumU = 0;
for i = 1:l
sumU = sumU + sum(obj(i).Energy,'all');
end
end
end
function neighbor_set = edge(obj)
neighbor_set = obj.Edge(:,2)';
end
%%
function obj = set_velocity(obj, force)
obj.Velocity = force;
end
function obj = add_loc(obj,dt)
obj.Loc_Gradient = [obj.Loc_Gradient; obj.Loc_Gradient(end,:) + dt * obj.Velocity];
obj.UpdateFlag = true;
end
%%
function r = loc(obj)
r = vertcat(obj.Loc);
end
function obj = setloc(obj,val)
obj(:).Loc = val;
end
end
end
16 changes: 16 additions & 0 deletions a_force.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function r = a_force(vindex_vector,f,v,width,height)
if length(vindex_vector)>1
r = zeros(length(vindex_vector),2);
%ticBytes(gcp);
parfor i = 1:length(vindex_vector)
%try
r(i,:) = analytic_force(vindex_vector(i),f,v,width,height);
%catch
%fprintf('Vertex%d encountered error when calculating force.\n',i);
%end
end
%tocBytes(gcp)
else
r = analytic_force(vindex_vector,f,v,width,height);
end
end
105 changes: 105 additions & 0 deletions analytic_force.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
function r = analytic_force(vindex,f,v,width,height)
[ccw,v] = ccwindex(vindex,f,v,width,height);
v0 = v(vindex);
v1 = v(ccw(1));
f1 = f(ccw(2));
v2 = v(ccw(3));
f2 = f(ccw(4));
v3 = v(ccw(5));
f3 = f(ccw(6));
edgerowv = [GammaP(f1)+Delta(v0,v1)+GammaP(f3), GammaP(f1)+Delta(v0,v2)+GammaP(f2), GammaP(f2)+Delta(v0,v3)+GammaP(f3)];
facerowv = [Kappa(f1), Kappa(f2), Kappa(f3)];
edgem = [diffovernorm(v0,v1); diffovernorm(v0,v2); diffovernorm(v0,v3)];
facem = [avgdiff(v1,v2); avgdiff(v2,v3); avgdiff(v3,v1)];
r = -(edgerowv*edgem + facerowv*facem);
end
%%
%handy functions for simplifying matrix multiplication above
function r = GammaP(fn)
r = fn.Gamma*fn.Perimeter;
end

function r = Delta(v0,vn)
[~,IA,~] = intersect(v0.Edge, circshift(vn.Edge, 1, 2),'rows');%note that IA and IB are not necessarily the same
r = v0.Delta(IA);
end

function r = Kappa(fn)
r = fn.K*(fn.Area-fn.A0);
end

function r = diffovernorm(v0,vn)
r = (v0.Loc-vn.Loc)./norm(v0.Loc-vn.Loc);
end

function r = avgdiff(v1,v2)
r = 0.5*[v2.Loc(2)-v1.Loc(2),v1.Loc(1)-v2.Loc(1)];
end
%%
function [r,v] = ccwindex(vindex,f,v,width,height)
%move vertex coordinates for non-neighboring simplices
neighbor_face_list = v(vindex).N_Face;
centroids = zeros(3,2);
for i = 1:3
centroids(i,:) = f(neighbor_face_list(i)).Centroid;
end
diffc = [centroids(2,:)-centroids(1,:);centroids(3,:)-centroids(1,:)];
diffc = vround(diffc,width,height);
for i = 1:2
vertex = f(neighbor_face_list(i+1)).Vertices;
for j = 1:length(vertex)
v(vertex(j)).Loc = v(vertex(j)).Loc - diffc(i,:);
centroids(i+1,:) = centroids(i+1,:) - diffc(i,:);
end
end
intersect_vertex = intersect(f(neighbor_face_list(2)).Vertices, f(neighbor_face_list(3)).Vertices);
if ~isempty(intersect_vertex)
for i = 1:length(intersect_vertex)
v(intersect_vertex(i)).Loc = v(intersect_vertex(i)).Loc + diffc(i,:);
end
end
e = edge(v(vindex));
location = loc(v(e));
if polyarea(location) > 0
circlev = [e(1),e(2),e(3)];
else
circlev = [e(1),e(3),e(2)];
end
if polyarea(centroids) > 0
circlef = [neighbor_face_list(1),neighbor_face_list(2),neighbor_face_list(3)];
else
circlef = [neighbor_face_list(1),neighbor_face_list(3),neighbor_face_list(2)];
centroids(2:3,:) = circshift(centroids(2:3,:),1);
end
%circlef store simplex indices, c store coordinates
index = 0;
for i = 1:3
A = [v(circlev(2)).Loc-v(circlev(1)).Loc; centroids(i,:)-v(circlev(1)).Loc];
if det(A)<0
index = i;
break
end
end
switch index
case 1
circlef = circshift(circlef,0);
case 2
circlef = circshift(circlef,-1);
case 3
circlef = circshift(circlef,1);
end
r(1)=circlev(1);
r(2)=circlef(1);
r(3)=circlev(2);
r(4)=circlef(2);
r(5)=circlev(3);
r(6)=circlef(3);
end
%%
function r = polyarea(location)
a1 = location(1:2,:);
a2 = location(2:3,:);
a3 = circshift(location,1);
a3 = a3(1:2,:);
r = det(a1)+det(a2)+det(a3);
end
12 changes: 12 additions & 0 deletions associated_u.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function asso_u = associated_u(vindex,simplex,vertex)
asso_u = 0;
face = vertex(vindex).N_Face;
for i = 1:length(face)
asso_u = asso_u + face_energy(face(i),simplex,vertex);
end
asso_u = asso_u - 2*sumU(vertex(vindex)) - sumU(vertex(vertex(vindex).Edge(:,2)'));
end

function uf = face_energy(findex, simplex, vertex)
uf= sumU(vertex(simplex(findex).Vertices));
end
13 changes: 13 additions & 0 deletions backup/calc_energy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function vertex = calc_energy(simplex,vertex)
for i = 1:length(vertex)
U = zeros(3,3);
for j = 1:length(vertex(i).N_Face)
f = vertex(i).N_Face(j);
U(1,j) = simplex(f).K/2*(simplex(f).Area-simplex(f).A0)^2;
U(2,j) = simplex(f).Gamma/2*(simplex(f).Perimeter)^2;
end
for j = 1:length(vertex(i).Edge)
U(3,j) = vertex(i).Delta(j)*vnorm(vertex(i).Edge(j,1),vertex(i).Edge(j,2),vertex);
end
vertex(i).Energy = U;
end
3 changes: 3 additions & 0 deletions backup/common_edge.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function r = common_edge(simplex1,simplex2)
r = intersect(simplex1.Vertices, simplex2.Vertices);
end
3 changes: 3 additions & 0 deletions backup/dismanhattan.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function r = dismanhattan(argin)
r = vertcat(argin(2:end,:)-argin(1,:));
end
70 changes: 70 additions & 0 deletions backup/mintersect.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
function [S,varargout] = mintersect(varargin)
% [S, iA, iB, iC, ...] = mintersect(A, B, C, ...)
% Returns the data S common to numerical vectors A, B, C..., with no
% repetitions. Output S is in sorted order.
% Return in iA, iB, ... index vectors such that S = A(iA) = B(iB) = ...
%
% Syntax: [...] = mintersect(A, B, C, ..., 'rows')
% A, B, are arrays and must have the same number of column n.
% MINTERSECT considers each row of input arguments as an entities
% for comparison. S is array of n-columns, each row appears at least once
% in each input array.
%
% See also: intersect, munion
% Author: Bruno Luong <[email protected]>
s = varargin(:);
rowflag = ischar(s{end}) && strcmpi(s(end),'rows');
if rowflag
s(end) = [];
end
nsets = size(s,1);
isallrowv = all(cellfun('size',s,1)==1);
for k = 1:nsets
sk = s{k};
if ~rowflag
sk = sk(:);
end
s{k} = [sk, k+zeros(size(sk,1),1)];
end
[v,L] = uniquerow(cat(1,s{:}));
[u,K,J] = uniquerow(v(:,1:end-1));
tf = accumarray(J,1)==nsets;
S = u(tf,:);
if isallrowv
S = S.';
end
if nargout > 1
nout = nargout-1;
if isempty(S)
out = cell(1,nout);
[out{:}] = deal([]);
else
l = cellfun('size',s,1);
i = cumsum(accumarray(1+cumsum(l),-l)+1);
iL = i(L);
a = bsxfun(@plus, K(tf), (0:nsets-1));
out = num2cell(reshape(iL(a),size(a)),1);
end
varargout = out;
end
end % mintersect
%%
function [u,I,J] = uniquerow(a)
% perform [u,I,J] = unique(a,'rows') but without overhead
if size(a,2) == 1
[b,K] = sort(a,'ascend');
else
[b,K] = sortrows(a,'ascend');
end
tf = [true; any(diff(b,1,1),2)];
i = find(tf);
u = b(i,:);
if nargout >= 2
I = K(i);
if nargout >= 3
J = double(tf);
J(K) = cumsum(J);
end
end
end % uniquerow

5 changes: 5 additions & 0 deletions backup/qquiver.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function qquiver(vindex,f,v,width,height)
loc = v(vindex).Loc;
f = a_force(vindex,f,v,width,height);
quiver(loc(1),loc(2),f(1),f(2));
end
Loading

0 comments on commit 0fa639e

Please sign in to comment.