Incremental compiling method and system for Modelica model

Through the incremental compilation method for Modelica models, only the modified part and its influential part of the Modelica model are identified and compiled, which solves the problem that Modelica model needs to be completely recompiled after local modification in the existing technology, and improves modeling efficiency and the availability of diagnostic information.

CN119759362AActive Publication Date: 2025-04-04武汉鼎元同立科技有限公司
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202411915284.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-24
Publication Date
2025-04-04
Estimated Expiration
2044-12-24

AI Technical Summary

Technical Problem

The existing Modelica model needs to be completely recompiled after local modification, resulting in a long compilation time, affecting modeling efficiency, and having too much compilation and diagnostic information, making it difficult to locate the modified part.

Method used

The incremental compilation method for Modelica model is adopted to obtain an abstract syntax tree by keyword matching the edited and modified Modelica model text, determine the changing part of the model, and instantiate it as an intermediate representation, integrate the intermediate representation of the unchanged part to obtain the complete representation of the model, and only the modified part and its influential part are compiled.

Benefits of technology

It significantly reduces the time-consuming and complete compilation of the model, improves modeling efficiency, reduces the output of compilation diagnostic information, and focuses on the user's modified parts, making it easier for users to locate model problems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119759362A_ABST
    Figure CN119759362A_ABST
Patent Text Reader

Abstract

The invention relates to a Modelica model-oriented incremental compiling method and a Modelica model-oriented incremental compiling system. The Modelica model-oriented incremental compiling method comprises the following steps of: carrying out keyword matching on an edited and modified Modelica model text to obtain an abstract syntax tree of a Modelica model; the abstract syntax tree comprises definitions and behaviors of all components in the Modelica model; on the basis of the abstract syntax tree and the previous change, determining a change part of edition and modification of the Modelica model; instantiating the change part of the Modelica model into an intermediate representation; the intermediate representation comprises a component variable tree and a component behavior list; integrating the intermediate representations of the changed part and the unchanged part of the Modelica model to obtain a complete representation of the Modelica model; through incremental compiling, rapid identification and local compiling of the model modification part can be realized, so that recompiling of the whole model is avoided, and the compiling efficiency is remarkably improved. And meanwhile, the output quantity of compiled diagnosis information can be effectively reduced through incremental compiling, so that the user can more easily obtain the diagnosis information related to the modified part, and the modeling experience is further improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of industrial Internet system modeling and simulation, and in particular to an incremental compilation method and system for Modelica models. Background Art

[0002] With the rapid development of the field of industrial Internet system modeling and simulation, the demand for high-precision and high-efficiency model compilation methods is becoming increasingly urgent. Modelica, as a declarative multi-domain system modeling language, has been widely used in the field of system modeling and simulation due to its powerful cross-domain modeling capabilities and openness. However, in practical applications, the compilation process of Modelica models often faces some challenges.

[0003] First of all, the variables of the equations in the Modelica models of large-scale systems in reality, such as rockets, cars, ships, etc., are huge, often tens of thousands or even hundreds of thousands. It usually takes a long time to fully compile these large-scale models. In the iterative process of modeling and simulation, modifying and verifying the model is a routine modeling operation, including adjusting parameters, adding and deleting components, modifying topology structures, etc. However, traditional Modelica modeling and simulation tools require the entire model to be recompiled to verify the effect of the modification, which is particularly time-consuming when the model is large, greatly affecting the modeling efficiency and the user experience of modeling and simulation tools. In addition, with the continuous and in-depth application of Modelica modeling and simulation technology, the complexity and scale of the model are also increasing, which will undoubtedly further aggravate the problem.

[0004] Furthermore, the processing of compilation diagnostics and log information is also an issue that cannot be ignored. Each full compilation will generate a large amount of compilation diagnostic information, and users usually only care about the diagnostic information related to the modified part. In a large model, it is undoubtedly a difficult task to filter out useful information for the modified part from the massive amount of complete diagnostics and log information. This not only increases the user's workload, but also reduces modeling efficiency. Summary of the invention

[0005] The present invention aims at the problem that a Modelica model needs to be completely recompiled after partial modification, and provides an incremental compilation method and system for Modelica models. Through incremental compilation, the modified part of the model can be quickly identified and partially compiled, thereby avoiding recompilation of the entire model and significantly improving the compilation efficiency. At the same time, incremental compilation can also effectively reduce the output of compilation diagnostic information, so that users can more easily obtain diagnostic information related to the modified part, further improving the modeling experience.

[0006] According to a first aspect of the present invention, there is provided an incremental compilation method for a Modelica model, comprising: Step 1, performing keyword matching on the edited and modified Modelica model text to obtain an abstract syntax tree of the Modelica model; the abstract syntax tree includes the definition and behavior of each component in the Modelica model; Step 2, determining the changed part of the Modelica model edited and modified based on the abstract syntax tree and the last change; Step 3, instantiating the changed part of the Modelica model into an intermediate representation; the intermediate representation includes: a variable tree of a component and a component behavior list; Step 4: Integrate the intermediate representations of the changed part and the unchanged part of the Modelica model to obtain a complete representation of the Modelica model.

[0007] Based on the above technical solution, the present invention can also make the following improvements.

[0008] Optionally, the process of obtaining the abstract syntax tree of the Modelica model in step 1 includes: Set the Modelica keyword matching list; The Modelica model text is parsed byte by byte, and when a keyword in the Modelica keyword matching list is matched, the content corresponding to the keyword is extracted to generate the abstract syntax tree.

[0009] Optionally, the keywords in the Modelica keyword matching list include: model definition, model name, component definition within the model, component name, model equation and end symbol; Extracting the content corresponding to the keyword to generate the abstract syntax tree includes: extracting the description corresponding to the component definition to generate an abstract syntax tree structure representing the definition and behavior of the component, and extracting the description corresponding to the model equation to generate an abstract syntax tree structure representing the meaning of the equation.

[0010] Optionally, the abstract syntax tree also includes a model name; the definition of a component in the Modelica model includes a component type and a component name, and the behavior of the component includes a component behavior statement obtained based on the component equation behavior.

[0011] Optionally, step 3 includes: When the Modelica is compiled for the first time, the Modelica model is fully compiled to obtain the intermediate representations of all components, and a generation model abstract syntax tree and an intermediate representation mapping table are constructed; After the Modelica model is edited and modified, all components of the Modelica model are traversed. When the abstract syntax tree of any component does not have a corresponding intermediate representation in the mapping table, it is determined that the component has been modified, and an intermediate representation of each modified component is generated as an intermediate representation of the changed part of the Modelica model, and the mapping table is modified accordingly.

[0012] Optionally, step 3 further includes: After determining that any component has been modified, the components affected by the modified component are analyzed according to the topological structure and variable behavior equations of the Modelica model, and an intermediate representation of the affected component is generated as the intermediate representation of the changed part of the Modelica model.

[0013] Optionally, the integration process in step 4 includes: Update the model component abstract syntax tree and intermediate representation mapping table; splicing the model component variable trees according to the component hierarchical relationship of the Modelica model to obtain a complete variable tree of the Modelica model; The behavior lists of the components are merged to obtain the complete behavior list of the Modelica model.

[0014] According to a second aspect of the present invention, there is provided an incremental compilation system for Modelica models, comprising: a model parser, a model change detection and dependency analysis module, a model instantiation module and a model integration module; The model parser is used to perform keyword matching on the edited and modified Modelica model text to obtain an abstract syntax tree of the Modelica model; the abstract syntax tree includes the definition and behavior of each component in the Modelica model; The model change detection and dependency analysis module is used to determine the changed part of the Modelica model edit based on the abstract syntax tree and the last change; The model instantiation module is used to instantiate the changed part of the Modelica model into an intermediate representation; the intermediate representation includes a variable tree of a component and a sequence of component behavior equations; The model integration module is used to integrate the intermediate representations of the changed part and the unchanged part of the Modelica model to obtain a complete representation of the Modelica model.

[0015] According to a third aspect of the present invention, there is provided an electronic device, comprising a memory and a processor, wherein the processor is used to implement the steps of an incremental compilation method for a Modelica model when executing a computer management program stored in the memory.

[0016] According to a fourth aspect of the present invention, there is provided a computer-readable storage medium on which a computer management program is stored. When the computer management program is executed by a processor, the steps of the incremental compilation method for Modelica models are implemented.

[0017] The present invention provides an incremental compilation method, system, electronic device and storage medium for Modelica models. When the model is partially modified, it supports compiling only the modified part of the model and the part affected by it, and obtains the complete representation of the model by integrating with the intermediate representation of the unchanged part, thereby reducing the time consumption of the complete compilation of the model and improving the modeling efficiency. At the same time, it also avoids the problem that the user needs to wait for a long time to compile after frequently modifying the model, and improves the user experience of the modeling tool. When incrementally compiling the modified part of the model, only the compilation diagnostic information of the modified part is output, focusing on the part modified by the user, avoiding the interference of a large amount of diagnostic information generated by the complete compilation of the model to the user, and facilitating the user to locate the model problem through the diagnostic information. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 A flowchart of an incremental compilation method for a Modelica model provided by an embodiment of the present invention; Figure 2 A schematic diagram of a model change detection process provided by an embodiment of the present invention; Figure 3 A schematic diagram of a model dependency analysis process provided by an embodiment of the present invention; Figure 4 A schematic diagram of a model integration process provided by an embodiment of the present invention; Figure 5 A schematic diagram of the principle flow chart provided for an embodiment of the present invention; Figure 6 A schematic diagram of the hardware structure of a possible electronic device provided by the present invention; Figure 7 A schematic diagram of the hardware structure of a possible computer-readable storage medium provided by the present invention. DETAILED DESCRIPTION

[0019] The principles and features of the present invention are described below in conjunction with the accompanying drawings. The examples given are only used to explain the present invention and are not used to limit the scope of the present invention.

[0020] Figure 1 A flowchart of an incremental compilation method for a Modelica model provided by an embodiment of the present invention is shown in FIG. Figure 1 As shown, the compilation method includes: Step 1, performing keyword matching on the edited and modified Modelica model text to obtain an abstract syntax tree of the Modelica model; the abstract syntax tree includes the definition and behavior of each component in the Modelica model.

[0021] Step 2: Determine the changed part of the Modelica model edit based on the abstract syntax tree and the last change.

[0022] Step 3: Instantiate the changed part of the Modelica model into an intermediate representation; the intermediate representation includes: the variable tree of the component and the component behavior list.

[0023] The intermediate representation of the compiled component definition is the component's variable tree, and the intermediate representation of the compiled component behavior is the component behavior list, which represents the variable structure and behavior logic of the model component.

[0024] Step 4: Integrate the intermediate representations of the changed and unchanged parts of the Modelica model to obtain a complete representation of the Modelica model.

[0025] The present invention provides a compilation method suitable for large-scale complex Modelica models. The system is based on an incremental Modelica model compilation method. The method can identify and compile only the parts of the model that have changed and are affected by the changes when the Modelica model is compiled, thereby significantly reducing the model compilation time and improving the modeling efficiency. At the same time, only the parts of the model that have been modified and affected by the changes are compiled, and the compilation diagnostic information can focus on the parts modified by the user, which is convenient for the user to locate the model problem by checking.

[0026] Example 1 Embodiment 1 provided by the present invention is an embodiment of an incremental compilation method for Modelica model provided by the present invention, combined with Figure 1 It can be seen that the embodiment of the compilation method includes: Step 1, performing keyword matching on the edited and modified Modelica model text to obtain an abstract syntax tree of the Modelica model; the abstract syntax tree includes the definition and behavior of each component in the Modelica model.

[0027] In a possible embodiment, the process of obtaining the abstract syntax tree of the Modelica model in step 1 includes: Sets the Modelica keyword matching list.

[0028] The Modelica model text is parsed byte by byte. When a keyword in the Modelica keyword matching list is matched, the content corresponding to the keyword is extracted to generate an abstract syntax tree.

[0029] In a possible embodiment, the keywords in the Modelica keyword matching list include: model definition, model name, component definition within the model, component name, model equation, and end symbol.

[0030] Extracting the content corresponding to the keyword to generate an abstract syntax tree includes: extracting the description corresponding to the component definition to generate an abstract syntax tree structure representing the definition and behavior of the component, and extracting the description corresponding to the model equation to generate an abstract syntax tree structure representing the meaning of the equation.

[0031] In a specific implementation, the Modelica keyword matching list is defined according to the Modelica specification, and the Modelica model text is parsed lexically and grammatically to obtain an abstract syntax tree of the model. An embodiment includes: The following Modelica model text: Model test Real a; equation a = time; end test; Model parsing process: First, the Modelcia keyword "Model" is matched, indicating model definition, followed by the model name, that is, the model name is test, and the abstract syntax tree structure of model test (including the model name) is obtained; the next Modelica keyword matched is "Real", indicating real component definition, followed by the component name, that is, the component name is a, and the abstract syntax tree structure of component a (including component name and component type) is obtained, and the abstract syntax tree of component a is added to the abstract syntax tree of model test; the next keyword matched is "equation", indicating the model equation area, and the content following it is the model equation description; the next keyword is "=", indicating an equation, and the left and right sides of "=" represent expressions with an equation relationship, where "a" represents the component name, and "time" is a Modelica keyword, indicating time, and the abstract syntax tree of the equation is obtained: the component named "a" is equal to time (time), which is added to the abstract syntax tree of model test; finally, the Modelica keyword "end" is matched, indicating the end of the model, followed by the model name, which is required to be consistent with the model name obtained by the previous analysis, that is, test.

[0032] After parsing is completed, the abstract syntax tree of the model test is obtained, which contains the abstract syntax tree of the real component a and the abstract syntax tree of the equation (a=time), which respectively represent the definition and behavior of the components in the model.

[0033] If it is illegal, an error message will be given to help users locate and modify it.

[0034] In a possible implementation manner, the abstract syntax tree also includes a model name; the definition of a component in a Modelica model includes a component type and a component name, and the behavior of the component includes a component behavior statement obtained based on the component equation behavior.

[0035] Step 2: Determine the changed part of the Modelica model edit based on the abstract syntax tree and the last change.

[0036] Step 3: Instantiate the changed part of the Modelica model into an intermediate representation; the intermediate representation includes: the variable tree of the component and the component behavior list.

[0037] In a possible implementation manner, step 3 includes: When Modelica is compiled for the first time, the Modelica model is fully compiled to obtain the intermediate representation of all components, and the generation model abstract syntax tree and intermediate representation mapping table are constructed.

[0038] After editing and modifying the Modelica model, all components of the Modelica model are traversed. When the abstract syntax tree of any component does not have a corresponding intermediate representation in the mapping table, it is determined that the component has been modified, and the intermediate representation of each modified component is generated as the intermediate representation of the changed part of the Modelica model, and the mapping table is modified accordingly.

[0039] like Figure 2 The figure shows a schematic diagram of the model change detection process provided by the embodiment of the present invention, combined with Figure 2 It can be seen that by checking the abstract syntax tree of the model component and the mapping table of the intermediate representation, if the abstract syntax tree of the component changes, it means that the component has been modified, then the intermediate representation corresponding to the component is also invalid and needs to be recompiled.

[0040] When the model is edited, the modified part will be parsed immediately to obtain the abstract syntax tree of the modified part, and the abstract syntax tree before the modification (which has expired) will be updated and replaced. At this time, the abstract syntax tree of the modified part has not been recompiled, and there is no corresponding intermediate representation, so its intermediate representation cannot be found in the mapping table. When the model is incrementally compiled, the components in the model are traversed. If the abstract syntax tree of the component does not have a corresponding intermediate representation in the mapping table, it means that the component has been modified and needs to be recompiled. After the modified part is recompiled, a new intermediate representation is obtained, and the old data in the mapping table that has expired is replaced with the modified new abstract syntax tree and the new intermediate representation. To judge the modified part of the model.

[0041] In a possible implementation manner, step 3 further includes: After determining that any component has been modified, the components affected by the modified component are analyzed based on the topological structure and variable behavior equations of the Modelica model, and an intermediate representation of the affected component is generated as the intermediate representation of the changed part of the Modelica model.

[0042] The intermediate representation of the components affected by the modified component is also invalid and needs to be recompiled.

[0043] In a specific implementation, the mapping table can be specifically represented by a C++ map. Based on the mapping table, the corresponding intermediate representation can be found through the abstract syntax tree of the component.

[0044] The identified components that need to be recompiled are reinstantiated to obtain the latest intermediate representation, and the compilation diagnostic information of the components is output.

[0045] like Figure 3 The figure shows a schematic diagram of the model dependency analysis process provided by an embodiment of the present invention, combined with Figure 3 It can be seen that this is a schematic diagram of the model dependency analysis process in the present invention. As an embodiment, the relationship between the component and the modified component in the model is analyzed to determine whether it is affected by the modified part. First, check whether the component type is a derived type of the modified component. If there is a derived relationship, there must be a dependency relationship, which is marked as an affected component; then check whether the component and the variants of the nested components refer to the modified component. If so, there may be a dependency relationship, and it is marked as an affected component from the perspective of functional correctness; finally, check whether the equation behavior in the component refers to the modified component. If so, it is marked as an affected component.

[0046] Step 4: Integrate the intermediate representations of the changed and unchanged parts of the Modelica model to obtain a complete representation of the Modelica model.

[0047] In a possible embodiment, the integration process in step 4 includes: Update the model component abstract syntax tree and intermediate representation mapping table.

[0048] According to the component hierarchical relationship of the Modelica model, the model component variable tree is spliced ​​to obtain the complete variable tree of the Modelica model.

[0049] Merge the behavior lists of the components to get the complete behavior list of the Modelica model.

[0050] like Figure 4 The figure shows a schematic diagram of the model integration process provided by an embodiment of the present invention, combined with Figure 4It can be seen that as an embodiment, the intermediate data representation obtained by instantiating the changed part of the model is integrated with the intermediate representation of the unchanged part to obtain a complete representation of the model. The intermediate representation obtained by recompiling the component includes a component variable tree and a component behavior list. First, the component variables are spliced ​​to the parent component variable tree, and then the complete edge variable tree of the model is obtained by splicing layer by layer according to the model hierarchy; then the component behavior list is merged into the model behavior list to obtain a complete model behavior list; finally, the model component abstract variable tree and the intermediate representation mapping table are updated.

[0051] Example 2 Embodiment 2 provided by the present invention is an embodiment of an incremental compilation system for Modelica models provided by the present invention. Figure 1 A structural diagram of an incremental compilation system for Modelica models provided by an embodiment of the present invention, combined with Figure 2 It can be seen that the embodiment of the compilation system includes: a model parser, a model change detection and dependency analysis module, a model instantiation module and a model integration module.

[0052] The model parser is used to perform keyword matching on the edited and modified Modelica model text to obtain the abstract syntax tree of the Modelica model; the abstract syntax tree includes the definition and behavior of each component in the Modelica model.

[0053] The main function of the model parser is to parse the Modelica model into an abstract syntax tree (AST). The subsequent compilation process is based on the model's abstract syntax tree.

[0054] The model change detection and dependency analysis module is used to determine the changed parts of the Modelica model edit based on the abstract syntax tree and the last change.

[0055] The model instantiation module is used to instantiate the changing part of the Modelica model into an intermediate representation; the intermediate representation includes the variable tree of the component and the sequence of component behavior equations.

[0056] The model integration module is used to integrate the intermediate representations of the changed part and the unchanged part of the Modelica model to obtain a complete representation of the Modelica model.

[0057] It can be understood that the incremental compilation system for Modelica models provided by the present invention corresponds to the incremental compilation method for Modelica models provided by the aforementioned embodiments. The relevant technical features of the incremental compilation system for Modelica models can refer to the relevant technical features of the incremental compilation method for Modelica models, which will not be repeated here.

[0058] Example 3 Embodiment 3 provided by the present invention is a specific application embodiment of an incremental compilation method for Modelica models provided by the present invention. The abstract syntax tree mainly includes: model name, component definition in the model (abstract syntax tree, including: component type, component name), component behavior (abstract syntax tree), and the collection of behaviors of all components is also the model behavior. The compilation process is to obtain the intermediate representation of the model based on the abstract syntax tree of the model. The intermediate representation of the component mainly includes: component variable tree (intermediate representation after component definition compilation), behavior statement (intermediate representation after component behavior compilation), and the compilation process is as follows: Step 1, Modelica model is hierarchical, model components can contain other components, and model components are compiled layer by layer according to the hierarchical relationship. Components with Modelica basic types (including: Real, Integer, Boolean, String, Enumeration) are the lowest level components and cannot contain other components. When compiling a component (also called instantiation), first determine the name, type and dimension of the component itself based on the abstract syntax tree of the component to obtain the component variable. If the component is not a Modelica basic type, it is also necessary to process the components inside the component. The variables of the internal components must be spliced ​​to the parent variables of the upper layer. The internal variables are used as child variables of the upper layer husband variables. They are processed layer by layer in turn to finally obtain a complete variable tree of the model.

[0059] Step 2: The compilation process instantiates the component behavior statement based on the abstract syntax tree of the component equation behavior. The instantiation process mainly locates the specific component variable pointed to by the component name recorded in the abstract syntax tree of the equation behavior, and finally constructs the behavior statement between the variables.

[0060] Here is an example: Model Model A Model B Real b; equation b = time; end B; Bx; Real a; equation a = xb; end A; Compilation process: Step 3, compile model A, first instantiate the components in A, including: component x and component a, where component x is not a Modelica basic type. Therefore, when instantiating component x to obtain variable x, its internal components are also instantiated. Its internal component b is a Modelica basic type, and variable b is directly instantiated. Variable b is spliced ​​to variable x; after component x is instantiated, component a is instantiated. Component a is a Modelica basic type, and variable a is directly instantiated.

[0061] Step 4, after the component instantiation is completed, the component behavior is instantiated, where the type B of component x contains the internal component b and the behavior of component b "b = time". When instantiating "b=time", the component variable b it points to is found according to the string "b", and the string "time" represents time, and finally the behavior statement "variable b equals time" is obtained; model A contains the behavior "a = xb" of component a. When instantiated, the component variable a it points to is found according to the string "a", and the internal variable b in variable x is found according to the string "xb", and finally the behavior statement "variable a equals internal variable b in variable x" is obtained.

[0062] Step 5: After all components in the model are compiled and instantiated, a complete variable tree and behavior statement of the model are obtained, that is, a complete intermediate representation of the model.

[0063] like Figure 5 The schematic diagram of the principle flow chart provided by the embodiment of the present invention is shown in FIG. Figure 5 It can be seen that the implementation principle of the incremental compilation method for Modelica model provided by the present invention is specifically as follows: S101: The model parser parses the model text into an abstract syntax tree according to the Modelica specification for use in subsequent compilation processes.

[0064] S102: The model change detection module checks the abstract syntax tree of the model component and the mapping table of the intermediate representation to obtain the modified part of the model.

[0065] S103: The model change dependency analysis module obtains the components affected by the modified components in the model according to the topological structure and variable behavior equation analysis of the model, and the affected components are also regarded as modified components.

[0066] S104: Instantiate the modified model component to obtain an intermediate representation of the component.

[0067] S105: Integrate the intermediate representation of the modified component with the intermediate representation of the unchanged part to obtain a complete representation of the model.

[0068] S106: Update the model component abstract syntax tree and intermediate representation mapping table.

[0069] See also Figure 6 , Figure 6 Schematic diagram of an electronic device provided by an embodiment of the present invention. Figure 6 As shown, an embodiment of the present invention provides an electronic device, including a memory 1310, a processor 1320, and a computer program 1311 stored in the memory 1310 and executable on the processor 1320. When the processor 1320 executes the computer program 1311, the following steps are implemented: keyword matching is performed on the edited and modified Modelica model text to obtain an abstract syntax tree of the Modelica model; the abstract syntax tree includes the definition and behavior of each component in the Modelica model; based on the abstract syntax tree and the last change, the changed part of the Modelica model edited and modified is determined; the changed part of the Modelica model is instantiated as an intermediate representation; the intermediate representation includes: a variable tree of the component and a component behavior list; the intermediate representation of the changed part of the Modelica model and the unchanged part are integrated to obtain a complete representation of the Modelica model.

[0070] See also Figure 7 , Figure 7 Schematic diagram of an embodiment of a computer-readable storage medium provided by the present invention. Figure 7 As shown, this embodiment provides a computer-readable storage medium 1400, on which a computer program 1411 is stored. When the computer program 1411 is executed by a processor, the following steps are implemented: keyword matching is performed on the edited and modified Modelica model text to obtain an abstract syntax tree of the Modelica model; the abstract syntax tree includes the definition and behavior of each component in the Modelica model; based on the abstract syntax tree and the last change, the changed part of the Modelica model edited and modified is determined; the changed part of the Modelica model is instantiated into an intermediate representation; the intermediate representation includes: a variable tree of the component and a list of component behaviors; the intermediate representations of the changed part and the unchanged part of the Modelica model are integrated to obtain a complete representation of the Modelica model.

[0071] An incremental compilation method, system, electronic device and storage medium for Modelica models provided by an embodiment of the present invention support compiling only the modified part of the model and the part affected by it when the model is partially modified, and obtains a complete representation of the model by integrating with the intermediate representation of the unchanged part, thereby reducing the time consumption of complete model compilation and improving modeling efficiency. At the same time, it also avoids the problem of users having to wait for a long time to compile after frequently modifying the model, and improves the user experience of the modeling tool. When incrementally compiling the modified part of the model, only the compilation diagnostic information of the modified part is output, focusing on the part modified by the user, avoiding the interference of a large amount of diagnostic information generated by the complete compilation of the model to the user, and facilitating the user to locate model problems through diagnostic information.

[0072] It should be noted that in the above embodiments, the description of each embodiment has its own emphasis, and for parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0073] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0074] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded computer, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0075] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0076] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0077] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.

[0078] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. An incremental compilation method for Modelica models, characterized in that: The compilation method comprises: Step 1, performing keyword matching on the edited and modified Modelica model text to obtain an abstract syntax tree of the Modelica model; the abstract syntax tree includes the definition and behavior of each component in the Modelica model; Step 2, determining the changed part of the Modelica model edited and modified based on the abstract syntax tree and the last change; Step 3, instantiating the changed part of the Modelica model into an intermediate representation; the intermediate representation includes: a variable tree of a component and a component behavior list; Step 4: Integrate the intermediate representations of the changed part and the unchanged part of the Modelica model to obtain a complete representation of the Modelica model.

2. The method according to claim 1, characterized in that The process of obtaining the abstract syntax tree of the Modelica model in step 1 includes: Set the Modelica keyword matching list; The Modelica model text is parsed byte by byte, and when a keyword in the Modelica keyword matching list is matched, the content corresponding to the keyword is extracted to generate the abstract syntax tree.

3. The compiling method according to claim 2, characterized in that: The keywords in the Modelica keyword matching list include: model definition, model name, component definition in the model, component name, model equation and end symbol; Extracting the content corresponding to the keyword to generate the abstract syntax tree includes: extracting the description corresponding to the component definition to generate an abstract syntax tree structure representing the definition and behavior of the component, and extracting the description corresponding to the model equation to generate an abstract syntax tree structure representing the meaning of the equation.

4. The compiling method according to claim 3, characterized in that: The abstract syntax tree also includes a model name; the definition of a component in the Modelica model includes a component type and a component name, and the behavior of the component includes a component behavior statement obtained based on the component equation behavior.

5. The compiling method according to claim 1, characterized in that: The step 3 comprises: When the Modelica is compiled for the first time, the Modelica model is fully compiled to obtain the intermediate representations of all components, and a generation model abstract syntax tree and an intermediate representation mapping table are constructed; After the Modelica model is edited and modified, all components of the Modelica model are traversed. When the abstract syntax tree of any component does not have a corresponding intermediate representation in the mapping table, it is determined that the component has been modified, and an intermediate representation of each modified component is generated as an intermediate representation of the changed part of the Modelica model, and the mapping table is modified accordingly.

6. The compiling method according to claim 5, characterized in that: The step 3 also includes: After determining that any component has been modified, the components affected by the modified component are analyzed according to the topological structure and variable behavior equations of the Modelica model, and an intermediate representation of the affected component is generated as the intermediate representation of the changed part of the Modelica model.

7. The compiling method according to claim 1, characterized in that: The integration process in step 4 includes: Update the model component abstract syntax tree and intermediate representation mapping table; According to the component hierarchical relationship of the Modelica model, the model component variable trees are spliced ​​to obtain a complete variable tree of the Modelica model; The behavior lists of the components are merged to obtain the complete behavior list of the Modelica model.

8. An incremental compilation system for Modelica models, characterized in that: The compilation system includes: a model parser, a model change detection and dependency analysis module, a model instantiation module and a model integration module; The model parser is used to perform keyword matching on the edited and modified Modelica model text to obtain an abstract syntax tree of the Modelica model; the abstract syntax tree includes the definition and behavior of each component in the Modelica model; The model change detection and dependency analysis module is used to determine the changed part of the Modelica model edit based on the abstract syntax tree and the last change; The model instantiation module is used to instantiate the changed part of the Modelica model into an intermediate representation; the intermediate representation includes a variable tree of a component and a sequence of component behavior equations; The model integration module is used to integrate the intermediate representations of the changed part and the unchanged part of the Modelica model to obtain a complete representation of the Modelica model.

9. An electronic device, characterized in that: The invention comprises a memory and a processor, wherein the processor is used to implement the steps of the incremental compilation method for Modelica model as described in any one of claims 1 to 7 when executing the computer management program stored in the memory.

10. A computer-readable storage medium, characterized in that: A computer management program is stored thereon, and when the computer management program is executed by a processor, the steps of the incremental compilation method for Modelica models as described in any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Code conversion method and device for pre-compiler, medium, and equipment

    CN114035805A

  • Modelica language model processing method and device and storage medium

    CN114840196A

  • Text programming language compiling method based on decoupling architecture

    CN116501330A

  • Verilog syntactic analysis method based on incremental compiling

    CN117270863A

  • Code processing method and device, electronic equipment and storage medium

    CN117971231A