Cross-platform code generation and system model integration method based on Modelica

Through the Modelica-based cross-platform code generation and system model integration method, the difficulty of cross-system transplantation of complex system models in the domestic process is solved, and rapid transplantation and integrated simulation are achieved, reducing costs and improving design efficiency.

CN119473243APending Publication Date: 2025-02-18BEIJING GONGGONG DIGITAL TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411426581.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-14
Publication Date
2025-02-18

AI Technical Summary

Technical Problem

In the process of domesticization, cross-system transplantation of complex system models is difficult, resulting in high design verification costs and insufficient compatibility and joint simulation capabilities between different software.

Method used

The cross-platform code generation and system model integration method based on Modelica is adopted to realize the rapid porting and integrated simulation of complex system models through system decomposition, model library construction, code generation and secondary encapsulation.

Benefits of technology

It reduces the cost of model transplantation and development, improves the adaptability and design efficiency between different platforms, and reduces the learning cost and simulation time of designers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119473243A_ABST
    Figure CN119473243A_ABST
Patent Text Reader

Abstract

The invention provides a cross-platform code generation and system model integration method based on Modelica, and relates to the technical field of digital twin modeling simulation. The cross-platform code generation and system model integration method based on Modelica comprises the following steps: step 1, constructing a complex system model; 2, quickly generating a system model code; 3, carrying out secondary packaging on the system model code; and 4, carrying out joint simulation analysis. According to the method, the digital prototype is constructed based on a full-system model library, different key components can be quickly selected for quick assembly, so that digital prototype models with different functional attributes are formed, a code generation tool is based on a unified main function, the reuse degree under different tasks is very high, and the code generation tool can be quickly assembled according to different task requirements. The method can quickly construct the digital prototype and generate the model code required by the test, greatly saves the test cost, can quickly generate the code, is used for realizing quick adaptation under different platforms, is simple to operate, and greatly reduces the platform transplantation cost of the digital prototype.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of digital twin modeling and simulation, and in particular to a cross-platform model code generation based on a Modelica model, and a method for agilely processing the generated model code to realize model integration simulation between different platforms. Background Art

[0002] With the rapid development of information technology, national security issues are becoming increasingly prominent. Reliance on foreign operating systems and software has become a significant security risk, as external forces could steal and damage national information through methods such as the insertion of malicious code. Domestically produced, independently controllable systems can effectively mitigate this risk and ensure the security of vital national information. The importance of independently controllable systems is particularly growing in key industrial sectors. Due to the differences between systems, the cross-system migration of the large number of models accumulated in previous phases is challenging. Given the current situation, a rapid model migration method is urgently needed to facilitate rapid design verification during the phase of localization.

[0003] Traditional industrial design simulation uses different software for different disciplines, and the compatibility of different software with domestic systems varies. For multi-domain joint simulation of large system models, it is extremely difficult to drive joint simulation using communication methods due to the differences in the communication methods supported by different software. Multi-disciplinary software does not have the ability to perform large-scale joint simulation analysis under cross-system conditions.

[0004] Modelica provides a unified modeling approach, enabling the use of a single modeling language to describe systems across multiple fields (such as mechanics, electronics, and controls). This reduces the number of models and mitigates the risks of model description, providing strong support for the simulation and design of complex engineering systems. Using the Modelica language for unified system model description effectively reduces software redundancy caused by diverse disciplines within complex systems. Using the Modelica language for unified system model description allows for a single packaged system model to form a multi-disciplinary system prototype, facilitating rapid migration and integration between systems.

[0005] Therefore, those skilled in the art provide a cross-platform code generation and system model integration method based on Modelica to solve the problems raised in the above background technology. Summary of the Invention

[0006] (1) Technical problems solved

[0007] In response to the shortcomings of the existing technology, the present invention provides a cross-platform code generation and system model integration method based on Modelica, which is used to meet the needs of rapid transplantation, verification and integration of complex system models in the current environment where the localization process is gradually accelerating. It provides a solution for the rapid transplantation and rapid application of early accumulated models, reduces the cost of model transplantation, and reduces the development cost between cross-platforms / software.

[0008] (2) Technical solution

[0009] To achieve the above objectives, the present invention is implemented through the following technical solutions:

[0010] A cross-platform code generation and system model integration method based on Modelica includes the following steps:

[0011] Step 1. Complex system model construction

[0012] Conduct system analysis based on system functions, performance, and disciplinary approaches, decompose the system components, and divide the complex system into several subsystems with different functions. The subsystems are then decomposed into several components, and the components are further decomposed into assemblies, until the level can be directly described using physical language and modeling language.

[0013] Step 2. Rapidly generate system model code

[0014] After completing the verification of the equipment, subsystem, and system models, write the response model call pseudocode. Based on the MWORKS physical model code generation function, integrate the model with the main function pseudocode, and select the target system for code generation.

[0015] Step 3. Secondary packaging of system model code

[0016] Port the model generation code to the target Kylin platform, integrate the communication components or other related functional functions into the digital prototype code as call functions, and match the corresponding data interfaces with the corresponding interfaces of the digital prototype;

[0017] Step 4. Conduct joint simulation analysis

[0018] The encapsulated digital prototype function can be directly called by Python, script instructions, C functions, etc. to perform joint simulation with the system and task system.

[0019] Furthermore, in step 1, the system decomposition process requires explanation of the model interface and model granularity (the level of detail of the model), as well as determination of relevant modeling theoretical basis.

[0020] Furthermore, in step 1, it also includes: using Modelica to build a system model library, the model library must completely cover the decomposition results obtained from the system decomposition, and be able to simulate the main indicators of concern to the system. After completing the development of the component and device model library, according to the actual physical topology of the system, a system model is established through drag-and-drop modeling. After the system is built, the subsystems and system models are tested using design data or experimental data, and the parameters that have not yet been determined in the model are estimated and calibrated.

[0021] Furthermore, in step 2, the model C code is translated using the MWORKS compiler. The compiler analyzes the equations, connections, and components of the Modelica model and generates corresponding C code. The generated code includes multiple files, including the model's main function, equation solver, and interface functions.

[0022] Furthermore, in step 2, the following is further included:

[0023] Automated code post-processing, such as adding annotations based on model-specific syntax, optimizing code structure, and ensuring that the generated code is compatible with the target platform's compiler and runtime environment;

[0024] Efficiently convert Modelica models into C code for simulation or real-time control on the target platform.

[0025] Furthermore, in the step 3, it also includes: taking the integrated digital prototype code as a whole, performing secondary packaging and integration of the corresponding interface information, combining the data (attributes) and the algorithms acting on the data together to form an independent unit for the integration of the digital prototype task system, and quickly forming new digital prototype packaging functions according to different task requirements.

[0026] Furthermore, in step 4, the Modelica digital prototype interface data and the physical system and experimental equipment data can be transmitted over the network through UDP or TCP / IP protocols, thereby realizing data interaction between the Modelica digital prototype model and the physical object and management system.

[0027] (3) Beneficial effects

[0028] The present invention provides a cross-platform code generation and system model integration method based on Modelica, which has the following beneficial effects:

[0029] 1. The present invention provides a cross-platform code generation and system model integration method based on Modelica. The digital prototype is constructed based on the full system model library and can be agilely assembled by quickly selecting different key components to form digital prototype models with different functional attributes. In addition, the code generation tool is based on a unified main function and is highly reusable under different tasks. According to different task requirements, the digital prototype can be quickly constructed and the model code required for the test can be generated, which greatly saves the test cost.

[0030] 2. The present invention provides a cross-platform code generation and system model integration method based on Modelica. The digital prototype can quickly generate code for rapid adaptation to different platforms. The operation is simple, which greatly reduces the cost of digital prototype platform transplantation and the cost of designers adapting to new platforms. By separating the design modeling simulation and model test dependency environment, unnecessary learning cost waste for designers is reduced and efficiency is improved.

[0031] 3. The present invention provides a cross-platform code generation and system model integration method based on Modelica, which can use a dictionary structure to map model data. It can quickly map large-scale interfaces or other platform data interactions, greatly reducing the time required for interface matching and the probability of errors caused by manual matching. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Figure 1 The overall design architecture diagram provided for the embodiment of the present invention;

[0033] Figure 2 A flowchart of the system model construction provided by an embodiment of the present invention;

[0034] Figure 3 This is an interface diagram of a code generation tool provided by an embodiment of the present invention;

[0035] Figure 4 This is a diagram of the generation result interface provided by an embodiment of the present invention;

[0036] Figure 5 This is a diagram of the joint simulation results provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0037] The following will be combined with the drawings in the specific embodiments of the present invention to clearly and completely describe the technical solutions in the specific embodiments of the present invention. Obviously, the specific embodiments described are only part of the specific embodiments of the present invention, rather than all the specific embodiments. Based on the specific embodiments of the present invention, all other specific embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.

[0039] A specific embodiment of the present invention provides a cross-platform code generation and system model integration method based on Modelica, comprising the following steps:

[0040] Step 1. Complex system model construction

[0041] Conduct system analysis based on system functions, performance, and disciplinary approaches, decompose the system components, and divide the complex system into several subsystems with different functions. The subsystems are then decomposed into several components, and the components are further decomposed into assemblies, until the level can be directly described using physical language and modeling language.

[0042] During the system decomposition process, it is necessary to explain the model interface and model granularity (the level of detail of the model), and determine the relevant modeling theoretical basis;

[0043] Use Modelica to build a system model library. The model library must fully cover the decomposition results obtained from the system decomposition and be able to simulate the main indicators of the system. After completing the development of the component and device model library, the system model is established through drag-and-drop modeling based on the actual physical topology of the system.

[0044] After the system is built, the subsystems and system models are tested using design data or experimental data, and the parameters that have not yet been determined in the model are estimated and calibrated;

[0045] Step 2. Rapidly generate system model code

[0046] After completing the verification of the equipment, subsystem, and system models, write the response model call pseudocode. Based on the MWORKS physical model code generation function, integrate the model with the main function pseudocode, and select the target system for code generation.

[0047] Use the MWORKS compiler to translate the model into C code. The compiler analyzes the equations, connections, and components of the Modelica model and generates the corresponding C code. The generated code includes multiple files, including the model's main function, equation solver, and interface functions.

[0048] Automated code post-processing, such as adding annotations and optimizing code structure based on model-specific syntax, ensures that the generated code is compatible with the target platform's compiler and runtime environment, and efficiently converts Modelica models into C code for simulation or real-time control on the target platform.

[0049] Step 3. Secondary packaging of system model code

[0050] Port the model generation code to the target Kylin platform, integrate the communication components or other related functional functions into the digital prototype code as call functions, and match the corresponding data interfaces with the corresponding interfaces of the digital prototype;

[0051] The integrated digital prototype code is treated as a whole, and the corresponding interface information is repackaged and integrated. The data (attributes) and the algorithms acting on the data are combined to form an independent unit for the integration of the digital prototype task system. New digital prototype package functions can be quickly formed according to different task requirements.

[0052] Step 4. Conduct joint simulation analysis

[0053] The encapsulated digital prototype function can be directly called by Python, script instructions, C functions, etc. to conduct joint simulation with the system and task system. It can also transmit the Modelica digital prototype interface data and the physical system and experimental equipment data through the network through UDP or TCP / IP protocol, realizing the data interaction between the Modelica digital prototype model and the physical and management systems.

[0054] The present invention will be described in detail below with reference to the accompanying drawings and in combination with examples. The overall solution architecture of the example is as follows: Figure 1 As shown, the specific steps include:

[0055] Step 1) Decompose the model architecture parameters based on the system's physical characteristics to obtain the bottom-level model decomposition results. Taking a servo motor as an example, first construct the top-level stator and rotor mechanical and electrical energy conversion equations, implement the basic equations for converting motor winding electrical energy into mechanical energy, and encapsulate them into an electrical winding model. Similarly, construct equivalent capacitor, equivalent resistor, motor drive shaft, and fixed bracket models.

[0056] The above components are combined and integrated to form the motor equipment model. Similarly, the power supply, transmission, and load models are constructed. The equipment models are integrated and combined through the corresponding interfaces to construct the system model. The Modelica system model construction process is as follows: Figure 2 As shown;

[0057] Step 2). Build the system model and call the main function. The main function includes setting the simulation time, setting the solution algorithm, opening the file stream, setting the file save path and reading and writing methods, performing initialization and initialization checks, and saving the simulation result file information;

[0058] Use code generation tools such as Figure 3 As shown in the figure, the model code related to the system model is generated. The tool interface is divided into the following sections:

[0059] 1) Target platform selection;

[0060] 2) Generate file format settings, solution algorithm settings, save directory settings, and main function import function area;

[0061] 3) Configurable parameter selection setting area;

[0062] 4) Log printing and display area;

[0063] Make reasonable selections in the order of toolbox numbers to generate Figure 4 The model file shown includes solver, generated code, parameter file, and main program.

[0064] Step 3). Perform secondary packaging on the model file generated in step 2). The main method is to Figure 4 The main.c function in the file shown performs secondary processing, and the function that drives the physical prototype can be called in the main function. The parameters related to the model are replaced with the same name to achieve two-way communication between the digital prototype and the physical prototype. At the same time, it can be deeply coupled with the overall task scheduling software and engineering through Python, C or calling FMU. Dictionary form can be used to quickly match and map different task data.

[0065] Step 4). You can run it directly in Kylin system Figure 4 .sh file in the command window to get the simulation results. The joint simulation form can also be used to use the script to call multiple functions as AI training model objects to generate simulation result files. At the same time, the real-time simulation results can be printed in the command window, such as Figure 5 shown.

[0066] Although specific embodiments of the present invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and variations can be made to these specific embodiments without departing from the principles and spirit of the invention, and the scope of the invention is defined by the appended claims and their equivalents.

Claims

1. A cross-platform code generation and system model integration method based on Modelica, characterized in that: The following steps are involved: Step 1. Complex system model construction Conduct system analysis based on system functions, performance, and disciplines, decompose the system components, and divide the complex system into several subsystems with different functions. The subsystems are further decomposed into several components, and the components are further decomposed into assemblies until the level can be directly described by physical language and modeling language. Step 2. Rapid generation of system model code After completing the verification of the equipment, subsystem, and system models, write the response model call pseudocode, integrate the model with the main function pseudocode based on the MWORKS physical model code generation function, and select the target system for code generation; Step 3. Secondary packaging of system model code Transplant the model generation code to the target Kylin platform, integrate the communication components or other related functional functions into the digital prototype code as calling functions, and match the corresponding data interfaces with the corresponding interfaces of the digital prototype; Step 4. Conduct joint simulation analysis The encapsulated digital prototype function can be directly called by python, script instructions, C functions, etc. to perform joint simulation with the system and task system.

2. A cross-platform code generation and system model integration method based on Modelica according to claim 1, characterized in that: In the step 1, the system decomposition process requires explanation of the model interface and model granularity, as well as determination of relevant modeling theoretical basis.

3. The method for cross-platform code generation and system model integration based on Modelica according to claim 1, characterized in that: In the step 1, it also includes: using Modelica to build a system model library, the model library must fully cover the decomposition results obtained from the system decomposition, and be able to simulate the main indicators of the system. After completing the development of the component and equipment model library, according to the actual physical topology of the system, the system model is established through drag-and-drop modeling. After the system is built, the subsystem and system model are tested using design data or test data, and the parameters that have not yet been determined in the model are estimated and calibrated.

4. The method for cross-platform code generation and system model integration based on Modelica according to claim 1, characterized in that: In step 2, the model C code is translated using the MWORKS compiler, which analyzes the equations, connections and components of the Modelica model and generates corresponding C code. The generated code includes multiple files, including the model's main function, equation solver, and interface function.

5. The method for cross-platform code generation and system model integration based on Modelica according to claim 1, characterized in that: In the step 2, it also includes: Automatic code post-processing, such as adding comments and optimizing code structure according to model-specific syntax, to ensure that the generated code is compatible with the compiler and runtime environment of the target platform; Efficiently convert Modelica models into C code for simulation or real-time control on the target platform.

6. The method for cross-platform code generation and system model integration based on Modelica according to claim 1, characterized in that: In the step 3, it also includes: taking the integrated digital prototype code as a whole, performing secondary packaging and integration of the corresponding interface information, combining the data and the algorithm acting on the data together to form an independent unit for the digital prototype task system integration, and quickly forming a new digital prototype packaging function according to different task requirements.

7. The method for cross-platform code generation and system model integration based on Modelica according to claim 1, characterized in that: In step 4, the Modelica digital prototype interface data and the physical system and experimental equipment data can be transmitted over the network through UDP or TCP / IP protocol to achieve data interaction between the Modelica digital prototype model and the physical system and management system.