# Topology Optimization Based Material Design for 3D Domains Using MATLAB
## 4 The MATLAB Code Implementation
### Model Order Reduction: Code Implementation
Similar to the first test example from the results presented in Table 2, it can be seen that the POD and on-the-fly methodologies have achieved the same values of the objective function with a smaller number of full dimensionality finite element analyses during the optimization procedure (i.e., macro scale), whereas the case of a typical solution of the problem with no application of any MOR technique and the use of AR for the macro scale have achieved the same objective function. Regarding the MOR technique used by the homogenization function (i.e., micro scale), it was observed that, in general, out of the six finite element analyses required by every homogenization call, half of them were carried out by relying on a reduced dimensionality. The resulting topologies have small differences. Thus, the result obtained for the on-the-fly implementation is presented in Figure 3.

### MBB Beam Test Example

Similar to the first and second test example, the parameters used for the formulation of the MBB beam test example are as follows: a structured finite element mesh of \(120\times 20\times 20\) along the the abscissa, ordinate, and applicate directions was used for the discretization of the macro domain and a \(20\times 20\times 20\) structured grid along the three directions for the discretization of the micro domain. In addition, the target volume was set equal to 40% of the design domain (i.e., the micro one), the penalization factor was set equal to 3, and no filter radius was applied. Regarding the MOR models, the parameters remained similar to the two previous test examples i.e.,the size of the reduced basis was set to 5 for the macro domain and to 3 for the micro domain, while the tolerance was set equal to 0.01 for both scales. For the approximate reanalysis technique, the frequency of the reduced basis update was set to 5 for the macro domain and 3 for the homogenization, and the tolerance for the compliance change and density change was set to 30 and 1.50, respectively. For the application of the loading and boundary conditions, _Lines_ 10 to 17 of the UCOpt3D function are modified, as follows:
```
1%USER-DEFINEDLOADDOFs
13i1=nelx/2;j1=nely;kl=0:nelz/2;%Coordinates
14 loadind=kl*(nelx+1)*(nely+1)+i1*(nely+1)+(nely+1-j1);%NodeIDs
15 loaddof=3*loadind(:)-1;%DOFs
16%USER-DEFINEDSUPPORTFIXEDDOFs
17
18 if=[00 nelxnelx];jf=[00000];kf=[0 nelz0 nelz];%Coordinates
19 fixedndid=kf*(nely+1)*(nelx+1)+i1*(nely+1)+(nely+1-jf);%NodeIDs
20 fixeddof=[3*fixedndid(:);3*fixedndid(:)-1;3*fixedndid(:)-2];%DOFs  
Figure 3: Optimized periodic unit cell for the cantilever beam test example macro structure. The loading and boundary conditions of these third examples are similar to the second example with the load applied at the top of the domain. Similar to the remarks reported for the first two examples presented previously (see Table 3), the POD and on-the-fly approaches achieve the same compliance value (larger than the no MOR application) with a much smaller number of iterations. Regarding the MOR technique applied in the homogenization function from the six finite element analyses performed for each homogenization, half were computed in the reduced space. The final topologies are similar between all approaches and the topology of the POD approach is presented in Figure 4.