Simulation method, device and computer equipment based on general code framework

By using a simulation method based on a general code framework, framework code is generated and simulation function class interface classes are created to realize the automated calling of simulation units and data serialization. This solves the development problem of complex distributed simulation platforms and improves simulation operation efficiency and development efficiency.

CN119203540BActive Publication Date: 2026-03-03NAT UNIV OF DEFENSE TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411286555.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-13
Publication Date
2026-03-03
Estimated Expiration
2044-09-13

AI Technical Summary

Technical Problem

Complex distributed simulation operation support platforms are difficult to call simulation services, and novice developers have a high probability of making mistakes. Traditional simulation service calls are inefficient, and users need to manage time to advance logic and do repetitive development work, which prolongs the system development time.

Method used

A simulation method based on a general code framework is adopted. The framework code is generated through simulation unit development tools, and interface classes that inherit from simulation function classes are created to realize the automatic calling of simulation units and data serialization. The automatic calling process of simulation services is encapsulated, and simple development interfaces and data processing modules are provided.

Benefits of technology

It reduces the difficulty of calling simulation services, decreases the probability of errors, improves simulation running efficiency, simplifies the development process, provides a reusable code framework, and reduces the difficulty and workload of integration development.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119203540B_ABST
    Figure CN119203540B_ABST
Patent Text Reader

Abstract

This invention relates to a simulation method, apparatus, and computer device based on a general code framework. The method includes: editing an object description file; dynamically generating framework code for the general code framework based on the object description file; generating corresponding data structures in the framework code based on object class and interaction class information from the object description file; creating interface classes that inherit from simulation function classes; adding a simulation unit to a co-simulation; calling relevant interface class functions to send and receive object class data and interaction message data in the simulation progress callback; serializing and deserializing the simulation running data input and output by the co-simulation according to the data structures; and calling a stop simulation interface to terminate the simulation when the simulation stops. This method provides a modifiable and reusable code framework for the convenient integration and development of simulation units, enabling automatic invocation of simulation middleware services and reducing the difficulty and workload of integration and development.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of co-simulation technology, and in particular to a simulation method, apparatus, and computer device based on a general code framework. Background Technology

[0002] Complex distributed simulation runtime support platforms typically provide a variety of simulation service call interfaces, sometimes numbering in the dozens, with inter-interface call dependencies. These interfaces must be invoked according to a prescribed call order and parameters. For novice developers, directly calling simulation services to develop distributed simulation systems is extremely difficult and prone to errors. Therefore, a generalized and automated method for calling simulation services is needed to reduce the difficulty for developers in calling simulation service interfaces for application development, while also reducing the probability of errors and achieving standardized and consistent development.

[0003] With the widespread application of complex distributed simulation, users are developing simulation units more and more frequently. Traditional simulation service calls require users to manage time advancement logic, manage simulation call processes, manage serialization functions, and handle various configurations, resulting in low development efficiency. Different users need to perform a lot of repetitive development work when developing simulation units, which prolongs the system development time. Summary of the Invention

[0004] Therefore, it is necessary to provide a simulation method, apparatus, and computer equipment based on a general code framework to address the aforementioned technical problems.

[0005] A simulation method based on a general code framework, the method comprising:

[0006] The object description file is edited using the common data model development tool of the simulation unit development tool. The framework code of the general code framework is dynamically generated based on the object description file. The corresponding data structure is generated in the framework code based on the object class and interaction class information in the object description file.

[0007] Create an interface class that inherits from the simulation function class; the simulation function class includes an object class function class, an interaction class function class, a main business processing class, and a callback data processing class.

[0008] The simulation unit calls the joint simulation interface to join the joint simulation. In the simulation advancement callback, it calls the relevant interface class functions to send and receive object class data and interaction message data. For the simulation running data input and output by the joint simulation, the simulation running data is serialized and deserialized according to the data structure respectively.

[0009] When the conditions for stopping the simulation are met, the simulation unit calls the stop simulation interface to end the simulation.

[0010] A simulation device based on a general code framework, the device comprising:

[0011] The framework generation module is used to edit the object description file using the common data model development tool of the simulation unit development tool, dynamically generate the framework code of the general code framework based on the object description file, and generate the corresponding data structure in the framework code based on the object class and interaction class information in the object description file.

[0012] The interface development module is used to create interface classes that inherit from the simulation function class; the simulation function class includes object class function class, interaction class function class, main business processing class, and callback data processing class.

[0013] The co-simulation module is used for simulation units to join co-simulation by calling the co-simulation interface. In the simulation progress callback, it calls relevant interface class functions to send and receive object class data and interaction message data. For the simulation run data input and output by co-simulation, it serializes and deserializes the simulation run data according to the data structure.

[0014] The simulation termination module is used to terminate the simulation by calling the stop simulation interface when the conditions for stopping the simulation are met.

[0015] A computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program performing the following steps:

[0016] The object description file is edited using the common data model development tool of the simulation unit development tool. The framework code of the general code framework is dynamically generated based on the object description file. The corresponding data structure is generated in the framework code based on the object class and interaction class information in the object description file.

[0017] Create an interface class that inherits from the simulation function class; the simulation function class includes an object class function class, an interaction class function class, a main business processing class, and a callback data processing class.

[0018] The simulation unit calls the joint simulation interface to join the joint simulation. In the simulation advancement callback, it calls the relevant interface class functions to send and receive object class data and interaction message data. For the simulation running data input and output by the joint simulation, the simulation running data is serialized and deserialized according to the data structure respectively.

[0019] When the conditions for stopping the simulation are met, the simulation unit calls the stop simulation interface to end the simulation.

[0020] A computer-readable storage medium having a computer program stored thereon, the computer program performing the following steps when executed by a processor:

[0021] The object description file is edited using the common data model development tool of the simulation unit development tool. The framework code of the general code framework is dynamically generated based on the object description file. The corresponding data structure is generated in the framework code based on the object class and interaction class information in the object description file.

[0022] Create an interface class that inherits from the simulation function class; the simulation function class includes an object class function class, an interaction class function class, a main business processing class, and a callback data processing class.

[0023] The simulation unit calls the joint simulation interface to join the joint simulation. In the simulation advancement callback, it calls the relevant interface class functions to send and receive object class data and interaction message data. For the simulation running data input and output by the joint simulation, the simulation running data is serialized and deserialized according to the data structure respectively.

[0024] When the conditions for stopping the simulation are met, the simulation unit calls the stop simulation interface to end the simulation.

[0025] The aforementioned simulation method, apparatus, and computer equipment based on a general code framework improve code execution efficiency and reduce unnecessary functional module generation by generating corresponding framework code for different co-simulations. It encapsulates the automated invocation process of simulation services, encapsulating the cumbersome and complex simulation service execution process within the code framework. It also exposes simple and easy-to-use secondary development interfaces for simulation units. Furthermore, it encapsulates a generalized serialization module for simulation execution data, generating the corresponding module functions when generating the code framework. This performs a significant amount of preparatory work for data processing during simulation execution, reducing data processing time and improving simulation efficiency. Users do not need to focus excessively on the complex interface invocation methods and simulation execution logic of the simulation middleware services when using the code framework; they can complete simulation unit development using the simple interface invocation of the framework code. This invention provides a modifiable and reusable code framework for convenient integrated development of simulation units, enabling automatic invocation of simulation middleware services and reducing the difficulty and workload of integration development. Attached Figure Description

[0026] Figure 1 This is a flowchart illustrating a simulation method based on a general code framework in one embodiment;

[0027] Figure 2 This is a schematic diagram of the simulation operation process in one embodiment;

[0028] Figure 3 This is a structural block diagram of a simulation device based on a general code framework in one embodiment;

[0029] Figure 4 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation

[0030] To make the objectives, technical solutions, and advantages of this invention clearer, the 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 merely illustrative and not intended to limit the invention.

[0031] In one embodiment, such as Figure 1 As shown, a simulation method based on a general code framework is provided, including the following steps:

[0032] Step 102: Use the common data model development tool of the simulation unit development tool to edit the object description file, dynamically generate the framework code of the general code framework based on the object description file, and generate the corresponding data structure in the framework code based on the object class and interaction class information in the object description file.

[0033] This invention provides development support for the interconnection, interoperability, and reuse of various LVC simulation resources based on simulation middleware services, and generates a general simulation code framework that conforms to simulation service standards and is compatible with simulation services. This code framework encapsulates the automated calling process of simulation services.

[0034] The general code framework can be automatically generated based on the common data model files in the co-simulation, and can be adapted to different simulation demonstration scenarios for different situations. While ensuring clear simulation operation logic, clear and unambiguous interfaces, and reasonable data exchange formats, it also ensures that the performance of the automated simulation service invocation process meets the transmission requirements of the simulation middleware. The automated simulation service invocation function mainly includes providing a simple and complete set of development interfaces for adding simulation units to the co-simulation; implementing various simulation operation logics in the simulation process; providing and constraining the data exchange format of the simulation middleware; providing serialization and deserialization functions for simulation middleware interaction data; supporting compilation into dynamic library form; supporting dynamic configuration of simulation unit subscription relationships; clear framework source code file classification; and a complete exception handling mechanism.

[0035] The business logic of simulation middleware relies entirely on simulation object description files. This invention simplifies redundant operations during simulation by dynamically generating framework code based on these object description files. Dynamic code generation allows for targeted optimization of code processing flows, reducing the complexity of simulation functionality. Dynamically generating framework code from object description files provides significant preparatory work for subsequent data serialization. For example, by pre-generating corresponding data structures in the framework code based on object class and interaction class information from the object description file, subsequent loading of the framework code can directly utilize the generated data structures for serialization and deserialization, improving runtime performance.

[0036] Specifically, after editing the object description file using the common data model development tool of the simulation unit development tool, the user generates framework code and a publication ordering relationship configuration file using the code framework generation function of the common data model development tool. The publication ordering relationship file and the framework code must be used together; after the user loads the framework code, the framework code will automatically read the configuration from the publication ordering relationship file. The generated files include a framework source code folder and the publication ordering relationship file. The framework source code folder contains the generated framework source code files and a VS project file. Opening the project file with VS will compile the generated framework source code into a dynamic library. The specific content of the publication ordering relationship file is generated based on the publication ordering relationships of each simulation unit configured in the object description file. The user needs to copy this file to the executable file directory of their program to implement the code framework configuration publication ordering relationship function.

[0037] The generated framework code includes external interface header files, data structure header files, and a `src` directory. The data structure header files define the structures of all object / interaction classes, composite data types, and enumeration data types required during the simulation. The external interface header files are declaration files for the functional classes provided to the user. These classes encapsulate most of the functions needed during the simulation, such as starting and stopping the simulation, updating / reflecting object classes, registering object instances, and sending and receiving interaction classes. Data reflection encoding is generally performed by inheriting from this class. The `src` directory contains all the code implementing the general framework functionality.

[0038] Step 104: Create an interface class that inherits from the simulation function class.

[0039] The simulation middleware provides users with secondary development interfaces through a code framework. While the conventional method of calling the code framework interface can meet the needs of most scenarios, some special scenarios, such as switching control between simulation threads and user threads, shared access to simulation resources, and copying raw data, require flexible manipulation of the code framework's internal data and functions. Therefore, the code framework provides two secondary development methods: interface calling and embedded inheritance. Both methods use the same automated simulation service invocation method, and the two methods can be switched by defining preprocessing macros.

[0040] Interface calling is the most common method in simulation unit development. This invention provides a clear and explicit set of external interfaces, through which users can complete all the functions of the middleware. This invention also provides a VS project file, which can compile the framework source code into a dynamic library. Users can use the code framework by loading the dynamic library, reducing repetitive compilation operations in some scenarios. Interface calling, as the name suggests, encapsulates complex simulation business logic, implements all the functions that the code framework can achieve within the code framework, extracts the functions that need to be exposed into simple and clear interfaces, and finally forms an interface header file and a set of source code directories. Through interface calling, users can quickly integrate the middleware without needing to understand the internal structure of the simulation middleware.

[0041] Embedded inheritance is a more advanced approach to developing simulation units. This invention provides a fully inheritable development source code based on actual user needs. In the framework code provided to users, a public object class and an ordering object class are generated for each object class, and an interaction class is generated for each interaction class. In addition, there are main business processing classes, callback data processing classes, etc. Users can clearly understand the overall structure of the code framework based on the object description file information, reducing the development difficulty of the embedded inheritance approach. The functional classes in the framework code are all abstract classes, which can all be inherited, and the interface functions can be overridden after inheritance. Through embedded inheritance, users can dynamically modify interface functions and directly simulate various data in the framework code, offering greater flexibility, but requiring users to have a certain understanding of the code framework.

[0042] Step 106: The simulation unit calls the joint simulation interface to join the joint simulation. In the simulation advancement callback, it calls the relevant interface class functions to send and receive object class data and interaction message data. For the simulation running data input and output by the joint simulation, the simulation running data is serialized and deserialized according to the data structure.

[0043] The code framework generates object class functional classes and interaction class functional classes for each object class and interaction class. These classes define all the attributes and parameters of the object class and interaction class itself. Based on the object description file information, the code framework defines the serialization rules for these class attributes and parameters. When data needs to be integrated into the co-simulation, the code framework automatically serializes the data according to the defined serialization rules. When data needs to be transmitted to the user, the code framework automatically deserializes the data according to the defined serialization rules. Defining serialization rules in the code framework can improve the efficiency of message serialization and reduce data processing time.

[0044] Step 108: When the conditions for stopping the simulation are met, the simulation unit calls the stop simulation interface to end the simulation.

[0045] In the aforementioned simulation method based on a general code framework, the object description file is edited using the common data model development tool of the simulation unit development tool. The framework code of the general code framework is dynamically generated based on the object description file. Corresponding data structures are generated in the framework code based on the object class and interaction class information in the object description file. Interface classes inheriting from the simulation function classes are created. The simulation unit calls the joint simulation interface to join the joint simulation. In the simulation progress callback, relevant interface class functions are called to send and receive object class data and interaction message data. For the simulation running data input and output by the joint simulation, the simulation running data is serialized and deserialized according to the data structure. When the simulation stop condition is met, the simulation unit calls the stop simulation interface to end the simulation. This embodiment of the invention can provide a modifiable and reusable code framework for the convenient integration and development of simulation units, realize automatic invocation of simulation middleware services, and reduce the difficulty and workload of integration and development.

[0046] In one embodiment, dynamically generating the framework code of a general code framework based on an object description file includes: copying a template file from the installation directory of the simulation middleware software; the template file contains fixed code sections and insertion position identifiers required to generate the framework code; and inserting specific simulation service automation call code at the corresponding identifier positions in the template file based on the object description file information to generate the code framework, wherein the inserted code is generated based on the content of the object description file.

[0047] In this embodiment, the framework code is generated using a template-insertion method. First, template files necessary for generating the framework code are provided in the middleware software installation directory. These template files contain most of the fixed code for automated simulation service calls and insertion point identifiers. Second, template files are copied sequentially from the middleware software installation directory. After each copy, the automated simulation service call code is inserted into the corresponding identifier positions in the template file based on the information in the object description file, forming a complete and logically clear simulation framework code. Using the template-insertion method significantly reduces the text manipulation work required for code generation, improves the efficiency of framework code generation, and enhances overall logical clarity.

[0048] In one embodiment, the method further includes: compiling the framework source code into a dynamic library using VS project files, and simulating developers using the code framework by loading the dynamic library.

[0049] In one embodiment, the code structure of the framework code includes a main functional part and branch modules organized by class; the main functional part is used to complete the simulation preparation work and start the simulation loop; the simulation preparation work includes simulation initialization work, announcement of order relationship configuration work, time management configuration work, and exception handling initialization work; the branch modules organized by class are used to generate functional classes for each simulation object class and interaction class, and define the data structures and algorithms related to the object class or interaction class through the functional classes.

[0050] In this embodiment, the simulation middleware has numerous functions and complex simulation business. The framework code adopts a main body-by-class branching approach to implement functional blocks for automated invocation of simulation services. First, the simulation initialization, order relationship announcement, time management configuration, and exception handling initialization are completed in the main function file, and the simulation loop begins. The time management logic is combined with the main simulation loop function, and the orderly operation of the entire simulation logic is controlled by message callbacks and event locks. Second, independent function classes and data structures are generated for each object class and interaction class. Each corresponding function class can independently complete its own simulation work, and the overall coordination in the main thread improves code readability.

[0051] In one embodiment, before the simulation unit calls the joint simulation interface to join the joint simulation, the method further includes: instantiating the interface class into an externally exposed interface; the externally exposed interface includes an active call interface and a callback interface.

[0052] In this embodiment, to meet the functional requirements of the simulation middleware, the code framework provides the following active call interfaces in the interface call mode: Get Simulation Running Status Interface, Start Simulation Interface, Stop Simulation Interface, Pause Simulation Interface, Continue Simulation Interface, Register Object Instance Interface, Delete Object Instance Interface, Send Object Instance Data Interface, Send Interactive Data Interface, Send TSO Object Instance Data Interface, Send TSO Interactive Data Interface, Send File Interface, Receive File Interface, Get Current Logical Time Interface, Query the Last Hour Stamp of TSO Events that Can Be Passed to the Local Co-simulation Unit Interface, Request Advance to an Event Point Interface, Co-simulation Save Interface, Co-simulation Restore Interface, Request Transfer of Object Instance Ownership Interface, Response to Transfer of Object Instance Ownership Interface, Request Acquisition of Object Instance Ownership Interface, Response to Acquisition of Object Instance Ownership Interface, Request Unconditional Transfer of Object Instance Ownership Interface, Request Shared Object Attribute Ownership Interface, Response to Shared Object Attribute Ownership Interface, Request Cancel Shared Object Attribute Ownership Interface, Initialize QoS Management Interface, Delete QoS Management Interface, User Save Data Interface, User Restore Previously Saved Data Interface.

[0053] To meet the functional requirements of the simulation middleware, the code framework provides the following callback interfaces in the interface call mode: object instance property reflection, interactive message reflection, simulation progress function, discovery of registered object instances, discovery of removed object instances, TSO object instance property reflection, TSO interactive message reflection, notification to user that a file has arrived, reflection of saved published object property values, reflection of saved ordered object property values, discovery of error types, discovery of request to transfer object instance ownership, discovery of response to transfer object instance ownership, discovery of request to acquire object instance ownership, discovery of response to acquire object instance ownership, discovery of request to share object property ownership, discovery of response to share object property ownership, discovery of request to cancel shared object property ownership, and reflection of shared object property values.

[0054] In one embodiment, the general code framework re-encapsulates the simulation middleware interface, abandoning the original complex calling logic and providing users with clear and explicit active call interfaces and callback interfaces. Simultaneously, the framework code categorizes the exposed interfaces, placing the interfaces primarily needed for joining the co-simulation at the beginning of the interface file. Users only need to call a few simple interfaces to successfully join the co-simulation and complete the simulation tasks. When users need to use deeper functionalities, they can then learn about and call other interfaces.

[0055] In one embodiment, before calling the reflection object attribute data function and the reflection interaction message function in the simulation advancement callback to send and receive object class data and interaction message data, the method further includes: defining an instance of the object instance data structure, assigning initial values ​​to the instance, and calling the code framework interface to add an object instance.

[0056] In one embodiment, for simulation runtime data input and output by co-simulation, serialization and deserialization of the simulation runtime data according to the data structure include: when simulation runtime data is input into the co-simulation, serialization of the simulation runtime data is automatically completed according to the serialization rules of the attributes and parameters of the object class functional class and the interaction class functional class; when simulation runtime data is output to the simulation developer, deserialization of the data is automatically completed according to the defined serialization rules. In this embodiment, the general code framework encapsulates a general serialization module for simulation runtime data. Generating corresponding serialization modules for different object description files provides strong targeting, improves serialization efficiency, improves simulation runtime efficiency, and reduces data processing time.

[0057] In one specific embodiment, users need to first generate framework code based on the object description file, and then load the framework code into their own development project for development. The development process is as follows:

[0058] Create an interface class that inherits from the simulation function class to receive ordered data and trigger simulation advance functions. The main inherited functions include simulation advance callback functions, reflection attribute data functions, and reflection interaction message functions. Specifically: the simulation advance callback function is passively called within each simulation time slice, primarily providing users with the opportunity to add their own business code to ensure consistency between their simulation unit's time and space and the middleware; the reflection attribute data function receives ordered object class data, and is passively triggered when other simulation units in the co-simulation publish the object instance data ordered by this simulation unit; the reflection interaction message function receives ordered interaction class data, and is passively triggered when other simulation units in the co-simulation publish the interaction class data ordered by this simulation unit.

[0059] Simulation begins. First, the code framework interface class is instantiated. The instantiation variables of the code framework interface class are defined inside the framework code and referenced in the header file of the code framework interface class. When instantiating the code framework interface class, the simulation function class inherited above needs to be used for instantiation. Call the join co-simulation interface to start the simulation. After calling this interface, the simulation unit joins the co-simulation and begins time progression and receiving ordered data.

[0060] Register object instances. Define an instance of the object instance data structure, assign initial values ​​to the instance, and call the code framework interface to add object instances.

[0061] Sending object instance / interaction class data. Object instance and interaction message data are sent in the simulation progress callback of the code framework; the object instance data is sent by calling the object attribute data sending interface; the interaction message data is sent by calling the interaction message interface; the simulation progress callback function is passively triggered once in each simulation step, typically publishing object instance data within it. This ensures that the publication of object instance data by the simulation unit is synchronized with the time progression of the co-simulation (provided time is controlled and limited); after joining co-simulation, interaction messages can be sent at any code location within the simulation unit.

[0062] Receive object instance / interaction class data. Object instance data is received in the reflection object property callback interface. The user determines whether the data matches the object class they need to subscribe to within the reflection object property callback function, receives the object instance data, and performs business processing. Interaction message data is received in the reflection interaction message callback. The user determines whether the data matches the interaction class they need to subscribe to within the reflection interaction message function, receives the interaction message data, and performs business processing.

[0063] Stop simulation. The simulation unit can stop the simulation by calling the Stop Simulation interface at an appropriate location. After the simulation stops, the data of the simulation unit in the co-simulation will be destroyed. The simulation unit can rejoin the co-simulation by calling the Start Simulation interface again.

[0064] In one specific embodiment, such as Figure 2 The simulation operation flowchart shown below illustrates the automated simulation service invocation process, which includes:

[0065] S11: Create a co-simulation. When a user joins a co-simulation, the co-simulation must be created first. If the co-simulation does not exist, it will be created; otherwise, it will be skipped.

[0066] S12: Simulation Unit Joins Simulation. When a co-simulation is successfully created or already exists, the simulation unit begins to request to join the co-simulation. If the joining is successful, it continues; otherwise, an exception error code is returned.

[0067] S13: Set up simulation unit publication / ordering relationship. After a simulation unit is successfully added to the co-simulation, the code framework calls the simulation middleware's native interface to request configuration of the publication / ordering relationship based on the publication / ordering relationship file generated simultaneously with the code framework. If the configuration is successful, continue; otherwise, return an exception error code.

[0068] S14: Set the simulation unit's time management strategy. After the simulation unit is successfully added to the co-simulation, the code framework will call the simulation middleware's time management interface to configure time management based on the object description file information generated when the framework code was generated. If the configuration is successful, it will continue; otherwise, it will return an exception error code.

[0069] S15: Simulation Unit Initialization. After configuring the subscription relationship and time management strategy, the simulation code framework initializes the simulation unit's information, including object class handles, interaction class handles, object class attribute handles, interaction class parameter handles, ownership management configurations, and interest management configurations. Next, the simulation code framework registers the instances added by the user before the simulation begins. If simulation initialization is successful, it continues; otherwise, it returns an exception error code.

[0070] S16: Start Simulation Progression Loop. After starting the simulation progression loop, the code framework calls the simulation progression callback function within the loop. This callback function can be implemented by the user through inheritance. When the simulation begins, the code framework calls this function, and the user-inherited function is also passively triggered. Users can implement business functions within this function, maintaining synchronization with the simulation progression pace. In each simulation progression loop, the code framework calls the simulation middleware's time progression function to request time progression. The simulation middleware determines whether to allow progression based on the timing strategies and business processing status of each simulation unit in the co-simulation. If the simulation middleware does not allow progression, the time progression function will block until the simulation middleware allows progression; if the simulation middleware allows progression, the time progression function will release the block and begin the next loop.

[0071] S17: Simulation unit exits simulation. When the simulation unit stops or terminates abnormally, the code framework will notify the simulation middleware to request to exit the simulation. If the exit is successful, it will continue; otherwise, it will return an exception error code.

[0072] S18: Destroy simulation resources. After a simulation unit exits the simulation, the code framework will notify the simulation middleware to destroy the relevant resource data of the current simulation unit. If this simulation unit is the last simulation unit in the current co-simulation, the simulation middleware should also destroy the co-simulation. If the destruction is successful, continue; otherwise, return an exception error code.

[0073] It should be understood that, although Figure 1 The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order in which these steps are executed, and they can be performed in other orders. Figure 1 At least some of the steps in the process may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.

[0074] In one embodiment, such as Figure 3 The present invention provides a simulation device based on a general code framework, comprising:

[0075] The framework generation module 302 is used to edit the object description file using the common data model development tool of the simulation unit development tool, dynamically generate the framework code of the general code framework based on the object description file, and generate the corresponding data structure in the framework code based on the object class and interaction class information in the object description file.

[0076] The interface development module 304 is used to create interface classes that inherit from the simulation function class; the simulation function class includes object class function class, interaction class function class, main business processing class, and callback data processing class.

[0077] The co-simulation module 306 is used for simulation units to call the co-simulation interface to join the co-simulation. In the simulation advancement callback, it calls the relevant interface class functions to send and receive object class data and interaction message data. For the simulation running data input and output by the co-simulation, it serializes and deserializes the simulation running data according to the data structure respectively.

[0078] The simulation termination module 308 is used to terminate the simulation by calling the stop simulation interface when the conditions for stopping the simulation are met.

[0079] Specific limitations regarding the simulation device based on the general code framework can be found in the limitations of the simulation method based on the general code framework above, and will not be repeated here. Each module in the aforementioned simulation device based on the general code framework can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in the computer device in hardware form, or stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to each module.

[0080] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 4 As shown, the computer device includes a processor, memory, network interface, display screen, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The network interface is used to communicate with external terminals via a network connection. When the computer program is executed by the processor, it implements a simulation method based on a general code framework. The display screen can be an LCD screen or an e-ink display screen. The input devices can be a touch layer covering the display screen, buttons, a trackball, or a touchpad mounted on the computer device casing, or an external keyboard, touchpad, or mouse.

[0081] Those skilled in the art will understand that Figure 4The structure shown is merely a block diagram of a portion of the structure related to the present invention and does not constitute a limitation on the computer device to which the present invention is applied. A specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0082] In one embodiment, a computer device is provided, including a memory and a processor, the memory storing a computer program, the processor executing the computer program to implement the steps of the method described above.

[0083] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps of the method described above.

[0084] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided by this invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.

[0085] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0086] The embodiments described above are merely illustrative of several implementations of the present invention, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of the invention. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these modifications and improvements all fall within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the appended claims.

Claims

1. A simulation method based on a general code framework, characterized in that, The method includes: The object description file is edited using the common data model development tool of the simulation unit development tool. The framework code of the general code framework is dynamically generated based on the object description file. The corresponding data structure is generated in the framework code based on the object class and interaction class information in the object description file. Create an interface class that inherits from the simulation function class; the simulation function class includes an object class function class, an interaction class function class, a main business processing class, and a callback data processing class. The simulation unit calls the joint simulation interface to join the joint simulation. In the simulation advancement callback, it calls the relevant interface class functions to send and receive object class data and interaction message data. For the simulation running data input and output by the joint simulation, the simulation running data is serialized and deserialized according to the data structure respectively. When the conditions for stopping the simulation are met, the simulation unit calls the stop simulation interface to end the simulation; For the simulation runtime data input and output by the co-simulation, serialization and deserialization of the simulation runtime data are performed according to the data structure, including: When simulation runtime data is connected to the co-simulation, the serialization of the simulation runtime data is automatically completed according to the serialization rules of the attributes and parameters of the object class function class and the interaction class function class; When simulation data is output to the simulation developer, it is automatically deserialized according to the defined serialization rules.

2. The method according to claim 1, characterized in that, Before the simulation unit calls the joint simulation interface to join the joint simulation, it also includes: Instantiate the interface class into an externally exposed interface; the externally exposed interface includes active call interfaces and callback interfaces.

3. The method according to claim 1, characterized in that, Before calling the reflection object property data function and reflection interaction message function in the simulation advancement callback to send and receive object class data and interaction message data, the following is also included: Define an instance of the object instance data structure, assign initial values ​​to the instance, and call the code framework interface to add object instances.

4. The method according to claim 1, characterized in that, The method further includes: The framework source code is compiled into a dynamic library using the VS project file, allowing developers to use the code framework by loading the dynamic library.

5. The method according to claim 1, characterized in that, The code structure of the framework code includes the main functional part and branch modules organized by class; The main functional section is used to complete the simulation preparation work and start the simulation cycle; the simulation preparation work includes simulation initialization, order relationship configuration, time management configuration, and exception handling initialization. Branching modules organized by class are used to generate functional classes for each simulation object class and interaction class. These functional classes define the data structures and algorithms associated with the object class or interaction class.

6. The method according to claim 1, characterized in that, The framework code that dynamically generates a generic code framework based on the object description file includes: Copy the template file from the installation directory of the simulation middleware software; the template file contains the fixed code sections and insertion position identifiers required to generate the framework code; Based on the object description file information, specific simulation service automation call code is inserted into the corresponding identifier position in the template file to generate a code framework. The inserted code is generated based on the content of the object description file.

7. A simulation device based on a general code framework applied to the method as described in any one of claims 1-6, characterized in that, The device includes: The framework generation module is used to edit the object description file using the common data model development tool of the simulation unit development tool, dynamically generate the framework code of the general code framework based on the object description file, and generate the corresponding data structure in the framework code based on the object class and interaction class information in the object description file. The interface development module is used to create interface classes that inherit from the simulation function class; the simulation function class includes object class function class, interaction class function class, main business processing class, and callback data processing class. The co-simulation module is used for simulation units to join co-simulation by calling the co-simulation interface. In the simulation progress callback, it calls relevant interface class functions to send and receive object class data and interaction message data. For the simulation run data input and output by co-simulation, it serializes and deserializes the simulation run data according to the data structure. The simulation termination module is used to terminate the simulation by calling the stop simulation interface when the conditions for stopping the simulation are met.

8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Code automatic generation method and device, electronic equipment and storage medium

    CN115857900A

  • Service-oriented simulation model reusable framework and integration method

    CN116774978A