If you want to make a topology optimization movie, simply follow this tutorial
In some designs, some elements may be desired to be solid or void (active or passive). A nely×nelx×nelz matrix with ones at elements desired to be solid, and a nely×nelx×nelz matrix with zeros at elements desired to be void can be added to the program.
Step.1: Save iteration history
Add the following lines after line 94
It should looks like this:
Step.2: Save the doMovie.m under the save directory as top3d.m
function doMovie
cutoffL = linspace(0,0.5,50);
i = 0;
while (1)
i = i + 1;
filename = ['xPhys_it',num2str(i,'%03d'),'.mat'];
if exist(filename,'file') == 0
break;
end
load(filename)
if i <= length(cutoffL)
cutoff = cutoffL(i);
else
cutoff = max(cutoffL);
end
plot_3d(xPhys, cutoff, 1, [0.7 0.7 0.7]);
drawnow
mov(i) = getframe(gcf);
end
movie2avi(mov, 'myTopopt.avi');
end
function [p] = plot_3d(x, cutoff, Alpha, fcolor)
if nargin < 4, fcolor = 'r'; end
[nely,nelx,nelz] = size(x);
aux = zeros(nely+2,nelx+2,nelz+2);
aux(2:end-1,2:end-1,2:end-1) = x;
cla, hold on, view(30,30), rotate3d on, axis equal, axis([0 nelx 0 nelz 0 nely]), box
set(gca,'YDir','reverse','ZDir','reverse','ZtickLabel',flipud(get(gca,'Ztick')'));
[X,Y,Z] = meshgrid(0:nelx+1,0:nely+1,0:nelz+1);
p = patch(isosurface(X-0.5,Z-0.5,Y-0.5,aux,cutoff),...
'FaceColor',fcolor,'EdgeColor','none','FaceAlpha',Alpha);
camlight, lighting gouraud;
axis off; box off; set(gcf, 'color', [1 1 1])
drawnow
end
Step.3: Run the program
After running the topology optimization, run the doMovie program
Here are some movies we made using this program: