Power system controller simulation method and system based on AI simulation framework

Through topological sorting and loop detection based on the AI simulation framework, and combining AI large model to generate controller module code, the efficiency and customization problems of existing power system simulation tools are solved, and efficient and reliable power system controller simulation is achieved.

CN120406201APending Publication Date: 2025-08-01NANJING KUNHONG DIGITAL TECHNOLOGY CO LTD +1
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510553551.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-29
Publication Date
2025-08-01

AI Technical Summary

Technical Problem

Existing power system simulation tools such as Simulink have problems such as closed source, difficulty in customization, and low operating efficiency, which are difficult to meet specific application needs. In addition, AI code generation based on natural languages has reliability and verification problems in power system simulation.

Method used

Using an AI simulation framework method, the controller model is generated through topological sorting and loop detection, combined with AI large model to assist in generating controller module code, and using Boost library to accelerate computing, a unified simulation function interface and dynamic binding technology are designed to achieve efficient and reliable controller simulation.

Benefits of technology

It improves the efficiency and accuracy of the power system controller simulation, reduces manual coding errors, supports a variety of controller components, enhances the flexibility and scalability of the simulation, and ensures the stability and accuracy of the simulation process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120406201A_ABST
    Figure CN120406201A_ABST
Patent Text Reader

Abstract

The invention discloses a power system controller simulation method and system based on an AI simulation framework, and relates to the technical field of power system controller simulation, and the method comprises the steps: creating a controller simulation framework, generating a topological structure of a controller model, carrying out topological sorting and loop detection processing, and calling a control element for simulation. A simulation result is visually displayed; a controller model code generator is created, codes of a controller module and corresponding unit test codes are generated in an auxiliary mode through an AI large model, a unified simulation function interface is set, and dynamic binding of the controller model code generator and a controller simulation framework is achieved. According to the power system efficient controller simulation method based on the hybrid topology-AI simulation framework, the problems of efficiency bottleneck and insufficient customization of an existing simulation tool in power system controller simulation are solved, and the simulation efficiency and accuracy of a power system controller are effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of power system controller simulation, and in particular, to a power system controller simulation method and system based on an AI simulation framework. Background Art

[0002] Real-time electromagnetic transient simulation of power systems usually adopts real-time fixed-step simulation with a small step size. Therefore, almost no consideration needs to be given to the stiffness problem and variable-step problem during the simulation process. This characteristic simplifies the implementation of controller simulation. However, existing simulation tools such as Simulink have problems such as closed source, difficult customization, and low operating efficiency, and it is difficult to meet specific application requirements.

[0003] In recent years, the development of artificial intelligence (AI) technology, especially large language models (LLMs), has brought new opportunities to code generation and software development. Using an AI large model to assist in generating the code of controller modules can improve development efficiency, reduce manual coding errors, and enhance code quality based on natural language descriptions.

[0004] However, this natural language-based code generation method is fundamentally different from traditional code generation based on structured models (such as software like Simulink). Traditional code generation usually relies on explicit structured models and can generate low-level code suitable for embedded execution to ensure the executability and efficiency of the code. While AI code generation based on natural language focuses more on improving the convenience and flexibility of code development. In industrial systems, experts still have concerns about the reliability and verification of AI-generated code, especially in critical fields such as power system simulation.

[0005] Therefore, how to make full use of the advantages of AI technology while ensuring code quality and execution efficiency has become an urgent challenge to be solved. Summary of the Invention

[0006] Based on this, it is necessary to provide a power system controller simulation method and system based on an AI simulation framework for the above technical problems.

[0007] In a first aspect, the present invention provides a power system controller simulation method based on an AI simulation framework, including:

[0008] S1. Create a controller simulation framework, generate the topological structure of the controller model, perform simulation by calling control elements through topological sorting and loop detection processing, and visually display the simulation results;

[0009] S2. Create a controller model code generator, use the AI large model to assist in generating the code of the controller module and the corresponding unit test code, and set a unified simulation function interface to achieve the dynamic binding between the controller model code generator and the controller simulation framework.

[0010] Furthermore, create a controller simulation framework, generate the topological structure of the controller model, through topological sorting and loop detection processing, call the control components for simulation, and visually display the simulation results including:

[0011] S11. Read the controller model data, based on the directed graph technology, sequentially perform topological modeling, topological sorting, loop detection and processing on the controller model, generate the execution order and dependency relationship of the control components, and introduce an optimization algorithm to accelerate the efficiency of topological sorting and loop detection;

[0012] S12. According to the execution order of the control components, call the simulation functions of each control component to execute the simulation tasks, and update the control component status and output within each simulation step;

[0013] S13. Collect and process the simulation results, evaluate and visually display the performance of the power system.

[0014] Furthermore, read the controller model data, based on the directed graph technology, sequentially perform topological modeling, topological sorting, loop detection and processing on the controller model, generate the execution order and dependency relationship of the control components, and introduce an optimization algorithm to accelerate the efficiency of topological sorting and loop detection including:

[0015] S111. Set the types and characteristics of the control components, as well as the port set and port connection rules, construct the topological structure of the controller model, and model it as a directed graph;

[0016] S112. Perform connectivity analysis on the directed graph of the controller model, calculate the connected components, and independently allocate each connected component to different computing units to achieve parallel computing;

[0017] S113. Use the topological sorting algorithm to sort the nodes in the directed graph to obtain the node arrangement, which represents the execution order and dependency relationship of the control component model;

[0018] S114. Traverse all nodes in the directed graph using the depth-first search algorithm, mark the access status of each node, detect whether there is a loop in the directed graph, and output the detection result;

[0019] S115. Use the graph algorithms in the Boost library to accelerate the calculation of loop detection and topological sorting.

[0020] Furthermore, the port set includes an output port set and an input port set;

[0021] The controller model includes a control element model, an external input signal and an external output signal;

[0022] The port connection rules are that an output port can be connected to multiple input ports, an input port can only have one connection from an output port, an output port cannot be the target of a connection, and all directed edges point from an output port to an input port;

[0023] In a directed graph, nodes represent control elements, and edges represent directed connections between ports. Each node corresponds to a control element and has a set of input ports and output ports.

[0024] Furthermore, a depth-first search algorithm is used to traverse all nodes in the directed graph, mark the access status of each node, and detect whether there is a loop in the directed graph. The output detection results include:

[0025] S1141. Create a visited set for storing all visited nodes in the directed graph; then create a recursive call stack set for storing nodes on the current recursive path as visited nodes; and mark the initial state of all nodes in the directed graph as unvisited.

[0026] S1142. Iterate each node in the directed graph. If any node v is not marked as visited, execute a depth-first search function starting from the node v.

[0027] S1143: Add the current node to the recursive call stack set, mark it as being visited, traverse all adjacent nodes of the current node, obtain the exploration status of all nodes, until all adjacent nodes are explored, move the current node from the recursive call stack set to the visited set, and return the detection result;

[0028] S1144. If any call in traversing all nodes in the directed graph returns a signal that a loop is detected, then the entire directed graph contains a loop; otherwise, there is no loop in the directed graph; and when a loop is detected, an artificial delay is introduced to release the feedback loop.

[0029] Furthermore, the node exploration status includes: loop discovery status, recursive exploration status, and visited status;

[0030] Among them, the loop is found if the adjacent node belongs to the recursive call stack set, indicating that there is a loop, and a loop detection signal is immediately returned;

[0031] In the recursive exploration case, if the adjacent node is not marked as visited, the depth-first search function is recursively called. If the recursive call returns a loop signal, the loop signal is passed upward.

[0032] The visited situation is that if the adjacent node has been marked as visited, it means that the adjacent node belongs to a branch in the directed graph that has been fully explored and does not form a loop with the current path, then the adjacent node is ignored and the exploration continues to the next adjacent node.

[0033] Furthermore, when a loop is detected, introducing an artificial delay to release the feedback loop includes:

[0034] For each control element in the loop, a simulation step is temporarily delayed, and the output of the node in the loop at the current step is used as the input of the next step.

[0035] Furthermore, a controller model code generator is created, and the AI large model is used to assist in generating the controller module code and the corresponding unit test code. A unified simulation function interface is set to achieve dynamic binding between the controller model code generator and the controller simulation framework, including:

[0036] S21. Create a prompt word template. When there is a new module code task, use the AI big model to generate the module code of each controller module in the power system controller;

[0037] S22. During the initialization of each controller module by the controller simulation framework, the simulation functions of each controller module are bound to a unified simulation interface using a callable object wrapper, so as to dynamically call the simulation functions of different controller modules during the simulation process.

[0038] Furthermore, when there is a new module code task, the module code of each controller module in the power system controller is generated using the AI big model, including:

[0039] S211, write a requirement description for the controller module to be generated to form a prompt word;

[0040] S212. Input the requirement description into the AI big model, implement the functions of the controller module by generating code, and generate unit test code;

[0041] S213. Review the generated code to verify the correctness of the code logic;

[0042] S214. Use code testing tools to perform static analysis on the code to check for potential errors and irregularities, and run unit tests to cover various boundary conditions and abnormal situations.

[0043] In a second aspect, the present invention further provides a power system controller simulation system based on an AI simulation framework, the system comprising:

[0044] A controller simulation framework for generating the topology of a controller model, processing through topological sorting and loop detection, invoking control components for simulation, and visually displaying the simulation results;

[0045] A controller model code generator for using an AI large model to assist in generating the code of a controller module and the corresponding unit test code, and setting a unified simulation function interface to achieve the dynamic binding of the controller model code generator and the controller simulation framework.

[0046] The beneficial effects of the present invention are as follows:

[0047] 1. Through an efficient controller simulation method for power systems based on a hybrid topology - AI simulation framework (HTASF), aiming to solve the problems of efficiency bottlenecks and insufficient customization in the simulation of power system controllers by existing simulation tools; by combining self - developed topology modeling technology with AI large - model - assisted controller code generation, the simulation efficiency and accuracy of power system controllers are effectively improved.

[0048] 2. By using an AI large model to assist in writing the code of the controller module, the development efficiency is improved, manual coding errors are reduced, and the high quality and consistency of the code are ensured.

[0049] 3. By designing a unified control element model and port topology structure, supporting various types of controller elements, facilitating user customization and extension, and improving the flexibility and scalability of simulation.

[0050] 4. By proposing a topological sorting and loop processing method for controller simulation, and introducing a time delay of one step, the feedback loop is successfully removed, ensuring the stability and accuracy of the simulation process.

[0051] 5. Through connectivity analysis, the simulation model is divided into multiple connected components, supporting parallel computing on multiple CPUs, significantly improving the simulation speed; by using C++'s std::function and function binding technology, the dynamic binding of component simulation functions is achieved, avoiding the performance overhead of traditional inheritance and virtual function methods, and improving the simulation operation efficiency. Description of the Drawings

[0052] The drawings described herein are used to provide a further understanding of the present invention, form a part of the present invention, and the schematic embodiments of the present invention and their descriptions are used to explain the present invention, and do not constitute an improper limitation to the present invention. In the drawings:

[0053] Figure 1 is a flowchart of a power system controller simulation method based on an AI simulation framework according to an embodiment of the present invention;

[0054] Figure 2It is a system principle block diagram of a power system controller simulation system based on an AI simulation framework according to an embodiment of the present invention;

[0055] Figure 3 It is the overall framework of a controller simulation framework and a controller code generator according to an embodiment of the present invention;

[0056] Figure 4 It is a schematic diagram of a typical control system structure according to an embodiment of the present invention;

[0057] Figure 5 It is a schematic diagram of the ADS-RTSim human-machine interface according to an embodiment of the present invention.

[0058] Reference numerals in the drawings: 1. Controller simulation framework; 2. Controller model code generator. Detailed implementation manners

[0059] In order to make the objectives, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention, but not to limit the present invention.

[0060] Please refer to Figure 1 , and a power system controller simulation method based on an AI simulation framework is provided, including:

[0061] S1. Create a controller simulation framework, generate the topological structure of the controller model, perform simulation by calling control elements through topological sorting and loop detection processing, and visually display the simulation results.

[0062] In the description of the present invention, creating a controller simulation framework, generating the topological structure of the controller model, performing simulation by calling control elements through topological sorting and loop detection processing, and visually displaying the simulation results include:

[0063] S11. Read the controller model data, and based on the directed graph technology, perform topological modeling, topological sorting, loop detection and processing on the controller model in sequence, generate the execution order and dependency relationship of the control elements, and introduce an optimization algorithm to accelerate the efficiency of topological sorting and loop detection.

[0064] In the description of the present invention, reading the controller model data, and based on the directed graph technology, performing topological modeling, topological sorting, loop detection and processing on the controller model in sequence, generating the execution order and dependency relationship of the control elements, and introducing an optimization algorithm to accelerate the efficiency of topological sorting and loop detection include:

[0065] S111. Set the type and characteristics of the control elements, as well as the port set and port connection rules, construct the topological structure of the controller model, and model it as a directed graph.

[0066] In the description of the present invention, the port set includes an output port set and an input port set.

[0067] The controller model includes a control element model, an external input signal, and an external output signal.

[0068] The port connection rule is that an output port can be connected to multiple input ports, an input port can only have one connection from an output port, an output port cannot be the target of a connection, and all directed edges point from the output port to the input port.

[0069] In a directed graph, nodes represent control elements and edges represent directed connections between ports. Each node corresponds to a control element and has a set of input ports and output ports.

[0070] Specifically, a control element is the basic unit that constitutes the control system model, and each element has specific functions and behaviors. In topological modeling, it is first necessary to define the type and characteristics of the element.

[0071] Among them, element classification: According to the functions and roles of the elements, the elements are divided into sensors, actuators, control algorithm units, etc.

[0072] Port definition: Each element has input and output ports, and the definition of the port includes the port type (such as analog signal, digital signal, etc.), the port direction (input or output), and the nature of the transmitted data.

[0073] The topological relationship is realized through numbering. Among them, the controller model includes:

[0074] 1) Control element model (Element): Each element contains several ports, which are divided into input ports and output ports. If an element has only output ports, it is an external input element; if it has only input ports, it is a controller output element. Among them, the port numbering rule is: the output port numbers are odd, and the input port numbers are even;

[0075] 2) External input signal: An element with only output ports represents the external input signal of the controller, and the port number is odd;

[0076] 3) External output signal: An element with only input ports (except for an oscilloscope) represents the external output signal of the controller, and the port number is even.

[0077] The port connection rules are as follows:

[0078] 1) An output port can be connected to multiple input ports;

[0079] 2) An input port can only have one connection from an output port;

[0080] 3) The output ports cannot be the targets of connections. All directed edges point from output ports (odd numbers) to input ports (even numbers).

[0081] The topological modeling of the controller is an important step in the simulation preparation phase, which involves the abstraction and mathematical description of control components and their interconnections. This process ensures that the simulation system can correctly understand and handle the interactions and data flows among various control components.

[0082] In addition, to accurately describe the topology of the controller, a mathematical model based on graph theory is used for representation.

[0083] The controller model can be modeled as a directed graph: G = (V, E). Where: V is the set of nodes, representing control components. Each node corresponds to a control component and has a set of input ports and output ports. E is the set of edges, representing the directed connections between ports.

[0084] Define the set of ports, including the set of output ports P out and the set of input ports P in . Each edge (e ∈ E) represents a connection from the output port of one component to the input port of another component, and can be expressed as: [p out p in , where p out ∈ P out , p in ∈ P in

[0085] The connection rules are as follows:

[0086] 1) The output ports can be connected to multiple input ports, that is, for a P out , there can be multiple edges (P out , P in );

[0087] 2) Each input port can only have one connection from an output port, that is, for each P in , there exists and only exists one P out such that (P out , P in ) ∈ E;

[0088] 3) All directed edges point from output ports to input ports, ensuring the directionality of the signal flow.

[0089] Therefore, the topology of the controller can be formally expressed as:

[0090] G = (V, E), E = {(p out , p in ) | p out ∈ Pout , p in ∈ P in};

[0091] For convenient calculation and analysis, a topological matrix A can be constructed, where: the dimension of A is the same as that of V. A ij = 1 indicates that there is a connection from the output port of component v i to the input port of component v j ; A ij = 0 indicates no connection relationship.

[0092] S112. Conduct a connectivity analysis on the directed graph of the controller model, calculate the connected components, and independently allocate each connected component to different computing units to achieve parallel computing.

[0093] Specifically, first conduct a connectivity analysis on the graph to prepare for parallel computing. The controller model usually contains multiple independent connected components, and each connected component can be independently simulated and calculated. The partitioning can be done by calculating the connected components of the graph. For a directed graph G = (V, E), its connected components C1, C2,..., C m satisfy:

[0094]

[0095] Each connected component C i can be independently allocated to different computing units (CPU cores) for parallel computing, thus significantly improving the simulation speed.

[0096] S113. Use the topological sorting algorithm to sort the nodes in the directed graph to obtain a node arrangement, which represents the execution order and dependency relationship of the control element model.

[0097] Specifically, in the simulation of power system controllers, topological sorting and loop processing play key roles, especially in ensuring the stability and accuracy of the system. The correct execution order of the controller system can significantly improve the efficiency and stability of the simulation.

[0098] The following steps are all for parallel processing of each connected component separately. The topological structure of the controller system can be modeled by graph theory. Represent the control elements as nodes in the graph, and the connections between the elements as edges in the graph.

[0099] Therefore, the control system can be modeled as a directed graph G = (V, E), where: V is the set of nodes, representing the control elements; E is the set of edges, representing the connections between the control elements.

[0100] In power system simulation, it is required that the execution order of all components conforms to the data dependency relationship. To determine these orders, a topological sorting algorithm is used. Topological sorting is an algorithm for linearly sorting the nodes of a directed acyclic graph (DAG, Directed Acyclic Graph). If G is a directed acyclic graph, the result of topological sorting is a node permutation (v1, v2, …, v n ), satisfying the following conditions:

[0101]

[0102] That is: if there is a directed edge (v i → v j ) from node v i to v j , then in the topological sorting, v i must be ranked before v j .

[0103] S114. Traverse all nodes in the directed graph using the depth-first search algorithm, mark the access status of each node, detect whether there is a loop in the directed graph, and output the detection result.

[0104] Specifically, in a control system, the existence of a loop will lead to a feedback loop, which may cause circular dependencies in the calculation process, thereby affecting the stability and accuracy of the simulation process. Therefore, it is necessary to detect and process the loops in the graph.

[0105] The detection of loops can be achieved through the depth-first search (DFS, Depth-First Search) algorithm of the graph. The DFS algorithm can effectively traverse all nodes in the graph and mark the visited nodes. If, during the DFS search process, the child node of the current node has been visited and is in the current recursive stack, it means that there is a loop in the graph.

[0106] Depth-first search (DFS) is an algorithm used to traverse or search tree or graph data structures. It starts from a starting node, explores as deep as possible along a path until it reaches the end of the path, and then backtracks to explore the next unvisited path. Utilizing this property of DFS, the presence of loops in the graph can be effectively detected. The core idea lies in tracking the state of each node during the DFS process. Generally, a node can have three states:

[0107] 1) Unvisited: The node has not been visited by DFS yet.

[0108] 2) Visiting: The node has been visited, and all its adjacent nodes (child nodes) have not been fully explored. This means that the node is on the current recursive call stack and is part of the currently explored path.

[0109] 3) Visited: The node and all its adjacent nodes (the entire subgraph) have been fully explored. The node has exited the recursive call stack.

[0110] In the description of the present invention, the depth - first search algorithm is used to traverse all nodes in a directed graph, mark the access status of each node, detect whether there is a loop in the directed graph, and the output detection results include:

[0111] S1141. Initialization: Create a visited set (a data structure, such as a set or a boolean array) to store all visited nodes in the directed graph. Then create a recursive call stack set (another data structure, such as a set or a boolean array) to store the nodes on the current recursive path as the nodes being visited. And mark the initial state of all nodes in the directed graph as unvisited.

[0112] S1142. Traverse the graph: Iterate over each node in the directed graph. If any node v is not marked as visited, start executing the depth - first search function from the node v.

[0113] S1143. Execution of the DFS auxiliary function DFS_Visit(node): Add the current node to the recursive call stack set, mark it as being visited, traverse all adjacent nodes of the current node, obtain the exploration situation of all nodes until all adjacent nodes are explored, move the current node from the recursive call stack set to the visited set, and return the detection result.

[0114] In the description of the present invention, the exploration situation of a node includes: the situation of finding a loop (Situation 1), the situation of recursive exploration (Situation 2), and the situation of being visited (Situation 3);

[0115] Among them, the situation of finding a loop means that if an adjacent node belongs to the recursive call stack set, it indicates that there is a loop, and immediately return the signal of detecting a loop;

[0116] The situation of recursive exploration means that if an adjacent node is not marked as visited, recursively call the depth - first search function. If the recursive call returns the signal of detecting a loop, pass the detected loop signal upward;

[0117] The situation of being visited means that if an adjacent node has been marked as visited, it indicates that the adjacent node belongs to a branch in the directed graph that has been fully explored and does not form a loop with the current path, then ignore the adjacent node and continue to explore the next adjacent node.

[0118] S1144: If any call during the traversal of all nodes in the directed graph returns a loop detection signal, then the entire directed graph contains a loop; otherwise, the directed graph does not contain a loop. When a loop is detected, an artificial delay is introduced to release the feedback loop.

[0119] In the description of the present invention, when a loop is detected, introducing an artificial delay to release the feedback loop includes:

[0120] For each control element in the loop, a simulation step is temporarily delayed, and the output of the node in the loop at the current step is used as the input of the next step.

[0121] Specifically, for each control element in the loop, its output is temporarily delayed by a simulation step Δt, that is, the node v in the loop i At the current step length t k The output at the moment will be used as the input for the next step. The mathematical representation is as follows:

[0122] y i (t k )=y i (t k-1 );

[0123] Where, v i is a node in the feedback loop, and its output is y i , then its output value is at the current step length t k This means that the output of the loop will no longer be fed back to the input immediately, but will be fed back to the input in the next simulation cycle t k+1 Used in.

[0124] S115. Use graph algorithms in the Boost library to accelerate the calculation of loop detection and topological sorting.

[0125] Specifically, to further improve the efficiency of topological sorting and loop processing, the present invention uses graph algorithms from the Boost library to accelerate loop detection and topological sorting calculations. The Boost library provides an efficient graph algorithm tool, BGL, that can quickly perform calculations on large-scale graph datasets. For example, during the topological sorting process, a depth-first search algorithm is used to traverse the graph and mark the access status of nodes. BGL provides high-performance functions such as boost::depth_first_search that can be directly applied to the modeled graph structure.

[0126] S12. According to the execution order of the control elements, the simulation function of each control element is called to execute the simulation task, and the state and output of the control element are updated within each simulation step.

[0127] S13. Collect and process the simulation results, and evaluate and visually display the performance of the power system.

[0128] S2. Create a controller model code generator, use the AI large model to assist in generating the code of the controller module and the corresponding unit test code, and set a unified simulation function interface to achieve the dynamic binding between the controller model code generator and the controller simulation framework.

[0129] Specifically, code generation technology has been widely used in the field of software engineering in recent years, especially in improving development efficiency and code quality. With the rapid development of deep learning technology, AI large models based on the Transformer architecture have made remarkable progress in the fields of natural language processing and code generation. The success of AI large models provides a new idea for the present invention. Especially in the automatic generation of controller dynamic models, it can effectively solve the problems of low efficiency and high error rate of manually writing code.

[0130] The Transformer model, as the basis of AI large models, its core idea is based on the self-attention mechanism, which can capture the correlation between elements at different positions in the input sequence, thus solving the long-distance dependence problem in traditional sequence processing methods. Through a large amount of training data, the Transformer model can not only learn the syntax rules of programming languages, but also capture the semantic information of programming languages. This enables AI large models to have powerful capabilities in code generation tasks and can generate source code that meets specific requirements according to the given requirement descriptions.

[0131] In the code generation of power system controllers, using AI large models can effectively combine general large model technology with the special requirements of the power system simulation field, and improve the generation efficiency and quality of controller module code. Through AI-assisted code generation, the following advantages can be achieved: 1) High degree of automation: Greatly reduce the workload of manually writing code, especially for code with strong repeatability and pattern; 2) Improved development efficiency: Accelerate the code writing, testing and debugging processes, and significantly shorten the development cycle; 3) Improved code quality: AI large models can generate code that meets standards according to code specifications and best practices, reducing the probability of human errors.

[0132] However, in the industrial field, the reliability and accuracy of code generated by AI are crucial. Therefore, the present invention adopts strict verification and testing measures, including static code analysis, unit testing, functional testing, etc., to ensure that the generated code meets industrial standards and requirements in actual applications.

[0133] In the description of the present invention, a controller model code generator is created. By using an AI large model to assist in generating the code of the controller module and the corresponding unit test code, and setting a unified simulation function interface, the dynamic binding of the controller model code generator and the controller simulation framework is realized, including:

[0134] S21. Create a prompt template. When there is a new module code task, use the AI large model to generate the module code of each controller module in the power system controller.

[0135] Specifically, the present invention uses an AI large model to generate the code of each module of the power system controller. These modules cover the basic components of the controller (such as transfer functions, integrators, filters, etc.) and the implementation of complex control strategies. To ensure the quality of code generation, the present invention has formed a professional prompt template through repeated debugging and optimization, which is the key to interacting with the AI model.

[0136] Prompts play a crucial role in the process of AI-assisted code generation. It not only determines the direction and quality of the code generated by the AI model but also ensures that the model can accurately understand the complexity and details of the requirements. By designing a reasonable prompt template, the deviation and inaccuracy of the generated code can be minimized.

[0137] In the description of the present invention, when there is a new module code task, using the AI large model to generate the module code of each controller module in the power system controller includes:

[0138] S211. Write a requirement description for the controller module to be generated to form a prompt.

[0139] Specifically, this step is reflected in the requirement description: Write a detailed requirement description for the controller module to be generated, including function description, input and output parameters, algorithm logic, etc., to form a new prompt. The key at this stage is to ensure the precise expression of the requirements and avoid interference from unclear descriptions on the generation results.

[0140] S212. Input the requirement description into the AI large model, and implement the function of the controller module through code generation and generate unit test code.

[0141] Specifically, this step is reflected in the AI model call: Input the requirement description into the AI model, implement the function of the controller module through the generated C++ code, and generate unit test code.

[0142] S213. Review the generated code to verify the correctness of the code logic.

[0143] Specifically, this step is embodied as manual review: conduct a preliminary manual review of the generated code to check the correctness of the code logic and ensure its compliance with coding specifications.

[0144] S214. Use a code testing tool to perform static analysis on the code, check for potential errors and non-standard phenomena, and cover various boundary conditions and exceptional situations by running unit tests.

[0145] Specifically, this step is embodied as code testing and verification: use tools (such as Clang-Tidy) for static analysis to check for potential errors and non-standardities. By running unit tests to cover various boundary conditions and exceptional situations, ensure the robustness and reliability of the code.

[0146] The following gives an example of implementing a second-order transfer function module. The prompt template is: "Implement the C++ class code and unit test code for a second-order transfer function, using the trapezoidal method for differentiation, with the formula Input signal u(t); output signal y(t)". Through this prompt template, the AI model can automatically generate code that meets the requirements and verify its functionality and stability through testing.

[0147] S22. During the initialization process of each controller module in the controller simulation framework, use a callable object wrapper to bind the simulation functions of each controller module to a unified simulation interface, so as to dynamically call the simulation functions of different controller modules during the simulation process.

[0148] Specifically, dynamic binding is an important concept in object-oriented programming, which means dynamically determining which method to call according to the actual situation during program execution. In C++, std::function provides the ability to implement dynamic binding, which can encapsulate functions, function pointers, Lambda expressions, etc. into a unified type, thereby enhancing the flexibility and reusability of the code.

[0149] In the controller simulation framework of the present invention, the dynamic binding technology effectively solves the problem of flexible support for multiple controller modules through std::function. When each controller module in the simulation framework is initialized, its specific simulation function will be bound to a unified simulation interface, enabling the dynamic call of the simulation functions of different controller modules during the simulation process. This technology makes the simulation framework no longer dependent on the specific types and implementations of controller modules, enhancing the scalability and flexibility of the system.

[0150] The key technologies for binding using std::function are as follows:

[0151] 1) Define a unified function interface, which defines a unified simulation function interface for all controller modules;

[0152] 2) For each instance of the controller module, during initialization, bind its member functions to the funcion function member of the controller;

[0153] 3) In the simulation loop, in the order of topological sorting, sequentially call the funcion function members of each instance of the controller module. When the simulation framework is running, it does not need to know the specific module types and implementation details, but only needs to call the bound members.

[0154] Compared with traditional inheritance and virtual function techniques, the call overhead of std::function is smaller, avoiding virtual table lookup and improving execution efficiency. At the same time, it reduces complex inheritance relationships and polymorphism mechanisms, making the code more concise and easier to maintain. Through this dynamic binding technology, the simulation framework can flexibly add new controller modules without modifying the core code.

[0155] Please refer to Figure 2 , and also provides a power system controller simulation system based on an AI simulation framework. This system includes:

[0156] A controller simulation framework for generating the topological structure of the controller model, through topological sorting and loop detection processing, calling control components for simulation, and visually displaying the simulation results.

[0157] A controller model code generator for using an AI large model to assist in generating the code of the controller module and the corresponding unit test code, and setting a unified simulation function interface to achieve the dynamic binding between the controller model code generator and the controller simulation framework.

[0158] The following further elaborates on the present invention in detail with reference to the accompanying drawings and specific embodiments.

[0159] The overall framework of the HTASF designed by the present invention is as Figure 3 shown.

[0160] The system architecture mainly consists of two core parts: a self-developed controller simulation framework and a controller dynamic model code generator assisted by an AI large model. During the simulation operation, these two parts cooperate closely to achieve efficient and reliable controller simulation.

[0161] The controller simulation framework is responsible for the core logic of the simulation, including the connectivity analysis, topological sorting, loop detection and processing of the controller model, as well as the control of the simulation process, etc. This part is written by human experts to ensure the reliability and stability of the system.

[0162] The controller model code generator is designed for the dynamic models of various controllers. It uses large AI models to generate high-quality code and corresponding unit test code. Through the std::function technology in C++, it is dynamically bound to the simulation framework, achieving modularity and scalability.

[0163] The simulation process includes the following main stages:

[0164] 1) Initialization stage: Read the controller model data, perform topological analysis and sorting, and detect and process feedback loops. This stage generates the execution order and dependencies of components, ensuring the correctness and stability of the simulation process.

[0165] 2) Simulation execution stage: According to the execution order determined in the initialization stage, call the simulation functions of each control component (including the dynamic model code generated by AI). Within each simulation time step, update the component states and outputs.

[0166] 3) Result analysis stage: Collect and process the simulation results, and evaluate and visually display the system performance.

[0167] Throughout the simulation process, the controller simulation framework and the dynamic model code generated by AI interact through a unified interface and data structure. The dynamic binding technology ensures that controller modules can be easily added or updated without modifying the core code of the framework, improving the flexibility and maintainability of the system.

[0168] To specifically illustrate the algorithm of the present invention, first, a typical control system is given, such as Figure 4 shown in the figure. In the figure, ABCDEFG all represent controller modules, and the directed graph with arrows represents the data flow of each controller module.

[0169] According to the algorithm of the present invention, first, topological modeling and connectivity analysis are performed to obtain connected subnets, which are assigned to specific CPU cores. Then, topological sorting is carried out, from input to output, and the sorting result is: ABCDEF; note that G and H are not in this result. Then, loop detection and processing are performed. EGC and FHA respectively form sub-loops, and the sub-loops are also sorted. For the connection points between the sub-loops and the main path, single-step delay links are inserted to avoid the existence of algebraic loops.

[0170] Assume that most controller modules already have built-in model code, but module E does not. Code is generated through large model AI technology, and the generated code is dynamically bound to the main program through std::bind and std::function.

[0171] The technology of the present invention has been industrially applied and has been integrated into the ADS-RTSim real-time simulation device developed by Southeast University. The ADS-RTSim device integrates and applies core technologies such as full-topology modeling of new energy power stations, small-step simulation of power electronics, and CPU / FPGA heterogeneous parallel computing, and has been applied in more than 10 new power system engineering projects in Jiangsu, Anhui, Zhejiang, Guizhou, etc. in China. Through the technology of the present invention, the device realizes the controller modeling function similar to Simulink and the joint operation with the real-time electromagnetic transient simulation of the power system.

[0172] The human-machine interface of the device is as Figure 5 shown. Different components can be selected through the left function area, and the system wiring diagram of each component can be established in the right display area to describe information such as the circuit structure, waveform signal, device parameters, and interface configuration of the power system controller model.

[0173] Since the code generation of the controller module is assisted by the AI large model, the development efficiency is improved. The time to add a new controller module is reduced from the original 1-2 days to about 20 minutes.

[0174] The experimental results and industrial product applications show that the method proposed in the present invention can accurately simulate the dynamic behavior of the controller, has good scalability and practicability, and provides an efficient and reliable new solution for the simulation of power system controllers.

[0175] In summary, by means of the above technical solution of the present invention, through the efficient controller simulation method for power systems based on the hybrid topology-AI simulation framework (HTASF), it aims to solve the problems of efficiency bottleneck and lack of customization in the simulation of power system controllers by existing simulation tools; by combining the independently developed topology modeling technology with the AI large model-assisted controller code generation, the simulation efficiency and accuracy of power system controllers are effectively improved. By using the AI large model to assist in writing the code of the controller module, the development efficiency is improved, manual coding errors are reduced, and the high quality and consistency of the code are ensured. By designing a unified control element model and port topology structure, various types of controller elements are supported, which is convenient for users to customize and expand, and the flexibility and scalability of the simulation are improved. By proposing a topology sorting and loop processing method for controller simulation, and introducing a one-step delay, the feedback loop is successfully removed, ensuring the stability and accuracy of the simulation process. Through connectivity analysis, the simulation model is divided into multiple connected components, supporting parallel computing of multiple CPUs, significantly improving the simulation speed; using the std::function and function binding technology of C++, the dynamic binding of component simulation functions is realized, avoiding the performance overhead of the traditional inheritance and virtual function methods, and improving the simulation operation efficiency.

[0176] It should be understood that although the steps in the flowchart of the accompanying drawings are shown sequentially in the direction of the arrows, these steps are not necessarily executed sequentially in the order indicated by the arrows. Unless there is a clear indication in the present invention, there is no strict order restriction for the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed alternately or in turn with at least a part of other steps or sub-steps or stages of other steps.

Claims

1. A simulation method for a power system controller based on an AI simulation framework, characterized in that Including: S1. Create a controller simulation framework, generate the topological structure of the controller model, process through topological sorting and loop detection, call control components for simulation, and visually display the simulation results; S2. Create a controller model code generator, use an AI large model to assist in generating the code of the controller module and the corresponding unit test code, and set a unified simulation function interface to achieve dynamic binding between the controller model code generator and the controller simulation framework.

2. The simulation method of a power system controller based on an AI simulation framework according to claim 1, wherein The creation of the controller simulation framework, generating the topological structure of the controller model, processing through topological sorting and loop detection, calling control components for simulation, and visually displaying the simulation results include: S11. Read the controller model data, based on the directed graph technology, successively perform topological modeling, topological sorting, loop detection and processing on the controller model, generate the execution order and dependency relationship of the control components, and introduce an optimization algorithm to accelerate the efficiency of topological sorting and loop detection; S12. According to the execution order of the control components, call the simulation functions of each control component to execute the simulation tasks, and update the state and output of the control components within each simulation step; S13. Collect and process the simulation results, evaluate and visually display the performance of the power system.

3. The simulation method of a power system controller based on an AI simulation framework according to claim 2, wherein The reading of the controller model data, based on the directed graph technology, successively perform topological modeling, topological sorting, loop detection and processing on the controller model, generate the execution order and dependency relationship of the control components, and introduce an optimization algorithm to accelerate the efficiency of topological sorting and loop detection includes: S111. Set the types and characteristics of the control components, as well as the port set and port connection rules, construct the topological structure of the controller model, and model it as a directed graph; S112. Perform connectivity analysis on the directed graph of the controller model, calculate the connected components, and independently allocate each connected component to different computing units to achieve parallel computing; S113. Use the topological sorting algorithm to sort the nodes in the directed graph to obtain the node arrangement, which represents the execution order and dependency relationship of the control component model; S114. Traverse all nodes in the directed graph using the depth-first search algorithm, mark the access status of each node, detect whether there is a loop in the directed graph, and output the detection result; S115. Use the graph algorithms in the Boost library to accelerate the calculation of loop detection and topological sorting.

4. The simulation method of a power system controller based on an AI simulation framework according to claim 3, characterized in that, The port set includes an output port set and an input port combination; The controller model includes a control component model, external input signals, and external output signals; The port connection rule is that the output port can be connected to multiple input ports, the input port can only have one connection from the output port, the output port cannot be used as the target of the connection, and all directed edges point from the output port to the input port; In the directed graph, the nodes represent control components, the edges represent the directed connections between ports, each node corresponds to a control component, and has a set of input ports and output ports.

5. A simulation method for a power system controller based on an AI simulation framework according to claim 3, characterized in that, The traversal of all nodes in the directed graph using the depth-first search algorithm, marking the access status of each node, detecting whether there is a loop in the directed graph, and outputting the detection result includes: S1141. Create a visited set for storing all visited nodes in the directed graph; then create a recursive call stack set for storing nodes on the current recursive path as visited nodes; and mark the initial state of all nodes in the directed graph as unvisited. S1142. Iterate each node in the directed graph. If any node v is not marked as visited, execute a depth-first search function starting from the node v. S1143: Add the current node to the recursive call stack set, mark it as being visited, traverse all adjacent nodes of the current node, obtain the exploration status of all nodes, until all adjacent nodes are explored, move the current node from the recursive call stack set to the visited set, and return the detection result; S1144. If any call in traversing all nodes in the directed graph returns a signal that a loop is detected, then the entire directed graph contains a loop; otherwise, there is no loop in the directed graph; and when a loop is detected, an artificial delay is introduced to release the feedback loop.

6. The simulation method of a power system controller based on an AI simulation framework according to claim 5, wherein The node exploration status includes: loop discovery status, recursive exploration status and visited status; Wherein, the loop detection situation is that if the adjacent node belongs to the recursive call stack set, it indicates that there is a loop, and a loop detection signal is immediately returned; The recursive exploration situation is that if the adjacent node is not marked as visited, the depth-first search function is recursively called, and if the recursive call returns a loop signal detected, the detected loop signal is passed upward; The visited condition is that if the adjacent node has been marked as visited, it means that the adjacent node belongs to a branch in the directed graph that has been fully explored and does not form a loop with the current path, then the adjacent node is ignored and the exploration continues to the next adjacent node.

7. A simulation method for a power system controller based on an AI simulation framework according to claim 5, characterized in that, When a loop is detected, introducing an artificial delay to release the feedback loop includes: For each control element in the loop, a simulation step is temporarily delayed, and the output of the node in the loop at the current step is used as the input of the next step.

8. A simulation method of a power system controller based on an AI simulation framework according to claim 1, characterized in that, The creation of a controller model code generator, using the AI large model to assist in generating controller module code and corresponding unit test code, and setting a unified simulation function interface to achieve dynamic binding between the controller model code generator and the controller simulation framework include: S21. Create a prompt word template. When there is a new module code task, use the AI big model to generate the module code of each controller module in the power system controller; S22. During the initialization of each controller module by the controller simulation framework, the simulation functions of each controller module are bound to a unified simulation interface using a callable object wrapper, so as to dynamically call the simulation functions of different controller modules during the simulation process.

9. A simulation method of a power system controller based on an AI simulation framework according to claim 8, characterized in that When there is a new module code task, the module code of each controller module in the power system controller is generated by using the AI large model, including: S211, write a requirement description for the controller module to be generated to form a prompt word; S212. Input the requirement description into the AI big model, implement the functions of the controller module by generating code, and generate unit test code; S213. Review the generated code to verify the correctness of the code logic; S214. Use a code testing tool to perform static analysis on the code, check for potential errors and irregularities, and cover various boundary conditions and exceptional situations by running unit tests.

10. A power system controller simulation system based on an AI simulation framework, which is used to implement the power system controller simulation method based on the AI simulation framework described in any one of claims 1-9, and is characterized in that, The system includes: A controller simulation framework for generating the topological structure of the controller model, performing simulation by calling control components through topological sorting and loop detection processing, and visually displaying the simulation results; A controller model code generator for using an AI large model to assist in generating the code of the controller module and the corresponding unit test code, and setting a unified simulation function interface to achieve the dynamic binding between the controller model code generator and the controller simulation framework.

Citation Information

Cited By

  • RC circuit health state assessment method

    CN120654633A