# A 99 line code for discretized Michell truss optimization written in Mathematica

- First Online:

- Received:
- Revised:
- Accepted:

DOI: 10.1007/s00158-010-0557-z

- Cite this article as:
- Sokół, T. Struct Multidisc Optim (2011) 43: 181. doi:10.1007/s00158-010-0557-z

- 32 Citations
- 2.3k Views

## Abstract

The main purpose of the paper is to provide an easy-to-use code for topological optimization of the least weight trusses, written in the Mathematica programming language. The main idea of the presented approach consists in using a fixed ground structure and the linear programming formulation of the optimization problem. The solver is based on the fast interior point method. The strong effort is done to create the effective generator of the computational model utilizing the high regularity of the ground structure and the high sparsity of the geometric matrix. The efficiency and reliability of the algorithm is confirmed in several numerical tests. Due to a linear programming formulation of the optimization problem the method presented in the paper assures finding the global optimum, hence it may be considered as the useful tool for verification of results obtained in other ways. The appended complete Mathematica code of the program developed will be supplied by the Publisher on SpringerLink.

### Keywords

Topology optimization of trussesGround structureLinear programmingInterior point methodSparse matrix representation## 1 Introduction

The optimum design problem: find the lightest, plane, pin-jointed frame of a bounded compliance, transmitting a given loading to a part of the boundary of the given feasible domain—turns out to be equivalent to the problem of finding the lightest pin-jointed frame of a bounded stress level, with equal stress limits in tension and compression, transmitting the loading to the prescribed boundary of the feasible domain, see Hemp (1973) and Achtziger (1997). The analytical solutions to this problem must satisfy the conditions of the theory of Michell trusses; see Hemp (1973) and Rozvany et al. (1995). These solutions exceed the class of trusses: they are discrete-continuous structures composed of the fibrous domains of orthogonal microstructure reinforced by bars of finite cross sections. These solutions can be approximated from within the subclass of trusses (i.e. pin-jointed frames of finite number of bars) or from within the continuum description thus giving up prediction of the reinforcing bars and excluding possibility of considering the point loads. Having at our disposal these two approximate methods to attack the initial problem it is thought appropriate yet to choose the discrete approximation—as free of the two drawbacks mentioned. The natural incorporation of the point loads seems here crucial; note that almost all available Michell solutions concern this class of loadings.

Note, however, that the sole knowledge of the Michell’s theory does not deliver hints of how the optimal layout looks like. Only having an impression of the correct layout one can construct the Hencky net and then endow it with appropriate mechanical properties. The complete solutions are rare. It is sufficient to stress here that the static part of the theory of Michell’s cantilever supported on a circle has only been put forward in the relatively new paper by Graczykowski and Lewiński (2005), where a proof of vanishing the duality gap between kinematic and static formulations of this problem has been published. Note also, that due to hyperbolicity of the governing equations of Michell’s trusses the layouts are usually composed of many subdomains with border lines being the lines of discontinuity of some stress components; see e.g. Fig. 3 in Graczykowski and Lewiński (2007).

Having in view the above mentioned properties of Michell trusses it is not easy to predict a new solution correctly: many layouts can be imagined as correct for the same load and the same feasible domain geometry. It is really not clear which of them should be discussed and which of them should be rejected a priori. The new layouts are not the simple composition of the known layouts. Some suggestions are very convincing, but may be misleading. Thus a theoretician needs an unbiased hint from the purely numerical side.

The really valuable numerical predictions of Michell-like structures do not draw upon the properties of the known analytical solutions. The genuine method of their construction was developed in Dorn et al. (1964); it is based on the concept of the ground structure composed of all bars connecting given regular set of nodes. Most of these bars are not necessary to equilibrate the applied loading and, consequently, disappear during the optimization process. This prediction, however, cannot be done in advance. The cross section areas are the main but not the only design variables. The crucial point of this approach is that the cross section areas may assume nonnegative values. Thus the zero values are admissible, which paves the way to find the catenary structures, capable of carrying only one set of loads. Let us remind here the funicular structures transmitting systems of parallel forces to fixed supports. Such a specific class of structures should be encompassed by the numerical methods. The ground structure methods satisfy this condition, provided that the global stiffness matrix is not required to be invertible.

The present paper is close in spirit to the paper by Gilbert and Tyas (2003), where the initial optimization problem has been rearranged to the so called plastic design formulation assuming the form of the linear programming problem. Gilbert and Tyas (2003) solved this problem with using the interior point method. They significantly improved the traditional ground structure approach by the iterative member adding technique.

The same numerical problem is solved in the present paper by other implementation of the interior point method, announced in Sokół and Lewiński (2009). The code has been written in Mathematica 7 symbolic language, seek Wolfram (2003). The method as such would be useless, without taking advantage of the geometric matrix being sparse. The details of the program are explained in Section 3, while the whole 99-line optimization code has been appended to the paper. This reference to the title of the popular paper by Sigmund (2001) has been suggested by anonymous Reviewer. The code listed here can be freely downloaded from the internet web page connected with this paper, see Online Resource 1.

The software developed applies to the case of plastic design with: (a) equal permissible stresses in tension and compression: *σ*_{T} = *σ*_{C}, (b) unequal stress bounds for tension and compression: \(\sigma_{T} \ne \sigma_{C}\). This numerical tool makes it possible to construct new optimal layouts for which the analytical solutions are unknown, and to check already published analytical solutions. In particular, the present paper confirms that the analytical results published in Lewiński et al. (1994a, b) for the case of *σ*_{T} = *σ*_{C} and in Graczykowski and Lewiński (2007) for the case of unequal stress limits—are correct. In particular, this software has delivered a numerical confirmation of the huge family of benchmarks being published in Graczykowski and Lewiński (2010).

The software developed has also made it possible to predict a correct layout of the unsolved till now problem of two symmetric parallel forces to be optimally transmitted to fixed nodes, in the case of the feasible domain being the half-plane. This numerical prediction has paved the way to find the analytical solution. The optimal layout turns out to compare favourably with the numerical results for the ground structures of high density; the reader is referred to Sokół and Lewiński (submitted) for the details.

Concluding, the software developed delivers numerical predictions of the characteristics of the optimal layouts with the volume predictions approaching the optimal volume with arbitrary accuracy. Since the analytical predictions are usually found by the kinematic method, while the numerical predictions follow from static consideration, this consistency of both the results—showing that the duality gap is slowly vanishing with increase of the density of the ground structure - simultaneously confirms correctness of the analytical results.

## 2 Minimum volume truss optimization problem

**P**and

**q**are the vectors of nodal loads and displacements.

**K**is the stiffness matrix and

*W*

_{0}is a given positive constant. The last inequality is understood component-wise i.e.

*A*

_{i}≥ 0. The cross section areas

*A*

_{i}are the main design variables. If the ground structure is viewed as fixed, the vector

**L**of bar lengths is prescribed. Note that the equilibrium equations are treated as equality constraints. The displacements

*q*

_{j}are state variables, independent of

*A*

_{i}. Thus the number of unknown variables is

*N*+

*M*. Finding numerical solution to problem (1) requires expensive methods of the nonlinear programming. Therefore, it is rather not applicable for large tasks corresponding to the ground structures of high density, with big

*N*and

*M*numbers.

**T**and

**C**are the vectors of tension and compression forces in bars and

**B**is the geometric matrix of components representing directional cosines of bars. The latter problem, being still equivalent to the problem (1), involves 2

*M*design variables but now it becomes a linear programming problem that can be solved by well-developed numerical tools, applicable for large number of unknowns. Thus the ground structures of high density may be successfully analyzed.

**B**

^{T}by the length of the corresponding bar, but

**H**may also be derived directly by computing the quotients \(\Delta x_i /L_i^2\) and \(\Delta y_i /L_i^2\). Note that for integer increments Δ

*x*

_{i}and Δ

*y*

_{i}the components of matrix

**H**are rational numbers and may be preserved in exact form (using appropriate software). For currently available optimization method it is not any advantage, but it may be important for future numerical treatments. To conclude, the truss topology optimization problem may be written in the standard form of linear programming as follows

**e**is a vector of length 2

*M*, whose entries are all equal to 1).

*P*is a referential load intensity and

*h*is an arbitrary chosen size of a structure (height, length, width, etc.). The optimal volume subject to constrained compliance may be written as

These formulas are important for proper interpretation and comparison of different results presented in the literature, see Gilbert and Tyas (2003) and Achtziger (2007). Further, we shall write \(\overline V _\sigma =\overline V\).

*T*

_{i}

*L*

_{i}/

*σ*

_{T}and the volumes of the bars under compression are equal to

*C*

_{i}

*L*

_{i}/

*σ*

_{C}. Thus we can formulate the following optimization problem

*κ*=

*σ*

_{T}/

*σ*

_{C}. Passing from (2) to (13) requires only a “cosmetic” change in the objective function. Note, however, that the latter problem is not equivalent to the problems previously discussed in this paper, see Rozvany (1996).

## 3 Details of numerical implementation

The choice of the adequate optimization method directly depends on the type of the problem to be solved. In the case of optimization problem (1) the general or specialized methods of nonlinear programming have to be applied. Usually they are expensive and limited to relatively small tasks. Contrary, the problems (2), (5) and (13) may be solved using linear programming methods. The most popular, the *simplex* or *revised simplex* methods are possible but not adequate for large-scale problems. In practice, such tasks with thousands of unknowns are almost intractable using these methods due to the exponentially growing time of computation regarding to the problem size. However, the newer and much more effective linear programming methods are becoming available. For today, the *interior point method* is one of the most reasonable choices. This method was developed by Karmarkar (1984) and later improved by Mehrotra (1992), Wright (1997) and Nocedal and Wright (1999). The method has even been successfully generalized to a class of nonlinear convex optimization problems. The basic idea of the method consists of a barrier function used to encode the convex set of constraints. Contrary to the simplex method which goes along the boundary, it moves through the interior of the feasible region and reaches the optimal solution asymptotically. Two most popular versions of this method: the primal affine scaling method and the primal–dual interior point method are presented in detail in the book by Bhatti (2000). The second version requires more memory but is significantly faster.

The next, very important topic in developing the whole algorithm is the generator of the computational model. It should be noted that the fixed ground structure has to be dense but at the same time very regular. It is composed of groups of identical elements (neglecting unessential translations in XY plane or XYZ space). The stiffness matrices as well as directional cosines are equal in these groups and may be calculated only once for a given group of bars. For a dense ground structure, thousands of bars in one group may exist so the final profit of the single calculation is significant. Moreover, due to high regularity of the mesh there is no need of creating nodes and elements like in a typical FEM program—they are optionally needed only for graphical presentations. In the program presented in this paper the patterns of elements are introduced to preserve the memory. The pattern includes the necessary and condensed data for the whole family of bars; they are: nodal increments, indices for loops, lengths and directional cosines of bars (see Appendix 1). To solve the optimization problem (2) all what is needed is creating the vectors **L**, **P** and the geometric matrix **B**. The last one requires, however, the further attention. It is clear that this matrix is very sparse. Independently of the problem size every row of it contains only four nonzero elements (or six for space trusses). This sparsity must be utilized to make the algorithm efficient. First of all, the sparse matrix representation allows to preserve a huge amount of memory and to deal with large-scale problems, that otherwise would be intractable. Additionally, the great benefit of the computation time may be achieved by avoiding unnecessary algebraic operations, especially multiplication by zero. Obviously it requires applying some specialized procedures (libraries) for sparse matrices, but in the present day they are commonly available. Concluding, the sparse matrix representation is essential for the overall efficiency of the algorithm, especially for large-scale problems. The larger problem size is—the greater benefit of memory and processor time may be achieved.

*N*

_{X},

*N*

_{Y},

*D*

_{X},

*D*

_{Y}. The first two denote the numbers of divisions of the rectangle in X and Y directions, and correspond to the “external” density. (Every node in the mesh is uniquely identified by a pair of integers, numbered from 0 to

*N*

_{X}and from 0 to

*N*

_{Y}for X and Y directions, respectively.) The next two numbers

*D*

_{X}and

*D*

_{Y}describe the “internal” density—it is a depth (in the Manhattan distance manner) of possible connections between nodes. In general these numbers may also be defined separately for X and Y directions. Nevertheless, if possible, they should be equal. It results from the fact that the ground structure should form the mesh of mutually orthogonal families of bars. Therefore, it is also strongly recommended that the basic cell of the mesh is square, rather than rectangular.

*SparseArray*[...] and

*LinearProgramming*[...,

*Method*→ “

*InteriorPoint*”] for details). Description of the internal implementation of the interior point method applied in Mathematica is included e.g. in Champion and Strzebonski (2008). The program has been divided into separate procedures (modules) that have thoroughly been tested and optimized for speed and memory usage. For example, to create a dynamic list, the natural but relatively slow functions

*Append*or

*AppendTo*are replaced by more efficient pair of functions

*Reap-Sow*. Many of auxiliary arrays were packed by

*ToPackedArray*function to preserve the memory. Thanks to a compact coding in Mathematica the program is short. Its listing is included in Appendix 1. The program is adjustable and offers the full control of the size and density of the ground structure as well as any loading and supports. The typical call to the program and its output are shown in Fig. 2. The block of input data is simple and takes only first four lines. The example of the data input presented below corresponds to a well known Michell cantilever; cf. Fig. 2.

For today only plane trusses were implemented and tested in the program. Theoretically the similar algorithm would be used for space trusses but the problem size increases dramatically, thus the smarter strategies are required in this case. It will be the topic of the further research and the next versions of the presented program.

## 4 Examples

The program described in the previous section has been thoroughly examined in many numerical tests. A few of them are presented bellow.

*Ph*/

*σ*

_{0}. It may be observed that middle supports as well as material in some regions are not necessary and disappear in the optimal structure. It is worth to note that the analytical solution is hard to obtain (it requires the advanced mathematical tools for solving hyperbolic differential equations and is based on Bessel and Lommel special functions). Contrary, the numerical solution may easily be obtained using the algorithm presented in this paper.

*Ph*/

*σ*

_{0}; this result is over 10% worse than exact one. The improvement of the solution may be achieved only after including bars with new directions; compare the results in Figs. 6–10. The influence of the internal density is evident. For the densest mesh 120 × 40 with internal density 20 × 20 (see Fig. 12), the result is very close to the exact solution; the relative error of the volume is equal to 0.11%. Topology and shape of the final truss correspond also very well to the exact layout shown in Fig. 3b.

*ByteCount*[],

*Timing*[], etc. The results are collected in Table 1. The first column describes the applied mesh density. The next two columns include the total numbers of nodes and elements. The RAM capacities needed for storing the matrix

**H**defined in (4) are given in two next columns, respectively for sparse and full matrix representations. The next (sixth) column includes the processor time used to solve the optimization problem. The next column presents the normalized, non-dimensional stress volume defined by (10) and the last column includes the relative error corresponding to the exact solution given by Lewiński et al. (1994a). Note that the speed and the numerical stability of the program are very good. The sparse matrix representation allows preserving a lot of memory. For example, in the last densest mesh almost 3.5 millions of design variables were used (two times the number of bars). This task requires more than 250 GB RAM just for storing matrix

**H**in full form and only 159 MB of RAM using sparse matrix representation. The profit is evident. The calculations were performed on Intel Core 2 Duo E8400/3 GHz based PC with 4 GB of RAM. This fact clearly demonstrates the power and efficiency of the presented approach. The last problem took only about 13 min, which is an excellent result for so large-scale problem.

Results of the first example regarding to efficiency

Mesh density | No. nodes | No. bars | RAM for | CPU time [s] | Volume \(\overline{V}_\sigma\) | Relative error [%] | |
---|---|---|---|---|---|---|---|

Sparse | Full | ||||||

60 × 20:1 × 1 | 1,281 | 4,880 | 0.34 | 188 | 0.3 | 15.0000 | 10.32 |

60 × 20:2 × 2 | 1,281 | 9,520 | 0.76 | 366 | 1.0 | 13.8671 | 1.98 |

60 × 20:3 × 3 | 1,281 | 18,328 | 1.56 | 705 | 1.8 | 13.6953 | 0.72 |

60 × 20:4 × 4 | 1,281 | 26,672 | 2.32 | 1,026 | 3.2 | 13.6580 | 0.45 |

60 × 20:5 × 5 | 1,281 | 42,448 | 3.75 | 1,632 | 5.4 | 13.6439 | 0.34 |

60 × 20:10 × 10 | 1,281 | 113,912 | 10.23 | 4,380 | 10.7 | 13.6350 | 0.28 |

60 × 20:20 × 20 | 1,281 | 280,136 | 25.29 | 10,772 | 43.3 | 13.6343 | 0.27 |

120 × 40:10 × 10 | 4,961 | 532,872 | 48.17 | 80,009 | 147.0 | 13.6126 | 0.11 |

120 × 40:20 × 20 | 4,961 | 1,745,496 | 158.68 | 262,080 | 768.0 | 13.6120 | 0.11 |

Results of the second example regarding to efficiency

Mesh density | No. nodes | No. bars | RAM for | CPU time [s] | Volume \(\overline{V}_\sigma\) | Relative error [%] | |
---|---|---|---|---|---|---|---|

Sparse | Full | ||||||

20 × 10:5 × 5 | 231 | 5,998 | 0.5 | 41 | 0.2 | 3.83790 | 1.78 |

40 × 20:10 × 10 | 861 | 73,172 | 6.6 | 1,900 | 5.0 | 3.80594 | 0.93 |

40 × 20:20 × 20 | 861 | 169,796 | 15 | 4,400 | 21.3 | 3.80593 | 0.93 |

80 × 40:20 × 20 | 3,321 | 1,115,216 | 102 | 112,000 | 290.0 | 3.78171 | 0.29 |

80 × 49:20 × 20 | 4,050 | 1,441,349 | 131 | 177,002 | 599.7 | 3.77643 | 0.15 |

100 × 61:20 × 20 | 6,262 | 2,406,373 | 219 | 457,510 | 1,312.4 | 3.77509 | 0.11 |

All trusses shown in Fig. 14 are structurally unstable. The same property characterizes the Michell continuum in Fig. 15. Despite this instability the solutions are correct, because the virtual work of the forces *P* on the zero-energy modes vanishes. This is discussed in detail in Sokół and Lewiński (submitted). The great advantage of the numerical method proposed is that it does not exclude such unstable structures from the algorithm. This complies with the Michell remark no III, p. 591 in Michell (1904). It should also be noted that due to direct solving of the linear programming problem (2) the method terminates with a guaranteed correct result.

*κ*=

*σ*

_{T}/

*σ*

_{C}have been examined: 1, 3, 5, 7, 9, 100. The selected optimal-numerical layouts are presented in Fig. 17. All of them have been executed for the ground structure of density 110 × 40:20:20, with 4,551 nodes and 1,587,926 elements. The volumes obtained in numerical way agree very well with the exact volumes reported in Graczykowski and Lewiński (2010). The layouts fit also very well. For example, the angle of flare of the upper fan matches well the theoretical value of this angle which is equal to \(\arctan (\sqrt \kappa)\). The comparison of the results is given in Table 3. One can notice that the relative error of the volume as well as CPU time increase for growing

*κ*. Thus the tasks with \(\kappa \ne 1\) are harder to solve. The program presented in the paper is capable of solving them successfully.

Comparison of analytical and numerical solutions

| \(\arctan (\sqrt \kappa)\) | Exact volume | Num. vol. \(\overline{V}_\sigma\) | Relative error [%] | CPU time [s] |
---|---|---|---|---|---|

1 | 45° | 11.8273 | 11.8406 | 0.112 | 579 |

3 | 60° | 23.2900 | 23.3176 | 0.118 | 720 |

5 | 66° | 34.6664 | 34.7083 | 0.121 | 731 |

7 | 69° | 46,0208 | 46,0777 | 0,124 | 753 |

9 | 72° | 57.3665 | 57.4380 | 0.125 | 788 |

100 | 84° | – | 573.8080 | – | 889 |

## 5 Conclusions

The computational program developed should serve as a convenient tool for predicting new exact solutions to the Michell problems. The listing of the program can be found in Appendix 1. It requires the Mathematica, version 6 or higher. The program is based on the concept of the ground structure and that is why it produces results which are not built on any knowledge of properties of the optimum layouts. This is the essential virtue of the method, since the complete theory of Michell structures has not been developed till now and we cannot unconditionally say that the properties noted in the most cited reference sources hold good in all specific cases.

The correct prediction of the solution of problem in Fig. 13 seems to be a success, since the pseudo truss in Fig. 15 is structurally unstable and this solution is highly sensitive to the position of forces *P*, in contrast to the better known cantilever solutions (e.g. Graczykowski and Lewiński 2010; Lewiński et al. 1994a, b) in which the Hencky net is independent of the loading applied.

## Acknowledgments

The paper was prepared within the Research Grant no N506 071338, financed by the Polish Ministry of Science and Higher Education, entitled: Topology Optimization of Engineering Structures. Simultaneous shaping and local material properties determination.

**Open Access**

This article is distributed under the terms of the Creative Commons Attribution Noncommercial License which permits any noncommercial use, distribution, and reproduction in any medium, provided the original author(s) and source are credited.