Modeling methods, devices, electronic equipment, and products based on the Python model library ModeLica.
By importing the PythonInterface model library into the Modelica environment, joint modeling of Python and Modelica is achieved, which solves the problems of large workload and low efficiency caused by manual code compilation in the existing technology, realizes the automated modeling process, reduces the probability of errors and improves efficiency.
Patent Information
- Application Number
- CN202410737676.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-07
- Publication Date
- 2025-11-14
- Estimated Expiration
- 2044-06-07
AI Technical Summary
When using Python for modeling in the Modelica environment, existing techniques require users to manually compile the code, which increases workload and reduces modeling efficiency.
By importing the PythonInterface model library into the Sysplorer modeling tool, a Python instantiation component for the Sysplorer model is generated. Based on this component, a Python file is called to generate Modelica text information, and finally, the Modelica model is constructed, realizing joint modeling of Python and Modelica.
It reduces the probability of errors, decreases the workload of model developers, improves modeling efficiency, and is suitable for large-scale application and promotion.
Smart Images

Figure CN118607222B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of software engineering processing technology, specifically relating to a Modelica modeling method, device, electronic device and product based on the Python model library. Background Technology
[0002] Since many algorithms are developed using Python, most modeling environments utilize Python; this is also true for Modelica modeling. However, in practical applications, using Python within the Modelica environment (an open, object-oriented, equation-based computer language environment) requires users to understand Python's underlying algorithm logic and call relationships, manually compile the corresponding code, and convert it into Modelica language before it can be used in the Modelica environment. This not only increases the workload of staff but also reduces modeling efficiency. Therefore, providing a modeling method that allows direct use of Python within the Modelica environment to improve modeling efficiency and reduce workload has become an urgent problem to solve. Summary of the Invention
[0003] The purpose of this invention is to provide a Modelica modeling method, device, electronic device, and product based on the Python model library, in order to solve the problems of large modeling workload and low efficiency in the existing technology.
[0004] To achieve the above objectives, the present invention adopts the following technical solution:
[0005] Firstly, a Modelica modeling method based on the Python model library is provided, including:
[0006] Obtain the PythonInterface model library and import the PythonInterface model library into the modeling tool, wherein the modeling tool includes the Sysplorer modeling tool;
[0007] Based on the modeling tool, a Sysplorer model is generated, and using the PythonInterface model library within the modeling tool, a Python instantiation component of the Sysplorer model is generated.
[0008] Obtain the Python file of the instantiated component and generate the Modelica text information of the Sysplorer model based on the Python file;
[0009] Using the Modelica text information, generate the Modelica model corresponding to the Sysplorer model.
[0010] Based on the above-disclosed content, this invention utilizes the Sysplorer modeling tool's ability to support simultaneous modeling of Modelica and Python files to achieve joint modeling of Modelica and Python using the Sysplorer modeling tool as a foundation. Specifically, during modeling, the PythonInterface model library is first imported into the Sysplorer modeling tool, and then a Sysplorer model is generated based on the Sysplorer modeling tool. Next, the imported PythonInterface model library is used to generate a Python instantiation component for the Sysplorer model, thereby enabling the calling of Python files. Then, based on the called Python file, this invention generates Modelica text information for the Sysplorer model. Finally, based on the Modelica text information and using the Sysplorer modeling tool, the corresponding Modelica model for the Sysplorer model can be generated.
[0011] Through the above design, this invention establishes a Python-Modelica joint modeling approach, enabling the direct use of Python algorithms to complete modeling within the Modelica environment. The entire process is transformed from manual operation to automated execution, which not only reduces the probability of errors and the workload of model developers but also improves modeling efficiency. Therefore, it is highly suitable for large-scale application and promotion.
[0012] In one possible design, the PythonInterface model library within the modeling tool is used to generate Python instantiation components of the Sysplorer model, including:
[0013] Configure the Python object call component in the PythonInterface model library within the modeling tool into the Sysplorer model to obtain the configured Sysplorer model;
[0014] The configured Sysplorer model is instantiated to obtain the Python instantiated component.
[0015] In one possible design, based on the Python file, the Modelica text information of the Sysplorer model is generated, including:
[0016] The Python file is parsed to obtain the input parameters, output parameters, and 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] Based on the Python file, and the data types of each input parameter, each output parameter, and the total number of parameters in the Python file, the Modelica text information of the Sysplorer model is generated.
[0019] In one possible design, the Python file is parsed to obtain the input parameters, output parameters, and total number of parameters in the Python file, including:
[0020] The Python file is parsed to obtain all Python classes in the file.
[0021] Determine whether each Python class contains a preset function, wherein the preset function includes the setp_impl function;
[0022] If so, then obtain the parameter list of each preset function;
[0023] Based on the list of parameters, the input parameters, output parameters, and total number of parameters in the Python file are determined.
[0024] In one possible design, if any preset function does not contain the preset function, the method further includes:
[0025] An error message is generated and displayed visually in a pop-up window.
[0026] In one possible design, based on the Python file, and the data types of each input parameter, 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] Obtain the file path and environment dependency path of the Python file;
[0028] 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, the Modelica text information of the Sysplorer model is generated.
[0029] In one possible design, the Modelica model corresponding to the Sysplorer model is generated using the Modelica text information, including:
[0030] Obtain the Modelica simulation function 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] Secondly, a Modelica modeling apparatus based on the Python model library is provided, including:
[0033] The library import 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;
[0034] An 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 within the modeling tool.
[0035] The Modelica text information generation unit is used to obtain the Python file of the Python instantiation component and generate Modelica text information of the Sysplorer model based on the Python file.
[0036] The model generation unit is used to generate the Modelica model corresponding to the Sysplorer model using the Modelica text information.
[0037] Thirdly, another Modelica modeling device based on the Python model library is provided. Taking the device as an electronic device as an example, it includes a memory, a processor, and a transceiver that are connected in sequence. 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 programs and execute the Modelica modeling method based on the Python model library as described in the first aspect or any possible design in the first aspect.
[0038] Fourthly, a storage medium is provided, on which instructions are stored, which, when executed on a computer, perform the Modelica modeling method based on the Python model library as described in the first aspect or any possible design of the first aspect.
[0039] Fifthly, a computer program product containing instructions is provided that, when the instructions are executed on a computer, causes the computer to perform the Modelica modeling method based on the Python model library as described in the first aspect or any possible design of the first aspect.
[0040] Beneficial effects:
[0041] (1) By establishing a Python-Modelica joint modeling method, this invention enables the direct use of Python algorithms in the Modelica environment to complete the modeling process, and the entire process is transformed from manual operation to automated operation. This not only reduces the probability of errors and the workload of model developers, but also improves the modeling efficiency; therefore, it is very suitable for large-scale application and promotion. Attached Figure Description
[0042] Figure 1 A flowchart illustrating the steps of the Modelica modeling method based on the Python model library provided in this embodiment of the invention; Figure 2 A schematic diagram of the structure of the Modelica modeling device based on the Python model library provided in an embodiment of the present invention;
[0043] Figure 3 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0044] 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 conjunction with the accompanying drawings and descriptions of the embodiments or the prior art. Obviously, the following description of the structure of the accompanying drawings is only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. It should be noted that the description of these embodiments is for the purpose of helping to 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. For example, a first unit may be referred to as a second unit, and similarly, a second unit may be referred to as a first unit, without departing from the scope of the exemplary embodiments of the invention.
[0046] It should be understood that the term "and / or" that may appear in this document is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can mean: A exists alone, B exists alone, and A and B exist simultaneously. The term " / and" that may appear in this document describes another relationship between related objects, indicating that two relationships can exist. For example, A / and B can mean: A exists alone, and A and B exist alone. In addition, the character " / " that may appear in this document generally indicates that the related objects before and after it are in an "or" relationship.
[0047] Example:
[0048] See Figure 1 As shown, the Modelica modeling method based on the Python model library provided in this embodiment utilizes the feature of the Sysplorer modeling tool that supports simultaneous modeling of Modelica and Python files. Based on the Sysplorer modeling tool, it achieves joint modeling of Modelica and Python. Specifically, during modeling, the PythonInterface model library is first imported into the Sysplorer modeling tool, and then a Sysplorer model is generated. Then, using the imported PythonInterface model library, a Python instantiation component of the Sysplorer model is generated, thereby enabling the calling of Python files based on this Python instantiation component. Finally, according to the call... The Python file generates Modelica text information for the Sysplorer model; finally, the Modelica model can be constructed based on this. Through the above design, this method allows modeling to be completed directly within the Modelica environment using Python files, transforming the entire process from manual to automated. This not only reduces the workload of model developers but also improves modeling efficiency, making it highly suitable for large-scale application and promotion. For example, this method can, but is not limited to, running on the modeling end. Optionally, the modeling end can, but is not limited to, a personal computer. It is understood that the aforementioned execution entity does not constitute a limitation on the embodiments of this application. Accordingly, the running steps of this method can, but are not limited to, the steps S1 to S4 below.
[0049] S1. Obtain the PythonInterface model library and import it into the modeling tool, which includes the Sysplorer modeling tool. In this embodiment, the PythonInterface model library can be pre-set in the modeling end, so that when in use, the model library can be directly called and imported into the Sysplorer modeling tool. Furthermore, 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. The Sysplorer modeling tool provides interface editing functions. It is integrated into the MWORKS.Sysplorer environment and provides two right-click menu options and two Python environment configuration interfaces. Thus, based on the Sysplorer modeling tool, Python files can be used to automatically generate Modelica text and complete the 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) Selecting a Python object, which pops up a Python file selection dialog box for users to select the Python file and its dependent file paths; (2) Editing PythonObject ports: which can pop up an "Edit PythonObject ports" 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 runtime environment and select Python dependent files, while the latter is used to import the Python classes to be used, configure the input and output port information, and write the configuration information into the Modelica text. Optionally, it is mainly recorded in the inputDims, inputTypes, outputDims and outputTypes fields inside the text.
[0051] Meanwhile, the PythonInterface model library is a standard model based on the Modelica language to support Python modules. It defines the standard specifications for simultaneous modeling in Modelica and Python, including initialization interfaces, single-step calculation interfaces, and termination call interfaces during the interaction process. It also supports the transmission of data types such as Real, Integer, Boolean, Npy_Int, Npy_Int, Npy_Bool, and Python Object in the Python environment.
[0052] Furthermore, the PythonInterface model library includes: the constructor module, the exchangeData module (a Python-based library primarily used to help developers acquire, transform, and store data), the destructor module, the CalcRealPortNumber module, and the CalcIntPortNumber module. The constructor module, located within PythonInterface.Communication.PythonObject.constructor in the model library, functions as an external function to call the "my_python_object.dll" dynamic link library and uses the initPythonMemory function.
[0053] The exchangeData module is located within PythonInterface.Communication.PythonObject.exchangeData. Its function is to call the "my_python_object.dll" dynamic link library as an external function and use the stepImpl function.
[0054] The destructor module is located within PythonInterface.Communication.PythonObject.destructor. Its function is to call the "my_python_object.dll" dynamic link library as an external function and use the freePythonMemory function.
[0055] Next, the CalcRealPortNumber module is located at:
[0056] Within PythonInterface.Communication.PythonObject.CalcRealPortNumber, its function is to calculate the required number of Integer type ports using the contents of the outputDims, outputTypes, and hasOutput fields in modelica.
[0057] Similarly, the CalcIntPortNumber module is located at:
[0058] Within PythonInterface.Communication.PythonObject.CalcIntPortNumber, its function is to calculate the required number of Integer type ports using the contents of the outputDims, outputTypes, and hasOutput fields in modelica.
[0059] Thus, based on this PythonInterface model library and the Sysplorer modeling tool, direct conversion between Modelica and Python can be achieved.
[0060] In practical implementation, after importing the PythonInterface model library, the Sysplorer model can be generated first, and a Python instantiation component of the model can be created so that Python files can be called based on the instantiation component later. The generation process of the Sysplorer model and the generation process of the instantiation component can be, but are not limited to, the steps shown in step S2 below.
[0061] S2. Based on the modeling tool, a Sysplorer model is generated, and using the PythonInterface model library within the modeling tool, a Python instantiation component of the Sysplorer model is generated. In specific implementations, the Sysplorer model can be, but is not limited to, pre-set in the modeling end and can be called when needed; of course, it can also be generated based on the human-computer interaction operation in response to the modeling human-computer interaction operation; simultaneously, after the Sysplorer model is established, its corresponding Python instantiation component can be generated; wherein, in this embodiment, the Python object call component in the PythonInterface model library within the modeling tool is first configured into the Sysplorer model, thereby obtaining the configured Sysplorer model; then, the configured Sysplorer model is processed to instantiate the component, so that the Python instantiation component is obtained after the component instantiation process.
[0062] In specific implementation, for example, the aforementioned Python object calling component can be, but is not limited to, using the PythonInterface.PythonObject.PythonObject module. That is, dragging the PythonInterface.PythonObject.PythonObject module from the PythonInterface model library into the user model (that is, the aforementioned Sysplorer model) and instantiating the component to obtain the Python instantiated component (and of course, the component name, such as base1). In this embodiment, the purpose of instantiating the component is to realize the calling of Python files, which is a common technique in the Python language, and its principle will not be elaborated here.
[0063] After obtaining the Python instantiation component of the Sysplorer model, the corresponding Python file can be called based on it to generate Modelica text information based on the called Python file. The file calling and Modelica text information generation process can be, but is not limited to, as shown in step S3 below.
[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 specific implementation, for example, but not limited to, responding to the Python object selection human-computer interaction operation of the Python instantiation component, the Python file corresponding to the Python instantiation component can be determined from the called Python file selection box. In this way, through human-computer interaction operation with the Python instantiation component (such as click operation), the Python file to be loaded can be selected in the pop-up selection box. This file is mainly used to parse the contained classes and the number of input and output parameters contained in the setp_impl function, etc. Therefore, it can be set as a configuration item in the aforementioned Python instantiation component.
[0065] After obtaining the corresponding Python file, 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. The Python file is parsed to obtain the input parameters, output parameters, and total number of parameters in the Python file, wherein the input parameters and output parameters are modeling parameters. In this embodiment, the Python file is first parsed to obtain all Python classes in the Python file (a class refers to a function package, which can contain functions (methods) and variables (attributes). It defines a collection of objects with the same attributes and methods and is the basis of object-oriented programming). Then, it is determined whether each Python class contains a preset function (in this embodiment, the preset function may 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 the parameter list, the input parameters, output parameters, and 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 message needs to be generated and displayed visually in a pop-up window.
[0067] Thus, after the aforementioned steps, the Python file can be parsed to obtain the names of each parameter in the file (i.e., the names of the input and output parameters). 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. The process of determining the aforementioned data type can be, but is not limited to, the steps shown in step S32 below.
[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 human-computer interaction operations for data type configuration, the data type of each input parameter and each output parameter may be determined from the data type option library; optionally, the data type options may include, but are not limited to, data types such as: Real, Integer, Boolean, Npy_Int, Npy_Int, Npy_Bool, Python Object, etc.
[0069] Thus, after obtaining the data type of each input parameter and each output parameter, the Modelica text information of the Sysplorer model can be generated by combining the Python file. The process can be, but is not limited to, the steps shown in S33 below.
[0070] S33. Based on the Python file, and the data types of each input parameter, each output parameter, and the total number of parameters in the Python file, generate the Modelica text information of the Sysplorer model. In this embodiment, the file path and environment dependency path of the Python file are first obtained. Then, 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, the Modelica text information of the Sysplorer model is generated. Specifically, the Modelica text information is obtained by processing the various fields in the Modelica text of the aforementioned data record (i.e., the inputDims, inputTypes, outputDims, and outputTypes fields mentioned above).
[0071] Therefore, through the aforementioned steps S31 to S33, the corresponding Modelica text information can be generated using a Python file; then, based on the Modelica text information, the Modelica model can be directly constructed, and the process can be, but is not limited to, as shown in step S4 below.
[0072] S4. Using the Modelica text information, generate the Modelica model corresponding to the Sysplorer model; in this embodiment, for example, but not limited to, first obtaining the Modelica simulation function library; then, based on the Modelica simulation function library and the Modelica text information, generate the Modelica model corresponding to the Sysplorer model.
[0073] Optionally, the Modelica simulation library is an external library, a DLL dynamic runtime library developed in C / C++, used to support the Modelica language in calling Python code and providing support for the Python environment. This library specifies the function calling process, data transmission methods, calculation of the number of input and output ports, etc., and can use a specified version of the Python environment to load .py files for simulation calculations.
[0074] Furthermore, the function library includes initialization interface functions, data interaction interface functions, and resource release interface functions. The initialization interface is used to initialize the Python file runtime environment, allocate memory resources, and initialize memory resources. During simulation calculations, it is called by the `constructor` module of the PythonInterface model library. The data interaction interface is used for data interaction, that is, inputting the current data of the model into Python functions for calculation and feeding the results back into the model. During simulation calculations, it is called by the `exchangeData` module in the PythonInterface model library. The resource release interface is used to terminate the use of the Python runtime environment and release system resources. It is called by the `destructor` module of the PythonInterface model library when the simulation calculation ends.
[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] Therefore, through the Modelica modeling method based on the Python model library described in detail in steps S11 to S4 above, this invention establishes a Python-Modelica joint modeling approach, which enables the direct use of Python algorithms to complete modeling in the Modelica environment, and the entire process is transformed from manual operation to automated operation. This not only reduces the probability of errors and the workload of model developers, but also improves 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, comprising:
[0078] The library import 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] An 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 within the modeling tool.
[0080] The Modelica text information generation 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 the Modelica model corresponding to the Sysplorer model 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 repeated 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 connected in sequence. 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 the first aspect of the embodiment.
[0084] For specific examples, the memory may include, but is not limited to, random access memory (RAM), read-only memory (ROM), flash memory, first-in-first-out (FIFO) memory, and / or first-in-last-out (FILO) memory, 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 using at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), PLA (Programmable Logic Array). The processor may also include a main processor and a coprocessor. The main processor, also known as the CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state.
[0085] In some embodiments, the processor may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the screen. For example, the processor may not be limited to microprocessors of the STM32F105 series, reduced instruction set computer (RISC) microprocessors, x86 architecture processors, or processors with integrated neural network processing units (NPUs). The transceiver may be, but is not limited to, a Wi-Fi transceiver, a Bluetooth transceiver, a General Packet Radio Service (GPRS) transceiver, a ZigBee (a low-power LAN protocol based on the IEEE 802.15.4 standard) transceiver, a 3G transceiver, a 4G transceiver, and / or a 5G transceiver. Furthermore, 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 repeated here.
[0087] The fourth aspect of this embodiment provides a storage medium for storing instructions containing 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 that, when executed on a computer, perform the Modelica modeling method based on the Python model library as described in the first aspect of the embodiment.
[0088] The storage medium refers to a carrier for storing data, which may include, but is not limited to, floppy disks, optical disks, hard disks, flash memory, USB flash drives, and / or memory sticks. 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 repeated here.
[0090] The fifth aspect of this embodiment provides a computer program product containing instructions that, when executed on a computer, cause the computer to perform the Modelica modeling method based on the Python model library as described in the first aspect of this embodiment, wherein the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device.
[0091] Finally, it should be noted that the above description is merely a preferred embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A Modelica modeling method based on the Python model library, characterized in that, include: Obtain the PythonInterface model library and import the PythonInterface model library into the modeling tool, wherein the modeling tool includes the Sysplorer modeling tool; Based on the modeling tool, a Sysplorer model is generated, and using the PythonInterface model library within the modeling tool, Python instantiation components of the Sysplorer model are generated, including: Configure the Python object call component in the PythonInterface model library within the modeling tool into the Sysplorer model to obtain the configured Sysplorer model; The configured Sysplorer model is instantiated to obtain the Python instantiated component. Obtain the Python file of the instantiated component, and based on the Python file, generate the Modelica text information of the Sysplorer model, including: The Python file is parsed to obtain the input parameters, output parameters, and 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; Based on the Python file, and 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. Using the Modelica text information, generate the Modelica model corresponding to the Sysplorer model.
2. The method according to claim 1, characterized in that, The Python file is parsed to obtain the input parameters, output parameters, and total number of parameters in the Python file, including: The Python file is parsed to obtain all Python classes in the file. Determine whether each Python class contains a preset function, wherein the preset function includes the setp_impl function; If so, then obtain the parameter list of each preset function; Based on the list of parameters, the input parameters, output parameters, and total number of parameters in the Python file are determined.
3. The method according to claim 2, characterized in that, If none of the preset functions contains the preset function, the method further includes: An error message is generated and displayed visually in a pop-up window.
4. The method according to claim 1, characterized in that, Based on the Python file, and the data types of each input parameter, each output parameter, and the total number of parameters in the Python file, the Modelica text information of the Sysplorer model is generated, including: Obtain the file path and environment dependency path of the Python file; 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, the Modelica text information of the Sysplorer model is generated.
5. The method according to claim 1, characterized in that, Using the Modelica text information, generate the Modelica model corresponding to the Sysplorer model, including: Obtain the Modelica simulation function library; Based on the Modelica simulation function library and the Modelica text information, a Modelica model corresponding to the Sysplorer model is generated.
6. A Modelica modeling device based on the Python model library, characterized in that, include: The library import 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; An 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 within the modeling tool. The Modelica text information generation unit is used to obtain the Python file of the Python instantiation component and generate Modelica text information of the Sysplorer model based on the Python file. The model generation unit is used to generate the Modelica model corresponding to the Sysplorer model using the Modelica text information. Based on the modeling tool, a Sysplorer model is generated, and using the PythonInterface model library within the modeling tool, Python instantiation components of the Sysplorer model are generated, including: Configure the Python object call component in the PythonInterface model library within the modeling tool into the Sysplorer model to obtain the configured Sysplorer model; The configured Sysplorer model is instantiated to obtain the Python instantiated component. Obtain the Python file of the instantiated component, and based on the Python file, generate the Modelica text information of the Sysplorer model, including: The Python file is parsed to obtain the input parameters, output parameters, and 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; Based on the Python file, and the data types of each input parameter, each output parameter, and the total number of parameters in the Python file, the Modelica text information of the Sysplorer model is generated.
7. An electronic device, characterized in that, include: A memory, a processor, and a transceiver are sequentially connected in communication, 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 programs and execute the Modelica modeling method based on the Python model library as described in any one of claims 1 to 5.
8. A computer program product containing instructions, characterized in that, When the instructions are executed on the computer, the computer performs the Modelica modeling method based on the Python model library as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Method for converting Python model to Modelica model
CN106681726A
Model data processing method and device, equipment and storage medium
CN114282284A