Rethinking Scientific Modeling: Toward Physically Consistent and Simulation-Executable Programmatic Generation

Yongqing Jiang, Jianze Wang, Zhiqi Shen, Zhenghong Lin, Jiayuan Wang, Yijian Yang, Kaoshan Dai, Haoran LuoarXiv 2026 · DOI

TL;DR

This paper introduces a physics-aware framework for Automatic Building Modeling (AutoBM), enabling Large Language Models (LLMs) to generate structural engineering code that is both syntactically correct and physically valid. By combining a novel domain-specific dataset (CivilInstruct), a two-stage reinforcement learning alignment strategy (RLA-SPC), and a rigorous evaluation benchmark (BMEval), the researchers successfully bridge the gap between natural language requirements and simulation-ready, code-compliant structural models.

What Problem Does This Paper Address?

While LLMs excel at general code generation, applying them to scientific and structural engineering modeling presents a unique challenge: the physical illusion. A general-purpose LLM might generate syntactically flawless Python code using structural analysis libraries like OpenSeesPy, but the resulting building design might violate fundamental laws of physics or engineering codes—resulting in structures prone to excessive lateral drift or unrealistic structural periods.

Traditional structural modeling relies heavily on manual parameterization and rigid, hard-coded rules, which lack scalability. To automate this process safely, LLMs must be constrained to generate code that is not only executable but also physically consistent and compliant with stringent engineering safety standards.

Methods

The authors formalize the AutoBM task and propose a two-stage reinforcement learning framework called RLA-SPC (Reinforcement Learning Alignment under Structural Physical Constraints) to enforce engineering compliance:

  1. Stage I: Domain Instruction Fine-Tuning (SFT): The model is fine-tuned on a specialized dataset to master the domain syntax, API usage patterns of OpenSeesPy, and basic engineering concepts.
  2. Stage II: Structural Physics-Constrained Alignment: To eliminate "physical illusions," the model is optimized using a physics-constrained variant of Group-Relative Policy Optimization (SPC-GRPO).

The core innovation lies in their Multi-Granularity Hybrid Reward (MGHR) function, which scores the generated code based on three tiers:

  • Format Compliance: Ensures correct Markdown and reasoning tags.
  • Logical Completeness: Uses a Hierarchical Abstract Syntax Tree (AST) to verify that essential structural components (topology, boundaries, loads, and solvers) are defined and free of undefined variables.
  • Sandbox-Based Physical Consistency: Executes the code inside an OpenSees sandbox. If it runs successfully, the framework calculates the relative error of the structure's fundamental period against ground-truth physics calculations, penalizing deviations.

The overall task workflow, bridging user prompts to physically validated code, is illustrated in Figure 3.

The definition and overview of the AutoBM task.

Datasets

The paper introduces two major data contributions:

  • CivilInstruct: A multi-part dataset containing 3,881 API tutorial pairs, ~3,100 parameterized long-code instances (~600 lines each), 3,500 execution error-oriented debugging Chain-of-Thought (Bug-CoT) samples, and 512 high-quality physics-informed expert samples. The dataset construction pipeline is detailed in Figure 4.
  • BMEval: A verification-driven evaluation benchmark consisting of 128 distinct evaluation cases spanning various building functions, story heights, and seismic intensities, complete with ground-truth structural periods derived via finite element analysis.
Overview of the CivilInstruct dataset construction procedure.

Key Insights and Ideas

  • The Grammatical and Physical Divide: Standard LLMs treat physical parameters as statistical tokens rather than real-valued variables bound by physical laws. For example, before alignment, Gemini-2.5-Flash achieved a high code executability score ($Pass@5 = 75.16\%$) but an abysmal strict engineering success score ($Pass@5_{strict} = 4.69\%$).
  • The Power of Negative Examples (Bug-CoT): Simply training models on "perfect" code isn't enough. Incorporating real execution error logs and debugging trajectories (Stage 1) drastically improves the model's resilience against syntax truncation and API misuse in long-form code generation.
  • Closed-Loop Self-Verification is Weak in Base Models: Even when explicitly prompted to "meet seismic design requirements," commercial models often output surface-level text compliance without executing the actual conditional branching logic required for true parameter adjustment.

An analysis of these common failure modes in unaligned models is shown in Figure 6.

Distribution and detailed analysis of engineering failure modes in AI-generated code.

Key Results

Applying the RLA-SPC framework to open-source models yielded massive performance leaps across the board:

  • Qwen2.5-Coder-7B-Instruct saw its strict engineering compliance score ($Pass@5_{strict}$) skyrocket from 0.47% to 74.53%, with its overall average score jumping from 6.71 to 75.64.
  • CodeLlama-7B-Instruct experienced a similar surge, with its overall average score rising from 5.71 to 72.14.
  • Seed-Coder-8B achieved the highest post-alignment overall average score of 80.03.

These results demonstrate that physics-constrained reinforcement learning successfully transitions LLMs from simple code writers to reliable scientific modeling assistants.

Limitations and Future Work

The authors note several boundaries to their current framework:

  • Simplified Scope: The framework is currently limited to elastic structural analysis and simplified 2D reinforced concrete frames. It does not yet support complex 3D spatial interactions or non-linear material degradation analysis.
  • Geographic Specificity: The domain knowledge and constraints were modeled primarily around Chinese seismic design specifications (GB50011-2010, etc.), meaning its generalizability to Eurocodes or US IBC standards remains unvalidated.
  • Human-in-the-Loop Necessity: The system is designed to assist engineering workflows, not replace professional structural design or regulatory safety sign-offs.

Summary updated

BibTeX
@misc{jiang2026rethinking,
  author = {Yongqing Jiang and Jianze Wang and Zhiqi Shen and Zhenghong Lin and Jiayuan Wang and Yijian Yang and Kaoshan Dai and Haoran Luo},
  title = {{Rethinking Scientific Modeling: Toward Physically Consistent and Simulation-Executable Programmatic Generation}},
  year = {2026},
  eprint = {2602.07083},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2602.07083},
}
Figure