3D Topology Optimization using MATLAB fmincon – Top3d/fmincon
In this tutorial, you will learn how to use Matlab1
fminconfunction as an optimizer in our 3d topology optimization program. It constrains six(6) main steps, i.e., Initialize Fmincon, Define Objective function, Hessian, Constraint, Output function and Call fmincon.
Note: the line numbers in each step is refer to as the code snippets in each step instead of the top3d program.
Step.0: Remove Codes from Top3d
Before we get started, please download the Top3d program if you haven’t done so.
Then, DELETE lines 64- 96 (mainly the while loop) in the program. The following steps start after line 63.
Step.1: Initialize fmincon
In this step, we are going to initialize parameters used by Matlab fmincon function.
- In line 2, a global variable
ceis defined.cewill be used in bothmyObjFcnandmyHessianFcn. - Since our constraint (volume constraint) is a function of
xPhysinstead of design variablex, we will define it in the functionmyConstrFcn - There are lots of
OPTIONSdefined forfminconTolX: user-defined terminarion criterion.MaxIter: maximum number of iterations.Algorithm: Matlabfminconhas many alogrithms, such as ‘sqp’, ‘active-set’, ‘trust-region-reflective’ and ‘interior-point’. The reason why we choose ‘interior-point’ instead of others is because ‘interior-point’ accepted user-supplied Hessian of the Lagrange function while ‘sqp’ and ‘active-set’ do not allow user to provide hessian. The hessian in ‘sqp’ or ‘active-set’ are approximated by the means of BFGS (Quasi-Newtown method).GradObj,GradConstr,Hessian,HessFcn: With analytic expressions of the gradients of the objective function, constraints and Hessian of the Lagrange function, the optimization algorithm will execute faster than numerical approximation.Display: display option is turned off. We will display iteration information in theOutputFcn.OutputFcn: we defined output function inmyOutputFcn, which will display iteration information, structural topology corresponding.PlotFcns: Matlab provides some built-in plot function,@optimplotfvalplots the function value.- Click here for more information out
fminconoptions.
Step.2: Define Objective function
The function to be minimized. myObjFcn is a function that accepts a vector x and returns a scalar f and the gradient vector gradf(x), the objective function evaluated at x.
In our problem (minimize compliance) the objective is given by
and the gradient is given by
Click here to learn more about problem statement, objective function and sensitivity analysis.
See Writing Objective Functions for details.
Step.3: Define Hessian
The Hessian of the Lagrangian is given by the equation:
In our problem the Hessian of the objective function can be expressed as:
since the constraint is linear constraint, the Hessian of the constraint
Details about the derivation of Hessian corresponding to the objective function is discussed in the paper.
myHessianFcn computes the Hessian at a point x with Lagrange multiplier structure lambda:
For details, see Hessian. For an example, see fmincon Interior-Point Algorithm with Analytic Hessian.
Step.4: Define Constraint
The function that computes the nonlinear inequality constraints and the nonlinear equality constraints . myConstrFcn accepts a vector x and returns the four vectors c, ceq, gradc, gradceq. c is a vector that contains the nonlinear inequalities evaluated at x, ceq is a vector that contains the nonlinear equalities evaluated at x, gradc, the gradient of c(x), and gradceq, the gradient of ceq(x).
In our problem, we only have one equality constraint, i.e., volume fraction constraint
Click here to learn more about problem statement and constraints.
For more information, see Nonlinear Constraints.
Step.5: Define Output Function
The myOutputFcn is a function that an optimization function calls at each iteration. The iteration information is displayed and the structural topology can be also displayed during the iteration process depends on users setting.
See Output Function.
Step.6: Call fmincon
Click here to learn more about Matlab fmincon or execute the following command line in the Matlab:
Step.7: Run the program
Now you can run the program, e.g., with the following Matlab command line:
If you have any questions, difficulties with this tutorial, please don’t hesitate to contact us.
-
MATLAB is a registered trademark of The MathWorks, Inc. For MATLAB product information, please contact The MathWorks, Inc., 3 Apple Hill Drive, Natick, MA 01760-2098, UNITED STATES, 508-647-7000, Fax: 508-647-7001, info@mathworks.com, www.mathworks.com. ↩