# Topology Optimization Based Material Design for 3D Domains Using MATLAB
## 4 The MATLAB Code Implementation
### Model Order Reduction: Code Implementation
From the results presented in Table 1 it can be seen that the POD and on-the-fly methodologies have achieved the same values of the objective function with a small 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. The value of the objective function in the first two approaches is larger than the other two, which is due the displacement field of the objective function being approximated as well. 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, and the result obtained for the POD implementation is presented in Figure 2. \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Approach** & **Total Optimization Loops** & **Full Optimization Loops** & **Compliance** \\ \hline FEA & 24 & 24 & 879.40 \\ POD & 21 & 11 & 918.18 \\ on-the-fly & 21 & 10 & 918.18 \\ AR & 24 & 13 & 879.40 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Bridge test example: Results of each MOR approach as well as the classic implementation

### 3D Wheel Test Example

Similar to the first test example, the parameters used for the formulation of the 3D wheel test example are as follows: a structured finite element mesh of \(80\times 40\times 80\) 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 was used for the discretization of the micro domain. In addition, the target volume was set equal to 30% of the design domain (i.e., the micro domain), the penalization factor was set equal to 3 and no filter application for the unit cell. Regarding the MOR models, for all three models 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. To apply the loading and boundary conditions for the 3D wheel, as described in [3], _Lines_ 10 to 17 are modified, as follows:
```
14%USER-DEFINEDLOADDOFs
15 il=nelx/2;jl=0;kl=0:nelz/2;%%Coordinates
16 loadnid=kl*(nelx+1)*(nely+1)+il*(nely+1)+(nely+1-jl);%NodeIDs
17 loaddof=3*loadnid(:)-1;%DOFs
18%USER-DEFINEDSUPPORT FIXEDDOFs
19 if=[00 nelxnelx];jf=[00000];kf=[0 nelz0 nelz];%Coordinates
20 fixednid=kf*(nely+1)*(nelx+1)+if*(nely+1)+(nely+1-jf);%NodeIDs
21 fixeddof=[3*fixednid(:);3*fixednid(:)-1;3*fixednid(:)-2];%DOFs
```
The results obtained from every MOR approach for the topology optimization and homogenization formulations are presented in Table 2. \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Approach** & **Total Optimization Loops** & **Full Optimization Loops** & **Compliance** \\ \hline FEA & 32 & 32 & 429,740 \\ POD & 26 & 24 & 500,120 \\ on-the-fly & 26 & 24 & 500,120 \\ AR & 32 & 10 & 429,740 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: 3D wheel: Results of each MOR approach as well as the classic implementation. Figure 2: Optimized periodic unit cell for the bridge test example macro structure.