Simulation method and device based on universal code framework and computer equipment
Through the simulation method based on the general code framework, the high error rate and low efficiency problems in the development of distributed simulation system are solved, automatic simulation service calls and data serialization are provided, the integrated development of simulation units is simplified, and simulation operation is improved efficiency.
Patent Information
- Application Number
- CN202411286555.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-13
- Publication Date
- 2024-12-27
- Estimated Expiration
- 2044-09-13
AI Technical Summary
In the development of complex distributed simulation systems, it is difficult for primary development users to directly call simulation services, which has a high probability of errors. In addition, traditional simulation service calls require time-based promotion logic, serialization functions and configuration, resulting in low development efficiency and increased repetitive work.
Using a simulation method based on a general code framework, edit object description files through simulation unit development tools, dynamically generate framework code, create interface classes inherited from simulation function classes, add joint simulation interfaces, perform data serialization and deserialization, and End the simulation when the stop condition is reached.
It reduces the difficulty of calling simulation services, reduces the probability of errors, improves development efficiency, provides a transformable code framework, realizes automated calls of simulation middleware services, and simplifies the integrated development process of simulation units.
Smart Images

Figure CN119203540A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of joint simulation technology, and in particular to a simulation method, device and computer equipment based on a universal code framework. Background Art
[0002] Complex distributed simulation operation support platforms usually provide a variety of simulation service call interfaces, the number of which can reach dozens, and there are interface call dependencies. The corresponding service interface needs to be called according to the specified call order and parameters. For novice development users, it is extremely difficult to directly call simulation services to develop distributed simulation systems, and the probability of errors is high. It is necessary to provide a universal and automated simulation service call method to reduce the difficulty for developers to call simulation service interfaces for application development, while 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, simulation call process, serialization functions and various configurations. The development efficiency is low. Different users need to carry out a lot of repetitive development work to develop simulation units, which prolongs the development time of the system. Summary of the invention
[0004] Based on this, it is necessary to provide a simulation method, device and computer equipment based on a general code framework to address the above technical problems.
[0005] A simulation method based on a general code framework, the method comprising:
[0006] Using a public data model development tool of a simulation unit development tool to edit an object description file, dynamically generating a framework code of a general code framework according to the object description file, and generating a corresponding data structure in the framework code according to object class and interaction class information in the object description file;
[0007] Creating an interface class inherited from a simulation function class; the simulation function class includes an object class function class, an interactive 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, calls the relevant interface class function in the simulation advancement callback to send and receive object class data and interactive message data, and serializes and deserializes the simulation running data accessed and output by the joint simulation according to the data structure;
[0009] When the simulation stop condition is reached, 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] A framework generation module, used to edit the object description file using the public data model development tool of the simulation unit development tool, dynamically generate the framework code of the general code framework according to the object description file, and generate the corresponding data structure in the framework code according to the object class and interaction class information in the object description file;
[0012] An interface development module is used to create an interface class inherited from a simulation function class; the simulation function class includes an object class function class, an interactive class function class, a main business processing class, and a callback data processing class;
[0013] The joint simulation module is used for the simulation unit to call the joint simulation interface to join the joint simulation, call the relevant interface class function in the simulation advancement callback to send and receive object class data and interactive message data, and serialize and deserialize the simulation running data accessed and output by the joint simulation according to the data structure;
[0014] The simulation end module is used for the simulation unit to call the simulation stop interface to end the simulation when the simulation stop condition is reached.
[0015] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0016] Using a public data model development tool of a simulation unit development tool to edit an object description file, dynamically generating a framework code of a general code framework according to the object description file, and generating a corresponding data structure in the framework code according to object class and interaction class information in the object description file;
[0017] Creating an interface class inherited from a simulation function class; the simulation function class includes an object class function class, an interactive 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, calls the relevant interface class function in the simulation advancement callback to send and receive object class data and interactive message data, and serializes and deserializes the simulation running data accessed and output by the joint simulation according to the data structure;
[0019] When the simulation stop condition is reached, the simulation unit calls the stop simulation interface to end the simulation.
[0020] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the following steps:
[0021] Using a public data model development tool of a simulation unit development tool to edit an object description file, dynamically generating a framework code of a general code framework according to the object description file, and generating a corresponding data structure in the framework code according to object class and interaction class information in the object description file;
[0022] Creating an interface class inherited from a simulation function class; the simulation function class includes an object class function class, an interactive 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, calls the relevant interface class function in the simulation advancement callback to send and receive object class data and interactive message data, and serializes and deserializes the simulation running data accessed and output by the joint simulation according to the data structure;
[0024] When the simulation stop condition is reached, the simulation unit calls the stop simulation interface to end the simulation.
[0025] The above-mentioned simulation method, device and computer equipment based on the general code framework, by generating corresponding framework codes for different joint simulations, improves the code operation efficiency, reduces the generation of unnecessary functional modules, encapsulates the automatic calling process of the simulation service, encapsulates the cumbersome and complex simulation service operation process in the code framework, and opens a simple and easy-to-call simulation unit secondary development interface. At the same time, it also encapsulates the generalized serialization module of the simulation operation data, and generates the corresponding module functions when generating the code framework, does a lot of prerequisite work for the data processing during the simulation operation, reduces the data processing time during the simulation operation, and improves the simulation operation efficiency. When using the code framework, the user does not need to pay too much attention to the complex interface calling method and simulation operation logic of the simulation middleware service, and can complete the simulation unit development using the simple interface call of the framework code. The present invention provides a transformable and reusable code framework for the convenient integrated development of the simulation unit, realizes the automatic call of the simulation middleware service, and reduces the difficulty and workload of the integrated development. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 A schematic diagram of a flow chart of a simulation method based on a general code framework in an embodiment;
[0027] Figure 2 A schematic diagram of a simulation operation flow in an embodiment;
[0028] Figure 3 is a structural block diagram of a simulation device based on a general code framework in one embodiment;
[0029] Figure 4 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0030] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0031] In one embodiment, Figure 1 As shown, a simulation method based on a general code framework is provided, comprising the following steps:
[0032] Step 102, edit the object description file using the public data model development tool of the simulation unit development tool, dynamically generate the framework code of the general code framework according to the object description file, and generate the corresponding data structure in the framework code according to the object class and interaction class information in the object description file.
[0033] The present invention provides development function support for the interconnection, interoperability and combined reuse of various simulation resources of LVC based on simulation middleware services, generates a simulation general code framework that meets the simulation service standards and is compatible with the simulation service, and the code framework encapsulates the automated calling process of the simulation service.
[0034] The general code framework can be automatically generated according to the public data model file in the joint simulation, and can adapt to different simulation demonstration scenarios for different scenarios. Under the premise of ensuring clear simulation operation logic, clear and clear interfaces, and reasonable data exchange format, it also ensures that the performance of the simulation service automation calling process meets the transmission requirements of the simulation middleware. The simulation service automation calling function mainly includes providing a simple set of development interfaces for simulation units to join joint simulations, realizing the various simulation operation logics of 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 forms, supporting dynamic configuration of simulation units to publish subscription relationships, clear framework source code file classification, and complete exception handling mechanisms.
[0035] The services of simulation middleware all rely on simulation object description files. The present invention adopts a method of dynamically generating framework codes according to object description files to simplify redundant operations during simulation operation. The method of dynamically generating codes can optimize the code processing flow in a targeted manner and simplify the operation complexity of simulation functions. Dynamically generating framework codes according to object description files can perform a large amount of prerequisite work for subsequent data serialization. For example, the corresponding data structure is generated in the framework code in advance according to the object class and interaction class information in the object description file. When the framework code is loaded later, serialization and deserialization can be directly performed according to the generated data structure to improve operation performance.
[0036] Specifically, after the user edits the object description file through the public data model development tool of the simulation unit development tool, the framework code and the published subscription relationship configuration file are generated through the code framework generation function of the public data model development tool. The published subscription relationship file and the framework code need to be used in conjunction with each other. After the user loads the framework code, the framework code will automatically read the configuration in the published subscription relationship file. The generated file contains a framework source code folder and a published subscription relationship file. The framework source code folder contains the generated framework source code file and the VS project file. The generated framework source code can be compiled into a dynamic library by opening the project file with VS. The specific content of the published subscription relationship file is generated based on the published subscription relationship of each simulation unit configured in the object description file. The user needs to copy the file to the executable file directory of his own program to implement the code framework configuration published subscription relationship function.
[0037] The generated framework code contains external interface header files, data structure header files and src directories. The data structure header files define the structures of all object classes / interaction classes, composite data types and enumeration data types required in the simulation process. The external interface header files are declaration files of the functional classes provided to users. This class encapsulates most of the functions required in the simulation process, such as starting simulation, stopping simulation, updating / reflecting object classes, registering object instances, sending and receiving interactive classes, etc. Data reflection coding is generally performed by inheriting this class. The src directory contains all the codes for implementing the general code framework functions.
[0038] Step 104, creating an interface class inherited from the simulation function class.
[0039] The simulation middleware provides users with secondary development interfaces by providing a code framework. The conventional method of calling the code framework interface can meet the needs of most scenarios. However, in some special scenarios, such as the switching control between simulation threads and user threads, shared access to simulation resources, copying original data, etc., it is necessary to flexibly operate the internal data and functions of the code framework. Therefore, the code framework provides two secondary development methods, one is the interface calling method, and the other is the embedded inheritance method. Both methods use the same simulation service automatic calling method, and the two methods can be switched by defining preprocessing macros.
[0040] The interface calling method is the most commonly used method for developing simulation units. The present invention provides a set of clear and explicit open interfaces, through which users can complete all functions of accessing the middleware. The present 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 the repeated compilation operations of users in some scenarios. The interface calling method, as the name implies, is to encapsulate the complex simulation business logic, implement all the functions that can be realized by the code framework within the code framework, and extract simple and clear interfaces from the functions that need to be opened, and finally form an interface header file and a set of source code directories. Through the interface calling method, users can quickly access the middleware without having to know too much about the internal structure of the simulation middleware.
[0041] The embedded inheritance method is a relatively in-depth method for developing simulation units. The present invention provides a set of fully inheritable development source codes according to the actual use needs of users. In the framework code provided to users, an object class publishing function class and an object class ordering function class are generated for each object class, and an interactive class function class is generated for each interactive class. In addition, there are main business processing classes, callback data processing classes, etc. Users can clearly know the general structure of the code framework based on the object description file information, reducing the development difficulty of the embedded inheritance method. The functional classes of the framework code are all abstract classes, and these classes can all be inherited. After inheritance, the interface functions inside can be rewritten. Through the embedded inheritance method, users can dynamically modify the interface functions, and can also directly simulate various types of data in the framework code. It is more flexible to use, but users need 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, calls the relevant interface class function in the simulation advancement callback to send and receive object class data and interaction message data, and serializes and deserializes the simulation running data accessed and output by the joint simulation according to the data structure.
[0043] The code framework generates object class function classes and interaction class function classes for each object class and interaction class. These classes define all the attributes and parameters of the object class and interaction class themselves. The code framework defines the serialization rules of the attributes and parameters of these classes based on the object description file information. When data needs to be connected to the joint simulation, the code framework automatically completes the serialization of the data according to the defined serialization rules. When data needs to be transmitted to the user, the code framework automatically completes the deserialization of the data according to the defined serialization rules. Defining serialization rules in the code framework can improve the efficiency of serialization messages and reduce data processing time.
[0044] Step 108: When the simulation stop condition is met, the simulation unit calls the simulation stop interface to end the simulation.
[0045] In the above-mentioned simulation method based on the general code framework, the public data model development tool of the simulation unit development tool is used to edit the object description file, the framework code of the general code framework is dynamically generated according to the object description file, the corresponding data structure is generated in the framework code according to the object class and interaction class information in the object description file, an interface class inherited from the simulation function class is built, the real unit calls the joint simulation interface to join the joint simulation, and calls the relevant interface class function in the simulation advancement callback to send and receive object class data and interaction message data. For the simulation operation data accessed and output by the joint simulation, the simulation operation data is serialized and deserialized according to the data structure respectively. When the condition for stopping the simulation is met, the simulation unit calls the stop simulation interface to end the simulation. The embodiment of the present invention can provide a transformable and reusable code framework for the convenient integrated development of the simulation unit, realize the automatic call to the simulation middleware service, and reduce the difficulty and workload of integrated development.
[0046] In one embodiment, dynamically generating framework code for a general code framework based on an object description file includes: copying a template file from an installation directory of a simulation middleware software; the template file contains a fixed code portion and an insertion position identifier required to generate the framework code; and according to the object description file information, inserting specific simulation service automation call code at a corresponding identification position in the template file to generate a code framework, wherein the inserted code is generated according to the content of the object description file.
[0047] In this embodiment, the framework code is generated by copying the template and inserting the code. First, the template file required for generating the framework code is provided in the middleware software installation directory. The template file contains most of the fixed codes and insertion position identifiers for the simulation service automation calls; secondly, the template files are copied from the middleware software installation directory in sequence. After each copy of the template file, the simulation service automation call code is inserted into the corresponding identification position of the template file according to the information of the object description file, forming a set of simulation framework codes with complete functions and clear logic. The copying template and inserting code method can greatly reduce the text operation work required for generating the code, improve the efficiency of framework code generation, and improve the overall logical clarity.
[0048] In one embodiment, the method further includes: using the VS project file to compile the framework source code into a dynamic library, and the simulation developer uses 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 simulation preparation and start the simulation cycle; the simulation preparation includes simulation initialization, publishing subscription relationship configuration, time management configuration and exception handling initialization; the branch modules organized by class are used to generate functional classes for each simulation object class and interaction class, and define data structures and algorithms related to the object class or interaction class through the functional class.
[0050] In this embodiment, the simulation middleware has many functions and the simulation business is complex. The framework code uses the main body-branching method to realize the functional block of the automatic call of the simulation service. First, in the main function file, the simulation initialization work, the publication of the order relationship work, the time management configuration work, the exception handling initialization work, etc. are completed and the simulation cycle is started. The time management logic is combined with the simulation main loop function, and the orderly operation of the entire simulation logic is controlled by message callback and event lock; secondly, an independent function class and data structure are generated for each object class and interaction class. Each corresponding function class can independently complete its own simulation work, and the readability of the code is improved by overall deployment in the main thread.
[0051] In one embodiment, before the simulation unit calls the joint simulation interface to join the joint simulation, it also includes: instantiating the interface class into an externally open interface; the externally open interface includes an active call interface and a callback interface.
[0052] In this embodiment, in order to meet the functional requirements of the simulation middleware, in the interface call mode, the code framework provides the following active calling interfaces: obtaining simulation running status interface, starting simulation interface, stopping simulation interface, pausing simulation interface, continuing simulation interface, registering object instance interface, deleting object instance interface, sending object instance data interface, sending interactive data interface, sending TSO object instance data interface, sending TSO interactive data interface, sending file interface, receiving file interface, obtaining current logical time interface, querying the minimum hour stamp interface of TSO events that can be subsequently passed to the local joint simulation unit, requesting to advance to an event point interface, joint simulation saving interface, joint simulation recovery interface, requesting to transfer object instance ownership interface, responding to transferring object instance ownership interface, requesting to obtain object instance ownership interface, responding to obtaining object instance ownership interface, requesting unconditional transfer of object instance ownership interface, requesting shared object attribute ownership interface, responding to shared object attribute ownership interface, requesting to cancel shared object attribute ownership interface, initializing QOS management interface, deleting QOS management interface, user saving data interface, user restoring previously saved data interface.
[0053] In order to meet the functional requirements of the simulation middleware, in the interface call mode, the code framework provides the following callback interfaces: object instance attribute reflection, interactive message reflection, simulation advancement process function, discovery of registered object instances, discovery of removed object instances, TSO object instance attribute reflection, TSO interactive message reflection, notification of user file arrival, reflection of saved published object attribute values, reflection of saved subscribed object attribute 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 obtain object instance ownership, discovery of response to obtain object instance ownership, discovery of request to share object attribute ownership, discovery of response to share object attribute ownership, discovery of request to cancel shared object attribute ownership, and reflection of shared object attribute values.
[0054] In one embodiment, the general code framework repackages the simulation middleware interface, abandons the original complex calling logic, and provides users with clear and explicit active calling interfaces and callback interfaces. At the same time, the framework code classifies the open interfaces, and divides the interfaces mainly needed to join the joint simulation operation into the front area of the interface file. Users only need to call a few simple interfaces to successfully join the joint simulation and complete the simulation business. When users need to continue to use deeper functions, they can understand 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, it also includes: defining an instance of the object instance data structure, assigning an initial value to the instance, and calling the code framework interface to add an object instance.
[0056] In one embodiment, for the simulation operation data accessed and output by the joint simulation, the simulation operation data is serialized and deserialized according to the data structure respectively, including: when the simulation operation data is accessed by the joint simulation, the serialization of the simulation operation data is automatically completed according to the serialization rules of the attributes and parameters of the object class function class and the interactive class function class; when the simulation operation data is output to the simulation developer, the data is automatically deserialized according to the defined serialization rules. In this embodiment, the general code framework encapsulates the generalized serialization module of the simulation operation data. The corresponding serialization modules are generated for different object description files, which has strong pertinence, improves the serialization efficiency, improves the simulation operation efficiency, and reduces the data processing time.
[0057] In a specific embodiment, when using the code framework, the user needs to first generate the framework code according to the object description file, and then load the framework code into his own development project for development. The development process is as follows:
[0058] Create an interface class inherited from the simulation function class to receive subscription data and trigger the simulation advancement function. The main inherited functions include the simulation advancement callback function, the reflection attribute data function, and the reflection interaction message function, among which: the simulation advancement callback function is passively called in each simulation time slice, and is mainly provided to users to add their own business code to be processed, to ensure that the time and space of their simulation units are consistent with the middleware; the reflection attribute data function is used to receive the subscribed object class data, and when other simulation units in the joint simulation publish the object instance data subscribed by this simulation unit, the interface will be passively triggered; the reflection interaction message function is used to receive the subscribed interaction class data, and when other simulation units in the joint simulation publish the interaction class data subscribed by this simulation unit, the interface will be passively triggered.
[0059] Start simulation. First, instantiate the code framework interface class. The instantiation variables of the code framework interface class are defined inside the framework code and referenced in the code framework interface class header file. When instantiating the code framework interface class, the above inherited simulation function class needs to be used for instantiation; call the join joint simulation interface to start simulation. After calling this interface, the simulation unit joins the joint simulation and starts time advancement and receiving order data.
[0060] Register an object instance. Define an instance of the object instance data structure and assign an initial value to the instance; call the code framework interface to add an object instance.
[0061] Send object instance / interaction class data. Send object instance and interaction message data in the simulation advancement callback of the code framework; call the send object attribute data interface to send object instance data; call the interaction message interface to send interaction message data; the simulation advancement callback function will be passively triggered once at each simulation step, and the object instance data is generally published in it, so that the pace of publishing object instance data of the simulation unit can be consistent with the time advancement pace of the joint simulation (under the premise that time is controlled and limited); after joining the joint simulation, the interaction message can be sent at any code position of the simulation unit.
[0062] Receive object instance / interaction class data. Receive object instance data in the reflection object attribute callback interface. Users determine whether it is the object class data they need to order in the reflection object attribute callback function, receive object instance data and perform business processing; receive interaction message data in the reflection interaction message callback. Users determine whether it is the interaction class data they need to order in the reflection interaction message function, receive interaction message data and perform business processing.
[0063] Stop simulation. The simulation unit can stop the simulation by calling the stop simulation interface at the appropriate location. After stopping the simulation, the data of the simulation unit in the joint simulation will be destroyed. The simulation unit can rejoin the joint simulation by calling the start simulation interface again.
[0064] In a specific embodiment, Figure 2 The simulation operation process diagram shown in the figure shows that the simulation service automatic call process includes:
[0065] S11: Create a joint simulation. When a user joins a joint simulation, he needs to create the joint simulation first. If the joint simulation does not exist, it will be created. If it exists, it will be skipped.
[0066] S12: The simulation unit joins the simulation. When the joint simulation is successfully created or the joint simulation already exists, the simulation unit starts to apply to join the joint simulation. If it succeeds, it will continue. Otherwise, an abnormal error code will be returned.
[0067] S13: Setting the simulation unit publication / subscription relationship. After the simulation unit successfully joins the joint simulation, the code framework calls the simulation middleware native interface to request configuration of the publication subscription relationship according to the publication subscription relationship in the publication subscription relationship file generated at the same time as the code framework is generated. If the configuration is successful, continue, otherwise return an abnormal error code.
[0068] S14: Setting the simulation unit time management strategy. After the simulation unit successfully joins the joint simulation, the code framework will call the simulation middleware time management interface to configure the time management according to the object description file information when the framework code is generated. If the configuration is successful, it will continue, otherwise it will return an abnormal error code.
[0069] S15: Simulation unit initialization. After configuring the published subscription relationship and time management strategy, the simulation code framework will initialize the information of the simulation unit, including the object class handle, interaction class handle, object class attribute handle, interaction class parameter handle, ownership management configuration, interest management configuration, etc. in the simulation unit. Secondly, the simulation code framework will register the instance added by the user before the simulation starts. If the simulation initialization is successful, it will continue, otherwise it will return an abnormal error code.
[0070] S16: Start the simulation advancement loop. After starting the simulation advancement loop, in the simulation advancement loop, the code framework calls the simulation advancement callback function, which is a callback function. The user can implement this function through the inheritance mode. When the simulation starts to advance, the code framework will call this function, and the function inherited by the user will also be passively triggered. The user can implement business functions in this function and keep pace with the simulation advancement. For each simulation advancement cycle, the code framework will call the time advancement function of the simulation middleware once to notify the simulation middleware to request time advancement. The simulation middleware determines whether to allow advancement based on the time strategy and business processing of each simulation unit in the joint simulation. If the simulation middleware does not allow advancement, the time advancement function will be blocked until the simulation middleware allows advancement. If the simulation middleware allows advancement, the time advancement function will release the blockage and start the next cycle advancement.
[0071] S17: The simulation unit exits the simulation. When the simulation unit stops the simulation or abnormally terminates the simulation, the code framework will notify the simulation middleware to request to exit the simulation. If the exit is successful, the simulation will continue; otherwise, an abnormal error code will be returned.
[0072] S18: Destroy simulation resources. After the 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 the simulation unit is the last simulation unit in the current joint simulation, the simulation middleware should also destroy the joint simulation. If the destruction is successful, continue, otherwise return an abnormal error code.
[0073] It should be understood that although Figure 1 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 1 At least part of the steps 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. 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 part of the sub-steps or stages of other steps.
[0074] In one embodiment, Figure 3 A simulation device based on a general code framework is provided, comprising:
[0075] The framework generation module 302 is used to edit the object description file using the public data model development tool of the simulation unit development tool, dynamically generate the framework code of the general code framework according to the object description file, and generate the corresponding data structure in the framework code according to the object class and interaction class information in the object description file;
[0076] The interface development module 304 is used to create an interface class inherited from the simulation function class; the simulation function class includes an object class function class, an interactive class function class, a main business processing class and a callback data processing class;
[0077] The joint simulation module 306 is used for the simulation unit to call the joint simulation interface to join the joint simulation, call the relevant interface class function in the simulation advancement callback to send and receive object class data and interactive message data, and serialize and deserialize the simulation running data accessed and output by the joint simulation according to the data structure respectively;
[0078] The simulation ending module 308 is used for the simulation unit to call the simulation ending interface to end the simulation when the simulation ending condition is met.
[0079] The specific limitation of the simulation device based on the general code framework can be referred to the limitation of the simulation method based on the general code framework in the above text, which will not be repeated here. Each module in the above-mentioned simulation device based on the general code framework can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor calls and executes the operations corresponding to the above modules.
[0080] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 4 As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a simulation method based on a general code framework is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covered on the display screen, or a key, trackball or touchpad set on the computer device housing, or an external keyboard, touchpad or mouse, etc.
[0081] Those skilled in the art will understand that Figure 4The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present invention, and does not constitute a limitation on the computer device to which the solution of the present invention is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0082] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the method in the above embodiment when executing the computer program.
[0083] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method in the above embodiment are implemented.
[0084] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided by the present 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. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0085] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, 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 above-mentioned embodiments only express several implementation modes of the present invention, and the description thereof is relatively specific and detailed, but it cannot be understood as limiting the scope of the invention. It should be pointed out that, for a person of ordinary skill in the art, several modifications and improvements can be made without departing from the concept of the present invention, and these all belong to the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the attached claims.
Claims
1. A simulation method based on a general code framework, characterized in that: The method comprises: Using a public data model development tool of a simulation unit development tool to edit an object description file, dynamically generating a framework code of a general code framework according to the object description file, and generating a corresponding data structure in the framework code according to object class and interaction class information in the object description file; Creating an interface class inherited from a simulation function class; the simulation function class includes an object class function class, an interactive 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, calls the relevant interface class function in the simulation advancement callback to send and receive object class data and interactive message data, and serializes and deserializes the simulation running data accessed and output by the joint simulation according to the data structure; When the simulation stop condition is reached, the simulation unit calls the stop simulation interface to end the simulation.
2. The method according to claim 1, characterized in that Before the simulation unit calls the join joint simulation interface to join the joint simulation, it also includes: The interface class is instantiated as an externally open interface; the externally open interface includes an active call interface and a callback interface.
3. The method according to claim 1, characterized in that 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, it also includes: Define an instance of the object instance data structure, assign initial values to the instance, and call the code framework interface to add the object instance.
4. The method according to claim 1, characterized in that: For the simulation running data input and output by the joint simulation, serialization and deserialization of the simulation running data according to the data structure include: When the simulation operation data is connected to the joint simulation, the serialization of the simulation operation data is automatically completed according to the serialization rules of the attributes and parameters of the object class function class and the interactive class function class; When simulation run data is output to the simulation developer, the data is automatically deserialized according to the defined serialization rules.
5. The method according to claim 1, characterized in that The method further comprises: Use VS project files to compile the framework source code into a dynamic library, and simulation developers use the code framework by loading the dynamic library.
6. The method according to claim 1, characterized in that The code structure of the framework code includes a main functional part and branch modules organized by category; The main function part is used to complete the simulation preparation work and start the simulation cycle; the simulation preparation work includes simulation initialization work, publishing subscription 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 respectively, and the data structures and algorithms related to the object class or interaction class are defined through the functional classes.
7. The method according to claim 1, characterized in that The framework code for dynamically generating a general code framework based on the object description file includes: Copying a template file from the installation directory of the simulation middleware software; the template file includes a fixed code portion and an insertion position identifier required for generating a framework code; According to the object description file information, insert specific simulation service automation calling code into the corresponding identification position of the template file to generate a code framework, wherein the inserted code is generated according to the content of the object description file.
8. A simulation device based on a general code framework, characterized in that: The device comprises: A framework generation module, used to edit the object description file using the public data model development tool of the simulation unit development tool, dynamically generate the framework code of the general code framework according to the object description file, and generate the corresponding data structure in the framework code according to the object class and interaction class information in the object description file; An interface development module is used to create an interface class inherited from a simulation function class; the simulation function class includes an object class function class, an interactive class function class, a main business processing class, and a callback data processing class; The joint simulation module is used for the simulation unit to call the joint simulation interface to join the joint simulation, call the relevant interface class function in the simulation advancement callback to send and receive object class data and interactive message data, and serialize and deserialize the simulation running data accessed and output by the joint simulation according to the data structure; The simulation end module is used for the simulation unit to call the simulation stop interface to end the simulation when the simulation stop condition is reached.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Simulation model system supporting reusing and development method thereof
CN102004635A
Simulation modeling method based on system design product and computer readable storage medium
CN113919138A
Code automatic generation method and device, electronic equipment and storage medium
CN115857900A
Service-oriented simulation model reusable framework and integration method
CN116774978A
General spacecraft simulation model description and construction method and system
CN118194429A
Cited By
Application program running method and device and electronic equipment
CN121579180A
