ModeLica modeling method and device based on Python model library, electronic equipment and product

By using the Python model library and Sysplorer modeling tool in the Modelica environment, Python-Modelica joint modeling is realized, which solves the problems of heavy modeling workload and low efficiency in the existing technology, improves the modeling efficiency and accuracy, and is suitable for Large-scale application.

CN118607222AActive Publication Date: 2024-09-06SHENZHEN JINGYUAN SHUYU TECH CO LTD

Patent Information

Application Number
CN202410737676.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-07
Publication Date
2024-09-06
Estimated Expiration
2044-06-07

AI Technical Summary

Technical Problem

When using the Python language in the Modelica environment, users need to understand the underlying algorithm logic and calling relationships, manually compile the code and convert it into the Modelica language, resulting in heavy modeling workload and low efficiency.

Method used

By providing a Modelica modeling method based on the Python model library, the Sysplorer modeling tool is used to import the PythonInterface model library, generate a Python instantiation component, and call the Python file based on the component to automatically generate Modelica text information and models, realizing Python-Modelica joint construction mold.

Benefits of technology

It reduces the workload of model developers, reduces the probability of errors, and improves modeling efficiency, making it possible to directly use Python algorithms to complete modeling in the Modelica environment, making it suitable for large-scale applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118607222A
    Figure CN118607222A
Patent Text Reader

Abstract

The invention discloses a Modelica modeling method and device based on a Python model library, electronic equipment and a product, the characteristic that a Sysplorer modeling tool can support simultaneous modeling of Modelica and Python files is utilized, and combined modeling of Modelica and Python is achieved on the basis of the Sysplorer modeling tool; the method comprises the following steps of: during modeling, firstly, importing a PythonInterface model library into a Sysplorer modeling tool, and then, generating a Sysplorer model; the method comprises the following steps: firstly, generating a Python instantiation component of a Sysplorer model by using an imported PythonInterface model library, so as to realize the calling of a Python file on the basis of the Python instantiation component, and then, generating a Python instantiation component of the Sysplorer model by using the Python instantiation component of the Sysplorer model; then, according to the called Python file, Modelica text information of a Sysplorer model is generated, and the Modelica text information is sent to the Sysplorer model; and finally, a Modelica model can be constructed on the basis of the Modelica model. Thus, in the whole modeling process, the python file can be directly used in the Modelica environment to complete modeling, and the whole process is changed into automatic operation from manual operation; therefore, not only is the workload of model developers reduced, but also the modeling efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of software engineering processing, and specifically relates to a Modelica modeling method, device, electronic equipment and product based on a Python model library. Background Art

[0002] Since many algorithms are currently developed based on Python, most modeling environments are used in conjunction with the Python language; this is also true for Modelica modeling; however, in actual application, to use the Python language in the Modelica environment (an open, object-oriented, equation-based computer language environment), users are required to know Python's underlying algorithm logic and calling relationships, and then manually compile the corresponding code and convert it into the Modelica language to implement its application in the Modelica environment; this will not only increase the workload of the staff, but also reduce the modeling efficiency; based on this, how to provide a modeling method that can directly use the Python language in the Modelica environment to improve modeling efficiency and reduce modeling workload has become an urgent problem to be solved. Summary of the invention

[0003] The purpose of the present invention is to provide a Modelica modeling method, device, electronic device and product based on Python model library, so as to solve the problems of large modeling workload and low efficiency in the prior art.

[0004] In order to achieve the above object, the present invention adopts the following technical solutions:

[0005] In a first aspect, a Modelica modeling method based on a Python model library is provided, comprising:

[0006] Obtaining a PythonInterface model library, and importing the PythonInterface model library into a modeling tool, wherein the modeling tool includes a Sysplorer modeling tool;

[0007] Based on the modeling tool, a Sysplorer model is generated, and a Python instantiation component of the Sysplorer model is generated using a PythonInterface model library in the modeling tool;

[0008] Obtaining the Python file of the Python instantiation component, and generating Modelica text information of the Sysplorer model based on the Python file;

[0009] The Modelica text information is used to generate a Modelica model corresponding to the Sysplorer model.

[0010] Based on the above disclosed content, the present invention utilizes the feature that the Sysplorer modeling tool can support the simultaneous modeling of Modelica and Python files, to realize the joint modeling of Modelica and Python based on the Sysplorer modeling tool; wherein, during modeling, the PythonInterface model library is first imported into the Sysplorer modeling tool, and then the Sysplorer model is generated based on the Sysplorer modeling tool; then, the PythonInterface model library is used to generate the Python instantiation component of the Sysplorer model, so as to realize the calling of the Python file based on the Python instantiation component; then, the present invention generates the Modelica text information of the Sysplorer model based on the called Python file; finally, based on the Modelica text information and using the Sysplorer modeling tool, the Modelica model corresponding to the Sysplorer model can be generated.

[0011] Through the above design, the present invention establishes a Python-Modelica joint modeling method, so that the Python algorithm can be directly used in the Modelica environment to complete the modeling, and the entire process is changed from manual operation to automatic operation, which not only reduces the error probability and the workload of model developers, but also improves the modeling efficiency; therefore, it is very suitable for large-scale application and promotion.

[0012] In a possible design, the PythonInterface model library in the modeling tool is used to generate the Python instantiation component of the Sysplorer model, including:

[0013] The Python object calling component in the PythonInterface model library in the modeling tool is configured into the Sysplorer model to obtain the configured Sysplorer model;

[0014] The configured Sysplorer model is subjected to instantiation component processing to obtain the Python instantiation component after the instantiation component processing.

[0015] In a possible design, based on the python file, Modelica text information of the Sysplorer model is generated, including:

[0016] Parsing the python file to obtain input parameters, output parameters and the total number of parameters in the python file, wherein the input parameters and the output parameters are modeling parameters;

[0017] Determine the data type of each input parameter and each output parameter in the Python file;

[0018] Modelica text information of the Sysplorer model is generated based on the python file, the data type of each input parameter, the data type of each output parameter and the total number of parameters in the python file.

[0019] In a possible design, the python file is parsed to obtain input parameters, output parameters and the total number of parameters in the python file, including:

[0020] Parse the python file to obtain all python classes in the python file;

[0021] Determine whether each Python class contains a preset function, wherein the preset function includes a setp_impl function;

[0022] If so, get the parameter list of each preset function;

[0023] Based on each parameter list, determine the input parameters, output parameters and total number of parameters in the python file.

[0024] In a possible design, if any preset function does not contain the preset function, the method further includes:

[0025] Generate an error prompt message and visually display the error prompt message in a pop-up window.

[0026] In a possible design, based on the python file, the data type of each input parameter, the data type of each output parameter, and the total number of parameters in the python file, the Modelica text information of the Sysplorer model is generated, including:

[0027] Get the file path and environment dependency path of the python file;

[0028] Modelica text information of the Sysplorer model is generated based on the file path, the environment dependency path, the total number of parameters, the data type of each input parameter, and the data type of each output parameter.

[0029] In a possible design, the Modelica text information is used to generate a Modelica model corresponding to the Sysplorer model, including:

[0030] Get the Modelica simulation library;

[0031] Based on the Modelica simulation function library and the Modelica text information, a Modelica model corresponding to the Sysplorer model is generated.

[0032] In a second aspect, a Modelica modeling device based on a Python model library is provided, comprising:

[0033] A library importing unit, used for acquiring a PythonInterface model library, and importing the PythonInterface model library into a modeling tool, wherein the modeling tool includes a Sysplorer modeling tool;

[0034] An instantiation unit, used to generate a Sysplorer model based on the modeling tool, and to generate a Python instantiation component of the Sysplorer model using a PythonInterface model library in the modeling tool;

[0035] A Modelica text information generating unit, used for obtaining a python file of the Python instantiation component, and generating Modelica text information of the Sysplorer model based on the python file;

[0036] The model generation unit is used to generate a Modelica model corresponding to the Sysplorer model by using the Modelica text information.

[0037] In a third aspect, another Modelica modeling device based on the Python model library is provided. Taking the device as an electronic device as an example, the device includes a memory, a processor and a transceiver which are communicatively connected in sequence, wherein the memory is used to store computer programs, the transceiver is used to send and receive messages, and the processor is used to read the computer program to execute the Modelica modeling method based on the Python model library as in the first aspect or any possible design in the first aspect.

[0038] In a fourth aspect, a storage medium is provided, on which instructions are stored. When the instructions are executed on a computer, the Modelica modeling method based on the Python model library as in the first aspect or any possible design of the first aspect is executed.

[0039] In a fifth aspect, a computer program product comprising instructions is provided, which, when executed on a computer, causes the computer to execute the Modelica modeling method based on the Python model library as in the first aspect or any possible design of the first aspect.

[0040] Beneficial effects:

[0041] (1) The present invention establishes a Python-Modelica joint modeling method, so that the Python algorithm can be directly used in the Modelica environment to complete the modeling, and the entire process is changed from manual operation to automatic operation. This not only reduces the error probability and the workload of model developers, but also improves the modeling efficiency; therefore, it is very suitable for large-scale application and promotion. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 A schematic diagram of the steps of the Modelica modeling method based on the Python model library provided in an embodiment of the present invention; Figure 2 A schematic diagram of the structure of a Modelica modeling device based on a Python model library provided by an embodiment of the present invention;

[0043] Figure 3 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0044] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the present invention will be briefly introduced below in combination with the drawings and the description of the embodiments or the prior art. Obviously, the following description of the structure of the drawings is only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. It should be noted that the description of these embodiments is used to help understand the present invention, but does not constitute a limitation of the present invention.

[0045] It should be understood that although the terms first, second, etc. may be used herein to describe various units, these units should not be limited by these terms. These terms are only used to distinguish one unit from another unit. For example, a first unit can be referred to as a second unit, and similarly, a second unit can be referred to as a first unit without departing from the scope of the exemplary embodiments of the present invention.

[0046] It should be understood that the term "and / or" that may appear in this article is merely a description of the association relationship between associated objects, indicating that three relationships may exist. For example, A and / or B can represent three situations: A exists alone, B exists alone, and A and B exist at the same time. The term " / and" that may appear in this article describes another type of association object relationship, indicating that two relationships may exist. For example, A / and B can represent two situations: A exists alone, and A and B exist alone. In addition, the character " / " that may appear in this article generally indicates that the previous and next associated objects are in an "or" relationship.

[0047] Example:

[0048] See also Figure 1 As shown, the Modelica modeling method based on the Python model library provided in this embodiment uses the feature that the Sysplorer modeling tool can support the simultaneous modeling of Modelica and Python files to realize the joint modeling of Modelica and Python based on the Sysplorer modeling tool; wherein, during modeling, the PythonInterface model library is first imported into the Sysplorer modeling tool, and then the Sysplorer model is generated; then, the Python instantiation component of the Sysplorer model is generated using the imported PythonInterface model library, so as to realize the calling of the Python file based on the Python instantiation component; then, according to the calling Python file to generate the Modelica text information of the Sysplorer model; finally, based on this, a Modelica model can be constructed; through the above design, this method can directly use python files in the Modelica environment to complete modeling during the entire modeling process, and the entire process is changed from manual operation to automatic operation; thereby, not only the workload of model developers is reduced, but also the modeling efficiency is improved; therefore, it is very suitable for large-scale application and promotion; among them, for example, this method can be but not limited to running on the modeling end side, optionally, the modeling end can be but not limited to a personal computer, it can be understood that the aforementioned execution subject does not constitute a limitation on the embodiments of the present application, and accordingly, the running steps of this method can be but not limited to the following steps S1 to S4.

[0049] S1. Obtain the PythonInterface model library, and import the PythonInterface model library into the modeling tool, wherein the modeling tool includes the Sysplorer modeling tool; in this embodiment, the PythonInterface model library can be set in advance in the modeling end, so that when in use, the model library can be directly called and imported into the Sysplorer modeling tool; further, this embodiment utilizes the feature of the Sysplorer modeling tool that supports simultaneous modeling of Modelica and Python files to realize the function of directly using Python files for modeling in the Modelica environment; wherein, the Sysplorer modeling tool is used to provide an interface editing function, which is integrated in the MWORKS.Sysplorer environment, and provides 2 right-click menu options and 2 python environment configuration interfaces, so that based on the Sysplorer modeling tool, Python files can be used to automatically generate Modelica text and complete modeling.

[0050] Among them, the two right-click menu options are used to provide users with optional operations. By selecting different items, different dialog boxes are entered to edit the model. Specifically, they can include: (1) Select Python object, pop up a python file selection dialog box for the user to select the python file and its dependent file path; (2) Edit PythonObject port: it can pop up an "Edit PythonObject port" dialog box to select the python class required by the user according to the python file selected by the user, and configure the input and output port information according to the step_impl function in the class; similarly, the two environment configuration interfaces are used to import Python objects and edit PythonObject port information. The former is used to import python files, configure the python operating environment and select python dependent files, and the latter is used to import the python class to be used, configure the input and output port information, and write the configuration information into the Modelica text. Optional, it is mainly recorded in the inputDims, inputTypes, outputDims, and outputTypes fields inside the text.

[0051] At the same time, the PythonInterface model library is a standard model based on the Modelica language to support python modules. It stipulates the standard specifications for simultaneous modeling of Modelica and Python, the initialization interface during the interaction process, the single-step calculation interface, the end call interface and a series of other standards, and supports the transmission of data types such as Real, Integer, Boolean, Npy_Int, Npy_Int, Npy_Bool, Python Object in the Python environment.

[0052] Furthermore, the PythonInterface model library includes: constructor module, exchangeData module (a library written in Python, mainly to help developers acquire, convert and store data), destructor module, CalcRealPortNumber module and CalcIntPortNumber module; among them, the constructor module is located in PythonInterface.Communication.PythonObject.constructor in the model library, and its function is: calling the "my_python_object.dll" dynamic link library in the form of an external function, and using the initPythonMemory function.

[0053] The exchangeData module is located in PythonInterface.Communication.PythonObject.exchangeData. Its functions are: calling the "my_python_object.dll" dynamic link library as an external function and using the stepImpl function.

[0054] The destructor module is located in PythonInterface.Communication.PythonObject.destructor. Its function is: calling the "my_python_object.dll" dynamic link library as an external function and using the freePythonMemory function.

[0055] Next, the CalcRealPortNumber module is located at:

[0056] PythonInterface.Communication.PythonObject.CalcRealPortNumber calculates the required number of ports of type Integer using the outputDims, outputTypes, and hasOutput fields in modelica.

[0057] Similarly, the CalcIntPortNumber module is located at:

[0058] PythonInterface.Communication.PythonObject.CalcIntPortNumber has the following function: calculate the required number of ports of type Integer through the contents of the outputDims, outputTypes, and hasOutput fields in modelica.

[0059] In this way, based on the PythonInterface model library and the Sysplorer modeling tool, direct conversion between Modelica and Python can be achieved.

[0060] In the specific implementation, after completing the import of the PythonInterface model library, the Sysplorer model can be generated first, and the Python instantiation component of the model can be established, so that the Python file can be called based on the instantiation component later; wherein, the generation process of the Sysplorer model and the generation process of the instantiation component can be but not limited to as shown in the following step S2.

[0061] S2. Generate a Sysplorer model based on the modeling tool, and generate a Python instantiation component of the Sysplorer model by using the PythonInterface model library in the modeling tool; in specific implementation, the Sysplorer model can be, but is not limited to, pre-set in the modeling end and can be called when used; of course, it can also be generated based on the human-computer interaction operation in response to the modeling human-computer interaction operation; at the same time, after the Sysplorer model is established, its corresponding Python instantiation component can be generated; wherein, this embodiment first configures the Python object call component in the PythonInterface model library in the modeling tool into the Sysplorer model, thereby obtaining the configured Sysplorer model; then, the configured Sysplorer model is instantiated and processed, so as to obtain the Python instantiation component after the instantiation component processing.

[0062] In specific implementation, for example, the aforementioned Python object calling component can be but not limited to: PythonInterface.PythonObject.PythonObject module, that is, the PythonInterface.PythonObject.PythonObject module in the PythonInterface model library is dragged into the user model (that is, the aforementioned Sysplorer model), and the component is instantiated to obtain a Python instantiated component (of course, the component name is also obtained, such as base1); in this embodiment, the purpose of instantiating the component is to realize the calling of Python files, which is a common technology in the Python language, and its principle will not be repeated.

[0063] After obtaining the Python instantiation component of the Sysplorer model, the corresponding Python file can be called based on it, so as to generate Modelica text information based on the called Python file, wherein the file calling and Modelica text information generation process can be but is not limited to as shown in the following step S3.

[0064] S3. Obtain the python file of the Python instantiation component, and generate the Modelica text information of the Sysplorer model based on the python file; in the specific implementation, for example, it can be but not limited to responding to the Python object selection human-computer interaction operation of the Python instantiation component to determine the python file corresponding to the Python instantiation component from the called python file selection box; in this way, through the human-computer interaction operation with the Python instantiation component (such as clicking operation), the python file to be loaded can be selected in the pop-up selection box, and the file is mainly used to parse the included classes and the number of input and output parameters included in the setp_impl function, etc., therefore, it can be set as a configuration item in the aforementioned Python instantiation component.

[0065] After the corresponding python file is called, the Modelica text information of the Sysplorer model can be generated based on it; for example, but not limited to, the following steps S31 to S33 can be used to obtain the Modelica text information.

[0066] S31. Parse the python file to obtain input parameters, output parameters and the total number of parameters in the python file, wherein the input parameters and the output parameters are modeling parameters; in this embodiment, the python file can be parsed first to obtain all python classes in the python file (a class refers to a function package, which can include functions (methods) and variables (attributes), which defines a collection of objects with the same attributes and methods, and is the basis of object-oriented programming); then, determine whether each python class contains a preset function (in this embodiment, the preset function can include but is not limited to the setp_impl function); specifically, if each python class contains the setp_impl function, the parameter list of each preset function can be obtained; finally, based on each parameter list, the input parameters, output parameters and the total number of parameters in the python file can be determined; of course, if any preset function does not contain the preset function, an error prompt message needs to be generated, and the error prompt message is visually displayed in the form of a pop-up window.

[0067] In this way, after the aforementioned steps, the parsing of the python file can be completed, and the names of the various parameters in the file (i.e., the names of the input parameters and the output parameters) can be obtained; then, it is necessary to determine the data type of the parameter so that Modelica text information can be generated based on the data type later; wherein, the aforementioned data type determination process can be but is not limited to as shown in the following step S32.

[0068] S32. Determine the data type of each input parameter and each output parameter in the python file; in specific implementation, for example, but not limited to, when responding to the data type configuration human-computer interaction operation, determine the data type of each input parameter and each output parameter from the data type option library; optionally, the data type options may include but are not limited to: Real, Integer, Boolean, Npy_Int, Npy_Int, Npy_Bool, Python Object and other data types.

[0069] In this way, after obtaining the data type of each input parameter and each output parameter, the Python file can be combined to generate the Modelica text information of the Sysplorer model, and the process can be but not limited to the following step S33.

[0070] S33. Based on the python file, the data type of each input parameter, the data type of each output parameter and the total number of parameters in the python file, the Modelica text information of the Sysplorer model is generated; in this embodiment, the file path and the environment-dependent path of the python file are first obtained, and then, based on the file path, the environment-dependent path, the total number of parameters, the data type of each input parameter and the data type of each output parameter, the Modelica text information of the Sysplorer model is generated; specifically, each field in the Modelica text in the aforementioned data record (i.e., the inputDims, inputTypes, outputDims, and outputTypes fields in the aforementioned example) is added, so that after the recording is completed, the Modelica text information is obtained.

[0071] Therefore, through the aforementioned steps S31 to S33, the python file can be used to generate the corresponding Modelica text information; then, based on the Modelica text information, the Modelica model can be directly constructed, and the process can be but not limited to as shown in the following step S4.

[0072] S4. Generate a Modelica model corresponding to the Sysplorer model using the Modelica text information; in this embodiment, for example, but not limited to, first obtain a Modelica simulation function library; then, based on the Modelica simulation function library and the Modelica text information, generate a Modelica model corresponding to the Sysplorer model.

[0073] Optionally, the Modelica simulation function library is an external function library, which is a DLL dynamic runtime library developed based on the C / C++ language, and is used to support the Python environment when the Modelica language calls the Python code; the function library specifies the function calling process, data transmission method, input and output port quantity calculation, etc., and can use the specified version of the Python environment to load the py file for simulation calculations.

[0074] Furthermore, the function library includes an initialization interface function, a data interaction interface function and a resource release interface function; wherein the initialization interface is used to initialize the Python file operating environment, memory resource application, and memory resource initialization, and is called by the constructor module of the PythonInterface model library during the simulation calculation process; the data interaction interface is used for data interaction, that is, inputting the current data of the model into the Python function for calculation, and feeding the result back to the model, and is called by the exchangeData module in the PythonInterface model library during the simulation calculation process; and the resource release interface is used to end the use of the Python operating environment and release system resources, and is called by the destructor module in the PythonInterface model library at the end of the simulation calculation.

[0075] In this way, the initPythonMemory, stepImpl, and freePythonMemory functions in the external function library can be called in sequence to complete the model simulation construction process, thereby obtaining the Modelica model corresponding to the Sysplorer model.

[0076] Thus, through the Modelica modeling method based on the Python model library described in detail in the aforementioned steps S11 to S4, the present invention establishes a Python-Modelica joint modeling method, so that the Python algorithm can be directly used in the Modelica environment to complete the modeling, and the entire process is changed from manual operation to automatic operation, thus not only reducing the error probability and the workload of model developers, but also improving the modeling efficiency; therefore, it is very suitable for large-scale application and promotion.

[0077] like Figure 2 As shown, the second aspect of this embodiment provides a hardware device for implementing the Modelica modeling method based on the Python model library described in the first aspect of the embodiment, including:

[0078] The library importing unit is used to obtain the PythonInterface model library and import the PythonInterface model library into the modeling tool, wherein the modeling tool includes the Sysplorer modeling tool.

[0079] The instantiation unit is used to generate a Sysplorer model based on the modeling tool, and to generate a Python instantiation component of the Sysplorer model using the PythonInterface model library in the modeling tool.

[0080] The Modelica text information generating unit is used to obtain the python file of the Python instantiation component and generate the Modelica text information of the Sysplorer model based on the python file.

[0081] The model generation unit is used to generate a Modelica model corresponding to the Sysplorer model by using the Modelica text information.

[0082] The working process, working details and technical effects of the device provided in this embodiment can be found in the first aspect of the embodiment and will not be described in detail here.

[0083] like Figure 3 As shown, the third aspect of this embodiment provides another Modelica modeling device based on the Python model library. Taking the device as an electronic device as an example, it includes: a memory, a processor and a transceiver that are communicatively connected in sequence, wherein the memory is used to store computer programs, the transceiver is used to send and receive messages, and the processor is used to read the computer program to execute the Modelica modeling method based on the Python model library as described in the first aspect of the embodiment.

[0084] For example, the memory may include, but is not limited to, random access memory (RAM), read only memory (ROM), flash memory, first input first output (FIFO) and / or first in last out (FILO), etc. Specifically, the processor may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). At the same time, the processor may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state.

[0085] In some embodiments, the processor may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. For example, the processor may not be limited to a microprocessor of the STM32F105 series, a reduced instruction set computer (RISC) microprocessor, an X86 architecture processor, or a processor with an integrated embedded neural network processing unit (NPU); the transceiver may be, but is not limited to, a wireless fidelity (WIFI) wireless transceiver, a Bluetooth wireless transceiver, a general packet radio service technology (General Packet Radio Service, GPRS) wireless transceiver, a ZigBee protocol (a low-power local area network protocol based on the IEEE802.15.4 standard, ZigBee) wireless transceiver, a 3G transceiver, a 4G transceiver and / or a 5G transceiver, etc. In addition, the device may also include, but is not limited to, a power module, a display screen, and other necessary components.

[0086] The working process, working details and technical effects of the electronic device provided in this embodiment can be found in the first aspect of the embodiment and will not be described in detail here.

[0087] The fourth aspect of this embodiment provides a storage medium storing instructions for the Modelica modeling method based on the Python model library as described in the first aspect of the embodiment, that is, the storage medium stores instructions, and when the instructions are run on a computer, the Modelica modeling method based on the Python model library as described in the first aspect of the embodiment is executed.

[0088] The storage medium refers to a carrier for storing data, which may include but is not limited to a floppy disk, a CD, a hard disk, a flash memory, a USB flash drive and / or a memory stick, and the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices.

[0089] The working process, working details and technical effects of the storage medium provided in this embodiment can be found in the first aspect of the embodiment and will not be described in detail here.

[0090] A fifth aspect of this embodiment provides a computer program product comprising instructions, which, when executed on a computer, causes the computer to execute the Modelica modeling method based on the Python model library as described in the first aspect of the embodiment, wherein the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices.

[0091] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A Modelica modeling method based on Python model library, characterized in that: include: Obtaining a PythonInterface model library, and importing the PythonInterface model library into a modeling tool, wherein the modeling tool includes a Sysplorer modeling tool; Based on the modeling tool, a Sysplorer model is generated, and a Python instantiation component of the Sysplorer model is generated using a PythonInterface model library in the modeling tool; Obtaining the Python file of the Python instantiation component, and generating Modelica text information of the Sysplorer model based on the Python file; The Modelica text information is used to generate a Modelica model corresponding to the Sysplorer model.

2. The method according to claim 1, characterized in that Using the PythonInterface model library in the modeling tool, the Python instantiation component of the Sysplorer model is generated, including: The Python object calling component in the PythonInterface model library in the modeling tool is configured into the Sysplorer model to obtain the configured Sysplorer model; The configured Sysplorer model is subjected to instantiation component processing to obtain the Python instantiation component after the instantiation component processing.

3. The method according to claim 1, characterized in that Based on the python file, the Modelica text information of the Sysplorer model is generated, including: Parsing the python file to obtain input parameters, output parameters and the total number of parameters in the python file, wherein the input parameters and the output parameters are modeling parameters; Determine the data type of each input parameter and each output parameter in the Python file; Modelica text information of the Sysplorer model is generated based on the python file, the data type of each input parameter, the data type of each output parameter and the total number of parameters in the python file.

4. The method according to claim 3, characterized in that The python file is parsed to obtain the input parameters, output parameters and the total number of parameters in the python file, including: Parse the python file to obtain all python classes in the python file; Determine whether each Python class contains a preset function, wherein the preset function includes a setp_impl function; If so, get the parameter list of each preset function; Based on each parameter list, determine the input parameters, output parameters and total number of parameters in the python file.

5. The method according to claim 4, characterized in that If any preset function does not contain the preset function, the method further includes: Generate an error prompt message and visually display the error prompt message in a pop-up window.

6. The method according to claim 3, characterized in that Based on the python file, the data type of each input parameter, the data type of each output parameter and the total number of parameters in the python file, Modelica text information of the Sysplorer model is generated, including: Get the file path and environment dependency path of the python file; Modelica text information of the Sysplorer model is generated based on the file path, the environment dependency path, the total number of parameters, the data type of each input parameter, and the data type of each output parameter.

7. The method according to claim 1, characterized in that Using the Modelica text information, a Modelica model corresponding to the Sysplorer model is generated, including: Get the Modelica simulation library; Based on the Modelica simulation function library and the Modelica text information, a Modelica model corresponding to the Sysplorer model is generated.

8. A Modelica modeling device based on Python model library, characterized in that: include: A library importing unit, used for acquiring a PythonInterface model library, and importing the PythonInterface model library into a modeling tool, wherein the modeling tool includes a Sysplorer modeling tool; An instantiation unit, used to generate a Sysplorer model based on the modeling tool, and to generate a Python instantiation component of the Sysplorer model using a PythonInterface model library in the modeling tool; A Modelica text information generating unit, used for obtaining a python file of the Python instantiation component, and generating Modelica text information of the Sysplorer model based on the python file; The model generation unit is used to generate a Modelica model corresponding to the Sysplorer model by using the Modelica text information.

9. An electronic device, characterized in that: include: A memory, a processor and a transceiver which are sequentially connected in communication, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program, and execute the Modelica modeling method based on the Python model library as described in any one of claims 1 to 7.

10. A computer program product comprising instructions, characterized in that When the instructions are executed on a computer, the computer is enabled to execute the Modelica modeling method based on the Python model library as claimed in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Method for converting Python model to Modelica model

    CN106681726A

  • Augmentation of virtual models

    CN108496168A

  • Model data processing method and device, equipment and storage medium

    CN114282284A

  • 3DE template establishment method and system based on Python language

    CN117057000A

  • AUTOSAR tool box based on Modelica model

    CN118094863A

Cited By

  • Script running result comparison method, system, equipment and product

    CN119377112A