Method and device for electromagnetic device simulation generation and optimization based on large language model
Patent Information
- Application Number
- CN202611030278.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-11
- Publication Date
- 2026-10-13
AI Technical Summary
然而,在目前的实际应用中,利用大语言模型辅助电磁仿真,大模型端与底层的电磁仿真执行端(如HFSS等大型CAE软件)之间缺乏数据底层的自动化联通通道,在使用时需手动提取模型生成的脚本并粘贴至本地环境执行,而工业级电磁仿真环境具有极高的严谨性,参数的微小变动极易导致几何拓扑冲突或网格划分异常
1、由于采用了获取用户输入的电磁器件需求提示词,将该需求提示词与系统提示词共同输入大语言模型,使大语言模型自动生成电磁仿真领域的第一结构仿真脚本,从而避免了用户手动编写仿真脚本的繁琐过程。为解决手动提取脚本易引发接口调用错误的问题,对生成的第一结构仿真脚本进行语法校验,在校验通过后由脚本执行器自动运行该脚本,并通过预设的电磁仿真应用程序接口直接连接仿真平台,驱动仿真平台构建三维物理几何模型并完成网格划分与电磁场求解,建立了大语言模型端与电磁仿真执行端之间的自动化联通通道,实现了从脚本生成到仿真执行的无缝衔接。在获得电磁仿真结果后,提取仿真性能矩阵并将其特征值与用户需求中的电磁性能指标值进行比对得到偏差指标集,进而在偏差指标集未满足预设收敛条件且未达到预设迭代次数的情况下,将偏差指标集与三维物理几何模型的参数变量输入大语言模型进行偏差解析以得到参数修正策略,根据该参数修正策略更新参数变量生成第二结构仿真脚本,并将第二结构仿真脚本作为新的第一结构仿真脚本重新执行语法校验及后续步骤,形成闭环迭代优化,直至偏差指标集满足预设收敛条件或达到预设迭代次数时提取满足当前条件的参数变量作为电磁器件的物理结构参数。通过上述技术方案,实现了从用户自然语言需求到仿真脚本生成、语法校验、自动化仿真执行、偏差分析与参数迭代优化的全流程自动化闭环,消除了人工介入环节,有效避免了手动操作导致的接口调用错误和工具链中断问题,显著提升了电磁器件仿真建模的效率与可靠性。所以,有效解决了相关技术中一旦手动提取脚本在驱动仿真软件时发生接口调用错误或求解报错,整个工具链便会直接中断,导致仿真建模的效率低下的问题。
Smart Images

Figure CN122904680A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer simulation technology, specifically to a method and device for generating and optimizing electromagnetic device simulations based on a large language model. Background Technology
[0002] With the rapid development of 5G / 6G communication, the Internet of Things, and high-frequency, high-speed electronic devices, the design of antennas and RF microwave devices faces stringent performance requirements. Against this backdrop, electromagnetic simulation and parameter optimization, as a core component of the electronic product development lifecycle, are becoming increasingly important. By constructing high-precision three-dimensional digital physical models for electromagnetic solutions, time-consuming physical prototype prototyping and testing can be effectively replaced. This not only significantly shortens the product development iteration cycle but also allows for the exploration of optimal performance designs that are difficult to discover intuitively by humans through parameter optimization.
[0003] In recent years, with the development of artificial intelligence technologies such as large language models, existing technologies have begun to attempt to use large language models to generate script code for electromagnetic simulation control APIs (such as the PyAEDT platform) in order to help engineers speed up modeling. However, in current practical applications, using large language models to assist electromagnetic simulation lacks an automated data communication channel between the large model and the underlying electromagnetic simulation execution end (such as large CAE software like HFSS). Users must manually extract the scripts generated by the model and paste them into the local environment for execution. However, industrial-grade electromagnetic simulation environments have extremely high rigor; even minor parameter changes can easily lead to geometric topology conflicts or abnormal mesh generation. If an interface call error or solution error occurs when manually extracting the script to drive the simulation software, the entire toolchain will be interrupted, resulting in low efficiency in simulation modeling. Summary of the Invention
[0004] This application provides a method and device for generating and optimizing electromagnetic device simulation based on a large language model, which can realize automated simulation modeling and improve simulation modeling efficiency.
[0005] The technical solution of this application embodiment is as follows: In a first aspect, embodiments of this application provide a method for electromagnetic device simulation generation and optimization based on a large language model, the method comprising: The system obtains the user-inputted requirements for electromagnetic devices, inputs the requirements and preset system prompts into a large language model, and generates a first structural simulation script. The requirements include electromagnetic performance indicators, and the system prompts include electromagnetic simulation specifications, material name mapping relationships, simulation scene templates, and output formats. The first structure simulation script is syntax-checked. If the check passes, the script executor is called to run the first structure simulation script. The preset electromagnetic simulation application interface is called to connect to the simulation platform including electromagnetic device structure simulation. The simulation platform is driven to build a three-dimensional physical geometry model. The three-dimensional physical geometry model is meshed and the electromagnetic field is solved to obtain the electromagnetic simulation results. Extract the simulation performance matrix of the electromagnetic simulation results, and compare the eigenvalues of the simulation performance matrix with the values of the electromagnetic performance indicators to obtain a set of deviation indicators; If the deviation index set does not meet the preset convergence condition and does not reach the preset number of iterations, the deviation index set and the parameter variables of the three-dimensional physical geometry model are input into the large language model for deviation analysis to obtain a parameter correction strategy. The parameter variables are then updated according to the parameter correction strategy to generate a second structure simulation script. The second structural simulation script is used as the first structural simulation script, and the step of performing syntax verification on the first structural simulation script is executed until the deviation index set meets the preset convergence condition or reaches the number of iterations. The parameter variables that meet the current conditions are extracted and used as the physical structural parameters of the electromagnetic device.
[0006] Secondly, embodiments of this application provide an electromagnetic device simulation generation and optimization system based on a large language model, the system comprising: The data acquisition module is used to acquire the user-input requirements for electromagnetic devices, input the requirements and preset system prompts into the large language model, and generate a first structural simulation script. The requirements include electromagnetic performance indicators, and the system prompts include electromagnetic simulation specifications, material name mapping relationships, simulation scene templates, and output formats. The simulation verification module is used to perform syntax verification on the first structure simulation script. If the verification passes, the script executor is called to run the first structure simulation script. The preset electromagnetic simulation application interface is called to connect to the simulation platform including electromagnetic device structure simulation. The simulation platform is driven to build a three-dimensional physical geometry model. The three-dimensional physical geometry model is meshed and the electromagnetic field is solved to obtain the electromagnetic simulation results. The deviation calculation module is used to extract the simulation performance matrix of the electromagnetic simulation results, and compare the feature values of the simulation performance matrix with the values of the electromagnetic performance indicators to obtain a set of deviation indicators. The parameter adjustment module is used to input the deviation index set and the parameter variables of the three-dimensional physical geometry model into the large language model for deviation analysis when the deviation index set does not meet the preset convergence condition and does not reach the preset number of iterations, to obtain the parameter correction strategy, and update the parameter variables according to the parameter correction strategy to generate a second structure simulation script. The script optimization module is used to take the second structure simulation script as the first structure simulation script, execute the step of performing syntax verification on the first structure simulation script until the deviation index set meets the preset convergence condition or reaches the number of iterations, and extract the parameter variables that meet the current conditions as the physical structure parameters of the electromagnetic device.
[0007] Thirdly, embodiments of this application provide an electronic device including a processor, a memory, a user interface, a communication bus, and a network interface. The processor, the memory, the user interface, and the network interface are respectively connected to the communication bus. The memory is used to store instructions. The user interface and the network interface are used to communicate with other devices. The processor is used to execute the instructions stored in the memory to cause the electronic device to perform the method described in any one of the first aspects.
[0008] Fourthly, embodiments of this application provide a computer-readable storage medium storing instructions that, when executed, perform the method described in any one of the methods provided in the first aspect above.
[0009] In summary, one or more technical solutions provided in the embodiments of this application have at least the following technical effects or advantages: 1. By acquiring user-input electromagnetic device requirement prompts, these prompts, along with system prompts, are input into the large language model. This allows the large language model to automatically generate the first-structure simulation script in the electromagnetic simulation field, thus avoiding the tedious process of manually writing simulation scripts. To address the issue of interface call errors easily caused by manually extracting scripts, the generated first-structure simulation script undergoes syntax validation. After successful validation, the script executor automatically runs the script and directly connects to the simulation platform through a preset electromagnetic simulation application programming interface. This drives the simulation platform to construct a three-dimensional physical geometry model and complete mesh generation and electromagnetic field solving, establishing an automated communication channel between the large language model and the electromagnetic simulation execution end, achieving seamless integration from script generation to simulation execution. After obtaining the electromagnetic simulation results, the simulation performance matrix is extracted, and its eigenvalues are compared with the electromagnetic performance index values in the user's requirements to obtain a set of deviation indicators. If the deviation indicator set does not meet the preset convergence conditions and the preset number of iterations has not been reached, the deviation indicator set and the parameter variables of the 3D physical geometry model are input into a large language model for deviation analysis to obtain a parameter correction strategy. Based on this strategy, the parameter variables are updated to generate a second structure simulation script. This second structure simulation script is then used as a new first structure simulation script to re-execute syntax verification and subsequent steps, forming a closed-loop iterative optimization. This process continues until the deviation indicator set meets the preset convergence conditions or the preset number of iterations is reached, at which point the parameter variables that meet the current conditions are extracted as the physical structure parameters of the electromagnetic device. This technical solution achieves a fully automated closed loop from user natural language requirements to simulation script generation, syntax verification, automated simulation execution, deviation analysis, and parameter iterative optimization. It eliminates manual intervention, effectively avoids interface call errors and toolchain interruptions caused by manual operation, and significantly improves the efficiency and reliability of electromagnetic device simulation modeling. Therefore, it effectively solves the problem in related technologies where the entire toolchain is directly interrupted when an interface call error or a solution error occurs while manually extracting the script to drive the simulation software, resulting in low efficiency of simulation modeling.
[0010] 2. By constructing an abstract syntax tree for precise source code-level local addressing and numerical replacement, the system can accurately locate the position of target parameters in the simulation script. It can precisely pinpoint the characters that need modification within the original source code, avoiding mismatches caused by parameter values appearing in comments or strings. It eliminates the instability risks associated with fully rewriting code in traditional large models during iterations. In multiple rounds of simulation optimization iterations, only core parameters are modified while freezing the electromagnetic physics framework, model boundaries, and other surrounding environment code. This significantly improves the robustness of automated simulation and effectively solves the problem of difficulty in converging generated electromagnetic code.
[0011] 3. In parameter tuning, which direction should the parameters be adjusted in, and what is the qualitative relationship between the estimated parameters and performance indicators? While large language models can provide accurate adjustment directions, they struggle to precisely calculate the optimal adjustment range. Parameter tuning, however, achieves both high efficiency and reliability in the optimization process. Attached Figure Description
[0012] Figure 1 This is a flowchart illustrating a method for generating and optimizing electromagnetic devices based on a large language model, provided in one embodiment of this application. Figure 2 This is a schematic diagram of the structure of an electromagnetic device simulation generation and optimization system based on a large language model provided in one embodiment of this application; Figure 3 This is a schematic diagram of the structure of an electronic device provided in one embodiment of this application. Detailed Implementation
[0013] To enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments.
[0014] In the description of the embodiments of this application, the words "for example" or "for instance" are used to indicate examples, illustrations, or explanations. Any embodiment or design that is described as "for example" or "for instance" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design options. Rather, the use of the words "for example" or "for instance" is intended to present the relevant concepts in a specific manner.
[0015] In the description of the embodiments of this application, the term "multiple" means two or more. For example, multiple systems means two or more systems, and multiple screen terminals means two or more screen terminals. Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the indicated technical features. Thus, a feature defined with "first" or "second" may explicitly or implicitly include one or more of that feature. The terms "comprising," "including," "having," and variations thereof all mean "including but not limited to," unless otherwise specifically emphasized.
[0016] While some automated simulation scripts or parameter scanning tools exist in related technologies, none can achieve a complete closed loop of "natural language requirements → automatic generation of executable simulation scripts → execution → automatic interpretation of results → iterative optimization." In particular, existing tools cannot automatically repair or adjust parameters when script execution errors occur or simulation results deviate from the target. With the development of large language models such as Claude and GPT, their code generation and natural language understanding capabilities have significantly improved. However, there are still no mature solutions for applying them to professional engineering simulation fields and solving technical challenges such as domain knowledge injection, automatic script repair, and multi-round optimization.
[0017] Based on this, embodiments of this application provide a method, system, electronic device, and readable storage medium for electromagnetic device simulation generation and optimization based on a large language model. This method first obtains user-inputted electromagnetic device requirement prompts, then inputs these prompts along with system prompts into a large language model. The large language model automatically generates a first-structure simulation script in the electromagnetic simulation field, thus avoiding the tedious process of manually writing simulation scripts. To address the issue of interface call errors easily caused by manual script extraction, the generated first-structure simulation script undergoes syntax validation. After successful validation, the script executor automatically runs the script and directly connects to the simulation platform through a preset electromagnetic simulation application interface. This drives the simulation platform to construct a three-dimensional physical geometry model and complete mesh generation and electromagnetic field solving, establishing an automated communication channel between the large language model and the electromagnetic simulation execution end, achieving seamless integration from script generation to simulation execution. After obtaining the electromagnetic simulation results, the simulation performance matrix is extracted, and its eigenvalues are compared with the electromagnetic performance index values in the user's requirements to obtain a set of deviation indicators. If the deviation indicator set does not meet the preset convergence conditions and the preset number of iterations has not been reached, the deviation indicator set and the parameter variables of the 3D physical geometry model are input into a large language model for deviation analysis to obtain a parameter correction strategy. Based on this strategy, the parameter variables are updated to generate a second structure simulation script. This second structure simulation script is then used as a new first structure simulation script to re-execute syntax verification and subsequent steps, forming a closed-loop iterative optimization. This process continues until the deviation indicator set meets the preset convergence conditions or the preset number of iterations is reached, at which point the parameter variables that meet the current conditions are extracted as the physical structure parameters of the electromagnetic device. This technical solution achieves a fully automated closed loop from user natural language requirements to simulation script generation, syntax verification, automated simulation execution, deviation analysis, and parameter iterative optimization. It eliminates manual intervention, effectively avoids interface call errors and toolchain interruptions caused by manual operation, and significantly improves the efficiency and reliability of electromagnetic device simulation modeling.
[0018] It should be noted that this electromagnetic device simulation generation and optimization method based on a large language model is used for the design of electromagnetic devices, such as the automated generation and optimization of passive devices like antennas, filters, and connectors.
[0019] The technical solutions provided in the embodiments of this application will be further described below with reference to the accompanying drawings.
[0020] Reference Figure 1 , Figure 1 This is a flowchart illustrating the electromagnetic device simulation generation and optimization method based on a large language model provided in this application embodiment. The electromagnetic device simulation generation and optimization method based on a large language model is applied to an electromagnetic device simulation generation and optimization system based on a large language model. The method is executed by a processor in an electronic device or a readable storage medium. The electromagnetic device simulation generation and optimization method based on a large language model includes steps S100, S200, S300, S400, and S500.
[0021] Step S100: Obtain the user-inputted requirements for electromagnetic devices, input the requirements and preset system prompts into the large language model, and generate the first structural simulation script. The requirements include electromagnetic performance indicators, and the system prompts include electromagnetic simulation specifications, material name mapping relationships, simulation scene templates, and output formats.
[0022] In one embodiment, electromagnetic devices refer to passive electromagnetic structural components in the fields of 5G / 6G communication, radar, and radio frequency circuits, including rectangular patch antennas, connectors, radio frequency filters, and PCB signal transmission structures. The requirement prompts are natural language text input by the user through the interactive interface, containing core simulation requirement data such as the operating frequency of the electromagnetic device, substrate material, geometric constraints, and electromagnetic performance indicators. These serve as the original input basis for generating the simulation script. Electromagnetic performance indicators are quantitative parameters used to evaluate the quality of electromagnetic devices, with core parameters including S11 return loss, insertion loss, operating bandwidth, resonant frequency, and antenna gain, providing standard thresholds for subsequent simulation deviation comparisons. System prompts are pre-packaged rule texts specific to the electromagnetic simulation field, integrating four core elements: electromagnetic simulation specifications, material name mapping relationships, simulation scene templates, and code output formats. These are used to constrain the large language model to generate compliant simulation code. The first structure simulation script is a complete Python executable code generated by the large language model based on the user requirement prompts and system prompts, conforming to PyAEDT syntax specifications and compatible with the HFSS simulation platform. It includes a complete code script for modeling, solving, and post-processing.
[0023] The electromagnetic simulation specifications provide a unified standard for writing simulation code, including mandatory code standards such as uniform units (millimeters), solution accuracy settings, mesh generation rules, boundary condition configuration, and post-processing export requirements. The material name mapping is a pre-defined table of engineering material names and their corresponding simulation parameters, covering commonly used electromagnetic materials such as FR4, Rogers RO4350B, pure copper, and air, and including fixed parameters such as dielectric constant, loss tangent, and conductivity to avoid simulation errors caused by non-standard model naming. The simulation scene templates are pre-defined code frameworks for different electromagnetic devices, divided into four main categories: antennas, filters, connectors, and PCB signal integrity, constructing the simulation code structure. The output format requires large language models to output only clean Python code blocks, without redundant text, comments, or natural language descriptions, ensuring the code can be directly called by the executor.
[0024] This system utilizes mainstream large language models such as Claude or GPT, the PyAEDT open-source library, and the HFSS electromagnetic simulation platform. First, on the interactive interface, the user inputs relevant requirement prompts based on the prompts. The system then captures the content of the input text through a pre-defined text transmission interface and aggregates it into standardized requirement prompts. For example, inputting "Design a 2.4GHz rectangular patch antenna, FR4 substrate, thickness 1.6mm, dielectric constant 4.4, requirement S11 < -10dB, operating bandwidth covering 2.4-2.48GHz" extracts the operating frequency, material parameters, dimensional constraints, and electromagnetic performance indicators, completing the requirement prompt encapsulation. Next, it retrieves locally stored system prompt text for electromagnetic simulation, including PyAEDT interface specifications, material mapping tables, four scene templates, and pure code output rules. Finally, the standardized requirement prompts are concatenated and merged with the system prompts to form the input prompts. By calling the Claude large language model via an API, input prompts are fed into the Claude large language model. The model, combined with formulas from the field of electromagnetic physics, processes the data automatically, outputting a first-level structural simulation script that includes all modules: project initialization, parametric modeling, material assignment, boundary conditions, frequency sweep solution, S-parameter export, and project saving. By calling the large language model, the technical barrier of manually writing traditional electromagnetic simulation scripts is broken down. Non-technical engineers can quickly generate compliant simulation code using natural language, significantly improving script completeness, standardization, and efficiency.
[0025] In one embodiment, the step of inputting the demand prompt and the preset system prompt into a large language model to generate a first structural simulation script includes, but is not limited to, the following steps: Step S110: After setting the cache identifier of the system prompt word, store it in the context cache area of the large language model.
[0026] Specifically, the cache identifier is a unique character label using the fixed encoding format "EM-SIM-LLM-001" to mark prompt words specific to the electromagnetic simulation system, enabling accurate retrieval of model cache data and differentiation from other business cache data. The context cache is a dedicated memory storage area for the large language model API, used to persistently store frequently reused prompt word data, supporting multi-turn dialogue and multi-turn iteration data reuse without repeatedly transmitting the full text.
[0027] The `cache_control` interface of the Claude model API is invoked to bind a unique, fixed cache identifier "EM-SIM-LLM-001" to the complete electromagnetic simulation system prompts, setting the cache priority to high, prioritizing other cached data. When the large language model call process is triggered, the system prompts are uploaded to the context buffer. The context buffer is searched first by the cache identifier. If a match is found, the fixed system prompt data is read directly for subsequent prompt integration.
[0028] Step S120: Analyze the electromagnetic device type in the requirement prompt, and match the corresponding script framework template from the simulation scene template according to the electromagnetic device type.
[0029] Specifically, the electromagnetic device type is a simulation device category extracted from user requirement prompts through semantic parsing. It is fixedly divided into four core types: antennas, filters, connectors, and PCB signal integrity, which are the core basis for template matching. The script framework template is a standardized Python code skeleton that has been pre-tested and verified in the HFSS environment for the four device types. Each template contains six core code segments: project initialization, geometric modeling, material assignment, boundary condition configuration, frequency sweep solution, and post-processing. The code interface is compliant and can be directly reused.
[0030] The system utilizes a lightweight semantic recognition algorithm based on a large language model, loads a local keyword semantic matching library, and performs full-text keyword retrieval and semantic association matching on user-requirement prompts. Preset core search keywords include antenna, patch antenna, array antenna, filter, bandpass filter, SMA connector, coaxial connector, PCB traces, and signal integrity, accurately identifying electromagnetic device types. Based on a "device type - script framework template" mapping database, a fixed association is established. Upon identifying the corresponding device type, a uniquely matching standardized framework template is automatically retrieved. Specifically: identifying antenna-related keywords retrieves an antenna-specific template; identifying filter-related keywords retrieves a filter-specific template; identifying connector-related keywords retrieves an RF connector-specific template; and identifying PCB-related keywords retrieves a PCB signal integrity template. After retrieving the template, each template is checked to ensure it contains the six core code segments, verifying the interface specifications and parameter compatibility of each segment. If missing code segments or non-standard interfaces are found, the official standard PyAEDT code is manually completed, and abnormal syntax is corrected to ensure the template structure is complete and directly reusable. The large-scale model code generation mode has been optimized from traditional free creation to standardized templates, which can avoid problems such as missing code structure, non-standard interfaces, and random syntax errors. It can significantly improve the success rate and stability of script execution code, while providing a stable foundation for subsequent accurate parameter positioning, in-situ replacement, and iterative optimization.
[0031] Step S130: Fill the required prompt words into the corresponding code segment of the script framework template to form a comprehensive prompt word, and input the comprehensive prompt word into the large language model to generate the first structure simulation script.
[0032] Specifically, the comprehensive prompts are a complete input text composed of cached and reused system prompts, standardized user requirement prompts, and matched script framework templates. This text serves as the input basis for generating simulation scripts from large models. The parameter precise filling mapping rule establishes a pre-defined correspondence between requirement parameters and template code segments, ensuring that different requirement parameters are accurately written into the corresponding modeling, solving, and post-processing code areas.
[0033] Based on preset parameter filling mapping rules, the core parameters in the requirement prompts, such as operating frequency, substrate material parameters, geometric constraints, electromagnetic performance indicators, and frequency sweep range, are precisely filled into the corresponding code segments of the matching script framework template one by one. This achieves deep integration of requirement parameters and template skeleton, forming a comprehensive prompt with complete structure and parameters. The comprehensive prompts are then processed by the large language model to solve the configuration requirements, generating complete Python code and outputting the first structure simulation script. Through the above process, the prompts are matched and processed before being input into the large language model to form comprehensive prompts. This simplifies the number of input prompts while ensuring that the prompts meet the requirements, thereby saving processing resources of the large language model and improving execution efficiency.
[0034] Step S200: Perform syntax verification on the first structure simulation script. If the verification passes, call the script executor to run the first structure simulation script, call the preset electromagnetic simulation application program interface to connect to the simulation platform including electromagnetic device structure simulation, drive the simulation platform to build a three-dimensional physical geometric model, perform mesh generation and electromagnetic field solution on the three-dimensional physical geometric model, and obtain electromagnetic simulation results.
[0035] In one embodiment, syntax verification is a comprehensive code inspection performed on the first structure simulation script, including both syntax format legality verification and dangerous operation safety verification, to proactively avoid code execution errors and security risks, and to remove invalid code. The script executor is a pre-defined Python code execution program that integrates subprocess scheduling, timeout monitoring, real-time streaming data capture, and exception capture and reporting functions, specifically designed for independently running simulation scripts. The electromagnetic simulation application programming interface is a standardized API interface based on the PyAEDT open-source library, which can remotely connect to the Ansys ElectronicsDesktop platform to achieve unmanned wake-up, control, and operation of the HFSS software. The simulation platform is the Ansys HFSS three-dimensional electromagnetic field full-wave simulation platform, which accurately solves Maxwell's equations based on the finite element method, completing the entire process of three-dimensional modeling of electromagnetic devices, mesh generation, electromagnetic field solving, and data post-processing. The three-dimensional physical geometric model is a digital three-dimensional model constructed based on the parameters of the first structure simulation script, replicating the physical characteristics of the actual electromagnetic device, such as its external structure, substrate material, metal patches, transmission lines, and assembly relationships. Mesh generation is the discretization process by which the continuous 3D geometric model of the simulation platform is decomposed into several finite element mesh units. The mesh accuracy directly determines the accuracy of the electromagnetic field solution and the simulation efficiency. Electromagnetic field solution is the core computational process by which the simulation platform, based on adaptive mesh units, solves Maxwell's equations using finite element algorithms to accurately calculate the electromagnetic field distribution, S-parameters, gain, bandwidth, and other electromagnetic characteristics of the device. The electromagnetic simulation results are the standardized data and visualizations output by the platform after the solution is completed, including quantitative indicators such as the S-parameter matrix, resonant frequency, operating bandwidth, antenna gain, field strength distribution cloud map, and loss data.
[0036] The first-structure simulation script undergoes full code inspection using abstract syntax tree parsing technology, simultaneously performing syntax format legality checks and high-risk operation interception checks. If the syntax is compliant and there are no high-risk operations, the verification is considered passed. If syntax errors or high-risk code are found, the large model repair mechanism is automatically triggered, iterating until the script passes. After successful verification, a dedicated script executor independently schedules the task, running the simulation script as a system subprocess with a fixed 10-minute execution timeout threshold to prevent program freezes and process blockages caused by script infinite loops and resource waiting. The local HFSS simulation platform is activated via the encapsulated PyAEDT API interface, automatically completing project initialization, project creation, 3D geometric model parameterization, material parameter assignment, and automated configuration of boundary conditions and excitation sources. The platform employs an adaptive mesh generation algorithm, refining the mesh (0.1mm accuracy) in the core radiation region, signal transmission region, and field strength concentration region of the device, while simplifying the mesh in empty air regions and field-free regions, balancing simulation accuracy and computational efficiency. Electromagnetic field numerical solutions are performed according to the user-preset frequency sweep range, completing the calculation of electromagnetic characteristics across the entire frequency band. After the solution is completed, the system automatically executes post-processing commands to batch export S-parameter data reports, electromagnetic field distribution cloud maps, and performance index parameter tables. All files are automatically classified and archived locally and synchronized to the database, supporting subsequent deviation comparison and iterative optimization.
[0037] The above process automates the entire simulation script process, from generation, security verification, automated execution to electromagnetic solution and result archiving, replacing the traditional mode of manual software operation and code debugging. The adaptive mesh generation strategy balances simulation accuracy and solution speed, and the simulation result error is controlled within the engineering allowable range, resulting in high accuracy. The subprocess isolation running mode completely avoids the problem of overall system crash caused by single script anomalies, greatly improving the stability and robustness of the simulation process.
[0038] In one embodiment, the syntax validation of the first structure simulation script includes, but is not limited to, the following steps: Step S210: Perform abstract syntax tree parsing on the first structure simulation script, traverse each node of the abstract syntax tree, and identify function call statements and system command statements in the first structure simulation script.
[0039] Specifically, the Abstract Syntax Tree (AST) is a tree-structured abstract representation of Python source code. Through lexical and syntactic analysis, it breaks down complete code into independent syntactic nodes such as function calls, variable assignments, loop statements, system commands, and constant definitions, accurately reflecting the code's true syntactic structure and execution logic. Function call statements are lines of code in the simulation script that call PyAEDT library functions and built-in Python functions; they are the core code units for simulation modeling, parameter configuration, solving, and post-processing. System command statements refer to lines of code in the script that involve operating system interaction, including system-level operation statements such as file reading / writing, deletion, network requests, system process start / stop, and disk traversal; these are the core targets for security verification.
[0040] The Python native AST standard library is invoked to read the complete source code of the first-structure simulation script. The script is then uniformly encoded into UTF-8 format, and blank lines, redundant indentation, redundant single-line comments, and invalid line breaks are removed, preserving the complete executable code logic and avoiding interference from invalid characters in syntax parsing. The preprocessed script is then scanned line by line and character by character using the `ast.tokenize()` interface to generate a standardized token sequence. Syntactic matching is performed on the ordered token sequence to verify the code's syntactic validity. Based on the code execution logic and nesting relationships, the hierarchical structure is analyzed, distinguishing between global code segments, function internal code segments, loop logic, parameter assignment logic, and function call logic, thus constructing a basic syntactic framework. The `ast.parse()` core interface is called to automatically transform the syntactic framework into a multi-level abstract syntax tree with `Module` as the root node, strictly adhering to the official Python AST node specifications. For the simulation script's specific structure, corresponding child nodes are automatically attached: `Assign` nodes are generated for parameter assignment statements, `Call` nodes for PyAEDT modeling functions, `Import` nodes for library import statements, and `Constant` nodes for parameter definitions. It automatically generates a structured and standardized abstract syntax tree, fully restoring the code hierarchy.
[0041] For the generated syntax tree, a depth-first traversal algorithm is used to traverse all nodes layer by layer, accurately filtering out Call type nodes (corresponding to all function call statements) and System type nodes (corresponding to all system command statements). Irrelevant nodes such as variable definitions, comment text, constant assignments, and blank lines are automatically filtered out, focusing on core risk assessment targets. For the selected target risk nodes, complete source information is automatically collected, including the called function name, module path, precise line number, column offset, call parameter content, and original code statement. This information is then compiled into a detailed list of script operation behaviors, providing accurate data support for subsequent risk matching, location, and remediation. Analysis through an abstract syntax tree avoids the limitations of regular expression matching and keyword filtering, providing accurate and reliable underlying data support for subsequent script security verification.
[0042] Step S220: Match the function call statement and the system command statement with a preset dangerous operation blacklist, which includes operations that trigger system-level sensitive events.
[0043] Specifically, the dangerous operation blacklist includes operations that trigger system-level sensitive events, such as file deletion, file rewriting, external network requests, system process startup / shutdown, registry modification, and local disk traversal. System-level sensitive events refer to operations that, upon execution, would cause local project file corruption, leakage of sensitive simulation data, abnormal system resource consumption, HFSS software crashes, or device security risks. A high-risk function mapping list is loaded, which is a list of specific executable functions corresponding to the blacklist, including high-risk interfaces such as os.remove, os.rmdir, requests.get, subprocess.call, and shutil.rmtree. A three-level progressive matching mechanism of "full-name precise matching + alias source matching + scenario semantic verification" is adopted to achieve full coverage and accurate identification of explicit and implicit high-risk operations for all function call nodes and system command nodes extracted by AST parsing. The specific matching logic is as follows: For all high-risk operations within the high-risk function mapping list, a standardized storage module path + function name structured field and its corresponding standard hash value are created. For each Call node extracted from the abstract syntax tree, complete call information is automatically extracted, including the imported module path, underlying library affiliation, and full function name. This information is then concatenated to generate a comparison structured field consistent with the blacklist format, and the unique hash value of this field is calculated in real time. The comparison hash value is then compared one-to-one with the pre-stored standard hash value in the blacklist. If the hash values are completely identical, the fields are considered to overlap completely, and the current call statement is an explicit high-risk operation. If the hash values are inconsistent, there is no overlap, and the process proceeds to the next level of verification.
[0044] For call nodes that do not match at the first level, a hidden risk tracing and judgment mechanism is activated. The Assign and Import nodes of the AST syntax tree are traversed in reverse to search for binding relationships where high-risk standard fields are assigned to custom variables or high-risk function aliases are imported. The variable-bound function fields obtained from the search are then compared with the blacklist standard fields using hash overlap. If the original function field obtained from the tracing overlaps with a blacklist high-risk field, and the current script contains a call to that custom variable, it is determined to be a hidden high-risk operation, thus patching the vulnerability of polymorphic code evasion detection.
[0045] To address the issue of misclassification of functions with the same name, a whitelist of scenarios specific to electromagnetic simulation is used to perform semantic secondary verification on fields that overlap in the first two levels of judgment. If a field exists in the whitelist and its name only happens to overlap, the mismatch is removed; if it does not match the whitelist, it is marked as high-risk, further improving the accuracy of the matching.
[0046] For each high-risk operation matched against the blacklist, the system automatically marks the risk level (high / medium), accurately records the corresponding line number, column offset, complete dangerous code content, and risk type, and generates a standardized risk detection log in real time. If no high-risk operation is matched, the script is marked as safe. Through these three layers of processing, the executability of the generated structural simulation script is ensured, and the accuracy of automated generation is improved.
[0047] Step S230: If neither the function call statement nor the system command statement is found to be on the dangerous operation blacklist, the first structure simulation script is determined to have passed the verification.
[0048] Specifically, if neither the function call statement nor the system command statement is found in the blacklist of dangerous operations, it indicates that there is no security risk in not executing the script. The first structure simulation script is then deemed to have passed verification, allowing the subsequent script execution and simulation solution process to proceed. This improves the stability and reliability of the entire simulation process and reduces the cost of manual troubleshooting and repair.
[0049] Step S240: If the dangerous operation blacklist is hit, the hit dangerous operation statement and its location information are sent back to the large language model, the large language model is called to generate a correction script, the correction script is used as the first structure simulation script, and the step of parsing the first structure simulation script using an abstract syntax tree is executed.
[0050] Specifically, if a node matches the blacklist of dangerous operations, it indicates a dangerous operation. The matched dangerous operation statement and its location information are sent back to the large language model. The Claude large language model is invoked, and a repair instruction is issued simultaneously: only high-risk code is deleted / replaced, while the core logic of simulation modeling, material assignment, solving, and post-processing is fully preserved. High-risk functions called during deformation are replaced in compliance with regulations, and missing code logic is simultaneously supplemented to ensure the script structure is complete and its functionality remains unchanged after repair, generating a corrected script. The generated corrected script is used as the first structural simulation script, and the step of parsing the abstract syntax tree of the first structural simulation script is executed. This process is repeated cyclically for a new round of traversal verification, continuously iterating and repairing to ensure the script can run normally. Through the automatic repair process, an automated correction loop is achieved, improving the degree of automation while ensuring the accuracy and security of script generation.
[0051] In one embodiment, the invocation of the script executor to run the first structure simulation script includes, but is not limited to, the following steps: Step S250: If the first structure simulation script passes the verification, write the first structure simulation script into the temporary execution path, call the script executor to run the first structure simulation script as a subprocess, and set the execution timeout threshold.
[0052] Specifically, the temporary execution path is a randomly generated, unique temporary folder path that is used to store compliant simulation scripts to be executed separately, avoiding conflicts with project files and historical files. The child process execution mode is a code execution method independent of the system's main process, possessing independent memory space and execution environment, achieving complete isolation between the simulation task and the main control system. The execution timeout threshold is a preset maximum script runtime threshold, set to 10 minutes, to avoid permanent process blockage caused by script infinite loops, resource waiting, and software freezes.
[0053] After script verification, the system generates a unique random temporary folder path using the UUID algorithm and creates an independent storage directory. The compliant first-structure simulation script is completely written to this temporary path, generating a directly executable Python source code file, and file permissions are locked to prevent tampering. The script executor calls the subprocess library to create an independent child process, independent of the main process's control. This child process loads the simulation script from the temporary path and starts the simulation execution task. The main process is only responsible for monitoring, logging, and exception handling, and does not participate in script computation. The stdout standard output pipe and stderr standard error pipe of the child process are bound using subprocess.PIPE to prepare for subsequent data capture. A 10-minute execution timeout threshold is uniformly configured for all child process simulation tasks. The running status of the child processes is monitored in real time. If the timeout reaches the threshold and execution is not completed, the child process is automatically terminated, the task is judged as timeout failure, and the exception repair process begins. The subprocess isolation running mode completely decouples the simulation task from the main control system. Script execution errors, memory leaks, and program crashes will not affect the normal operation of the main control system, greatly improving the overall system stability. Temporary path isolation storage avoids file conflicts and data tampering issues. Fixed timeout thresholds effectively prevent process blockage and ensure the controllability of simulation tasks.
[0054] Step S260: During the execution of the subprocess, the output stream and error stream of the script executor are captured in real time, and the execution status of the first structure simulation script is determined based on the error stream.
[0055] Specifically, the output stream refers to the standard log information output during normal script operation, including positive data such as modeling progress, solution progress, parameter loading status, and normal execution prompts, used to monitor the normal simulation process. The error stream refers to the standard error information output when the script malfunctions, including core data such as error type, error description, code stack, and cause of the exception, serving as the core basis for fault location and repair. The real-time capture mechanism refers to a millisecond-level data stream monitoring mode that synchronously collects all output and error data during the subprocess's execution. At the moment the subprocess starts, the system simultaneously starts dual data stream monitoring threads, binding them to the standard output stream and standard error stream respectively, setting a millisecond-level real-time capture frequency to monitor the script's running status throughout. During simulation execution, the system captures normal operation logs, progress information, and parameter loading results from the output stream in real time, and synchronously captures all abnormal error data from the error stream, caching it in system memory in real time to prevent data loss. The execution status is judged in real time based on the error stream data: if there are no error messages in the error stream and the output stream shows that the solution is complete, the execution is considered successful; if there is valid error data in the error stream, the program terminates abnormally, or times out, the execution is considered failed. It enables full-process visual monitoring of the simulation operation status, accurately distinguishes between normal operation and abnormal fault scenarios, and provides complete and accurate raw data support for subsequent error location, intelligent repair and process control.
[0056] It should be noted that when the execution state is free of error flow, the subsequent modeling and processing are carried out according to the first structural simulation script to generate electromagnetic simulation results. Step S300 is then executed to proceed with subsequent steps and realize a complete automated structural simulation process.
[0057] Step S270: If the execution status is execution failure, extract the error type and error stack information from the error stream, input the error type, the error stack information and the first structure simulation script into the large language model, and output the repaired script.
[0058] Specifically, error types refer to the standardized classification of script execution anomalies, including common failure types in simulation scenarios such as parameter type errors, API call errors, material parameter mismatches, software version compatibility errors, resource permission errors, and memory overflow errors. Error stack information refers to the complete code call chain corresponding to the error, the line number of the exception code, parameter exception details, and the program termination node, providing data for accurately locating the root cause of the fault. The repaired script is a new executable script generated by the large model based on the complete error context, accurately locating the fault point, analyzing the cause of the anomaly, correcting the erroneous code, and retaining the normal logic.
[0059] When execution fails, the error stream data is parsed, invalid logs and redundant information are filtered out, and core data such as standardized error types, complete error stack information, abnormal code locations, and fault descriptions are accurately extracted and packaged into a fault data package. The extracted error type, error stack information, and the original first-structure simulation script are bound together and input into the called Claude large language model, providing the model with a complete context for fault reproduction, localization, and repair. The large model, combined with PyAEDT interface specifications, HFSS simulation rules, and electromagnetic domain knowledge, automatically analyzes the root cause of the fault, corrects the abnormal code, and generates a syntactically compliant and executable repaired script. Through this process, manual fault analysis and code modification are replaced, achieving fully automated fault location and repair for simulation script execution, lowering the barrier to entry for non-professional users.
[0060] Step S280: Replace the first structure simulation script in the temporary execution path with the repaired script and re-execute it until the execution is successful or the preset retry limit is reached.
[0061] Specifically, delete the invalid original first-structure simulation script from the temporary execution path, and write the completely repaired script generated by the large model into that path, keeping the file path and execution entry point unchanged. Only update the code content; no modification to the process configuration is required. After the script replacement is complete, repeat steps S250-S270 to run and test the script. Increment the counter by 1 after each successful repair execution. If the execution is successful within the preset retry limit, proceed normally to the subsequent result parsing process.
[0062] It should be noted that once the preset retry limit is reached, the iteration process terminates, all error messages and repair attempt logs are compiled, a fault report is generated and sent back to the user, prompting manual intervention to adjust requirements or environment configurations. By constraining the retry limit, the problem of infinite iteration loops can be avoided, achieving a balance between intelligence and controllability, and ensuring the stable operation of the platform.
[0063] Step S300: Extract the simulation performance matrix of the electromagnetic simulation results, and compare the eigenvalues of the simulation performance matrix with the values of the electromagnetic performance indicators to obtain a set of deviation indicators.
[0064] In one embodiment, the simulation performance matrix is a multi-dimensional standardized quantized dataset output after the simulation solution is completed. It is the core data set characterizing the performance of electromagnetic devices, including full-dimensional simulation parameters such as S11 return loss, S21 insertion loss, resonant frequency, operating bandwidth, antenna gain, VSWR, and loss tangent. The electromagnetic performance indicators are the device design target thresholds preset in the user's initial requirement prompts, including quantitative standards such as target resonant frequency, maximum allowable S11 loss, minimum operating bandwidth, and minimum gain. They serve as the basis for determining whether the simulation results are qualified. The deviation indicator set is a multi-dimensional deviation quantified data set generated by comparing the eigenvalues of the simulation performance matrix with the user's preset electromagnetic performance indicators one by one. It includes the deviation value, deviation ratio, and deviation direction (too large / too small) of each indicator, serving as the basis for subsequent parameter iterative optimization.
[0065] After the simulation is completed, the system automatically reads the original simulation data exported from HFSS according to preset feature value extraction rules, and extracts core performance parameters in batches: capturing key data such as full-band S-parameter values, actual resonant frequency, effective operating bandwidth, maximum antenna gain, and peak insertion loss. After normalization, these data are organized into a standardized two-dimensional simulation performance matrix to unify data accuracy. The preset feature value extraction rules include effective frequency band filtering, peak feature extraction, data normalization, and invalid value removal. These rules are used to accurately extract effective performance parameters from the original simulation results and remove invalid and redundant data. Effective frequency band filtering uses the target operating frequency band preset by the user as a threshold, retaining only simulation data within the frequency band and removing invalid sampled data outside the band. Peak feature extraction focuses on capturing core feature values for different electromagnetic performance indicators, rather than retaining all sampled data. For S11 return loss, the minimum loss peak value within the operating frequency band is automatically captured; for operating bandwidth, the continuous effective frequency range that meets the S11 < -10dB threshold is captured; for antenna gain, the maximum gain value within the frequency band is captured; for insertion loss, the maximum loss peak value within the frequency band is captured.
[0066] The extracted feature values of the simulation performance matrix are precisely aligned and compared with the target values of electromagnetic performance indicators in the user's requirement prompts, establishing a one-to-one correspondence between "simulation measured value - target standard value" and covering all preset performance indicators. Deviation data for each indicator is calculated, with core calculation dimensions including: absolute deviation value = measured value - target value, and relative deviation ratio = absolute deviation value / target value × 100%. The deviation direction is also marked (positive deviation is larger / negative deviation is smaller). All deviation data, deviation levels, and outliers are summarized to generate a complete and structured set of deviation indicators, accurately locating performance parameters that have not met the standards. This achieves automated quantitative analysis of simulation results with high data accuracy. The structured deviation indicator set can accurately locate device performance shortcomings and parameter deviation problems, providing precise and quantitative data support for subsequent adaptive parameter adjustment and simulation iterative optimization.
[0067] Step S400: If the deviation index set does not meet the preset convergence condition and does not reach the preset number of iterations, the deviation index set and the parameter variables of the three-dimensional physical geometry model are input into the large language model for deviation analysis to obtain a parameter correction strategy. The parameter variables are updated according to the parameter correction strategy to generate a second structure simulation script.
[0068] In one embodiment, the preset convergence condition is a pre-defined simulation iteration termination criterion, which means that the relative deviation ratio of all electromagnetic performance indicators in the deviation index set is ≤3%, indicating that the current electromagnetic device performance has met the user's design goals and no further iterative optimization is needed. The preset iteration number is the maximum number of iterations set, which can be 10 times, to avoid the infinite iteration problem caused by non-convergence in extreme scenarios, balancing optimization accuracy and system operating efficiency. Parameter variables refer to the adjustable core physical structure parameters in the three-dimensional physical geometric model, which are key variables affecting the performance of electromagnetic devices. These include fine-tunable parameters such as antenna patch length, patch width, substrate thickness, feed position, filter resonant pillar size, and connector aperture, and are the adjustment objects of iterative optimization. The parameter correction strategy is a standardized parameter adjustment scheme generated by the large language model combined with deviation distribution characteristics, electromagnetic physical characteristics, and device structural constraints. It includes the adjustment direction of each parameter variable, the basic adjustment amount, and the associated constraint conditions, and is used to guide the accurate updating of parameters. The second structure simulation script is a completely new compliant simulation script based on the first structure simulation script. It only completes the precise replacement of the core parameter variable values, while the rest of the code structure, simulation configuration, and execution logic remain completely unchanged. It is used for a new round of simulation iteration and solving.
[0069] The relative deviation ratios of each performance index within the deviation index set are measured to determine if all meet the convergence condition of ≤3%. Next, the number of iterations completed is counted to determine if it is less than a preset upper limit of 10 iterations. If the preset number of iterations has not been reached and the deviation index set meets the preset convergence condition, the adjustment ends, a second structure simulation script is generated, and step S500 is executed. If the preset number of iterations has been reached but the preset convergence condition has not been met, manual intervention is prompted, and the calculation is recalculated after intervention.
[0070] If the deviation index set fails to meet the preset convergence condition and the preset number of iterations has not been reached, it indicates that further adjustments are needed. The generated structured deviation index set, the original values of all parameter variables corresponding to the 3D physical geometric model, the physical meaning of the parameter variables, and their performance correlations are fully encapsulated into a standardized input data package and input to the called Claude large language model. Here, the deviation index set represents the quantified deviation data between the simulated measured values and the target values, and the parameter variables represent the original structural parameters of the current simulation model, together serving as the basis for model deviation analysis and the generation of correction strategies. The large language model loads its built-in electromagnetic device parameter correlation knowledge base, combines it with electromagnetic physical constraint rules for parsing, and obtains the parameter correction strategy output by the large language model. Based on the parameter correction strategy, the parameter variables are adjusted to generate a second structural simulation script. By using a dual constraint of convergence threshold and iteration count, the problems of invalid and infinite iterations are completely avoided. By relying on a large model and combining electromagnetic physics rules to analyze deviations, the precise correlation and matching of "performance deviation - structural parameters" is achieved, eliminating blind parameter adjustments. By adopting an optimization method that only updates parameters and retains the overall script structure, the targeting of iterative optimization is guaranteed, while avoiding the randomness of code and the risk of new errors caused by rewriting the entire script, thus greatly improving the efficiency and stability of iterative optimization.
[0071] In one embodiment, updating the parameter variables according to the parameter correction strategy to generate a second structural simulation script includes, but is not limited to, the following steps: Step S410: Perform abstract syntax tree parsing on the first structure simulation script to generate the abstract syntax tree corresponding to the first structure simulation script.
[0072] Specifically, the complete source code of the compliant first-structure simulation script stored in the temporary execution path is read, uniformly encoded in UTF-8 format, and blank lines, redundant indentation, invalid comments, and redundant newlines at the end are automatically removed, retaining only the executable core code and eliminating the interference of invalid characters on parsing accuracy. The native Python AST standard library is called to perform lexical analysis, syntax verification, and hierarchical structure analysis in sequence. A standardized abstract syntax tree with Module as the root node is generated through the core interface ast. For the simulation script's specific structure, core child nodes such as Assign nodes, Call function call nodes, and Constant nodes are precisely attached. Then, a depth-first traversal algorithm is used to traverse all child nodes of the syntax tree, fixing the line number, col_offset column offset, end line, and end column position information of each node, achieving a precise mapping between syntax tree nodes and the original source code; finally, the complete syntax tree is serialized and stored. The above process is similar to step S210 and will not be elaborated here. Constructing the abstract syntax tree provides an accurate basis for subsequent adjustments.
[0073] Step S420: Traverse the assignment statement nodes in the abstract syntax tree to obtain the variable names of each assignment statement node.
[0074] Specifically, assignment statement nodes are the core syntax nodes in the abstract syntax tree used to define parameter variables and assign initial values. They serve as the storage carriers for geometric parameters, material parameters, and simulation configuration parameters in the simulation script. Variable names are parameter identifiers defined on the left side of the assignment statement, uniquely distinguishing each simulation parameter, such as `patch_length` (patch length), `sub_h` (substrate thickness), and `freq_target` (target frequency), and are keywords for parameter matching. A depth-first traversal algorithm is used to traverse all child nodes of the abstract syntax tree layer by layer, accurately filtering and extracting all Assign type assignment statement nodes, automatically filtering irrelevant nodes such as function calls, loop statements, comments, and constant outputs, focusing on core parameter definition nodes. The `targets` attribute of each Assign node is traversed, identifying the variable identifiers on the left side of the node, removing variable modifiers and format characters, and extracting clean, standardized variable names; simultaneously, the original parameter values corresponding to that node are associated and bound, forming a "variable name - original value" mapping dataset. All parsed variable names are summarized, automatically removing duplicate variables, generating a complete list of parameter variables for the first-structure simulation script, unifying the variable naming format, and providing a standardized data foundation for subsequent parameter matching.
[0075] Step S430: Match the variable names of each assignment statement node with the names of the parameter variables to determine the target assignment statement node corresponding to the parameter variables.
[0076] Specifically, the parameter variables are the structural parameters that need to be adjusted and optimized in the parameter correction strategy, serving as the target objects for iterative optimization. The target assignment statement node is the Assign assignment node that completely matches the parameter variable name, and is the sole target node for subsequent parameter value replacement. The standardized names of all parameter variables in the parameter correction strategy are extracted and matched one-to-one with the list of script variable names collected in step S420, constructing a dataset of variable mappings to be matched. A character-complete matching algorithm is used to compare the names of the parameter variables to be optimized with the names of the script parsed variables, strictly enforcing full-character equivalence judgment. A match is considered successful only when the two names are completely identical in characters, capitalization, and suffixes. The Assign assignment nodes corresponding to successfully matched variables are marked as target assignment statement nodes, and the corresponding original parameter values and node position information are bound synchronously. Variables that fail to match are automatically marked as invalid parameters and do not participate in this iteration of optimization, avoiding invalid operations. Through strict full-character precise matching, it is ensured that only target parameters are optimized without modifying other normal parameters; the optimization nodes are accurately located, narrowing the subsequent source code location range and improving the efficiency and accuracy of parameter replacement.
[0077] Step S440: Determine the source code location of the parameter definition statement corresponding to the parameter variable in the first structure simulation script based on the position attribute of the target assignment statement node.
[0078] Specifically, the node's positional attributes are the precise coordinate parameters of the abstract syntax tree node, including `lineno` (statement start line number), `col_offset` (parameter value start column offset), `end_lineno` (statement end line number), and `end_col_offset` (parameter value end column offset), serving as the basis for source code location. The parameter definition statement is the complete line of code in the script used to assign the original value of the parameter variable, containing the variable name, assignment operator, original value, unit comments, and other complete content. The complete positional attribute data of the target assignment statement node is read to accurately obtain the coordinates of the parameter definition statement's start line, end line, parameter value start column, and parameter value end column. The complete first-structure simulation script is divided into a list of strings line by line. Based on the node's start and end line numbers, the target code line corresponding to the parameter definition statement is precisely located, eliminating interference from other irrelevant code lines. Based on the start and end column offsets, the pure character range of the parameter's original value is precisely selected within the target code line, automatically removing irrelevant characters such as variable names, assignment operators, comments, and units, locking the value region to be replaced, thus obtaining the source code location in the first-structure simulation script. By constructing an abstract syntax tree, it provides core guarantees for parameter tuning, variable location, and other functions.
[0079] Step S450: Calculate the updated value of the parameter variable according to the parameter correction strategy.
[0080] In one embodiment, calculating the updated value of the parameter variable according to the parameter correction strategy includes, but is not limited to, the following steps: Step S451: Extract the adjustment direction and basic adjustment amount corresponding to the parameter variable from the parameter correction strategy, wherein the adjustment direction indicates whether the parameter variable should be increased or decreased.
[0081] Specifically, both the adjustment direction and the base adjustment amount are parameters output by the large model. The adjustment direction indicates whether the parameter variable should increase or decrease, used to determine the polarity of the parameter value adjustment. The base adjustment amount is the standard adjustment range output, serving as the baseline adjustment value for unbiased scaling, with units consistent with the corresponding parameter variable. From the structured data of the parameter correction strategy (in JSON format), the corresponding adjustment direction identifier and base adjustment amount value are extracted from the current parameter variable to complete data validation. If the adjustment direction is to increase, the polarity is marked as +1; if it is to decrease, the polarity is marked as -1, and the base adjustment amount retains uniform precision. This provides standardized basic data for subsequent adaptive scaling calculations.
[0082] Step S452: Obtain the current deviation amount corresponding to the target performance index associated with the parameter variable from the deviation index set.
[0083] Specifically, electromagnetic performance indicators strongly correlated with current parameter variables are considered, such as patch length corresponding to resonant frequency and substrate thickness corresponding to bandwidth and loss. Parameter adjustments directly affect the performance of these indicators. The current deviation refers to the absolute difference between the simulated measured performance indicator and the user-preset target value, serving as core data for quantifying the magnitude of the deviation. Based on a preset correlation mapping table between parameters and performance indicators, the target performance indicator corresponding to the current parameter variable is matched from the deviation indicator set, and the current deviation of that indicator is extracted. Current deviation = measured value - target value, filtering out irrelevant performance deviation data. This achieves precise binding between parameter adjustments and performance deviations, ensuring that each parameter optimization targets the corresponding performance weakness and improving the targeting of iterative optimization. The correlation mapping table is a two-dimensional correlation data table, constructed offline based on classical electromagnetic transmission line theory, antenna radiation mechanism, and filter resonance characteristics, combined with a large amount of HFSS simulation and measured sensitivity experimental data. After batch parameter scanning tests, the core structural parameters with the highest sensitivity and greatest influence on each performance indicator are selected, forming a correlation relationship storage table.
[0084] For example, in the mapping table, patch length corresponds to the resonant frequency; the influence rule is that as the length increases, the resonant frequency decreases; patch width corresponds to the operating bandwidth; the influence rule is that as the width increases, the bandwidth widens; substrate thickness corresponds to the insertion loss and VSWR; feed position corresponds to the impedance matching and S11 return loss; and resonant pillar size corresponds to the filter passband frequency. A variable name hash-based precise retrieval and matching algorithm is used to achieve fully automatic deviation extraction. Specifically, this includes reading the name of the variable to be tested and generating a field hash value; performing an equivalence match with the pre-stored parameter variable name field hash library in the mapping table; if the hashes are completely identical, the unique corresponding target electromagnetic performance indicator is locked; using the performance indicator name as the retrieval primary key, the corresponding measured value, target value, and absolute deviation are precisely indexed in the structured deviation indicator set; and deviation data of other irrelevant performances are removed, retaining only the valid current deviation corresponding to the current parameter, thus completing the precise extraction of deviation data.
[0085] Step S453: Calculate the ratio of the current deviation to the target value of the target performance index to obtain the deviation ratio.
[0086] Specifically, the ratio of the current deviation to the target value of the target performance indicator is calculated, multiplied by 100%, and the absolute value is calculated to avoid interference from positive and negative deviations, quantifying only the magnitude of the deviation. This provides a unified data basis for subsequent adaptive scaling factor calculations.
[0087] Step S454: Determine the adjustment scaling factor based on the deviation ratio; the larger the deviation ratio, the larger the adjustment scaling factor.
[0088] Specifically, the scaling factor is used to dynamically correct the weight coefficient of the basic adjustment amount, realizing an adaptive optimization logic where the larger the deviation, the larger the adjustment magnitude. The larger the deviation ratio, the larger the scaling factor.
[0089] In one embodiment, determining the scaling factor based on the deviation ratio includes, but is not limited to, the following steps: When the deviation ratio is less than a first threshold, the adjustment scaling factor takes a first preset value less than 1; when the deviation ratio is greater than a second threshold, the adjustment scaling factor takes a second preset value greater than 1; when the deviation ratio is between the first threshold and the second threshold, the adjustment scaling factor is determined by linear interpolation based on the deviation ratio. Wherein, the first threshold is less than the second threshold.
[0090] In some possible embodiments of this application, the first threshold and the second threshold are deviation ratio judgment thresholds, which can be set to 5% and 15%, respectively. When the deviation ratio is < 5%, it is determined to be close to the convergence state, and the scaling factor is adjusted to a first preset value, which can be 0.4, to achieve small-scale fine-tuning and avoid overcorrection. When the deviation ratio is > 15%, it is determined to be seriously deviating from the target, and the scaling factor is adjusted to a second preset value, which can be 1.8, to amplify the adjustment range, quickly reduce the performance deviation, and improve the convergence speed. When 5% ≤ deviation ratio ≤ 15%, the scaling factor is continuously calculated using a linear interpolation formula. The specific calculation process is: scaling factor = first preset value + (deviation ratio - first threshold) × (second preset value - first threshold) / (second threshold - first threshold), which realizes that the scaling factor increases smoothly and linearly with the deviation ratio, ensuring that the adjustment range is continuous without sudden changes. By using a three-level branch threshold determination and a linear interpolation algorithm, the parameter adjustment range can be adaptively adapted to all scenarios. It can finely adjust small deviations and quickly correct large deviations, which solves both the optimization oscillation problem of small deviations and the slow convergence problem of large deviations, thus greatly improving the iterative convergence efficiency and optimization accuracy.
[0091] Step S455: Multiply the base adjustment amount by the adjustment scaling factor to obtain the actual adjustment amount.
[0092] Specifically, the basic adjustment amount is multiplied by the adjustment scaling factor to obtain the actual adjustment amount, so that the parameter adjustment range is fully adapted to the current performance deviation state, taking into account both optimization speed and optimization accuracy. Since the basic adjustment amount output by the large model is too large or too small, it can be adjusted by adjusting the scaling factor to adapt to the current electromagnetic device indicators, which is conducive to rapid simulation construction and improves efficiency.
[0093] Step S456: According to the adjustment direction, increase or decrease the original value of the parameter variable by the actual adjustment amount to obtain the updated value of the parameter variable.
[0094] Specifically, since the adjustment direction of the large model output is accurate, when the adjustment direction is increasing, the updated value = the original value of the parameter variable + the actual adjustment amount; when the adjustment direction is decreasing, the updated value = the original value of the parameter variable - the actual adjustment amount. This achieves automated and precise updating of parameter variables, replacing manual experience-based adjustments, significantly improving the accuracy and adaptability of parameter optimization, and benefiting non-professionals in the work.
[0095] Step S460: Replace the original value in the parameter definition statement with the updated value, keep the script content in the first structure simulation script unchanged except for the parameter definition statement, and generate the second structure simulation script.
[0096] Specifically, based on the position in the parameter definition statement locked in step S440, the original value in the parameter definition statement is replaced with the updated value at that position, while maintaining the original code line format, comments, units, and indentation. After the replacement, the split code lines are reassembled into complete source code, ensuring no formatting damage or missing characters. The modified complete source code is then stored and a second-structure simulation script is generated, automatically marking the iteration count, updated parameter information, and update time for easy tracing of subsequent iterations. This approach minimizes changes to the script content, avoiding the randomness, syntax errors, and logical changes caused by rewriting the entire code of a large model; it ensures a high degree of uniformity in the script structure across multiple iterations, facilitating parameter change tracing and performance comparison analysis, and significantly improving the stability and reliability of the iteration process.
[0097] Step S500: Use the second structure simulation script as the first structure simulation script, and execute the step of performing syntax verification on the first structure simulation script until the deviation index set meets the preset convergence condition or reaches the number of iterations. Extract the parameter variables that meet the current conditions and use them as the physical structure parameters of the electromagnetic device.
[0098] In one embodiment, the iterative loop mechanism uses the generated second structure simulation script as a completely new first structure simulation script, repeatedly executing a closed-loop process of verification, execution, solution, deviation comparison, and parameter optimization. The iteration termination condition is a dual termination condition: first, the deviation ratio of all performance indicators is ≤3% (convergence achieved); second, the cumulative number of iterations reaches 10 (maximum termination). Iteration stops when either condition is met. The parameter variables at the time the current condition is met represent the set of parameter variables corresponding to the current simulation model at the time of iteration termination, which are the electromagnetic device structural parameters with optimal performance and conforming to the design objectives.
[0099] Based on the second structure simulation script generated in step S400, the first structure simulation script is used. The script execution entry point is reset, and the process automatically jumps to step S200, repeating the entire process of syntax verification, security detection, subprocess execution, simulation solving, performance extraction, and deviation comparison. After each complete optimization loop, a counter automatically increments by 1, recording the cumulative iteration count in real time for upper limit determination. After each deviation comparison, a termination determination is performed synchronously: first, a convergence determination, checking if the deviation ratio of all performance indicators is ≤3%; second, a count determination, checking if the cumulative iteration count is ≥10. If the convergence condition is met, the current simulation performance is deemed satisfactory, and all current parameter variables are extracted as the optimal physical structure parameters. If the iteration upper limit is reached but convergence is not complete, the set of parameters with the closest performance and smallest deviation among 10 iterations is selected as the optimal physical structure parameters. The final optimal physical structure parameters, iteration process data, performance deviation change curves, and optimal simulation results are all summarized and archived to generate a final device design parameter report.
[0100] A fully automated closed-loop generation and iterative optimization system was constructed, eliminating the need for manual intervention in parameter adjustment and simulation retry, thus achieving intelligent optimization of electromagnetic device design. Through dual constraints of convergence threshold and iteration upper limit, optimization accuracy is guaranteed while avoiding the risk of infinite iteration. The final output optimal parameters take into account both design specifications and engineering feasibility, with iterative convergence accuracy within 3%. Compared with traditional manual iteration, efficiency is greatly improved, and device design and debugging costs are significantly reduced.
[0101] like Figure 2As shown in the figure, this application embodiment provides an electromagnetic device simulation generation and optimization system 100 based on a large language model. This system 100 acquires user-inputted electromagnetic device requirement prompts via a data acquisition module 110, inputs the requirement prompts and preset system prompts into the large language model, and generates a first structural simulation script. The requirement prompts include electromagnetic performance indicators, and the system prompts include electromagnetic simulation specifications, material name mapping relationships, simulation scene templates, and output formats. A verification simulation module 120 performs syntax verification on the first structural simulation script. If the verification passes, a script executor is invoked to run the first structural simulation script. A preset electromagnetic simulation application interface is invoked to connect to a simulation platform including electromagnetic device structural simulation, driving the simulation platform to construct a three-dimensional physical geometry model. The three-dimensional physical geometry model is then meshed and the electromagnetic field is solved to obtain... The electromagnetic simulation results are obtained; the deviation calculation module 130 extracts the simulation performance matrix of the electromagnetic simulation results, and compares the eigenvalues of the simulation performance matrix with the values of the electromagnetic performance indicators to obtain a deviation index set; then, the parameter adjustment module 140, when the deviation index set does not meet the preset convergence condition and has not reached the preset number of iterations, inputs the deviation index set and the parameter variables of the three-dimensional physical geometry model into the large language model for deviation analysis to obtain a parameter correction strategy, and updates the parameter variables according to the parameter correction strategy to generate a second structure simulation script; the script optimization module 150 uses the second structure simulation script as the first structure simulation script, and executes the step of performing syntax verification on the first structure simulation script until the deviation index set meets the preset convergence condition or reaches the number of iterations, and extracts the parameter variables that meet the current conditions as the physical structure parameters of the electromagnetic device.
[0102] It should be noted that the data acquisition module 110 is connected to the verification simulation module 120, the verification simulation module 120 is connected to the deviation calculation module 130, the deviation calculation module 130 is connected to the parameter adjustment module 140, and the parameter adjustment module 140 is connected to the script optimization module 150.
[0103] It should also be noted that the apparatus provided in the above embodiments is only illustrated by the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus and method embodiments provided in the above embodiments belong to the same concept, and their specific implementation process can be found in the method embodiments, which will not be repeated here.
[0104] This application also discloses an electronic device. (See reference...) Figure 3 , Figure 3 This is a schematic diagram of the structure of an electronic device according to an embodiment of this application. The electronic device 500 may include: at least one processor 501, at least one network interface 504, a user interface 503, a memory 505, and at least one communication bus 502.
[0105] The communication bus 502 is used to enable communication between these components.
[0106] The user interface 503 may include a display screen and a camera. Optionally, the user interface 503 may also include a standard wired interface and a wireless interface.
[0107] The network interface 504 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface).
[0108] The processor 501 may include one or more processing cores. The processor 501 connects to various parts of the server using various interfaces and lines, and performs various server functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in memory 505, and by calling data stored in memory 505. Optionally, the processor 501 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array. The processor 501 may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and Modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the content required for display; and the modem handles wireless communication. It is understood that the modem may also be implemented as a separate chip without being integrated into the processor 501.
[0109] The memory 505 may include random access memory (RAM) or read-only memory. Optionally, the memory 505 may include a non-transitory computer-readable storage medium. The memory 505 may be used to store instructions, programs, code, code sets, or instruction sets. The memory 505 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as touch function, sound playback function, image playback function, etc.), instructions for implementing the above-described method embodiments, etc.; the data storage area may store data involved in the above-described method embodiments, etc. Optionally, the memory 505 may also be at least one storage device located remotely from the aforementioned processor 501. (Refer to...) Figure 3 The memory 505, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and an application program for electromagnetic device simulation generation and optimization based on a large language model.
[0110] exist Figure 3 In the illustrated electronic device 500, the user interface 503 is mainly used to provide an input interface for the user and acquire user input data; while the processor 501 can be used to call an application program stored in the memory 505, which is a simulation generation and optimization method for electromagnetic devices based on a large language model. When executed by one or more processors 501, the electronic device 500 performs one or more methods as described in the above embodiments. It should be noted that, for the foregoing method embodiments, for the sake of simplicity, they are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, because according to this application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0111] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0112] In the various embodiments provided in this application, it should be understood that the disclosed apparatus can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some service interface; the indirect coupling or communication connection between apparatuses or units may be electrical or other forms.
[0113] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0114] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0115] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage device (CMD). Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned memory includes various media capable of storing program code, such as USB flash drives, portable hard drives, magnetic disks, or optical disks.
[0116] The above are merely exemplary embodiments of this disclosure and should not be construed as limiting the scope of this disclosure. Any equivalent changes and modifications made in accordance with the teachings of this disclosure shall still fall within the scope of this disclosure. Other embodiments of this disclosure will readily conceive of those skilled in the art upon consideration of the specification and the disclosure of practical truths.
[0117] This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not described in this disclosure. The specification and embodiments are to be considered exemplary only, and the scope and spirit of this disclosure are defined by the claims.
Claims
1. A method for simulation generation and optimization of electromagnetic devices based on a large language model, characterized in that, The method includes: The system obtains the user-inputted requirements for electromagnetic devices, inputs the requirements and preset system prompts into a large language model, and generates a first structural simulation script. The requirements include electromagnetic performance indicators, and the system prompts include electromagnetic simulation specifications, material name mapping relationships, simulation scene templates, and output formats. The first structure simulation script is syntax-checked. If the check passes, the script executor is called to run the first structure simulation script. The preset electromagnetic simulation application interface is called to connect to the simulation platform including electromagnetic device structure simulation. The simulation platform is driven to build a three-dimensional physical geometry model. The three-dimensional physical geometry model is meshed and the electromagnetic field is solved to obtain the electromagnetic simulation results. Extract the simulation performance matrix of the electromagnetic simulation results, and compare the eigenvalues of the simulation performance matrix with the values of the electromagnetic performance indicators to obtain a set of deviation indicators; If the deviation index set does not meet the preset convergence condition and does not reach the preset number of iterations, the deviation index set and the parameter variables of the three-dimensional physical geometry model are input into the large language model for deviation analysis to obtain a parameter correction strategy. The parameter variables are then updated according to the parameter correction strategy to generate a second structure simulation script. The second structural simulation script is used as the first structural simulation script, and the step of performing syntax verification on the first structural simulation script is executed until the deviation index set meets the preset convergence condition or reaches the number of iterations. The parameter variables that meet the current conditions are extracted and used as the physical structural parameters of the electromagnetic device.
2. The method according to claim 1, characterized in that, The step of updating the parameter variables according to the parameter correction strategy to generate the second structural simulation script includes: The first structure simulation script is parsed using an abstract syntax tree to generate an abstract syntax tree corresponding to the first structure simulation script. Traverse the assignment statement nodes in the abstract syntax tree to obtain the variable names of each assignment statement node; Match the variable names of each assignment statement node with the names of the parameter variables to determine the target assignment statement node corresponding to the parameter variables; Based on the position attribute of the target assignment statement node, determine the source code position of the parameter definition statement corresponding to the parameter variable in the first structure simulation script; The updated value of the parameter variable is calculated according to the parameter correction strategy; Replace the original values in the parameter definition statement with the updated values, and keep the script content in the first structure simulation script unchanged except for the parameter definition statement, to generate the second structure simulation script.
3. The method according to claim 2, characterized in that, The step of calculating the updated value of the parameter variable according to the parameter correction strategy includes: Extract the adjustment direction and basic adjustment amount corresponding to the parameter variable from the parameter correction strategy, wherein the adjustment direction indicates whether the parameter variable should be increased or decreased; Obtain the current deviation amount corresponding to the target performance index associated with the parameter variable from the deviation index set; Calculate the ratio of the current deviation to the target value of the target performance index to obtain the deviation ratio; The scaling factor is determined based on the deviation ratio, and the larger the deviation ratio, the larger the scaling factor. Multiply the base adjustment amount by the adjustment scaling factor to obtain the actual adjustment amount; Based on the adjustment direction, the original value of the parameter variable is increased or decreased by the actual adjustment amount to obtain the updated value of the parameter variable.
4. The method according to claim 3, characterized in that, The step of determining the scaling factor based on the deviation ratio includes: When the deviation ratio is less than a first threshold, the adjustment scaling factor takes a first preset value less than 1; when the deviation ratio is greater than a second threshold, the adjustment scaling factor takes a second preset value greater than 1; when the deviation ratio is between the first threshold and the second threshold, the adjustment scaling factor is determined by linear interpolation based on the deviation ratio. Wherein, the first threshold is less than the second threshold.
5. The method according to claim 1, characterized in that, The step of inputting the demand prompts and preset system prompts into the large language model to generate a first structure simulation script includes: The system prompt words are set with a cache identifier and then stored in the context cache area of the large language model; The electromagnetic device type in the requirement prompt is parsed, and the corresponding script framework template is matched from the simulation scene template according to the electromagnetic device type; The required prompt words are filled into the corresponding code segment of the script framework template to form a comprehensive prompt word. The comprehensive prompt word is then input into the large language model to generate the first structure simulation script.
6. The method according to claim 1, characterized in that, The syntax validation of the first structure simulation script includes: The first structured simulation script is parsed using an abstract syntax tree, and each node of the abstract syntax tree is traversed to identify function call statements and system command statements in the first structured simulation script. The function call statement and the system command statement are matched with a preset dangerous operation blacklist, which includes operations that trigger system-level sensitive events; If neither the function call statement nor the system command statement is found to be on the dangerous operation blacklist, the first structure simulation script is deemed to have passed the verification. If the blacklist of dangerous operations is hit, the hit dangerous operation statement and its location information are sent back to the large language model, the large language model is called to generate a correction script, the correction script is used as the first structure simulation script, and the step of parsing the abstract syntax tree of the first structure simulation script is executed.
7. The method according to claim 6, characterized in that, The step of calling the script executor to run the first structure simulation script includes: If the first structural simulation script passes the verification, the first structural simulation script is written to a temporary execution path, the script executor is called to run the first structural simulation script as a subprocess, and the execution timeout threshold is set. During the execution of the subprocess, the output stream and error stream of the script executor are captured in real time, and the execution status of the first structure simulation script is determined based on the error stream; If the execution status is execution failure, the error type and error stack information are extracted from the error stream, and the error type, the error stack information and the first structural simulation script are input into the large language model to output the repaired script. The repaired script replaces the first structure simulation script in the temporary execution path, and is re-executed until execution is successful or the preset retry limit is reached.
8. A simulation generation and optimization system for electromagnetic devices based on a large language model, characterized in that, The system includes: The data acquisition module is used to acquire the user-input requirements for electromagnetic devices, input the requirements and preset system prompts into the large language model, and generate a first structural simulation script. The requirements include electromagnetic performance indicators, and the system prompts include electromagnetic simulation specifications, material name mapping relationships, simulation scene templates, and output formats. The simulation verification module is used to perform syntax verification on the first structure simulation script. If the verification passes, the script executor is called to run the first structure simulation script. The preset electromagnetic simulation application interface is called to connect to the simulation platform including electromagnetic device structure simulation. The simulation platform is driven to build a three-dimensional physical geometry model. The three-dimensional physical geometry model is meshed and the electromagnetic field is solved to obtain the electromagnetic simulation results. The deviation calculation module is used to extract the simulation performance matrix of the electromagnetic simulation results, and compare the feature values of the simulation performance matrix with the values of the electromagnetic performance indicators to obtain a set of deviation indicators. The parameter adjustment module is used to input the deviation index set and the parameter variables of the three-dimensional physical geometry model into the large language model for deviation analysis when the deviation index set does not meet the preset convergence condition and does not reach the preset number of iterations, to obtain the parameter correction strategy, and update the parameter variables according to the parameter correction strategy to generate a second structure simulation script. The script optimization module is used to take the second structure simulation script as the first structure simulation script, execute the step of performing syntax verification on the first structure simulation script until the deviation index set meets the preset convergence condition or reaches the number of iterations, and extract the parameter variables that meet the current conditions as the physical structure parameters of the electromagnetic device.
9. An electronic device, characterized in that, The device includes a processor, a memory, a user interface, a communication bus, and a network interface. The processor, the memory, the user interface, and the network interface are respectively connected to the communication bus. The memory is used to store instructions. The user interface and the network interface are used to communicate with other devices. The processor is used to execute the instructions stored in the memory to cause the electronic device to perform the method as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores instructions that, when executed, perform the method as described in any one of claims 1-7.