arXiv:2611.12027cs.CENov 2026

Manuscript Offprint

arXiv:2611.12027

An open source Python code for three-dimensional topology optimization in single precision on a consumer GPU

Leonilson Toffoli Pedrini, Rodolfo G. M. Andrade, Rafael M. Ferro

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Three-dimensional topology optimization solves linear systems with millions of unknowns at every design iteration. Consumer graphics cards run far faster in single than in double precision, and open codes for them mostly address minimum compliance. This educational article presents TOF3D, an open source Python code for density-based topology optimization in single precision on one consumer GPU. It solves four classes of problems: stress constrained minimum compliance, robust minimum compliance against manufacturing errors, compliant mechanisms and bone-like porous infill. The stiffness operator is applied without assembly, and the conjugate gradient method is preconditioned by geometric multigrid. Rounding the element matrix to single precision gave rigid body motions a spurious energy and changed compliances by up to 5.4%. Forming the element products from differences of nodal displacements reduced this error to 1.3×10−51.3 \times 10^{-5} at no cost in time. Adjoint sensitivities agreed with finite differences to within 1.7×10−61.7 \times 10^{-6}, and the solutions agreed with Ansys Mechanical APDL to within 4.1×10−104.1 \times 10^{-10} with the same element. On an RTX 3060 with 12 GB, one design iteration of a cantilever took 0.46 s with 0.5 million elements and 15 s with 33.5 million. On the same card and problem, an open GPU code that applies its operator in double precision took 3.7 and 21 s with 0.5 and 4.2 million elements and ran out of memory on larger meshes. Eight cases fixed in a protocol before the runs took 9 to 35 minutes each with 4.2 to 5.2 million elements.

Keywords: topology optimization, graphics processing units, stress constraints, robust formulation, compliant mechanisms, porous infill

1 Introduction

Topology optimization distributes material in a design domain to meet a structural goal under given loads and supports (Bendsøe and Sigmund 2003). Besides stiffness, parts in service must keep the stress below a limit and tolerate the erosion and dilation that manufacturing causes. Compliant mechanisms must also deliver a prescribed motion, and parts built by additive manufacturing may

carry a porous infill. Density-based formulations exist for each of these requirements. The relaxed von Mises stress aggregated by a PP-norm handles the stress limit (Bruggi 2008; Le et al. 2010; Holmberg et al. 2013), and the robust formulation optimizes the eroded, intermediate and dilated designs together (Sigmund 2009; Wang et al. 2011). For compliant mechanisms the objective is an output displacement (Sigmund 1997), and for infill, local volume constraints produce a bone-like structure (Wu et al. 2018). In three dimensions, however, each design iteration solves one or more linear systems with millions of unknowns, and the cost of these solutions limits the resolution at which the formulations are studied.

Educational codes made topology optimization accessible. The 99-line Matlab code of Ferrari and Sigmund (2020) solves two-dimensional minimum compliance problems in seconds, and its 125-line version extends them to three dimensions. Open source implementations followed, built on general finite element libraries or on sparse solvers, some with an optional GPU solver (Ferro and Pavanello 2023; Kim and Kang 2025). For large meshes, a PETSc framework for computer clusters produced giga-voxel designs (Aage et al. 2017); at the other end, interactive apps brought two- and three-dimensional optimization to handheld devices at coarse resolution (Aage et al. 2013; Nobel-Jørgensen et al. 2015). Wang et al. (2025) combined a matrix-free operator with an adapted multigrid preconditioner in Matlab and reached 128 million elements on a desktop computer with 64 GB of memory, for minimum compliance and porous infill.

Graphics processing units (GPUs) offer another route to large meshes. Several GPU codes applied the stiffness matrix element by element or without assembling it (Schmidt and Schulz 2011; Martínez-Frutos and Herrero-Pérez 2015; Ratnakar et al. 2022), and Wu et al. (2016) combined a matrix-free operator with a geometric multigrid preconditioner to reach high resolution on one GPU. Clusters of GPUs extended these codes to larger meshes and to robust optimization (Martínez-Frutos and Herrero-Pérez 2016; Herrero-Pérez and Martínez Castejón 2021). Träff et al. (2023) released open codes in Futhark and OpenMP and optimized a cantilever with 65.5 million elements over 100 design iterations in about two hours on one A100 GPU. Zhao et al. (2024) wrote a multigrid code in Taichi for fiber-reinforced composites with 33.6 million elements, and Zhang et al. (2023) released a GPU solver for inverse homogenization. On a consumer card, Jia et al. (2026) imposed length scale and local volume constraints with 151 million degrees of freedom. Most of these works optimize stiffness.

Stress, robustness against manufacturing errors and mechanisms appear in fewer GPU works.

Martínez-Frutos and Herrero-Pérez (2016) treated robustness as a probabilistic problem with random loads and material properties, not as the erosion and dilation of the design. Dugast and To (2023) optimized support structures for metal additive manufacturing with the stress as objective on an A100 GPU, and verified their mechanical model against Ansys. Most GPU codes also assume data center cards with large memory and fast double precision, whereas consumer cards offer less memory and favor single precision (Träff et al. 2023). Finite element solvers on such hardware have kept their accuracy by mixed precision iterative refinement, which computes the residual in double precision (Göddeke et al. 2007). To the knowledge of the authors, no open code combines stress constraints, robustness, compliant mechanisms and porous infill in three dimensions on a consumer GPU, with its responses cross-checked against a commercial finite element code.

Thus, this work aims to provide TOF3D, an open source Python code developed by the authors for density-based topology optimization in three dimensions, in single precision, on one consumer GPU. The code solves four classes of problems: (i) minimum compliance under a stress constraint, (ii) robust minimum compliance against manufacturing errors, (iii) compliant mechanisms in standard and robust form, and (iv) bone-like porous infill. The work makes four contributions. The first is a single code, under the MIT license, that runs the four classes on a 12 GB card. The second is the verification: adjoint gradients checked against finite differences, and optimized designs cross-checked against Ansys Mechanical APDL. The third is the time and memory of each class on meshes with millions of elements, measured also against an open GPU code on the same card. These numbers serve as a reference for other GPU codes and for learned surrogates, neural networks trained to predict optimized designs (Sigmund 2022; Woldseth et al. 2022). The fourth concerns the single precision that consumer cards favor. Rounding the element stiffness matrix to single precision gives rigid body motions a spurious energy, and on meshes with millions of elements this changed compliances by up to 5.4%. Computing the element products from differences of nodal displacements reduces this error to 1.3×10−51.3 \times 10^{-5} at no cost in time and keeps the operator and all vectors in single precision.

Algorithm 1 One design iteration of TOF3D

1: Filter ρ\rho by FFT, Eq. (6), and project it for each design, Eq. (7) 2: Set EeE_e by Eq. (1) and rebuild the coarse operators, Eq. (5) 3: for each load case do 4: Solve Eq. (2) by MGCG from the previous u\mathbf{u}, with the operator of Eq. (4) 5: end for 6: Evaluate the objective and constraints of Eq. (8); solve the adjoint systems by MGCG 7: Form the sensitivities, Eq. (12), and carry them back through the projection and the filter 8: Update ρ\rho by the MMA, with its dual subproblem solved on the GPU 9: Double β\beta at fixed iterations; robust problems refresh the volume bound Vd∗V_d^* of the dilated design every 20 iterations

References (42)