arXiv:2611.00803math.OCOct 2026

Manuscript Offprint

arXiv:2611.00803

Agent4FreeFem: A Verification-Guided Framework for Autonomous Topology Optimization

Zhipu Cui, Helin Gong, Shengfeng Zhu

Abstract

Topology optimization has become an indispensable design tool in the aerospace, automotive, and mechanical engineering industries. Yet bringing a new problem from its description to an optimized result remains slow, expert-dependent, and unreliable: the workflow spans many manually connected stages, each new problem requires solver code to be written and debugged manually, and such code often fails or yields incorrect results. We present Agent4FreeFem, a pipeline driven by a large language model that turns a natural-language problem description into a set of verified optimization results without manual solver-code development or debugging. The pipeline keeps the problem definition unmodified, localizes errors using independent sources of evidence, and completes constrained repairs automatically, thereby providing efficient end-to-end automation, autonomous execution, and verifiable results. We evaluated Agent4FreeFem on a suite of single-physics and coupled multiphysics problems. Every case passed runtime verification and finished within the repair budget of each stage.

Keywords: Large language models, topology optimization, level-set method, code generation, self-correction

Mathematical Subject Classification: 49Q10, 68T50, 90C90

1 Introduction

Topology optimization determines the optimal material layout inside a prescribed design domain under given physical constraints, without assuming any preconceived structure. Since the seminal works [1,2], the method has grown into an indispensable industrial design tool [3]: it is used to lighten aerospace brackets and aircraft components, to stiffen automotive chassis and engine mounts, to shape mechanical parts, and to design civil structures, among others. By routinely saving material and reducing weight while improving structural performance, topology optimization shortens design cycles and lowers manufacturing cost, and with the spread of additive manufacturing its intricate optimized geometries have become increasingly manufacturable.

Despite this maturity, taking a new problem from a description to an optimized result remains slow, expert-dependent, and fragile. First, the process is time-consuming. The workflow spans many disconnected stages, including mathematical formulation, mesh generation, weak-form derivation, solver configuration, and tuning of the optimization loop, each handled in a separate tool; repeated cross-stage handoffs account for a substantial portion of the turnaround time. Second, the process requires a high level of

*School of Mathematical Sciences, East China Normal University, Shanghai 200241, China. (52300155021@stu.ecnu.edu.cn)

†SJTU Paris Elite Institute of Technology, Shanghai Jiao Tong University, Shanghai 200240, China. (gonghelin@sjtu.edu.cn)

‡Corresponding author. School of Mathematical Sciences, East China Normal University, Shanghai 200241, China. (sfzhu@math.ecnu.edu.cn) expertise. Every new problem requires a specialist who understands both the underlying physics and numerical computing to hand-write and debug the solver code. Third, the process suffers from low reliability. Hand-written solver code often compiles yet fails at runtime or converges to incorrect solutions because of errors in weak forms, signs, units, boundary conditions, or parameter scales, and locating such errors is itself a major effort. Recent benchmarks of LLM-generated finite-element code report similarly low pass rates [4, 5], confirming that merely writing code is far from producing a correct, runnable solver.

Large language models (LLMs) are capable of generating code [6], yet scientific coding remains challenging for them [7], and their finite-element code still exhibits low pass rates [4, 5]. For mechanics and engineering design, multi-agent LLM collaborations have been shown to solve mechanics problems [8], agentic LLMs have been fine-tuned for finite-element methods [9], and LLM agents generate CAD models from text [10]. On the industrial side, LLM-based virtual assistants are being embedded into commercial CAE products such as AnsysGPT [11], and autonomous agent systems built on reasoning-and-acting frameworks handle large-scale industrial scheduling [12], highlighting the practical demand for autonomous engineering pipelines.

Topology optimization has begun to attract LLM-based automation. Liang et al. [13] integrate large language models into the conceptual design stage of topology optimization: the model interprets the natural-language design requirements and supports the development of an initial conceptual design, yet its assistance stops at the pre-processing stage, since the downstream numerical pipeline, from the PDE formulation and discretization to the solver implementation, is still assembled by experts, and the model's output is not automatically linked to an executed optimizer. Yang et al. [14] use an LLM as an online optimization controller that monitors the convergence of a SIMP solver and adaptively selects its continuation parameters, but the LLM operates inside the existing solver that has already been written and debugged by experts, so the dominant cost of the workflow, writing and debugging the solver code itself, remains unaddressed. Heyrani Nobari et al. [15] train a deep generative foundation model that directly predicts optimized topologies in a shape- and resolution-free manner, which shifts the cost to data: it requires a large corpus of solved problems for training, inherits the distribution of that corpus, and produces designs without a PDE-constrained solve to verify the resulting designs. Lin et al. [16] present TO-Master, a tool-orchestrated LLM agent that assembles density-based topology-optimization models from natural-language instructions and drives a fixed JAX-FEM optimization core; the supported formulations are pre-implemented in the core, and the mesh and the boundary conditions are confirmed by the human user. Park and Chung [17] introduce a multi-agent framework, TopOptAgents, demonstrated on benchmark problems, in which a specification validator, a code team, and a design critic refine the formulation, the FEniCS implementation, and the converged designs through four interleaved loops, with the critic judging rendered designs against a rubric of validity, consistency, convergence, and design quality.

To address these challenges, we present Agent4FreeFem, an agentic pipeline that turns a natural-language problem description into a set of verified optimization results without manual solver-code development or debugging. The pipeline consists of four stages. During Initialization, an example-selection step first scores the problem files against a reference library and selects the most relevant reference examples; the LLM then parses the description into a structured problem specification and a mesh specification, annotating each value to indicate whether it was extracted from the source or designed to fill a gap, using the selected reference specifications as contextual guidance. Generation has the LLM write the solver code in the AutoFreeFEM domain-specific language [18] in accordance with that specification, aided by the selected reference programs and meshes. Execution runs the generated code through the AutoFreeFEM library and the FreeFem++ solver [19] with an automatic parameter sweep, producing optimized designs. Reflection has two responsibilities: when an execution produces no design snapshot at all, it classifies the failure as a program error, repairs the code, and re-executes; when the sweep runs to completion, it first performs an overall check of the designs and then post-processes the results, for example by composing the design screenshots and cleaning up the temporary files.

The central methodological principle of Agent4FreeFem is to preserve the problem definition, localize errors using independent sources of evidence, and perform constrained repairs automatically. This principle is implemented in three ways. First, every value in the specification carries its extracted/designed source annotation, so extracted values stay verbatim, designed values carry rationales, and the problem definition is never altered by any later stage. Second, the deterministic checks, the semantic review, and the real execution evidence locate errors independently of one another. Third, each repair modifies only the flagged entries, and cases that fail to pass within the repair budget are set aside for human review rather than silently accepted. This approach offers three main advantages:

  • Efficient connectivity. Problem parsing, mesh handling, code generation, solving, and parameter tuning are automatically chained inside a single pipeline, from the natural-language description all the way to the finished sweep; no manual handoff between stages is needed, so the entire flow proceeds efficiently.

  • Process autonomy. The modeling specification, the selection of reference examples, and the code generation are all performed autonomously by the LLM, and the pipeline automatically runs the solver and performs the parameter sweeps, so that no manual solver-code development is required. Each decision is recorded in an operation log, and the automatic parameter sweeps provide supporting evidence, making the results reproducible and auditable.

  • Process verifiability. The generated code undergoes deterministic static checks and runtime verification. If a check fails, the pipeline automatically classifies the error, repairs the code, and reruns it until the run passes or a given repair budget is exhausted.

We validate Agent4FreeFem with the level-set method on 34 different examples spanning 6 problem types: linear elasticity, nonlinear elasticity, linear thermal conduction, nonlinear thermal conduction, Stokes flow, and coupled thermo-elasticity. All 2,050 solver runs passed runtime verification: 2,048 runs from the 32 suite cases, 64 parameter combinations per case, and two runs from the extension cases.

The remainder of this paper is organized as follows. Section 2 reviews the preliminaries. Section 3 presents the methodology of Agent4FreeFem. Section 4 reports the experimental results. Section 5 concludes the paper.

References (37)