Disclosure of Invention
In view of this, the embodiment of the application provides a Linux-based FMU model generating method and device, which aims to solve the problem that the existing model cannot be correctly operated in a GCAir simulation engine-based real-time simulator.
In a first aspect, an embodiment of the present application provides a Linux-based FMU model generating method, including:
establishing an FMU pre-packaging model based on modeling software;
packaging to generate a Windows-based FMU model by using the FMU pre-packaging model;
And compiling the Windows-based FMU model by utilizing a compiling code tool to generate a Linux-based FMU model.
Optionally, the establishing the FMU pre-package model based on the modeling software includes:
Setting a result output interface and a fixed step length solver;
and based on the modeling software, establishing an FMU pre-packaging model by utilizing the result output interface and a fixed-step length solver.
Optionally, the encapsulating to generate the FMU model based on Windows by using the FMU pre-encapsulation model includes:
setting a save type and a path for exporting a model;
and according to the storage type and the path of the derived model, the Windows-based FMU model is encapsulated and created, and is an FMU model for retaining source codes.
Optionally, compiling the FMU model based on Windows by using a compiling code tool to generate the FMU model based on Linux, including:
Decompressing the FMU model based on Windows to obtain a file set, wherein the file set comprises source folders;
Copying a plurality of files of the compiled code tool to the sources folder, wherein the plurality of files of the compiled code tool comprise running files;
running the running files in the sources folder with the identity of an administrator;
Copying a result file set to the Windows-based FMU model to generate a Linux-based FMU model, wherein the result file set is a plurality of files of a compiled code tool except the running file in the source folder.
Optionally, before the decompressing the FMU model based on Windows to obtain the file set, the method further includes:
decompressing the Makefile program to obtain a plurality of files of the compiled code tool.
Optionally, after the modeling software is used to build the FMU pre-package model, the method further includes:
acquiring an operation curve of the FMU pre-encapsulation model;
After compiling the Windows-based FMU model with the compiling code tool to generate a Linux-based FMU model, the method further includes:
Importing the Linux-based FMU model into a simulation engine, wherein the simulation engine comprises an upper computer local Windows simulation engine and a lower computer Linux real-time simulation engine;
Acquiring a first simulation result, wherein the first simulation result is a simulation result of a local Windows simulation engine of the upper computer;
Obtaining a second simulation result, wherein the second simulation result is a simulation result of the lower computer Linux real-time simulation engine;
Comparing the first simulation result, the second simulation result and the running curve of the FMU pre-encapsulation model to verify the simulation capability of the FMU model based on Linux.
In a second aspect, an embodiment of the present application provides a Linux-based FMU model generating apparatus, including:
The model creation module is used for creating an FMU pre-encapsulation model based on modeling software;
the packaging module is used for packaging and generating a Windows-based FMU model by utilizing the FMU pre-packaging model;
And the compiling module is used for compiling the FMU model based on Windows by utilizing a compiling code tool to generate the FMU model based on Linux.
Optionally, the compiling module includes:
the first decompression unit is used for decompressing the FMU model based on Windows to obtain a file set, wherein the file set comprises sources folders;
a first copying unit configured to copy a plurality of files of the compiled code tool to the sources folder, the plurality of files of the compiled code tool including an operation file;
The operation module is used for operating the operation files in the sources folder according to the identity of the administrator;
and the second copying unit is used for copying a result file set to the Windows-based FMU model to generate a Linux-based FMU model, wherein the result file set is a plurality of files of a compiling code tool except the running file in the sources folder.
In a third aspect, an embodiment of the present application provides an apparatus, where the apparatus includes a memory and a processor, where the memory is configured to store instructions or codes, and the processor is configured to execute the instructions or codes, so that the apparatus performs the Linux-based FMU model generating method according to any one of the first aspect.
In a fourth aspect, an embodiment of the present application provides a computer storage medium, where code is stored, and when the code is executed, a device that executes the code implements the Linux-based FMU model generating method of any one of the first aspect.
The embodiment of the application provides a method and a device for generating an FMU model based on Linux, which are characterized in that when the method is executed, an FMU pre-packaging model is built based on modeling software, the FMU pre-packaging model is used for packaging to generate an FMU model based on Windows, and finally, a compiling code tool is used for compiling the FMU model based on Windows to generate the FMU model based on Linux. Therefore, the FMU model based on Windows is compiled and modified through the compiling code tool, so that the FMU model based on Windows is adaptive to a real-time simulator, has real-time simulation capability and is consistent with the simulation result of the original environment modeling software, the problem that the existing model cannot be correctly operated in the real-time simulator based on GCAir simulation engines is solved, and meanwhile, the FMU model based on Windows non-real-time simulation function is achieved.
Detailed Description
FMI (Functional Mock-up Interface) is an open, third party standard Interface protocol independent of modeling software, enabling models to be packaged as FMUs (Functional Mock-up units) according to the FMI protocol. And through an FMI interface, the method and the system realize joint simulation with other heterogeneous software supporting FMI.
The simulation engine (SimulationEngine) of GCAir simulation test integrated software developed by Beijing Shiguan Jinyang technology development limited is an entity which actually runs a simulation model, receives a command of an upper computer GCAir through a TCP to perform simulation calculation, and feeds simulation result data back to GCAir in real time.
When the real-time simulation calculation is performed, the simulation engine IP address of the lower computer (real-time simulator) can be configured in the simulation tool of the upper computer GCAir to perform real-time simulation. Referring to fig. 1, fig. 1 is a configuration diagram of an IP address of a lower computer simulation engine according to an embodiment of the present application. In this way, the Linux real-time simulation engine can inherit all functions of the Windows version simulation engine, for example, the existing GCAir simulation model can be transited from the Windows version simulation engine to the real-time simulation engine.
When the FMU is automatically recompiled, the real-time simulation engine automatically tries to compile a corresponding Linux version dynamic library, and packages a new FMU to replace the old FMU. If the FMU file does not contain an available Linux version dynamic library, the real-time simulation engine searches the Makefile under the source code path of the FMU, if the Makefile does not exist, the configuration script is continuously searched, and if the Makefile does not exist, the FMU cannot be compiled. Therefore, GCAir real-time simulation has certain requirements on the model, namely, the FMU file operated by the GCAir real-time simulator needs to meet at least one of (1) a 64-bit Linux version dynamic library(s) containing the model, and (2) a source code containing the model and a corresponding Makefile or configuration script, and can be compiled correctly under a Linux system.
The method provided by the embodiment of the application is executed by computer equipment and is used for solving the problem that the existing model cannot be correctly operated in the real-time simulation machine based on GCAir simulation engine.
It will be apparent that the described embodiments are only some, but not all, embodiments of the application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
Referring to fig. 2, fig. 2 is a flowchart of a method for generating a Linux-based FMU model according to an embodiment of the present application, including:
Step S201, based on modeling software, establishing an FMU pre-packaging model.
Currently, modeling software common in the engineering field includes Simulink, simulationX, AMESim, dymola, C/C++, fortran, and the like. All the modeling software can convert the FMU file, but the derived FMU model does not have the capability of directly operating the real-time simulator at GCAir. Thus, one of the above modeling software can be utilized first to prepare the environment and build a preliminary FMU pre-package model.
And S202, encapsulating and generating a Windows-based FMU model by utilizing the FMU pre-encapsulation model.
And packaging the FMU pre-packaging model on the basis of the modeling software, and packaging to generate a Windows-based FMU model.
The FMU model based on Windows can be essentially regarded as a compressed package, the suffix name of which is changed, and the directory structure conforming to the FMU model can be operated correctly. Referring to fig. 3, fig. 3 is a directory structure diagram of an FMU model according to an embodiment of the present application. In the figure, FMU model Simcap includes sources (including simcap. C, fmuTemplate. H), documents (including index. Html, including plot_h. PNG), binaries (including win64, win64 including simcap. Dll), model description. Xml, and model. Png.
When the above file is provided, folder simcap is compressed to simcap.zip (only the. Zip compression algorithm) using a compression tool (e.g., 7 zip), then the. Zip is modified to. FMU, and the FMU is ready to be used after simcap.
It should be noted that the names of the directory folders are all necessary and the names are not changed as much as possible, win64 represents a computer for 64 bits, dll files are necessary, source files under the source folders may not be provided if the codes are required to be kept secret, model. Png is a display icon of the FMU and model description. Xml is necessary for providing basic information of the FMU.
And S203, compiling the FMU model based on Windows by utilizing a compiling code tool to generate the FMU model based on Linux.
The compiling code tool can perform 'makefile' compiling operation on the FMU model based on Windows, so that a compiled result is a Linux version FMU model supporting GCAir real-time simulator running. Preferably, the compiled code tool may be a compiled code tool makefile_gen.exe developed by beijing, singer science and technology development limited.
In summary, according to the embodiment, the FMU model based on Windows is compiled and modified by the compiling code tool, so that the FMU model is a Linux-based FMU model which can be adapted to a real-time simulator, has real-time simulation capability and is consistent with the simulation result of the original environment modeling software, the problem that the existing model cannot be correctly operated in the real-time simulator based on GCAir simulation engines is solved, and meanwhile, the FMU model has a Windows non-real-time simulation function.
In the embodiment of the present application, there are a plurality of possible implementations of the steps described in fig. 2, and the following descriptions are provided separately. It should be noted that the implementations presented in the following description are only exemplary and not representative of all implementations of the embodiments of the present application.
Referring to fig. 4, the flowchart of another method of the Linux-based FMU model generating method according to the embodiment of the present application includes:
And step S401, establishing an FMU pre-packaging model based on modeling software.
Specifically, a result output interface and a fixed-step length solver can be set first, and then an FMU pre-packaging model is established by utilizing the result output interface and the fixed-step length solver based on modeling software.
Taking modeling software as Simulink as an example, a process of setting a result output interface and a fixed-step-length solver is introduced. Fig. 5 is a schematic diagram of a result output interface provided in an embodiment of the present application. Through the Simulink definition result output interface, a basis can be provided for checking whether the simulation result of the packaged FMU model in GCAir simulation test integrated environment is consistent with the result of the original modeling software simulation environment, the process of setting the fixed-step solver is shown in FIG. 6, and FIG. 6 is a schematic diagram of setting the fixed-step solver provided by the embodiment of the application. Simulink solvers can be divided into two main categories, variable-step solvers and fixed-step solvers. In view of the simulation requirements, a fixed-step solver must be used in generating the real-time operation code, and thus the solver needs to be set as a fixed-step solver.
As a possible implementation mode, after the FMU pre-packaging model is established based on modeling software, an operation curve of the FMU pre-packaging model is acquired, so that whether the model can normally operate or not can be confirmed on the one hand, and contrast data can be provided for testing and checking after subsequent packaging on the other hand. Referring to fig. 7, fig. 7 is a graph illustrating operation of the FMU pre-package model according to an embodiment of the present application.
And step S402, packaging and generating a Windows-based FMU model by utilizing the FMU pre-packaging model.
Referring to fig. 8, fig. 8 is a schematic diagram of a save type according to an embodiment of the present application. The save types of the encapsulated Windows-based FMU model include Web view, protected model. Thus, the save type can be selectively set as an independent FMU.
Referring to fig. 9, fig. 9 is a schematic path diagram of a derived model according to an embodiment of the present application. The path for deriving the model may be set as needed, and is not limited herein. As a possible implementation, only "Save source code to FMU" may be checked in the export dialog, and the source code is reserved, so that the Windows-based FMU model created by encapsulation is the FMU model that retains the source code, depending on the save type and the path of the export model.
The generated FMU model based on Windows may refer to fig. 10, and fig. 10 is a schematic diagram of the FMU model based on Windows provided in the embodiment of the present application.
And S403, decompressing the Makefile program to obtain a plurality of files of the compiled code tool.
The Makefile program is a compiled code tool program developed by beijing world guan yang technology development limited company, and the Makefile program is decompressed to obtain a plurality of files of the compiled code tool, wherein the plurality of files of the compiled code tool comprise an operation file makefile_gen.exe, and further comprise fmi2functions.h, fmi2functions types.h, fmi2types platform.h, makefile and a using method txt file, and fig. 11 is a schematic diagram of a plurality of files of the compiled code tool provided by the embodiment of the application.
Step S404, decompressing the FMU model based on Windows to obtain a file set.
As a possible implementation, decompressing the Windows-based FMU model may use a compression tool 7zip. Referring to fig. 12, fig. 12 is a schematic diagram of a decompressed FMU model based on Windows according to an embodiment of the present application. Decompressing the obtained file set, including source folders.
And step S405, copying a plurality of files of the compiled code tool to the sources folder.
Referring to fig. 13, fig. 13 is a schematic diagram of a copy file according to an embodiment of the present application. After the files are copied to the source folders, the files in the source folders can be utilized to change the files of the compiling code tool by operating the operation files, so that the modification of the FMU model is realized.
Step S406, running the running files in the source folders with the identity of the administrator.
Referring to fig. 14, fig. 14 is a schematic operation diagram provided in an embodiment of the present application. And running the running file with the identity of the manager, changing a plurality of files of the compiled code tool, and realizing the reconstruction of the FMU model. After the operation is successful, a subsequent step may be performed, and whether the operation is successful or not may be determined through a makefile file, referring to fig. 15, and fig. 15 is a schematic diagram for determining the operation success according to the embodiment of the present application. And judging whether the operation is successful or not according to the content selected by the black frame.
And S407, copying the result file set to the FMU model based on Windows to generate the FMU model based on Linux.
The result file set is a plurality of files of the compiled code tool except the running file in the sources folder. And copying the result file set to the Windows-based FMU model, namely copying fmi2functions, fmi2functions types, fmi2types platform, and Makefile into a compressed package of the original FMU model. Referring to fig. 16, fig. 16 is a schematic diagram illustrating replication provided in an embodiment of the present application. Therefore, the FMU of the two versions is combined, so that the FMU has the Linux real-time and Windows non-real-time simulation functions at the same time, and the two simulation results are kept consistent.
Step S408, verifying the simulation capability of the FMU model based on Linux.
The method comprises the steps of firstly importing the Linux-based FMU model into a simulation engine, wherein the simulation engine comprises an upper computer local Windows simulation engine and a lower computer Linux real-time simulation engine, then obtaining a first simulation result which is the simulation result of the upper computer local Windows simulation engine, then obtaining a second simulation result which is the simulation result of the lower computer Linux real-time simulation engine, and finally comparing the first simulation result, the second simulation result and the running curve of the FMU pre-encapsulation model to verify the simulation capability of the Linux-based FMU model. If the three are the same, the simulation capability of the FMU model based on Linux is proved to meet the preset requirement.
As a possible implementation manner, the simulation engine may be GCAir simulation engines, the Linux-based FMU model may be first imported GCAir, see fig. 17, fig. 17 is a schematic importing diagram provided by an embodiment of the present application, then a local Windows simulation engine is set to obtain a first simulation result, see fig. 18 and 19, fig. 18 is a schematic engine setting diagram provided by an embodiment of the present application, fig. 19 is a schematic first simulation result provided by an embodiment of the present application, then a lower computer Linux real-time simulation engine is changed to obtain a second simulation result, see fig. 20 and 21, fig. 20 is a schematic engine setting diagram provided by an embodiment of the present application, fig. 21 is a schematic second simulation result provided by an embodiment of the present application, and finally, the first simulation result, the second simulation result and an operation curve of the FMU pre-package model are compared to verify the simulation capability of the Linux-based FMU model.
In summary, according to the embodiment, the FMU model based on Windows is compiled by expanding the compiling code tool, so that the FMU model based on Windows is modified, the FMU model based on Linux which is adaptive to a real-time simulator and has real-time simulation capability and consistent with the simulation result of the original environment modeling software is provided as a floor-type implementation scheme, the problem that the existing model cannot be correctly operated in the real-time simulator based on GCAir simulation engines is solved, the FMU model based on Windows is provided with a non-real-time simulation function, and the simulation capability of the FMU model after modification is verified by comparing the obtained simulation result with the simulation result before modification, so that the accuracy of the method is improved.
The embodiments of the present application provide some specific implementation manners of the Linux-based FMU model generating method, and based on this, the present application also provides a corresponding device. The apparatus provided by the embodiment of the present application will be described in terms of functional modularization.
Referring to fig. 22, a schematic structural diagram of a Linux-based FMU model generating apparatus includes a model creation module 2201, an encapsulation module 2202, and a compiling module 2203.
The model creation module 2201 is configured to create an FMU pre-encapsulation model based on modeling software;
The packaging module 2202 is configured to generate a Windows-based FMU model by using the FMU pre-packaging model;
the compiling module 2203 is configured to compile the FMU model based on Windows by using a compiling code tool, and generate the FMU model based on Linux.
As a possible implementation manner, the model creation module 2201 includes:
The first setting unit is used for setting a result output interface and a fixed-step length solver;
And the model creation unit is used for establishing an FMU pre-encapsulation model by utilizing the result output interface and the fixed-step length solver based on the modeling software.
As one possible implementation, the packaging module 2202 includes:
a second setting unit configured to set a save type and a path from which the model is derived;
and the packaging unit is used for packaging and creating the Windows-based FMU model according to the storage type and the path of the derived model, wherein the Windows-based FMU model is an FMU model for retaining source codes.
As a possible implementation manner, the compiling module 2203 includes:
the first decompression unit is used for decompressing the FMU model based on Windows to obtain a file set, wherein the file set comprises sources folders;
a first copying unit configured to copy a plurality of files of the compiled code tool to the sources folder, the plurality of files of the compiled code tool including an operation file;
The operation module is used for operating the operation files in the sources folder according to the identity of the administrator;
and the second copying unit is used for copying a result file set to the Windows-based FMU model to generate a Linux-based FMU model, wherein the result file set is a plurality of files of a compiling code tool except the running file in the sources folder.
As a possible implementation manner, the device further comprises:
and the second decompression unit is used for decompressing the Makefile program to obtain a plurality of files of the compiled code tool.
As a possible implementation manner, the device further comprises:
The curve acquisition module is used for acquiring an operation curve of the FMU pre-encapsulation model;
The model importing module is used for importing the Linux-based FMU model into a simulation engine, wherein the simulation engine comprises an upper computer local Windows simulation engine and a lower computer Linux real-time simulation engine;
the first simulation module is used for obtaining a first simulation result, wherein the first simulation result is a simulation result of the local Windows simulation engine of the upper computer;
The second simulation module is used for obtaining a second simulation result, wherein the second simulation result is a simulation result of the lower computer Linux real-time simulation engine;
and the comparison module is used for comparing the first simulation result, the second simulation result and the running curve of the FMU pre-encapsulation model so as to verify the simulation capability of the FMU model based on Linux.
The embodiment of the application also provides corresponding equipment and a computer storage medium, which are used for realizing the scheme provided by the embodiment of the application.
The device comprises a memory and a processor, wherein the memory is used for storing instructions or codes, and the processor is used for executing the instructions or codes to enable the device to execute the Linux-based FMU model generating method according to any embodiment of the application.
The computer storage medium stores codes, and when the codes are executed, equipment for executing the codes realizes the Linux-based FMU model generating method according to any embodiment of the application.
The "first" and "second" in the names of "first", "second" (where present) and the like in the embodiments of the present application are used for name identification only, and do not represent the first and second in sequence.
From the above description of embodiments, it will be apparent to those skilled in the art that all or part of the steps of the above described example methods may be implemented in software plus general hardware platforms. Based on such understanding, the technical solution of the present application may be embodied in the form of a software product, which may be stored in a storage medium, such as a read-only memory (ROM)/RAM, a magnetic disk, an optical disk, etc., and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network communication device such as a router) to perform the method according to the embodiments or some parts of the embodiments of the present application.
In this specification, each embodiment is described in a progressive manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for the device embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and reference is made to the description of the method embodiments for relevant points. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art will understand and implement the present invention without undue burden.
The foregoing description of the exemplary embodiments of the application is merely illustrative of the application and is not intended to limit the scope of the application.