Modelica external object data serialization method and device

By defining serialization and deserialization interface functions in the Modelica external object class definition, the problem that complex Modelica models cannot implement solver state cache is solved, and debugging efficiency and continuity are improved.

CN119578104AActive Publication Date: 2025-03-07武汉鼎元同立科技有限公司
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202411744489.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-30
Publication Date
2025-03-07
Estimated Expiration
2044-11-30

AI Technical Summary

Technical Problem

The complex Modelica model that integrates external objects in the prior art cannot implement solver state cache, resulting in low debugging work efficiency and affecting the progress of model development.

Method used

By defining the serialization and deserialization interface functions in the external object class definition, the serialization and deserialization of external object data is realized, so that external object data is cached and restored during the simulation process.

Benefits of technology

It realizes effective serialization and deserialization of external object data, avoids simulation restarts, and improves the efficiency and continuity of model debugging.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119578104A_ABST
    Figure CN119578104A_ABST
Patent Text Reader

Abstract

The invention relates to a Modelica external object data serialization method and a Modelica external object data serialization device, which can avoid confusion with other external object operation methods by defining serialization and deserialization interface functions in an external object class definition, thereby reducing the analysis difficulty; by defining serialization and deserialization interface functions of an external object, a solver program can realize reading and writing of a data memory of the external object. In engineering modeling and simulation application, based on the purposes of historical asset model reuse, intellectual property protection and the like, application of an external object model is very common, the solver state caching function is further improved, the technical problem that solver state caching cannot be achieved through a complex Modelica model integrating an external object is solved, and the method has the advantages of being high in practicability and easy to popularize. And the debugging work efficiency of the problem model is greatly improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of system modeling and simulation, and in particular to a Modelica external object data serialization method and device. Background Art

[0002] Modelica is an object-oriented multi-domain system modeling language. Its non-causal modeling, multi-domain support, and object-oriented features enable it to efficiently and flexibly describe complex systems that are interdisciplinary and multi-subsystem coupled, making it an ideal choice for complex dynamic system modeling and simulation, and is widely used in the automotive, aerospace, energy, construction and other industries. In the actual modeling and simulation application process, complex system models described by the Modelica language often have mathematical properties such as large equation scale, strong nonlinearity, and rigidity, resulting in low simulation efficiency, poor result accuracy, and non-convergence of iterations. When a simulation anomaly occurs, the modeler expects to debug the model in the abnormal time interval, which requires restarting the solver and simulating to the abnormal time and then performing single-step debugging. During the problem debugging process, it may be necessary to restart the simulation multiple times in a cycle. If the model simulation efficiency is low and the anomaly occurs late, then restarting the solver and simulating to the abnormal time is a very time-consuming process, which seriously reduces the continuity and efficiency of the debugging work and affects the progress of model development. In order to avoid the work efficiency problems caused by the above-mentioned cyclic restart simulation, one simulation method is to pre-cache the solver state at a certain time before the abnormal moment occurs, load the cached solver state during the debugging phase, and perform simulation and debugging based on this state, thereby avoiding simulation restart.

[0003] To achieve the above goals, the solver state cache program must be able to read the model data and simulation data that can fully represent the solver state, so as to restore the simulation state at the time during the debugging phase. As an open physical modeling language, Modelica integrates models described by other languages ​​by standardizing the definition of external functions and external objects. External objects are data memories managed by other languages ​​and are invisible to the solver program. For example, the solver state cache program cannot obtain this part of the data memory during the caching phase, nor can it restore this part of the data memory during the state recovery phase. This means that complex Modelica models integrated with external objects can only be debugged by restarting the simulation. Therefore, realizing the serialization and deserialization of Modelica external object data is an urgent problem to be solved. Summary of the invention

[0004] In view of this, it is necessary to provide a Modelica external object data serialization method and device to solve the defect that the complex Modelica model integrating external objects in the prior art cannot realize solver state caching.

[0005] In order to solve the above problems, in a first aspect, an embodiment of the present invention provides a Modelica external object data serialization method, comprising: Constructing an external object model of external object data, the external object model comprising a serialization interface function and a deserialization interface function, the serialization interface function is used to convert state information of the external object data into byte data that can be stored or transmitted, and the deserialization interface function is used to restore the byte data to the state information of the external object data; At least one target component simulation model built based on the multi-domain unified modeling language Modelica is selected from the preset model library. During the simulation process, when the solver executes the state caching program, when caching the external object data of the external object model, if it is determined that a serialization interface function exists, the serialization interface function is called to retrieve the external object data. During the simulation process, when the solver executes the state recovery program, when restoring the external object data of the external object model, if it is determined that a deserialization interface function exists, the deserialization interface function is called to restore the external object data.

[0006] Preferably, the serialization interface function includes a first input parameter, a second input parameter and an output parameter; The first input parameter is used to receive external object data to be serialized; The second input parameter is a string variable, which is used to receive or provide array space for storing external object data during serialization and to indicate the required array space size during output; The first output parameter is used to return the success status of the serialization operation or the size of the array space required for the external object data; The deserialization interface function includes a third input parameter for receiving external object data to be deserialized; The fourth input parameter, as a string variable, contains the byte data used to restore the external object data status information; The second output parameter is used to return the success status of the deserialization operation.

[0007] Preferably, after constructing the external object model of the external object data, the method further includes: Generate serialization interface function and deserialization interface function to external object registration function of external object model; If there are other function definitions in addition to the constructor and destructor in the external object class definition, text matching is used to determine whether they are serialization interface function and deserialization interface function definitions. If not, an error is reported; If the serialization interface function and the deserialization interface function are defined in the external object class definition, the serialization interface function and the deserialization interface function are generated into the external object registration function of the external object model code.

[0008] Preferably, after selecting at least one target component simulation model constructed based on the multi-domain unified modeling language Modelica from the preset model library, the method further includes: After starting the simulation, the solver calls the external object registration function in the instantiation phase to obtain the data memory address of the external object data, as well as the serialization interface function handle and the deserialization interface function handle.

[0009] Preferably, the solver records the data memory address of the external object data, and uses the data memory address as a parameter to pass a specific address when subsequently calling the external object registration function operation method; The external object registration function completes the registration process by constructing an external object instance, allocating a destructor handle, a serialization interface function handle, and a deserialization interface function handle, and assigning them to corresponding member variables of the ExtObjectManager data structure.

[0010] Preferably, the solver further provides an external object management data structure ExtObjectManager, which is used to store the data memory address, destructor handle, serialization interface function handle and deserialization interface function handle of the external object data, wherein the definition of the data structure of the ExtObjectManager includes: The member variable obj is used to store the data memory address of the external object data; The member variable dtor is the destructor handle, which is used to release the memory of external object data; The member variable sel is a serialization interface function handle, which is used to convert external object data into a byte sequence; The member variable dsel is the deserialization interface function handle, which is used to restore external object data from a byte sequence.

[0011] Preferably, when caching the external object data of the external object model, if it is determined that there is a serialization interface function, the serialization interface function is called to retrieve the external object data, and during the simulation process, when the solver executes the state recovery program, when restoring the external object data of the external object model, if it is determined that there is a deserialization interface function, the deserialization interface function is called to restore the external object data, including: During the simulation process, when the solver executes the state cache program to cache the simulation model data of the target component, for the external object data in the simulation model of the target component, the solver detects whether there is a serialization interface function for the external object data; if the serialization interface function exists, the solver calls the serialization interface function to obtain and cache the external object data; if the serialization interface function does not exist, the solver outputs a warning prompt message indicating that the serialization operation cannot be performed on the external object data; During the simulation process, when the solver executes a state recovery program to restore the target component simulation model data, for the external object data in the target component simulation model, the solver detects whether there is a deserialization interface function for the external object data; if the deserialization interface function exists, the solver calls the deserialization interface function to restore the external object data; if the deserialization interface function does not exist, the solver outputs a warning prompt message, indicating that the external object data cannot be deserialized.

[0012] In a second aspect, an embodiment of the present invention provides a Modelica external object data serialization device, comprising: The first module constructs an external object model of external object data, wherein the external object model includes a serialization interface function and a deserialization interface function, wherein the serialization interface function is used to convert the state information of the external object data into byte data that can be stored or transmitted, and the deserialization interface function is used to restore the byte data to the state information of the external object data; The second module selects at least one target component simulation model built based on the multi-domain unified modeling language Modelica from a preset model library. During the simulation process, when the solver executes a state caching program and caches the external object data of the external object model, if it is determined that a serialization interface function exists, the serialization interface function is called to retrieve the external object data. During the simulation process, when the solver executes a state recovery program and restores the external object data of the external object model, if it is determined that a deserialization interface function exists, the deserialization interface function is called to restore the external object data.

[0013] In a third aspect, the present invention further provides an electronic device, including a memory and a processor, wherein: The memory is used to store programs; The processor is coupled to the memory and is used to execute the program stored in the memory to implement the steps in the Modelica external object data serialization method as described in the embodiment of the first aspect of the present invention.

[0014] In a fourth aspect, the present invention further provides a computer-readable storage medium for storing a computer-readable program or instruction, which, when executed by a processor, can implement the steps in the Modelica external object data serialization method as described in the embodiment of the first aspect of the present invention.

[0015] Compared with the prior art, the Modelica external object data serialization method provided by the present invention can avoid confusion with other external object operation methods by defining its serialization and deserialization interface functions in the external object class definition, thereby reducing the difficulty of parsing; by defining the serialization and deserialization interface functions of the external object, the solver program can realize the reading and writing of the external object data memory. In engineering modeling and simulation applications, the use of external object models has been very common for the purposes of historical asset model reuse and intellectual property protection. The present invention further improves the solver state cache function, solves the technical problem that the complex Modelica model with integrated external objects cannot realize the solver state cache, and greatly improves the debugging efficiency of the problem model. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1 A flow chart of the Modelica external object data serialization method provided by the present invention; Figure 2 This is a flow chart of external object data serialization according to an embodiment of the present invention; Figure 3 This is a flow chart of external object data deserialization according to an embodiment of the present invention; Figure 4 A structural block diagram of a Modelica external object data serialization device provided by an embodiment of the present invention; Figure 5 This is a structural block diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0017] The preferred embodiments of the present invention are described in detail below in conjunction with the accompanying drawings, wherein the accompanying drawings constitute a part of this application and are used together with the embodiments of the present invention to illustrate the principles of the present invention, but are not used to limit the scope of the present invention.

[0018] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0019] Data serialization means that during data transmission, the data structure or object needs to be encoded, and then transmitted in the network or other transmission media according to this encoding. The data receiver needs to decode it according to the corresponding deserialization rules to obtain the data. Similarly, in the data storage process, serialization and deserialization methods are also required to store the serialized data in a storage medium that is not easy to lose. When the data needs to be obtained, the serialized data in the storage medium is decoded to obtain the original data.

[0020] In view of this, the present invention provides a Modelica external object data serialization method and device, which can avoid confusion with other external object operation methods by defining its serialization and deserialization interface functions in the external object class definition, thereby reducing the difficulty of parsing. The following will be explained and introduced through multiple embodiments.

[0021] Figures 1 to 3 The flowchart of the Modelica external object data serialization method provided by the present invention is as follows. Figure 1 As shown, the Modelica external object data serialization method includes steps S1 to S5, wherein: S1. Construct an external object model of external object data, wherein the external object model includes a serialization interface function and a deserialization interface function; Specifically, the serialization interface function is used to convert the state information of the external object data into byte data that can be stored or transmitted, and the deserialization interface function is used to restore the byte data to the state information of the external object data.

[0022] It should be noted that the external object in this embodiment refers to the entity structure that needs to be simulated and modeled, and the external object data includes the initial state or condition of the external object, as well as input parameter data, environmental parameter data and interactive behavior data, etc., among which the input parameter data is the input parameters that the external object may provide to the simulation model, such as control signals, external stimuli, etc. These parameters may change over time and are used to simulate the impact of the external object on the simulation model; the environmental parameter data is the external environment parameters of the simulation model, such as temperature, humidity, air pressure, wind speed, etc. These parameters may affect the behavior and performance of the simulation model, and therefore need to be considered during the simulation process; the interactive behavior data is the interactive behavior data between the external object and the simulation model, such as communication protocols, data exchange formats, etc. These data define the interaction methods and rules between the external object and the simulation model to ensure that they can correctly exchange data and transfer information.

[0023] Specifically, in this embodiment, the external object model based on Modelica is a car system model, which includes an engine subsystem, a chassis subsystem, an electrical subsystem, etc. Through physical modeling and mathematical modeling, the variables and equations in the car describe the dynamic behavior of the car system. Model simulation is to calculate these equations to obtain the results of the variables. An external object is also a model. Its variables and other data information is a piece of memory space, and then those solution equations are encapsulated into operation methods. After Modelica integrates this external object, it can calculate or obtain its internal variables by calling its operation methods. For example, the chassis subsystem of the car is represented by an external object. This subsystem undertakes the body subsystem. The movement of the suspension will affect the height, posture and vehicle load of the body. These contents can be described by establishing corresponding mathematical equations, and then providing corresponding operation methods for calculation. These calculation results are the state of the system, which needs to be cached for the next state update calculation. The memory of the external object is used to cache the state information of this model.

[0024] It should be noted that external objects provide a mechanism to encapsulate complex data structures or resources (such as file handles, network connections, and complex objects in external libraries) into objects for use in Modelica models. External objects mainly include the following three parts: Constructor: creates external resources, namely memory data; Destructor: release external resources; Operation method: perform specific operations on external objects; An example of an external object is given below, in which the external function is implemented in C language, including a constructor Constructor, a destructor Destructor, and operation methods SetElement and GetElement.

[0025] Among them, the structure definition (ExternalObj): int nelem;: This is an integer variable used to store the length of the buffer array.

[0026] double* buffer;: This is a pointer to a double type, used to dynamically allocate an array to store cache data.

[0027] Constructor: Input parameter: int n, indicating the length of the cache array to be created.

[0028] Function: Allocate memory to the ExternalObj structure and its buffer member. The buffer is initialized to an array of length n+1, and all elements are initialized to 0 using memset.

[0029] Return value: Returns a pointer to the newly created ExternalObj structure.

[0030] Destructor: Input parameter: void* data, which is a pointer to an ExternalObj structure, but uses the void* type to provide generality.

[0031] Function: Release the memory occupied by the ExternalObj structure and its buffer member.

[0032] Note: This function first checks if the pointer passed in is NULL to avoid errors when trying to free a NULL pointer.

[0033] Operation method (SetElement and GetElement): SetElement: Allows the user to set the value at a specified index position in the cache array.

[0034] GetElement: Allows the user to get the value at a specified index position in the cache array.

[0035] Input parameters: void* data (pointer to ExternalObj structure), int ith (index of the element to be set), and for SetElement double val (value to be set).

[0036] This embodiment also provides a Modelica model ExtObjExample that defines a class named ExternalObj, which extends ExternalObject. The ExternalObj class encapsulates the constructor and destructor of the external object implemented in C language, as well as the operation functions for setting and getting array elements. These C functions are connected to the Modelica model through the external "C" declaration.

[0037] In the Modelica model, an instance of the ExternalObj class is created by the C language Constructor function, which accepts an integer n as input and returns a pointer to the ExternalObj structure (represented as an object of type ExternalObj in Modelica). The destructor Destructor accepts an object of type ExternalObj as input and releases the memory associated with the object.

[0038] The SetElem and GetElem functions are used to set and get the elements of the array in the ExternalObj object, respectively. These functions are implemented by the external C language SetElement and GetElement functions, which accept an ExternalObj object, an integer index and a real value as input (for SetElem), or only accept an ExternalObj object and an integer index as input (for GetElem), and return a real value (for GetElem).

[0039] Since the Modelica model cannot directly access the data memory constructed by the C language, it must read or write the data memory through the provided operation methods (i.e., SetElem and GetElem functions). This encapsulation ensures a clear interface between the Modelica model and external C code and allows the Modelica model to interact with external objects in a type-safe manner.

[0040] This embodiment defines two special operation methods to implement serialization and deserialization of external object data. When the user defines these two operation methods of external objects, the corresponding external object serialization and deserialization function interfaces are generated into the external object registration function of the model code when the model is compiled. In the simulation instantiation stage, the solver calls the external object registration function to obtain the serialization and deserialization function handles of the external object. When the solver executes the state cache program, it further calls the external object serialization function to obtain the data memory. In the debugging stage, the solver executes the state recovery program to reset the data memory of the current external object through the deserialization interface with the previously serialized data.

[0041] The user builds an external object model according to the Modelica language specification, including defining its constructor, destructor, and related operation methods. In the external object class definition, in addition to the constructor and destructor, the serialization interface function and the deserialization interface function are further defined. These two interface functions must be defined in the external object class definition, otherwise the compiler can only treat them as ordinary operation methods.

[0042] 1) The Modelica language specification supports object-oriented modeling, which is similar to the object-oriented modeling of C++. It studies the properties and behaviors of objects through abstraction, forms specific types, such as defining a car type, and then instantiating this type when using it.

[0043] 2) Type definition is to use keywords provided by modeling language or programming language, such as Class, and then describe the properties and behaviors of the object according to the language specification. For some specific things, such as built-in types, they are pre-defined by the language, and the name of this type is fixed, just like a keyword. Users can inherit these basic types (base classes) and further refine the definition of the types they need.

[0044] 3) The external object class is a base class pre-defined in the Modelica language specification. It has no actual content, and the specific constructors, destructors, and operation methods need to be implemented by the user.

[0045] 4) This embodiment is aimed at system modeling and simulation. When modeling a system, an external object class may be used, that is, some models need to be expressed using this type. When this type is specifically defined, its serialization and deserialization interface needs to be further implemented. This embodiment defines the form of this interface function and the subsequent usage mechanism.

[0046] 5) Currently, the Modelica language specification defines that only constructors and destructors can be defined in an external object class definition, but many related operation methods can be defined. If this embodiment treats the serialization and deserialization interface functions as ordinary operation methods, it will be difficult to identify and parse the operation methods as serialization or deserialization functions during the compilation process. If this class definition is directly extended, in addition to defining the constructor and destructor when defining the external object, the serialization and deserialization functions are defined together, which is equivalent to treating the latter two as a default interface similar to the constructor and destructor, which can reduce the difficulty of compilation and improve efficiency.

[0047] S2. Compile the system model. If an external object model is integrated, generate the external object serialization interface function and deserialization interface function into the external object registration function of the model code.

[0048] It should be noted that when compiling a system model that integrates an external object model and generating model code, the corresponding external object parser is expanded in the compiler in advance. Since the Modelica language specification limits the external object class definition to only two function definitions, the constructor and the destructor, the compiler needs to expand the external object parser. When the parser processes the external object class definition, if there are other function definitions in addition to the constructor and the destructor in the external object class definition, it determines whether the serialization interface function serialize and the deserialization interface function deserialize are defined through text matching. If not, an error is reported. If the serialization interface function serialize and the deserialization interface function deserialize are defined in the external object class definition, they are generated into the external object registration function of the model code.

[0049] S3, after starting the simulation, the solver calls the external object registration function in the instantiation phase to obtain the data memory address of the external object data, as well as the serialization interface function handle and the deserialization interface function handle; S4 selects at least one target component simulation model built based on the multi-domain unified modeling language Modelica from the preset model library, and when the solver executes the state cache program during the simulation process, when caching the external object data of the external object model, if it is determined that there is a serialization interface function, the serialization interface function is called to retrieve the external object data; Specifically, during the simulation process, when the solver executes the state caching program to cache the target component simulation model data, for the external object data in the target component simulation model, the solver detects whether there is a serialization interface function for the external object data; if the serialization interface function exists, the solver calls the serialization interface function to obtain and cache the external object data; if the serialization interface function does not exist, the solver outputs a warning prompt message, indicating that the external object data cannot be serialized.

[0050] S5. During the simulation process, when the solver executes the state recovery program, when restoring the external object data of the external object model, if it is determined that a deserialization interface function exists, the deserialization interface function is called to restore the external object data.

[0051] Specifically, during the simulation process, when the solver executes a state recovery program to restore the target component simulation model data, for the external object data in the target component simulation model, the solver detects whether there is a deserialization interface function for the external object data; if the deserialization interface function exists, the solver calls the deserialization interface function to restore the external object data; if the deserialization interface function does not exist, the solver outputs a warning prompt message, indicating that the external object data cannot be deserialized.

[0052] Based on the above embodiment, as a preferred implementation, the serialization interface function includes a first input parameter, a second input parameter and an output parameter; The first input parameter is used to receive external object data to be serialized; The second input parameter is a string variable, which is used to receive or provide array space for storing external object data during serialization and to indicate the required array space size during output; The first output parameter is used to return the success status of the serialization operation or the size of the array space required for the external object data; The deserialization interface function includes a third input parameter for receiving external object data to be deserialized; The fourth input parameter, as a string variable, contains the byte data used to restore the external object data status information; The second output parameter is used to return the success status of the deserialization operation.

[0053] It should be noted that the serialization interface function serialize implements the storage of the data of the external object obj with a memory size of size bytes into the byte array space. The first input parameter of the serialization interface function is the external object; the second input parameter is the string variable byte, which is the array space provided by the solver state cache program, and the array space size is size bytes. The size variable is an output variable, because the solver state cache program must first know the size of the external object data to provide enough array space. Therefore, in addition to realizing data serialization, the serialization function can also be used to obtain the data memory size of the external object. This is achieved through different parameter passing calling methods: 1) If the given byte parameter is a null pointer when calling the serialization interface function, this function should calculate the data memory size of the external object and return it through the output variable size; 2) If the given byte parameter when calling the serialization interface function is not a null pointer, this function should perform the serialization operation and store the external object data memory into the byte array space.

[0054] The meaning of deserialization: the reverse operation of extracting a data structure from a series of bytes, that is, the process of converting binary data back to the original object. The deserialization described in this embodiment refers to resetting the state information of an external object instance with byte data in a given array space. The above-mentioned deserialization interface function deserialize implements resetting the state of the external object obj with size bytes of data in the byte array space. The first input parameter of the deserialization interface function is the external object; the second input parameter is the string variable byte, which is the external object serialization data provided by the solver state cache program, and the array space size is size bytes.

[0055] Based on the above embodiment, as a preferred implementation, if the compilation system model integrates an external object model, the external object serialization interface function and the deserialization interface function are generated into the external object registration function of the model code, including: Generate serialization interface function and deserialization interface function to external object registration function of external object model; If there are other function definitions in addition to the constructor and destructor in the external object class definition, text matching is used to determine whether they are serialization interface function and deserialization interface function definitions. If not, an error is reported; If the serialization interface function and the deserialization interface function are defined in the external object class definition, the serialization interface function and the deserialization interface function are generated into the external object registration function of the external object model code.

[0056] Based on the above embodiment, as a preferred implementation, the solver records the data memory address of the external object data, and when subsequently calling the external object registration function operation method, the data memory address is used as a parameter to pass the specific address; The external object registration function completes the registration process by constructing an external object instance, allocating a destructor handle, a serialization interface function handle, and a deserialization interface function handle, and assigning them to corresponding member variables of the ExtObjectManager data structure.

[0057] Based on the above embodiment, as a preferred implementation, the solver also provides an external object management data structure ExtObjectManager, which is used to store the data memory address, destructor handle, serialization interface function handle and deserialization interface function handle of the external object data, wherein the definition of the data structure of the ExtObjectManager includes: The member variable obj is used to store the data memory address of the external object data; The member variable dtor is the destructor handle, which is used to release the memory of external object data; The member variable sel is a serialization interface function handle, which is used to convert external object data into a byte sequence; The member variable dsel is the deserialization interface function handle, which is used to restore external object data from a byte sequence.

[0058] Figure 4 The structural block diagram of the Modelica external object data serialization device provided by the present invention is shown in FIG. Figure 4 In a preferred embodiment of the present invention, the present invention provides a Modelica external object data serialization device 400, comprising: The first module 401 constructs an external object model of external object data, wherein the external object model includes a serialization interface function and a deserialization interface function, wherein the serialization interface function is used to convert the state information of the external object data into byte data that can be stored or transmitted, and the deserialization interface function is used to restore the byte data to the state information of the external object data; The second module 402 selects at least one target component simulation model built based on the multi-domain unified modeling language Modelica from a preset model library. During the simulation process, when the solver executes a state caching program and caches external object data of an external object model, if it is determined that a serialization interface function exists, the serialization interface function is called to retrieve the external object data. During the simulation process, when the solver executes a state recovery program and restores external object data of an external object model, if it is determined that a deserialization interface function exists, the deserialization interface function is called to restore the external object data.

[0059] The Modelica external object data serialization device provided by the present invention executes the Modelica external object data serialization method provided by the above embodiments through the first module 401 and the second module 402. The Modelica external object data serialization method has been described in detail in the above embodiments, and will not be repeated in this embodiment.

[0060] Figure 5 The structural block diagram of the electronic device provided by the present invention is as follows: Figure 5 As shown, the present invention also provides an electronic device, and the electronic device 500 can be a computing device such as a mobile terminal, a desktop computer, a notebook, a palm computer, and a server. The electronic device 500 includes a processor 501 and a memory 502, wherein the memory 502 stores a Modelica external object data serialization program 505.

[0061] In some embodiments, the memory 502 may be an internal storage unit of a computer device, such as a hard disk or memory of the computer device. In other embodiments, the memory 502 may also be an external storage device of the computer device, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the computer device. Furthermore, the memory 502 may also include both an internal storage unit of the computer device and an external storage device. The memory 502 is used to store application software and various types of data installed on the computer device, such as program codes installed on the computer device. The memory 502 may also be used to temporarily store data that has been output or is to be output. In one embodiment, when the Modelica external object data serialization program 505 is executed by the processor 501, the following steps are implemented: S1. Construct an external object model of external object data, wherein the external object model includes a serialization interface function and a deserialization interface function; S2. Compile the system model. If the external object model is integrated, generate the external object serialization interface function and deserialization interface function into the external object registration function of the model code; S3, after starting the simulation, the solver calls the external object registration function in the instantiation phase to obtain the data memory address of the external object data, as well as the serialization interface function handle and the deserialization interface function handle; S4, selecting at least one target component simulation model built based on the multi-domain unified modeling language Modelica from the preset model library, and when the solver executes the state cache program during the simulation process, when caching the external object data of the external object model, if it is determined that there is a serialization interface function, calling the serialization interface function to retrieve the external object data; S5. During the simulation process, when the solver executes the state recovery program, when restoring the external object data of the external object model, if it is determined that a deserialization interface function exists, the deserialization interface function is called to restore the external object data.

[0062] In some embodiments, the processor 501 may be a central processing unit (CPU), a microprocessor or other data processing chip, used to run program codes stored in the memory 502 or process data, such as executing a Modelica external object data serialization program.

[0063] This embodiment also provides a computer-readable storage medium, on which a Modelica external object data serialization program is stored. When the Modelica external object data serialization program is executed by a processor, the following steps are implemented: S1. Construct an external object model of external object data, wherein the external object model includes a serialization interface function and a deserialization interface function; S2. Compile the system model. If the external object model is integrated, generate the external object serialization interface function and deserialization interface function into the external object registration function of the model code; S3, after starting the simulation, the solver calls the external object registration function in the instantiation phase to obtain the data memory address of the external object data, as well as the serialization interface function handle and the deserialization interface function handle; S4 selects at least one target component simulation model built based on the multi-domain unified modeling language Modelica from the preset model library, and when the solver executes the state cache program during the simulation process, when caching the external object data of the external object model, if it is determined that there is a serialization interface function, the serialization interface function is called to retrieve the external object data; S5. During the simulation process, when the solver executes the state recovery program, when restoring the external object data of the external object model, if it is determined that a deserialization interface function exists, the deserialization interface function is called to restore the external object data.

[0064] The above-mentioned embodiments only express several implementation methods of the present invention, and the description thereof is relatively specific and detailed, but it cannot be understood as limiting the scope of the patent of the present invention. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention. Therefore, the protection scope of the patent of the present invention shall be subject to the attached claims.

[0065] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A Modelica external object data serialization method, characterized in that: include: Constructing an external object model of external object data, the external object model comprising a serialization interface function and a deserialization interface function, the serialization interface function is used to convert state information of the external object data into byte data that can be stored or transmitted, and the deserialization interface function is used to restore the byte data to the state information of the external object data; At least one target component simulation model built based on the multi-domain unified modeling language Modelica is selected from the preset model library. During the simulation process, when the solver executes the state caching program, when caching the external object data of the external object model, if it is determined that a serialization interface function exists, the serialization interface function is called to retrieve the external object data. During the simulation process, when the solver executes the state recovery program, when restoring the external object data of the external object model, if it is determined that a deserialization interface function exists, the deserialization interface function is called to restore the external object data.

2. The Modelica external object data serialization method according to claim 1, characterized in that: The serialization interface function includes a first input parameter, a second input parameter and an output parameter; The first input parameter is used to receive external object data to be serialized; The second input parameter is a string variable, which is used to receive or provide array space for storing external object data during serialization and to indicate the required array space size during output; The first output parameter is used to return the success status of the serialization operation or the size of the array space required for the external object data; The deserialization interface function includes a third input parameter for receiving external object data to be deserialized; The fourth input parameter, as a string variable, contains the byte data used to restore the external object data status information; The second output parameter is used to return the success status of the deserialization operation.

3. The Modelica external object data serialization method according to claim 1, characterized in that: After the external object model of the external object data is constructed, the following step is also included: Generate serialization interface function and deserialization interface function to external object registration function of external object model; If there are other function definitions in addition to the constructor and destructor in the external object class definition, text matching is used to determine whether they are serialization interface function and deserialization interface function definitions. If not, an error is reported; If the serialization interface function and the deserialization interface function are defined in the external object class definition, the serialization interface function and the deserialization interface function are generated into the external object registration function of the external object model code.

4. The Modelica external object data serialization method according to claim 3, characterized in that: After selecting at least one target component simulation model based on the multi-domain unified modeling language Modelica from the preset model library, it also includes: After starting the simulation, the solver calls the external object registration function in the instantiation phase to obtain the data memory address of the external object data, as well as the serialization interface function handle and the deserialization interface function handle.

5. The Modelica external object data serialization method according to claim 4, characterized in that: The solver records the data memory address of the external object data, and uses the data memory address as a parameter to pass the specific address when subsequently calling the external object registration function operation method; The external object registration function completes the registration process by constructing an external object instance, allocating a destructor handle, a serialization interface function handle, and a deserialization interface function handle, and assigning them to corresponding member variables of the ExtObjectManager data structure.

6. The Modelica external object data serialization method according to claim 5, characterized in that: The solver also provides an external object management data structure ExtObjectManager, which is used to store the data memory address, destructor handle, serialization interface function handle and deserialization interface function handle of the external object data, wherein the definition of the data structure of the ExtObjectManager includes: The member variable obj is used to store the data memory address of the external object data; The member variable dtor is the destructor handle, which is used to release the memory of external object data; The member variable sel is a serialization interface function handle, which is used to convert external object data into a byte sequence; The member variable dsel is the deserialization interface function handle, which is used to restore external object data from a byte sequence.

7. The Modelica external object data serialization method according to claim 4, characterized in that: When caching the external object data of the external object model, if it is determined that there is a serialization interface function, the serialization interface function is called to retrieve the external object data. During the simulation process, when the solver executes the state recovery program, when restoring the external object data of the external object model, if it is determined that there is a deserialization interface function, the deserialization interface function is called to restore the external object data, including: During the simulation process, when the solver executes the state cache program to cache the simulation model data of the target component, for the external object data in the simulation model of the target component, the solver detects whether there is a serialization interface function for the external object data; if the serialization interface function exists, the solver calls the serialization interface function to obtain and cache the external object data; if the serialization interface function does not exist, the solver outputs a warning prompt message indicating that the serialization operation cannot be performed on the external object data; During the simulation process, when the solver executes a state recovery program to restore the target component simulation model data, for the external object data in the target component simulation model, the solver detects whether there is a deserialization interface function for the external object data; if the deserialization interface function exists, the solver calls the deserialization interface function to restore the external object data; if the deserialization interface function does not exist, the solver outputs a warning prompt message, indicating that the external object data cannot be deserialized.

8. A Modelica external object data serialization device, characterized in that: include: The first module constructs an external object model of external object data, wherein the external object model includes a serialization interface function and a deserialization interface function, wherein the serialization interface function is used to convert the state information of the external object data into byte data that can be stored or transmitted, and the deserialization interface function is used to restore the byte data to the state information of the external object data; The second module selects at least one target component simulation model built based on the multi-domain unified modeling language Modelica from a preset model library. During the simulation process, when the solver executes a state caching program and caches the external object data of the external object model, if it is determined that a serialization interface function exists, the serialization interface function is called to retrieve the external object data. During the simulation process, when the solver executes a state recovery program and restores the external object data of the external object model, if it is determined that a deserialization interface function exists, the deserialization interface function is called to restore the external object data.

9. An electronic device, It is characterized in that comprising a memory and a processor, wherein: The memory is used to store programs; The processor is coupled to the memory and is used to execute the program stored in the memory to implement the steps in the Modelica external object data serialization method described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: Used to store computer-readable programs or instructions, which, when executed by a processor, can implement the steps of the Modelica external object data serialization method described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • File serialization method of model library of physical modeling language Modelica

    CN102043657A

  • External serialization and deserialization

    CN102981841A

  • Object serialization method and device

    CN103593194A

  • Object-oriented cache writing-in-in method and device as well as object-oriented cache reading method and device

    CN106095698A

  • Serialization and deserialization methods and apparatuses, computer device and storage medium

    CN107463668A