You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
2.8 KiB
98 lines
2.8 KiB
function x = ApplySymmetry(x,sym)
|
|
[nely,nelx] = size(x);
|
|
|
|
switch sym
|
|
case 'iso'
|
|
sym = 'cubic';
|
|
case 'ort'
|
|
sym = 'normal';
|
|
case 'ant'
|
|
sym = 'orth';
|
|
end
|
|
|
|
switch sym
|
|
% 4-fold symmetry across diagonals
|
|
case 'diag'
|
|
x = (x+x')/2;
|
|
x = rot90(x);
|
|
x = (x+x')/2;
|
|
x = rot90(x);
|
|
|
|
% 4-fold symmetry across normals
|
|
case 'normal'
|
|
for row = 1:nelx
|
|
for col = 1:nelx/2
|
|
x(row,col) = (x(row,col) + x(row,nelx-col+1))/2;
|
|
x(row,nelx+1-col) = x(row,col);
|
|
end
|
|
end
|
|
|
|
for col = 1:nelx
|
|
for row = 1:nelx/2
|
|
x(row,col) = (x(row,col) + x(nelx-row+1,col))/2;
|
|
x(nelx+1-row,col) = x(row,col);
|
|
end
|
|
end
|
|
|
|
% 4-fold rotational symmetry
|
|
case 'rota'
|
|
A = x;
|
|
A90 = rot90(A);
|
|
A180 = rot90(A,2);
|
|
A270 = rot90(A,3);
|
|
E = zeros(nelx);
|
|
temp = 0.25*(A(1:nelx/2,1:nelx/2)+A90(1:nelx/2,1:nelx/2)+A180(1:nelx/2,1:nelx/2)+A270(1:nelx/2,1:nelx/2));
|
|
for ii = 1:3
|
|
E(1:nelx/2,1:nelx/2) = temp;
|
|
E = rot90(E);
|
|
end
|
|
E(1:nelx/2,1:nelx/2) = temp;
|
|
x = E;
|
|
|
|
% Cubic symmetry
|
|
case 'cubic'
|
|
A = x;
|
|
A90 = rot90(A);
|
|
A180 = rot90(A,2);
|
|
A270 = rot90(A,3);
|
|
E = zeros(nelx);
|
|
temp = 0.25*(A(1:nelx/2,1:nelx/2)+A90(1:nelx/2,1:nelx/2)+A180(1:nelx/2,1:nelx/2)+A270(1:nelx/2,1:nelx/2));
|
|
for ii = 1:3
|
|
E(1:nelx/2,1:nelx/2) = temp;
|
|
E = rot90(E);
|
|
end
|
|
E(1:nelx/2,1:nelx/2) = temp;
|
|
x = E;
|
|
|
|
for row = 1:nelx
|
|
for col = 1:nelx/2
|
|
x(row,col) = (x(row,col) + x(row,nelx-col+1))/2;
|
|
x(row,nelx+1-col) = x(row,col);
|
|
end
|
|
end
|
|
|
|
for col = 1:nelx
|
|
for row = 1:nelx/2
|
|
x(row,col) = (x(row,col) + x(nelx-row+1,col))/2;
|
|
x(nelx+1-row,col) = x(row,col);
|
|
end
|
|
end
|
|
|
|
case 'orth'
|
|
x1 = x(1:nely/2, 1:nelx/2);
|
|
x3 = x(nely/2+1:end, nelx/2+1:end);
|
|
x1 = (rot90(rot90(x3))+x1)/2;
|
|
x3 = rot90(rot90(x1));
|
|
|
|
x(1:nely/2, 1:nelx/2) = x1;
|
|
x(nely/2+1:end, nelx/2+1:end) = x3;
|
|
|
|
x2 = x(1:nely/2, nelx/2+1:end);
|
|
x4 = x(nely/2+1:end, 1:nelx/2);
|
|
x2 = (rot90(rot90(x4))+x2)/2;
|
|
x4 = rot90(rot90(x2));
|
|
|
|
x(1:nely/2, nelx/2+1:end) = x2;
|
|
x(nely/2+1:end, 1:nelx/2) = x4;
|
|
end
|
|
end
|