A simulation model packaging method and system
By encapsulating internal variables such as simulation time and error information into output variables, the non-convergence and error reporting problems when the simulation model interacts with third-party software are solved, enabling more flexible control and more efficient multi-platform co-simulation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- TECHNICAL INST OF PHYSICS & CHEMISTRY - CHINESE ACAD OF SCI
- Filing Date
- 2024-09-29
- Publication Date
- 2026-04-10
AI Technical Summary
In existing technologies, after a simulation model is packaged into an fmu file, internal variables such as simulation time and error information cannot be directly set as output variables. This leads to problems such as non-convergence, interruption, or errors when interacting with third-party software, and the state of the simulation model cannot be effectively controlled.
Internal variables such as simulation time and error information are encapsulated as output variables, and an fmu file is generated using EL language code and the deck platform. Input and output variables are defined, and the running state of the simulation model is controlled by special internal variables.
It enables better deployment and data interaction of simulation models in third-party software, improves the flexibility and accuracy of simulation models, and enhances the time synchronization and error diagnosis capabilities of multi-platform joint simulation.
Smart Images

Figure CN119397739B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of system simulation, and in particular to a method and system for encapsulating simulation models. Background Technology
[0002] With the advancement of technology and the needs of practical engineering, the requirement for multidisciplinary collaborative simulation is extremely urgent. In the construction of large-scale, multi-domain simulation systems, it is usually necessary to connect simulation models built on multiple software platforms.
[0003] In recent years, breaking down the incompatibility barriers between mainstream simulation tools in different professional fields and achieving multidisciplinary, cross-platform, and high-precision all-digital simulation has become a crucial development direction in the simulation field. Under this trend, the FMI (Functional Mock-up Interface) standard was born in 2008 and has been widely and deeply applied. It has now become the most widely accepted and applied interface standard for the interoperability and reuse of functional and performance models globally. To date, more than one hundred leading global software-in-the-loop, hardware-in-the-loop, and software development tools support the FMI standard. Different modeling and simulation software can use this standard to export their models as FMU (Functional Mock-up Unit) models, which can then be integrated into other simulation software or platforms to achieve co-simulation. This solves the long-standing problem of how to use models developed by different modeling tools for co-simulation.
[0004] After the simulation model is packaged into an .fmu file, this .fmu file is deployed in third-party lab management software. The start, stop, and pause functions of the simulation model are controlled by system variables of the third-party lab management software. For example, when the simulation model is deployed in third-party lab management software such as Veristand, the ModelCommand variable is used to control the start, stop, and pause functions of the simulation model. During this process, the internal variables of the simulation model itself do not participate in controlling the state of the simulation model in the third-party lab management software.
[0005] The simulation model, after successfully running in the simulation software, is packaged into an FMU file and then deployed in third-party lab management software. During this process, whether deployed in the third-party lab management software or interacting with the new third-party software, some variables need to be set as input variables—meaning some variables are controlled by the third-party software to input commands into the simulation model. Unless the original simulation model has sufficient adaptive capabilities, during data interaction, the simulation model may fail to converge, interrupt operation, or report errors. Because the simulation model has been packaged into an FMU file, various failure messages encountered during data interaction with the third-party software, including error messages related to the simulation model itself, are not accessible to the operator. In the original simulation model, the error message variable #error is an internal variable; during the packaging into the FMU file, internal variables cannot be directly set as output variables.
[0006] Another important internal variable in the simulation model is the simulation time (time). In the original simulation model, the simulation time (time) is an internal variable. However, internal variables cannot be directly set as output variables during the process of encapsulating the model into an FMU file.
[0007] To overcome these shortcomings, this application proposes a simulation model encapsulation method and system. Summary of the Invention
[0008] The purpose of this application is to provide a simulation model encapsulation method and system, which aims to solve the above-mentioned problems.
[0009] To achieve the above objectives, this application provides the following technical solution:
[0010] This application provides a method for encapsulating simulation models, including:
[0011] Introducing internal variables into a pre-established simulation model, wherein the internal variables include simulation time, error messages, and special internal variables;
[0012] Compile the simulation model, generate components, and verify the components;
[0013] A simulation environment is established based on the aforementioned components, and EL language code is written in the simulation environment to control the running state of the simulation model.
[0014] The simulation environment and the EL language code are used to generate a deck platform, and the simulation model is then packaged into an fmu file based on the deck platform.
[0015] Furthermore, the step of introducing internal variables into the pre-established simulation model, wherein the internal variables include simulation time, error information, and special internal variables, specifically includes the following steps:
[0016] The simulation time is encapsulated into a simulation time component, and the output of the simulation time component is a simulation time value, which is set to a real value of analog quantity type; the error information is encapsulated into an error information component, and the output of the error information component is an error information value, which is set to a real value of analog quantity type.
[0017] Furthermore, the steps of compiling the simulation model, generating components, and verifying the components specifically include the following steps:
[0018] Place the packaged simulation time component and error information component in the same frame as the main loop model of the simulation model, and then compile them;
[0019] The simulation model is compiled to generate components, and the components are then verified.
[0020] Furthermore, the steps of establishing a simulation environment based on the components, writing EL language code in the simulation environment, and controlling the running state of the simulation model specifically include the following steps:
[0021] After component verification, a simulation environment is established, and EL language code is written into the simulation environment;
[0022] Introduce the special internal variable into the EL language code and define the running state of the simulation model under different assignment conditions for the special internal variable;
[0023] Controlling the simulation model includes, but is not limited to: controlling the simulation model to initialize global variables, and controlling the simulation model to run and stop.
[0024] Furthermore, the step of generating a deck platform using the simulation environment and the EL language code, and then encapsulating the simulation model into an fmu file based on the deck platform, specifically includes the following steps:
[0025] The deck platform is generated using the simulation environment and the EL language code, i.e., based on the EL experiment code;
[0026] Set the input and output variables on the deck platform;
[0027] Using the aforementioned deck platform, the simulation model is packaged into an fmu file, and the fmu file type for interaction with third-party software is selected.
[0028] Furthermore, the step of setting input and output variables on the deck platform specifically includes the following steps:
[0029] Variables that will be controlled by third-party software are defined as input variables;
[0030] Define the simulation time value output by the simulation time component and the error information value output by the error information component as output variables;
[0031] The special internal variables are defined as input variables and output variables;
[0032] The output variables include, but are not limited to, process values calculated for the simulation model: temperature, pressure, flow rate, and liquid level.
[0033] Furthermore, the fmu file is deployed by third-party software;
[0034] After deployment, the running state of the simulation model is jointly controlled by special internal variables set in the deck platform and control variables of third-party software.
[0035] Test the running status of the simulation model in the third-party software, determine whether to output simulation time value and error information value, and interact with the third-party software.
[0036] This application provides a simulation model packaging system, including:
[0037] Model building module: Introduces internal variables into a pre-built simulation model, including simulation time, error messages, and special internal variables;
[0038] Compilation module: Compiles the simulation model, generates components, and verifies the components;
[0039] Control module: Based on the components, a simulation environment is established, and EL language code is written in the simulation environment to control the running state of the simulation model;
[0040] Encapsulation module: Generates a deck platform using the simulation environment and the EL language code, and encapsulates the simulation model into an fmu file based on the deck platform.
[0041] This application provides an apparatus comprising a processor and a memory coupled to the processor, wherein the memory stores program instructions for implementing a simulation model encapsulation method; the processor is configured to execute the program instructions stored in the memory to implement a simulation model encapsulation.
[0042] This application provides a storage medium storing processor-executable program instructions for executing a simulation model packaging method.
[0043] This application provides a simulation model encapsulation method and system, which has the following beneficial effects:
[0044] (1) By encapsulating important internal variables such as simulation time and error information into output variables, the simulation model deployed in third-party laboratory management software can provide more functions; for example, simulation time can be used to write sequential control logic or trigger important events to achieve time synchronization between the simulation model and the third-party software, thereby realizing time synchronization of multi-platform joint simulation; while error information can be used for error diagnosis.
[0045] (2) The introduction of special internal variables (simulinkSFunctionMode) and the use of EL language code make the control of the simulation model more flexible and convenient; by changing the value of simulinkSFunctionMode, the initialization, running, stopping and other states of the simulation model can be controlled.
[0046] (3) The output accuracy problem of the simulation time component was solved by taking the logarithm, which avoided the accuracy loss caused by insufficient resolution of the analog quantity acquisition module and improved the running efficiency and accuracy of the simulation model.
[0047] (4) After the simulation model is packaged into an fmu file, it is easier to deploy and co-simulate in third-party software that supports the FMI standard, which enhances the portability and reusability of the simulation model and promotes multidisciplinary and cross-platform simulation collaboration. Attached Figure Description
[0048] Figure 1 This is a flowchart illustrating a simulation model encapsulation method according to Embodiment 1 of this application;
[0049] Figure 2 This is a schematic diagram of the structure of a simulation model packaging system according to Embodiment 2 of this application;
[0050] Figure 3 This is a schematic diagram of the device structure in Embodiment 3 of this application;
[0051] Figure 4 This is a schematic diagram of the storage medium structure of Embodiment 4 of this application. Detailed Implementation
[0052] It should be understood that the specific embodiments described herein are merely illustrative of this application and are not intended to limit this application.
[0053] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of the embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0054] Example 1
[0055] Please see Figure 1 This is a flowchart illustrating a simulation model encapsulation method according to Embodiment 1 of this application; the steps include:
[0056] S1: Introduce internal variables into the pre-established simulation model, where the internal variables include simulation time, error messages, and special internal variables.
[0057] In this embodiment, a simulation model is established based on the dynamic simulation software EcosimPro. The simulation time (time) is encapsulated into a simulation time component, and the output of the simulation time component is the simulation time value, which is set to a real value of analog quantity type. The error information is encapsulated into an error information component, and the output of the error information component is the error information value, which is set to a real value of analog quantity type.
[0058] Specifically, for simulation models of hydrogen-helium refrigerators and liquefied hydrogen-helium reactors, the simulation time under complex operating conditions is a very large constant, often reaching hundreds of thousands of seconds. It is essential to transmit the simulation time to an external source when packaging the model into an FMU file. This allows for the use of the simulation model's time to write sequential control logic during data interaction with third-party software, or to trigger important events using the simulation model's time, thereby achieving time synchronization between the simulation model and the third-party software.
[0059] The simulation time is encapsulated into a simulation time component, outputting a real value in analog quantity type. During HIL (Hardware-in-the-Loop) simulation, due to the resolution limitations of the analog acquisition module, directly sending the simulation time to third-party software results in too low accuracy. In this case, the real value output by the simulation time component in analog quantity type can be logarithmically calculated to base 10, and the logarithmic result can be sent as a real value in analog quantity type to the third-party software. The third-party software then performs an antilogarithmic operation on the logarithmic result to obtain the complete real value in analog quantity type, i.e., the original simulation time.
[0060] S2: Compile the simulation model, generate components, and verify the components.
[0061] In this embodiment, the simulation time component and the error information component do not need to be connected to the main loop of the simulation model. Simply place the packaged simulation time component and the error information component in the same frame as the main loop model of the simulation model, and it will run smoothly after compilation.
[0062] After the simulation model is compiled, a component (partition) is generated, and the component (partition) is validated.
[0063] S3: Establish a simulation environment based on the components, write EL language code in the simulation environment, and control the running state of the simulation model.
[0064] In this embodiment, a simulation environment is established after component verification, and EL language code is written into the simulation environment.
[0065] In the EL language code, introduce the special internal variable (simulinkSFunctionMode) to define the running state of the simulation model under different assignment conditions. For example: when simulinkSFunctionMode == 1, the simulation model performs global variable initialization; when simulinkSFunctionMode == 3, the simulation model starts running; and when simulinkSFunctionMode == 5, the simulation model stops running.
[0066] S4: Generate a deck platform using the simulation environment and the EL language code, and encapsulate the simulation model into an fmu file based on the deck platform.
[0067] In this embodiment, the deck platform is generated using the simulation environment (experiment) and the EL language code, i.e., based on the ELexperiment code.
[0068] Input and output variables are set on the deck platform: variables controlled by third-party software are defined as input variables; simulation time values output by the simulation time component and error information values output by the error information component are defined as output variables; special internal variables are defined as input and output variables; variables calculated and output by the simulation model, such as temperature, pressure, flow rate, and liquid level, are defined as output variables.
[0069] Using the Deck platform, the simulation model is encapsulated into an FMU file, selecting the FMU file type suitable for interaction with third-party software. The FMU file is deployed by the third-party software. After deployment, the simulation model's running state is jointly controlled using special internal variables set by the Deck platform and control variables of the third-party software. The running state of the simulation model in the third-party software is tested to determine whether simulation time values and error information values are output, and data interaction with the third-party software is performed.
[0070] Specifically, when the generated .fmu file is deployed by third-party software, such as Veristand, the running status of the entire simulation model can be controlled in the workspace interface using different values of the special internal variable simulinkSFunctionMode. This method, combined with the control variables built into the third-party laboratory management software, such as simulinkSFunctionMode and Model Command, makes operation more convenient during the deployment and running of the simulation model.
[0071] It's understandable that the simulation time value output by the simulation time component can be used by third-party software. If necessary, a logarithmic operation can be performed before outputting the value to avoid the problem of low acquisition accuracy in the analog quantity acquisition module. Simulation time can be used to write sequential control logic, or to trigger important events, thereby achieving time synchronization between the simulation model and third-party software, and ultimately enabling time synchronization in multi-platform co-simulation.
[0072] The error message values output by the error information component can be used for error diagnosis. Before developing a simulation model with sufficient adaptability, many errors will be encountered during debugging and interaction with third-party software. By observing the values of the error message variables, it can be determined whether the error is caused by the simulation model itself or by external operations; that is, fault diagnosis during multi-platform co-simulation debugging.
[0073] In summary, Embodiment 1 of this application generates components and a simulation environment by introducing internal variables into the simulation model; a deck platform is generated based on the simulation environment and EL language code; and the simulation model is encapsulated into an FMU file using the deck platform. When deploying the FMU file generated in this application in third-party laboratory management software such as Veristand, the introduced special internal variables can be used to enhance the functionality and ease of operation of the encapsulated simulation model.
[0074] Example 2
[0075] Please see Figure 2This is a schematic diagram of the structure of a simulation model packaging system according to Embodiment 2 of this application; the specific content includes:
[0076] Model building module: Introduces internal variables into a pre-built simulation model, including simulation time, error messages, and special internal variables;
[0077] Compilation module: Compiles the simulation model, generates components, and verifies the components;
[0078] Control module: Based on the components, a simulation environment is established, and EL language code is written in the simulation environment to control the running state of the simulation model;
[0079] Encapsulation module: Generates a deck platform using the simulation environment and the EL language code, and encapsulates the simulation model into an fmu file based on the deck platform.
[0080] Example 3
[0081] Please see Figure 3 This is a schematic diagram of the device structure in Embodiment 3 of this application. The device 50 includes a processor 51 and a memory 52 coupled to the processor 51.
[0082] The memory 52 stores program instructions for implementing the above-described simulation model encapsulation method.
[0083] The processor 51 is used to execute program instructions stored in the memory 52 to implement a simulation model package.
[0084] The processor 51 can also be referred to as a CPU (Central Processing Unit).
[0085] Processor 51 may be an integrated circuit chip with signal processing capabilities. Processor 51 may also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), an off-the-shelf programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. A general-purpose processor may be a microprocessor or any conventional processor.
[0086] Example 4
[0087] Please see Figure 4This is a schematic diagram of the storage medium in Embodiment 4 of this application. The storage medium in this embodiment stores a program file 61 capable of implementing all the above methods. This program file 61 can be stored in the storage medium in the form of a software product, including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods of various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks, or devices such as computers, servers, mobile phones, and tablets.
[0088] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, apparatus, article, or method that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, apparatus, article, or method. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, apparatus, article, or method that includes that element.
[0089] The above description is only a preferred embodiment of this application and does not limit the patent scope of this application. Any equivalent structural or procedural changes made based on the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.
[0090] Although embodiments of this application 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 embodiments without departing from the principles and spirit of this application, the scope of which is defined by the appended claims and their equivalents.
[0091] Of course, the present invention may have many other embodiments. Based on this embodiment, other embodiments obtained by those skilled in the art without any creative effort are all within the scope of protection of the present invention.
Claims
1. A method for encapsulating a simulation model, characterized in that, include: Introducing internal variables into a pre-established simulation model, wherein the internal variables include simulation time, error messages, and special internal variables; Specifically, it includes: The simulation time is encapsulated into a simulation time component, and the output of the simulation time component is a simulation time value, which is set to a real value of analog quantity type; the error information is encapsulated into an error information component, and the output of the error information component is an error information value, which is set to a real value of analog quantity type. When building simulation models based on the dynamic simulation software EcosimPro, the simulation time for hydrogen-helium refrigerators and hydrogen-helium liquefiers is a very large constant under complex operating conditions, often reaching hundreds of thousands of seconds. When performing HIL hardware-in-the-loop simulation, the real value of the analog quantity output by the simulation time component is logarithmically divided to base 10, and the result of the logarithm is sent as a real value of the analog quantity to the third-party software. The third-party software then performs an antilogarithmic operation on the logarithmic result to obtain the complete real value of the analog quantity, i.e., the original simulation time. The process of compiling the simulation model, generating components, and verifying the components specifically includes the following steps: placing the encapsulated simulation time component and error information component in the same frame as the main loop model of the simulation model, and compiling them; after the simulation model is compiled, generating components, and verifying the components; A simulation environment is established based on the aforementioned components, and EL language code is written in the simulation environment to control the running state of the simulation model. The simulation model is generated into an FMU file using the simulation environment and the EL language code, and then packaged into an FMU file based on the Deck platform. Specifically, this includes: The deck platform is generated using the simulation environment and the EL language code, i.e., based on the EL experiment code; Input and output variables are set on the deck platform: variables controlled by third-party software are defined as input variables; simulation time values output by the simulation time component and error information values output by the error information component are defined as output variables; special internal variables are defined as input and output variables; output variables include process values calculated for the simulation model, but are not limited to: temperature, pressure, flow rate, and liquid level; Using the aforementioned deck platform, the simulation model is packaged into an fmu file, and the fmu file type for interaction with third-party software is selected.
2. The simulation model encapsulation method according to claim 1, characterized in that, The steps of establishing a simulation environment based on the aforementioned components, writing EL language code within the simulation environment, and controlling the operational state of the simulation model specifically include the following steps: After component verification, a simulation environment is established, and EL language code is written into the simulation environment; Introduce the special internal variable into the EL language code, define the running state of the simulation model under different assignment conditions, and control the stopping of the simulation model; Controlling the simulation model includes, but is not limited to: controlling the simulation model to initialize global variables, and controlling the simulation model to run and stop.
3. The simulation model encapsulation method according to claim 1, characterized in that, The fmu file is deployed by third-party software; After deployment, the running state of the simulation model is jointly controlled by special internal variables set in the deck platform and control variables of third-party software. Test the running status of the simulation model in the third-party software, determine whether to output simulation time value and error information value, and interact with the third-party software.
4. A simulation model packaging system, characterized in that, The system implements a simulation model encapsulation method as described in any one of claims 1-3; the system includes: Model building module: Introduces internal variables into a pre-built simulation model, including simulation time, error messages, and special internal variables; Compilation module: Compiles the simulation model, generates components, and verifies the components; Control module: Based on the components, a simulation environment is established, and EL language code is written in the simulation environment to control the running state of the simulation model; Encapsulation module: Generates a deck platform using the simulation environment and the EL language code, and encapsulates the simulation model into an fmu file based on the deck platform.
5. A device, characterized in that, The device includes a processor and a memory coupled to the processor, wherein the memory stores program instructions for implementing a simulation model encapsulation method according to any one of claims 1-3; the processor is used to execute the program instructions stored in the memory to implement a simulation model encapsulation.
6. A storage medium, characterized in that, The device stores processor-executable program instructions for performing a simulation model encapsulation method according to any one of claims 1-3.
Citation Information
Patent Citations
Static analysis method and platform for product packaging and transportation, storage medium and application
CN112270116A
Real-time dynamic simulation platform for large hydrogen liquefier or refrigerator
CN114035493A
Modeling simulation method and device for aero-engine and storage medium
CN114625026A
Method for describing and simulating function block model from FMU model to configuration software
CN115098218A