Real-Time Structure Generation Based on Data-Driven Using Machine Learning

: Topology optimization results are highly dependent on the given design constraints and boundary conditions. Moreover, small changes in initial design conditions can result in different topological conﬁgurations, which makes topology optimization time-consuming in a given design constraint domain and inefﬁcient in structural design. To address this problem, a data-driven real-time topology optimization framework and method coupled with machine learning by using a principal component analysis algorithm combined with a feedforward neural network are developed in this paper. Meanwhile, through the ofﬂine training, the mapping relationship between initial design conditions and topology optimization results is obtained. From this mapping, we estimate the optimal topologies for novel loading conﬁgurations. Numerical examples display that the online prediction results are consistent with the results of the topology optimization method. Furthermore, the network parameters are calibrated, and accurate structure prediction is achieved based on the algorithm. In addition, this method ensures the accuracy of high-resolution structural prediction on the premise of small samples.


Introduction
With the increasing demand for structural functions, topology optimization has been introduced into various fields for structure design, such as aerospace, engineering applications, electronic devices, and biomedicine [1][2][3][4][5]. So far, topology optimization has been developed to be one of the most effective ways to acquire new structures satisfied various design requirements [6][7][8][9][10]. With the continuous improvement of the theoretical system of topology optimization, varieties of methods have been developed to achieve the optimization of structures. At present, the solid isotropic material with penalization (SIMP) method [11], level set method [12], and moving morphable components (MMC) method [13] are widely used and implemented in topology optimization. Additionally, the evolutionary structural optimization (ESO) method [14], genetic algorithm (GA) method [15], and phase field method [16] are also efficient methods for structure optimization. Multiple constraints such as stress constraints [17], multi-material constraints [18], and other constraints are habitually considered in topology optimization design. Moreover, for the structural design of additive manufacturing, the thickness constraint of the minimum printable thickness [19] and the printing angle are as well as considered during the molding process [20]. Therefore, topology optimization provides a reference for structural design, in which multiple constraints make the design results much closer to engineering practice. Compared to the traditional structure design, topology optimization under multiple constraints provides more ideas for structure design. However, the iterative process of optimizing calculation is extremely time-consuming unless the time of iteration is greatly reduced or replaced by another more efficient method.

Structural Optimization Theory and Data Sample
The purpose of topology optimization is to provide the best material distribution in the designated design area according to the given load and boundary conditions. In other words, a certain mechanical performance index of the optimized configuration can reach the maximum value. Messerschmitt-Blkow-Blohm (MBB) beam problem is used as an example of real-time topology optimization implementation in this study. In the MBB model, the length and width of the beam are represented by N x and N y , respectively. The design domain is discretized into N x × N y rectangular grids for finite element calculations, and the density ρ of each element controls the presence or absence of the material. F(x, y) describes the load at the x, y points in the Cartesian coordinate system as seen in Figure 1.
To reduce the amount of calculation, the beam is processed symmetrically and the DOF (degree of freedom) of x in the middle part is constrained. The goal of topological optimization is to seek the topological configuration of the MBB beam with maximum stiffness at a specific volume fraction. The objective function, C, represents the work performed by various configurations under load. The optimal solution is obtained by seeking the minimum value of the objective function. In the present research, the goal of topology optimization is maximum stiffness, and the objective function is equivalent to minimum compliance. The constraints can be described as volume constraints, equilibrium equations, and density constraints, so the problem description can be expressed as Equation (1): : where U and F are the displacements and global force, respectively. G is the global stiffness matrix. gj and uj are the stiffness matrix and displacement vector of the element. xj is the design variable. V and V0 are the design material volume and design area volume. The density interpolation function is chosen to give the modulus of the element as Equation (2): where E0 and Emin are the material modulus and minimum modulus, respectively. p is the penalty coefficient of the modulus, which is set to 3 here. A batch of random loads is used as input data for the topology optimization program, and a series of optimization results (1500) is obtained as a database. The input of the topology optimization program TOP88 is set to (100, 50, 0.25, 3, 1.5, 1, F(x,y)), which corresponds to (nelx, nely, volfrac, penalization coefficient, filter radius, filter function, load The goal of topological optimization is to seek the topological configuration of the MBB beam with maximum stiffness at a specific volume fraction. The objective function, C, represents the work performed by various configurations under load. The optimal solution is obtained by seeking the minimum value of the objective function. In the present research, the goal of topology optimization is maximum stiffness, and the objective function is equivalent to minimum compliance. The constraints can be described as volume constraints, equilibrium equations, and density constraints, so the problem description can be expressed as Equation (1): : where U and F are the displacements and global force, respectively. G is the global stiffness matrix. g j and u j are the stiffness matrix and displacement vector of the element. x j is the design variable. V and V 0 are the design material volume and design area volume. The density interpolation function is chosen to give the modulus of the element as Equation (2): where E 0 and E min are the material modulus and minimum modulus, respectively. p is the penalty coefficient of the modulus, which is set to 3 here. A batch of random loads is used as input data for the topology optimization program, and a series of optimization results (1500) is obtained as a database. The input of the topology optimization program TOP88 is set to (100, 50, 0.25, 3, 1.5, 1, F(x,y)), which corresponds to (nelx, nely, volfrac, penalization coefficient, filter radius, filter function, load coordinates). The topology optimization program in this paper is adapted from the program of the group of Andreassen et al. [29], and part of the optimization results are exhibited in Figure 2. The red arrow in Figure 2 represents load, and the value of C indicates compliance. coordinates). The topology optimization program in this paper is adapted from the program of the group of Andreassen et al. [29], and part of the optimization results are exhibited in Figure 2. The red arrow in Figure 2 represents load, and the value of C indicates compliance.

Deep Learning and Training
The MATLAB toolbox is used to build a neural network for predicting topology-optimized structural designs. The network is divided into two stages: the offline training stage and the online prediction stage. Before the offline training, the sample should be collected by the topology optimization program as the training set and contrast set. Then, the network is built by using a principal component analysis (PCA) algorithm combined with a feedforward neural network. Firstly, the training samples are reduced to the feature image by the PCA algorithm. Secondly, the load-weight relationship is established by the feedforward neural network. Finally, the relationship between the load and the optimization result is obtained. Based on the above stages, new load information is selected and input into the neural network to return a new weight W by online prediction, and real-time topology optimization is realized.

Data Reduction
The PCA algorithm is a dimensionality reduction method for preprocessing highdimensional feature data, which improves the data processing speed by removing noise [30]. The optimization results need to be reduced to gain a certain number of feature images via the PCA algorithm before training. The PCA algorithm flow is shown in Figure  3. If the design domain size is Nx × Ny matrix, the single optimization result is represented by a matrix of rows. Then, the result of optimization O is a K × L matrix, and the centralized image of the result can be expressed as

Deep Learning and Training
The MATLAB toolbox is used to build a neural network for predicting topologyoptimized structural designs. The network is divided into two stages: the offline training stage and the online prediction stage. Before the offline training, the sample should be collected by the topology optimization program as the training set and contrast set. Then, the network is built by using a principal component analysis (PCA) algorithm combined with a feedforward neural network. Firstly, the training samples are reduced to the feature image by the PCA algorithm. Secondly, the load-weight relationship is established by the feedforward neural network. Finally, the relationship between the load and the optimization result is obtained. Based on the above stages, new load information is selected and input into the neural network to return a new weight W by online prediction, and real-time topology optimization is realized.

Data Reduction
The PCA algorithm is a dimensionality reduction method for preprocessing highdimensional feature data, which improves the data processing speed by removing noise [30]. The optimization results need to be reduced to gain a certain number of feature images via the PCA algorithm before training. The PCA algorithm flow is shown in Figure 3. If the design domain size is N x × N y matrix, the single optimization result is represented by a matrix of rows. Then, the result of optimization O is a K × L matrix, and the centralized image of the result can be expressed as where O is the mean value of the optimization result. In order to reduce the dimension of data, the covariance matrix C = YY T is constructed. The C is a K-order square matrix with K eigenvectors, and the eigenvectors with smaller eigenvalues are unimportant features. According to the size of eigenvalues, the first M-order eigenvectors are selected as the new covariance matrices J, which is the result of PCA dimensionality reduction (M << K).

Deep Learning and Training
The MATLAB toolbox is used to build a neural network for predicting topology-optimized structural designs. The network is divided into two stages: the offline training stage and the online prediction stage. Before the offline training, the sample should be collected by the topology optimization program as the training set and contrast set. Then the network is built by using a principal component analysis (PCA) algorithm combined with a feedforward neural network. Firstly, the training samples are reduced to the feature image by the PCA algorithm. Secondly, the load-weight relationship is established by the feedforward neural network. Finally, the relationship between the load and the optimization result is obtained. Based on the above stages, new load information is selected and input into the neural network to return a new weight W by online prediction and real-time topology optimization is realized.

Data Reduction
The PCA algorithm is a dimensionality reduction method for preprocessing highdimensional feature data, which improves the data processing speed by removing noise [30]. The optimization results need to be reduced to gain a certain number of feature images via the PCA algorithm before training. The PCA algorithm flow is shown in Figure  3. If the design domain size is Nx × Ny matrix, the single optimization result is represented by a matrix of rows. Then, the result of optimization O is a K × L matrix, and the centralized image of the result can be expressed as where W is the mapping weight. The original K optimization results are integrated into M eigen-images by the PCA method for data dimensionality reduction. The weight W corresponding to the new design condition is the key to realizing real-time topology optimization. Subsequently, establishing the mapping relationship between load F and weight W is necessary.

Feedforward Neural Network
It is well known that a feedforward neural network is the most widely used neural network, which can realize the functions of classification, regression, and clustering. The regression function can be used to express the mapping relationship between load and eigen-image. Generally, the network can be divided into the input layer, the hidden layer, and the output layer. A four-layer feedforward neural network is shown in Figure 4. The information obtained from the input layer is transmitted to the hidden layer for training, and then the trained information goes into the output layer and returns the output value. This process of offline training is to train a feedforward neural network and establish the nonlinear mapping relationship between load F i and weight W i . The load information F i is an input and the weight W is set as a label. Trainlm is selected as the training function, the learning function is learngdm, and the mean square error is used to calculate the error of samples. The trained network can realize online prediction, and real-time topology optimization can be achieved by combining the PCA algorithm.
× M. It indicates that the optimization results can be linearly combined by these eigen images. An equation of a linear mapping relationship between optimization results and eigen-images KL O  established as Equation (3): where W is the mapping weight.
The original K optimization results are integrated into M eigen-images by the PCA method for data dimensionality reduction. The weight W corresponding to the new de sign condition is the key to realizing real-time topology optimization. Subsequently, es tablishing the mapping relationship between load F and weight W is necessary.

Feedforward Neural Network
It is well known that a feedforward neural network is the most widely used neura network, which can realize the functions of classification, regression, and clustering. Th regression function can be used to express the mapping relationship between load and eigen-image. Generally, the network can be divided into the input layer, the hidden layer and the output layer. A four-layer feedforward neural network is shown in Figure 4. Th information obtained from the input layer is transmitted to the hidden layer for training and then the trained information goes into the output layer and returns the output value This process of offline training is to train a feedforward neural network and establish th nonlinear mapping relationship between load Fi and weight Wi. The load information F is an input and the weight W is set as a label. Trainlm is selected as the training function the learning function is learngdm, and the mean square error is used to calculate the erro of samples. The trained network can realize online prediction, and real-time topology op timization can be achieved by combining the PCA algorithm.

The Implementation of Real-Time Topology Optimization Algorithm
The real-time topology optimization is generally divided into four stages, as shown in Figure 5. The first stage is sample collection, in which the training set and contrast se are obtained through the topology optimization program. The second stage is the dat dimension reduction stage. In this stage, the training set is transformed into a featured image by the PCA algorithm, and the linear mapping relationship is established to obtain the weight W. The third stage is the offline training stage, in which the load information corresponding to the training set is input and labeled as weight W to train the neural net work. The fourth stage is the final online prediction stage. New load information is se lected and input into the neural network to return the new weight W, and new optimiza tion results are obtained by combining the eigen-images. The online prediction phase i completed instantaneously, which represents the realization of real-time topology optimi zation.

The Implementation of Real-Time Topology Optimization Algorithm
The real-time topology optimization is generally divided into four stages, as shown in Figure 5. The first stage is sample collection, in which the training set and contrast set are obtained through the topology optimization program. The second stage is the data dimension reduction stage. In this stage, the training set is transformed into a featured image by the PCA algorithm, and the linear mapping relationship is established to obtain the weight W. The third stage is the offline training stage, in which the load information corresponding to the training set is input and labeled as weight W to train the neural network. The fourth stage is the final online prediction stage. New load information is selected and input into the neural network to return the new weight W, and new optimization results are obtained by combining the eigen-images. The online prediction phase is completed instantaneously, which represents the realization of real-time topology optimization. Processes 2023, 11, x FOR PEER REVIEW 7 of 18

Discussion on Network Parameters
The training effect involves many parameters, such as the number of samples D, the size of design domain L, the number of feature images M, the number of layers H of the neural network, and the amount of neurons N. In order to determine the optimal value of the parameters, the control variable method is used to analyze the influence of the parameters. The TRAINLM function is selected as the training function, the LEARNGDM function as the adaptation learning function and the TANSIG function is selected as the regularization function. Meanwhile, the function of subsequent network training settings remains the same. The prediction accuracy is expressed by the mean square error (MSE) as Equation (4): where D is the number of samples, and the d y is the density value of the predicted structure. It is very important to determine the influence of eigen-images M on network training. Considering the computational efficiency, 500 samples are used to train the network. The layer of networks is set to 2, the neurons are set to 100, and the eigen-images M is taken from 10 to 200. One of the optimization results is selected to compare with the predicted results as shown in Figure 6.

Discussion on Network Parameters
The training effect involves many parameters, such as the number of samples D, the size of design domain L, the number of feature images M, the number of layers H of the neural network, and the amount of neurons N. In order to determine the optimal value of the parameters, the control variable method is used to analyze the influence of the parameters. The TRAINLM function is selected as the training function, the LEARNGDM function as the adaptation learning function and the TANSIG function is selected as the regularization function. Meanwhile, the function of subsequent network training settings remains the same. The prediction accuracy is expressed by the mean square error (MSE) as Equation (4): where D is the number of samples, and the y d is the density value of the predicted structure. It is very important to determine the influence of eigen-images M on network training. Considering the computational efficiency, 500 samples are used to train the network. The layer of networks is set to 2, the neurons are set to 100, and the eigen-images M is taken from 10 to 200. One of the optimization results is selected to compare with the predicted results as shown in Figure 6.
The number of neurons N is one of the parameters of neural network. It is necessary to analyze the influence of the number of neurons on network training. Considering the computational efficiency, 200 samples are used to train the network. The layers of network are set to 2, the eigen-images are set to 20, and the numbers of neurons are taken from 10 to 150 to produce 15 sets of samples for training. The prediction images are shown in Figure 7. Figure 8 displays the error analysis in view of the M and the N. When M is in the range of 15-25% of the sample size, the error is stable at the range of 2.65-2.7%, and the minimum error is 2.663% when M is 22% of the sample size D. The same trend is also reflected in the prediction image. When M is 110, the best prediction effect is obtained. When M is greater than 130, the image begins to appear over-fitting. This is because the excessive value of M leads to unnecessary features and too small a value of M leads to the phenomenon of under-fitting as well. The error analysis indicates that when N is in the range of 15-30% of the sample size, the error is stable at 3.6-3.8%, and the minimum error is 3.658% when M is 20% of the sample size. This is also reflected in the prediction image. When N is 40, the best prediction effect is obtained. When N is greater than 100, the image begins to appear over-fitting. This is also because the excessive value of N leads to unnecessary features, and too small a value of N leads to the phenomenon of under-fitting. It is obvious that the training effect is optimal when N ≈ M. According to the results obtained by analyzing the errors of the control variables, when the values of the M and the N are both at 20% of the training samples, the minimum prediction error is obtained. It is not difficult to understand from the principle of neural networks, each neuron corresponds to an intrinsic image. In this way, when the weights are mapped as labels, a better training effect can be achieved.  As for depth H of the network, the most basic structure is the two-layer structure with one hidden layer and one output layer. When the number of hidden layers is over two, it is called a deep neural network. In order to determine the influence of H, 200 samples are used to train the network. The number of neurons N is set to 20, the number of eigenimages M is set to 20, and the number of hidden layers is taken from 2 to 8 to produce 7 sets of samples for training. The prediction images and the errors are shown in Figures 9 and 10, separately. The error analysis indicates that when the value of H goes into 2-5, the error is less than 3.8%. When H is greater than 5, the image begins to appear over-fitting. The error of the three-layer network and four-layer network is 3.742% and 3.764%, respectively. Considering the computational cost, the number of hidden layers is set to 2.  Figure 8 displays the error analysis in view of the M and the N. When M is in the range of 15-25% of the sample size, the error is stable at the range of 2.65-2.7%, and the minimum error is 2.663% when M is 22% of the sample size D. The same trend is also reflected in the prediction image. When M is 110, the best prediction effect is obtained. When M is greater than 130, the image begins to appear over-fitting. This is because the excessive value of M leads to unnecessary features and too small a value of M leads to the phenomenon of under-fitting as well. The error analysis indicates that when N is in the range of 15-30% of the sample size, the error is stable at 3.6-3.8%, and the minimum error is 3.658% when M is 20% of the sample size. This is also reflected in the prediction image. When N is 40, the best prediction effect is obtained. When N is greater than 100, the image begins to appear over-fitting. This is also because the excessive value of N leads to unnecessary features, and too small a value of N leads to the phenomenon of under-fitting. It is obvious that the training effect is optimal when N ≈ M. According to the results obtained by analyzing the errors of the control variables, when the values of the M and the N are both at 20% of the training samples, the minimum prediction error is obtained. It is not difficult to understand from the principle of neural networks, each neuron corresponds to an intrinsic image. In this way, when the weights are mapped as labels, a better training effect can be achieved. As for depth H of the network, the most basic structure is the two-layer structure with one hidden layer and one output layer. When the number of hidden layers is over two, it is called a deep neural network. In order to determine the influence of H, 200 samples are used to train the network. The number of neurons N is set to 20, the number of eigen-images M is set to 20, and the number of hidden layers is taken from 2 to 8 to produce 7 sets of samples for training. The prediction images and the errors are shown in Figures 9 and 10, separately. The error analysis indicates that when the value of H goes into 2-5, the error is less than 3.8%. When H is greater than 5, the image begins to appear over-fitting. The error of the three-layer network and four-layer network is 3.742% and 3.764%, respectively. Considering the computational cost, the number of hidden layers is set to 2. As for depth H of the network, the most basic structure is the two-layer structure with one hidden layer and one output layer. When the number of hidden layers is over two, it is called a deep neural network. In order to determine the influence of H, 200 samples are used to train the network. The number of neurons N is set to 20, the number of eigen-images M is set to 20, and the number of hidden layers is taken from 2 to 8 to produce 7 sets of samples for training. The prediction images and the errors are shown in Figures 9 and 10, separately. The error analysis indicates that when the value of H goes into 2-5, the error is less than 3.8%. When H is greater than 5, the image begins to appear over-fitting. The error of the three-layer network and four-layer network is 3.742% and 3.764%, respectively. Considering the computational cost, the number of hidden layers is set to 2.  In order to analyze the influence of the number of samples D, the layer of the network is set to 2, the eigen-images M are set to 20 and the number of neurons N is set to 20. The number of samples is taken from 100 to 1400. The prediction images are shown in Figure  11. It indicates that when the number of samples exceeds 500, the detail loss and prediction errors begin to appear on the prediction images, which is not consistent with common sense. This is because the values of N and M do not change with the number of samples, which leads to the inadequacy of network fitting ability. When the number of samples ranges from 100 to 400, the proportion of M is in 5-20%, which further validates the previous conclusion of the M value. In order to analyze the influence of the number of samples D, the layer of the network is set to 2, the eigen-images M are set to 20 and the number of neurons N is set to 20. The number of samples is taken from 100 to 1400. The prediction images are shown in Figure 11. It indicates that when the number of samples exceeds 500, the detail loss and prediction errors begin to appear on the prediction images, which is not consistent with common sense. This is because the values of N and M do not change with the number of samples, which leads to the inadequacy of network fitting ability. When the number of samples ranges from 100 to 400, the proportion of M is in 5-20%, which further validates the previous conclusion of the M value.

Realization of Real-Time Topology Optimization
An efficient real-time topology optimization network is established through parameter impact analysis, which gives an accurate calibration of the network parameters. Based on the research, the prediction effect of real-time topology optimization is first determined by the sample size, and a sufficient number of samples can compensate for the problem Figure 11. Initial prediction result of training 4 with different D.

Realization of Real-Time Topology Optimization
An efficient real-time topology optimization network is established through parameter impact analysis, which gives an accurate calibration of the network parameters. Based on the research, the prediction effect of real-time topology optimization is first determined by the sample size, and a sufficient number of samples can compensate for the problem of insufficient network fitting ability to some extent. When the number of neurons is about 20% of the sample size, the network fitting ability is the strongest. Under the premise of comprehensively considering the calculation and calculation consumption, a proper increase in the number of layers of the neural network can obtain a better prediction effect.
After the parameter calibration, the value or value range of the network parameters are determined. The number of neurons in the input layer is equal to the first dimension K of the weight w, and the number of neurons in each hidden layer is coincident with the input layer. The number of neurons in the output layer is concurrent with the dimension of the label (load), which is set constant to 2. The number of hidden layers is set to 2. As shown in Table 1, the value of eigen-images M and the number of neurons N are adjusted according to the value of sample size D. The prediction images are shown in Figure 12, and the errors are shown in Figure 13, respectively. As can be seen from the two figures, in the beginning, the prediction effect is very poor due to the lack of sample sizes. As the number of samples increases, the accuracy of image prediction increases synchronously. When the D reaches 500, the results are predicted as acceptably accurate. When D is 500,600,700, the network training time is 121.43 S, 178.54 S, and 252.76 S, respectively. The new load conditions are printed into the network, and the online prediction time is only 10-2 S, which is realized in real-time topology optimization. The prediction accuracy can be improved by segmenting and filtering the results of the preliminary prediction.

Results and Discussion
A topology optimization model based on artificial neural network learning is proposed. Through the PCA algorithm, the training data are screened in advance to eliminate interference or redundant data and the data dimension is reduced. Then, through the comparative analysis of different training network parameters, the best training framework is found, so that it can obtain more accurate prediction results with less sample data.
Compared with the work of Ulu et al. [25], our algorithm particularly studies the influence of dimensionality reduction parameters and neural network parameters on the prediction results. Selecting appropriate parameters can significantly reduce the offline training data samples required for network training, and the prediction structure is more accurate.
Compared with the convolutional decoding and coding network adopted by Yu et al. [27], our network adopts the architecture of data dimensionality reduction and a full connection network. Before network training, we preprocess the samples by means of data dimensionality reduction to remove redundant information. Therefore, compared with Yu et al. [27] using 10,000 training samples to achieve accurate prediction of the structure, our algorithm can achieve the same effect with only 700 samples, that is, our algorithm has less sample dependency and stronger learning ability.

Conclusions
This study proposes a data-driven real-time topology optimization method that combines data dimensionality reduction with machine learning to achieve a design structure at the instant of a given design condition. The impact of the network parameters on the prediction accuracy is discussed and then the optimal parameter configuration scheme is obtained. It indicates the network prediction effect is the best when the number of hidden layers H is two and the number of neurons N is at 20% of the number of samples. In addition, when the number of samples K is greater than 500 as a threshold, the network error converges, and it decreases with the increasing number of samples.
The predicted image obtained by this method has higher resolution and more computational efficiency, and the demand sample is less. However, this method has certain limitations. Although the generation of the load is random, the boundary conditions in the example are fixed. This limitation can be solved by a combination of boundary conditions and loads. This study demonstrates the advantages of combining machine learning with topology optimization and broad development prospects, providing more efficient and accurate optimization methods and tools for structural design.