Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sigmund’s 99-line topology optimization top.m

Similar presentations

Presentation on theme: "Sigmund’s 99-line topology optimization top.m"— Presentation transcript:

1 Sigmund’s 99-line topology optimization top.m
Function is remarkable achievement of squeezing so much content into so few lines. An important ingredient in the saving is limiting the geometry to be rectangular and limiting the elements to be square. In addition it uses an optimality criterion method that is easy to implement and understand, but not necessarily the most efficient. It is possible to use it without much understanding, but studying it is a good opportunity to review the basics of SIMP The 99-line code for topology optimization is impressive, especially that 15 of these lines are comments. This is achieved by limiting the geometry to a rectangle and limiting the finite element to squares. In addition the optimization algorithm is an optimality criterion method that we will cover in a different lecture. It is easy to implement and understand, but it is not the most efficient. The objective of this lecture is to get you acquainted with the function.

2 Initialization and finite element analysis
%%%% A 99 LINE TOPOLOGY OPTIMIZATION CODE BY OLE SIGMUND, JANUARY 2000 %%% %%%% CODE MODIFIED FOR INCREASED SPEED, September 2002, BY OLE SIGMUND %%% function top(nelx,nely,volfrac,penal,rmin); % INITIALIZE x(1:nely,1:nelx) = volfrac; loop = 0; change = 1.; % START ITERATION while change > 0.01 loop = loop + 1; xold = x; % FE-ANALYSIS [U]=FE(nelx,nely,x,penal); First let’s look at the calling sequence. The first two parameters are the number of elements in the x direction and y direction. Since these elements are square of length one, we also specify this way the dimensions of the beam we are designing. The next input parameter is the volume fraction, which specifies what percentage of the area of the rectangular domain we want to use for the structure. Penal is the exponent of the density in the relationship between Young’s modulus and the density. It is called penal because it penalizes densities that are different from zero or one. The last parameter is rmin, which specifies the minimum size of a feature. It is intended to prevent very fine meshes from trying to create very fine features that may be noise rather than reality. The initialization sets the vector x, which is the vector of densities to the volume fraction, that is uniform design, and then we set the iteration loop. Here it is worth sounding two alarms. First, the condition for terminating the iteration is absolute rather than relative, and it is quite small compared to the values of the compliances that one can get. Second, there is no limit on the number of iterations, so when it does not converge it can go on forever. The last line is the finite element analysis, that we will look into the next slide.

3 Finite element function
function [U]=FE(nelx,nely,x,penal) [KE] = lk; K = sparse(2*(nelx+1)*(nely+1), 2*(nelx+1)*(nely+1)); F = sparse(2*(nely+1)*(nelx+1),1); U = zeros(2*(nely+1)*(nelx+1),1); for elx = 1:nelx for ely = 1:nely n1 = (nely+1)*(elx-1)+ely; n2 = (nely+1)* elx +ely; edof = [2*n1-1; 2*n1; 2*n2-1; 2*n2; 2*n2+1; 2*n2+2; 2*n1+1; 2*n1+2]; K(edof,edof) = K(edof,edof) + x(ely,elx)^penal*KE; end % DEFINE LOADS AND SUPPORTS (HALF MBB-BEAM) F(2,1) = -1; fixeddofs = union([1:2:2*(nely+1)],[2*(nelx+1)*(nely+1)]); alldofs = [1:2*(nely+1)*(nelx+1)]; freedofs = setdiff(alldofs,fixeddofs); % SOLVING U(freedofs,:) = K(freedofs,freedofs) \ F(freedofs,:); U(fixeddofs,:)= 0; We start by generating the stiffness matrix of a single element using the 1k function. Note that all the elements have the same stiffness matrix except for a multiplier, which is Young’s modulus. Next we tell Matlab to treat the stiffness matrix and force vector as sparse entities where it stores only the non-zero elements. The node numbering is going up from the right side of the beam, so that node 1 is at the bottom right. For example, with 10 element in the y direction, there will be 11 nodes going vertically, and the first element will have nodes 1,12, 13, 2. With each node having two degrees of freedom (x, and y displacements), the degrees of freedom associated with element 1 are 1,2,23,24,25,26, 3,4. These are set in edof. The stiffness matrix of the element is scaled by Young’s modulus and added to the global K. There is a single force in the negative y direction at node 1. Recall that this is done for half of a simply supported beam. So the boundary conditions set the x-displacement to zero on the symmetry plane on the right, and the bottom node y displacement at the simple support point.

4 Compliance calculation and its sensitivity
[KE] = lk; c = 0.; for ely = 1:nely for elx = 1:nelx n1 = (nely+1)*(elx-1)+ely; n2 = (nely+1)* elx +ely; Ue = U([2*n1-1;2*n1; 2*n2-1;2*n2; 2*n2+1;2*n2+2; 2*n1+1;2*n1+2],1); c = c + x(ely,elx)^penal*Ue'*KE*Ue; dc(ely,elx) = -penal*x(ely,elx)^(penal-1)*Ue'*KE*Ue; end % FILTERING OF SENSITIVITIES [dc] = check(nelx,nely,rmin,x,dc); The calculation of the compliance and its sensitivity is done element by element and added together. This is followed by filtering of the sensitivities that we will discuss in the next slide.

5 Low pass filter for sensitivity
Average sensitivities with adjacent elements that are within the feature size rmin Dist(k,i) is the distance between centers of element i and element k. By averaging the sensitivities of elements that are within rmin distance from the current element, we are removing the mechanism of having very small features. Here the average is taken with the weighting proportional to the density of the elements and the rmin minus the distance between the elements.

6 Effect of rmin Rmin=0.1 Nelx=200,nely=40,volfrac=0.4, penal=3, rmin=2
To illustrate the effect of rmin, we select rmin=2, which means that we average sensitivities with the immediately adjacent elements. The figures on the left show that by doubling the number of elements in each direction we get a sharper image of the topology, but features on a finer scale. The figure on the right shows that if we set rmin low, that is do not use the filter, we will get a checkerboard pattern. That is the feature size will reduce to the element size and could not be trusted.


Download ppt "Sigmund’s 99-line topology optimization top.m"

Similar presentations

Ads by Google