Method and system for building compilable customized module
The generation of custom modules for chemical process simulation through graphical modeling and Flex/Bison tools solves the problem of lack of universality and complexity of custom modules in the existing technology, and achieves the effect of rapid construction and multi-scene adaptation.
Patent Information
- Application Number
- PCT/CN2024/139823
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-12-29
- Filing Date
- 2024-12-17
- Publication Date
- 2025-07-03
AI Technical Summary
Existing custom modules lack versatility in chemical process simulation, requiring a lot of manual coding, customization and trial and error, with high complexity and time costs, making it difficult to flexibly deal with non-standard equipment or special processes.
The modeling language file is generated using graphical modeling, and the lexical and grammar analyzer is generated using Flex and Bison tools. The abstract syntax tree is converted into C++ language through syntax translation, compiled into executable binary files, and imported into the simulation platform for simulation and optimization.
It realizes chemical engineers to quickly build custom modules, reduces simulation complexity and time cost, is suitable for users with average code capabilities, and supports seamless switching of multiple application scenarios.
Smart Images

Figure CN2024139823_03072025_PF_FP_ABST
Abstract
Description
A method and system for constructing a compilable custom module Technical Field
[0001] The present invention relates to the technical field of chemical process simulation software development, and in particular to a method and system for constructing a compilable custom module. Background Art
[0002] In the chemical industry, process simulation is a key technology, commonly used to analyze, optimize, and design plant processes. Traditional process simulation tools and software provide standard model libraries, but these models are often difficult to directly apply to non-standard equipment or special processes, such as powder fluidized bed reactors, membrane separation processes, and bio-fermentation processes. Addressing the process simulation challenges of these non-standard equipment or special processes is crucial for chemical engineers. Currently, most major process simulation software programs have custom modules to support users in independently modeling and solving complex problems. Custom module construction generally uses modeling languages (for specific or multiple fields) such as Modelica and gProms, or general-purpose programming languages such as Fortran, C, and Python. Domain-Specific Languages (DSLs) sacrifice problem-solving capabilities in other fields and focus on describing key concepts in a specific domain. They allow for flexible and efficient expression within the domain and are currently the mainstream custom module modeling language.
[0003] However, currently available custom modules generally lack versatility and are unable to flexibly cope with various non-standard equipment or special processes. They usually require a lot of manual coding, customization, and trial and error, which increases the complexity and time cost of simulation and is not suitable for chemical engineers with average coding skills. Summary of the Invention
[0004] (1) Technical issues to be solved
[0005] In view of the above-mentioned shortcomings and deficiencies of the prior art, the present invention provides a method and system for constructing a compilable custom module, which solves the technical problems that existing custom modules generally lack versatility, require a lot of manual coding, customization and trial and error, and are complex and time-consuming.
[0006] (2) Technical solution
[0007] In order to achieve the above objectives, the main technical solutions adopted by the present invention include:
[0008] In a first aspect, an embodiment of the present invention provides a method for constructing a compilable custom module, comprising:
[0009] Customize the module according to the process, set the modeling language syntax, and use text modeling combined with graphical modeling to generate the modeling language file corresponding to the custom module;
[0010] Establish text matching rules and grammar matching rules, and use flex to generate lexical analyzer source files from text matching rules, and use bison to generate parser source files from grammar matching rules;
[0011] A lexical analyzer is used to analyze the lexical structure of the modeling language file, and based on the analyzed lexical structure, a syntax analyzer is used to analyze the grammar of the code text of the modeling language to generate an abstract syntax tree;
[0012] Traverse the syntax tree, generate a translated C++ file for the modeling language based on the syntax translation configuration file, and compile the C++ file into an executable binary file;
[0013] Import the constructed custom modules and executable binary files into the simulation platform to perform process simulations of different scenarios for process simulation, optimization and parameter adjustment.
[0014] The method for constructing a compilable custom module proposed in this embodiment uses graphical modeling to allow users to quickly write modeling language files. Utilizing Flex and Bison tools, a lexical analyzer and parser are generated, which then generate an abstract syntax tree. The abstract syntax tree is then converted into C++ through syntax translation, and the C++ source code is finally compiled into an executable binary file. By integrating with a corresponding simulation system, rapid debugging of process steps can be achieved on a personal computer, while also seamlessly adapting the custom model to various application scenarios.
[0015] Optionally, the modeling language syntax includes: equations, data involved in the equations, control flow statements and data structures, and the data involved in the equations include variables and parameters.
[0016] Optionally, equations are used to describe the basic framework of the model behavior; the expressions of equations support basic arithmetic operators, exponential functions, logarithmic functions, trigonometric functions, and mathematical and physical function libraries;
[0017] Variables are used to describe the computational quantities in an equation;
[0018] Parameters are used to describe fixed values or invariants in a system, including real numbers, integers, Boolean values, and strings;
[0019] Control flow statements include conditional statements and loop structures, which are used to perform different operations or repeatedly perform operations based on conditions;
[0020] Data structures are used to organize data with set logic.
[0021] Optionally, a modeling language file corresponding to the custom module is generated by combining text modeling with graphical modeling; including:
[0022] According to the process, a graphical interface is used to provide a user-defined configuration interface; the configuration interface includes: preset commonly used tables, drop-down boxes and input boxes;
[0023] Preview the customized configuration interface and generate the corresponding modeling language file;
[0024] Configure the expressions and corresponding declarations of the equations of parameter and variable relationships in the equation configuration interface in turn, and generate the modeling language into the modeling language file.
[0025] Optionally, the drop-down box includes: flash type according to the configuration characteristics of the process, including pressure-temperature, pressure-heat load, pressure-phase fraction, temperature-heat load, temperature-phase fraction and effective phase; effective phase includes: gas-liquid, gas phase only, liquid phase only, gas-liquid-free water, gas-liquid-wastewater and gas-liquid-liquid;
[0026] Input boxes include: number input box and text input box; text input boxes include: name / identifier input box, description / comment input box, unit input box, data range / limit input box, file path input box, code / script input box and custom information input box;
[0027] The digital input box includes: temperature, pressure, gas phase fraction, heat load, composition, volume, etc.
[0028] The preset common tables include: preset port types, preset parameters and preset variables; preset port types include fluid ports, conventional solid ports, unconventional solid ports, polymer ports and hot stream ports; preset parameters include startup status, string identifiers and enumerations; preset variables include temperature, pressure, molar flow rate, molar mass, molar volume, gas phase fraction, volume, composition, concentration, volume flow rate and mass flow rate.
[0029] Optionally, establish text matching rules and grammar matching rules, including:
[0030] Text matching rules are used to describe how Flex recognizes strings in a modeling language file as corresponding tokens when reading the file. Strings include: syntax keywords, logical keywords, delimiters, and data types.
[0031] Grammar matching rules are used to describe how Bison combines tokens to form corresponding relationships when reading tokens. Grammar matching rules include:
[0032] Define the token value of the token read, and read the syntax keywords, delimiters and data types according to the definition;
[0033] Define the identifier-expression relationship and the statement grammar description, and generate structured data based on the nested level of the identifier-expression relationship and the grammar statement description: define the identifier as a class, and the content of the identifier as an object; define different expressions as different classes, and the identifier as a member; define different statement grammars as a class, and the expression and identifier as members; use pointers to point to the target for storage according to the nested level of the statement grammar.
[0034] Optionally, a lexical analyzer is used to analyze the lexical structure of the modeling language file, including: checking the syntax tree for syntax errors including declaration and definition, identifier type, control flow and uniqueness. If there are errors, feedback is given to the user interface. If there are no errors, proceed to the next step.
[0035] Optionally, traversing the syntax tree includes: each time a leaf node is traversed, if the syntax type of the current leaf node has configuration information in the syntax translation configuration file, then taking out the configuration information and generating a translated C++ text for the translation result of the subtree according to the configuration in the configuration information.
[0036] In a second aspect, an embodiment of the present invention provides a construction system capable of compiling a custom module, comprising:
[0037] Modeling language writing module, used to customize modules according to process, set modeling language syntax, and generate modeling language files corresponding to customized modules by combining text modeling with graphical modeling;
[0038] The parser creation module is used to create text matching rules and grammar matching rules, and use flex to generate the source program file of the lexical analyzer from the text matching rules, and use bison to generate the source program file of the syntax analyzer from the grammar matching rules;
[0039] A syntax tree generation module is used to analyze the lexical structure of the modeling language file using a lexical analyzer, and based on the analyzed lexical structure, analyze the grammar of the code text of the modeling language using a syntax analyzer to generate an abstract syntax tree;
[0040] The translation C++ file generation module is used to traverse the syntax tree, generate the translation C++ file of the modeling language according to the translation configuration file of the syntax, and compile the C++ file into an executable binary file;
[0041] The process simulation module is used to import the constructed custom modules and executable binary files into the simulation platform to perform process simulation of different scenarios for flash tank simulation, optimization and parameter adjustment.
[0042] In a third aspect, an embodiment of the present invention provides a computer system comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of any of the above methods when executing the computer program.
[0043] (3) Beneficial effects
[0044] The beneficial effects of the present invention are as follows: the method and system for constructing a compilable custom module enable users to quickly write modeling language files through graphical modeling. Utilizing Flex and Bison tools, a lexical analyzer and a parser are generated, which then generate an abstract syntax tree. The abstract syntax tree is then converted into C++ through syntax translation, and the C++ source code is finally compiled into an executable binary file. In conjunction with a corresponding simulation system, rapid debugging of process steps can be achieved on a personal computer, while the custom model can be seamlessly adapted to various application scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] FIG1 is a flow chart of a method for constructing a compilable custom module in Example 1 of the present invention;
[0046] FIG2 is a schematic diagram of a self-defined flash vaporization model configuration interface in Example 1 of the present invention;
[0047] FIG3 is a schematic diagram of a modeling language (partial) of the self-defined flash vaporization model in Example 1 of the present invention;
[0048] FIG4 is a schematic diagram of a Texaco downflow entrained flow gasifier in Example 2 of the present invention;
[0049] FIG5 is a schematic diagram (partial) of a graphically defined variable diagram in Example 2 of the present invention. DETAILED DESCRIPTION
[0050] In order to better explain the present invention and facilitate understanding, the present invention is described in detail below through specific implementation methods in conjunction with the accompanying drawings.
[0051] The method and system for constructing a compilable custom module proposed in the embodiment of the present invention allow users to quickly write modeling language files through graphical modeling, and use Flex and Bison tools to generate a lexical analyzer and a syntax analyzer, which are then converted into an abstract syntax tree. The abstract syntax tree is then converted into C++ language through syntax translation, and finally the C++ source code is compiled into an executable binary file. By cooperating with the corresponding simulation system, rapid debugging of the process can be achieved on a personal computer, and the custom model can be seamlessly switched to a variety of application scenarios. The embodiment of the present invention can flexibly cope with various non-standard equipment or special processes without a large amount of manual coding, customization and trial and error, reducing the complexity and time cost of the simulation, and is suitable for use by chemical engineers with average coding capabilities.
[0052] To better understand the above technical solutions, exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments described herein. Instead, these embodiments are provided to enable a clearer and more thorough understanding of the present invention and to fully convey the scope of the present invention to those skilled in the art.
[0053] Example 1
[0054] FIG1 is a flow chart of a method for constructing a compilable custom module in Example 1 of the present invention. The method for constructing a compilable custom module in this embodiment includes:
[0055] S1: Customize the module according to the process, set the modeling language syntax, and use text modeling combined with graphical modeling to generate the modeling language file corresponding to the custom module.
[0056] In this embodiment, the modeling language syntax includes: equations, data involved in the equations, control flow statements and data structures, and the data involved in the equations include variables and parameters.
[0057] Equations are used to describe the basic framework of model behavior; equation expressions support basic arithmetic operators, exponential functions, logarithmic functions, trigonometric functions, and mathematical and physical function libraries;
[0058] Variables are used to describe the computational quantities in an equation;
[0059] Parameters are used to describe fixed values or invariants in a system, including real numbers, integers, Boolean values, and strings;
[0060] Control flow statements include conditional statements and loop structures, which are used to perform different operations or repeatedly perform operations based on conditions;
[0061] Data structures are used to organize data with set logic.
[0062] Use text modeling combined with graphical modeling to generate the modeling language file corresponding to the custom module (see Figure 3), including:
[0063] According to the process, a graphical interface is used to provide a user-defined configuration interface; the configuration interface includes: preset commonly used tables, drop-down boxes and input boxes;
[0064] Preview the customized configuration interface and generate the corresponding modeling language file;
[0065] Configure the expressions and corresponding declarations of the equations of parameter and variable relationships in the equation configuration interface in turn, and generate the modeling language into the modeling language file.
[0066] During implementation, the following parameters can be set during the flash tank calculation process:
[0067] The drop-down box includes: according to the configuration characteristics of the process, see Figure 2, including flash type, flash type includes pressure-temperature, pressure-heat load, pressure-phase fraction, temperature-heat load, temperature-phase fraction and effective phase; effective phase includes: gas-liquid, gas phase only, liquid phase only, gas-liquid-free water, gas-liquid-wastewater and gas-liquid-liquid;
[0068] Input boxes include: numeric input boxes and text input boxes; text input boxes include: name / identifier input box, description / comment input box, unit input box, data range / limit input box, file path input box, code / script input box and custom information input box. Among them, the name / identifier input box is used to receive the user's input of the name or identifier of the process element, parameter, variable or configuration; the description / comment input box is a text box that provides users with input descriptions or comments of the process configuration element to better understand the meaning of the configuration; the unit input box allows users to enter unit information related to the configuration element, such as temperature units or pressure units; the data range / limit input box is used for users to define input data ranges or limits, such as minimum values, maximum values, or specific allowed values; the file path input box is used for users to enter file paths, which is suitable for configuration scenarios that require reference to external resources; the code / script input box provides users with text boxes for entering specific codes or scripts to achieve advanced custom configuration. Other custom information input boxes are used for users to input custom information according to process and configuration requirements to meet specific user needs.
[0069] The digital input box includes: temperature, pressure, gas phase fraction, heat load, composition, volume, etc.
[0070] The preset common tables include: preset port types, preset parameters and preset variables; preset port types include fluid ports, conventional solid ports, unconventional solid ports, polymer ports and hot stream ports; preset parameters include startup status, string identifiers and enumerations; preset variables include temperature, pressure, molar flow rate, molar mass, molar volume, gas phase fraction, volume, composition, concentration, volume flow rate and mass flow rate.
[0071] In the custom flash model of this embodiment, the port types include: conventional fluid ports and hot stream ports. The preset variables are shown in Table 1:
[0072] Table 1 Variables involved in the self-defined flash model
[0073] In this embodiment, the expressions and corresponding statements of the equations for configuring the relationship between parameters and variables in the configuration interface, and the equations involved in the custom flash model are shown in Table 2:
[0074] Table 2 Equations involved in the self-defined flash model
[0075] S2: Establish text matching rules and grammar matching rules, and use flex to generate the source program file of the lexical analyzer from the text matching rules, and use bison to generate the source program file of the syntax analyzer from the grammar matching rules.
[0076] In this embodiment, text matching rules and grammar matching rules are established, including:
[0077] Text matching rules are used to describe how Flex recognizes strings in a modeling language file as corresponding tokens when reading the file. Strings include: syntax keywords, logical keywords, delimiters, and data types.
[0078] Grammar matching rules are used to describe how Bison combines tokens to form corresponding relationships when reading tokens. Grammar matching rules include:
[0079] Define the token value of the token read, and read the syntax keywords, delimiters and data types according to the definition;
[0080] Define the identifier-expression relationship and the statement grammar description, and generate structured data based on the nested level of the identifier-expression relationship and the grammar statement description: define the identifier as a class, and the content of the identifier as an object; define different expressions as different classes, and the identifier as a member; define different statement grammars as a class, and the expression and identifier as members; use pointers to point to the target for storage according to the nested level of the statement grammar.
[0081] S3: A lexical analyzer is used to analyze the lexical structure of the modeling language file, and based on the analyzed lexical structure, a syntax analyzer is used to analyze the grammar of the code text of the modeling language to generate an abstract syntax tree.
[0082] In this embodiment, a lexical analyzer is used to analyze the lexical structure of the modeling language file, including: checking the syntax tree for grammatical errors including declarations and definitions, identifier types, control flow and uniqueness. If there are errors, feedback is given to the user interface. If there are no errors, the next step is performed.
[0083] S4: Traverse the syntax tree, generate a translated C++ file for the modeling language based on the syntax translation configuration file, and compile the C++ file into an executable binary file.
[0084] In this embodiment, traversing the syntax tree includes: each time a leaf node is traversed, if the syntax type of the current leaf node has configuration information in the syntax translation configuration file, then taking out the configuration information and generating a translated C++ text for the translation result of the subtree according to the configuration in the configuration information.
[0085] S5: Import the constructed custom modules and executable binary files into the simulation platform to perform process simulation for different scenarios of process simulation, optimization and parameter adjustment.
[0086] The method for constructing compilable custom modules proposed in this embodiment utilizes an intuitive graphical user interface. Users can select and configure custom modules by simply dragging and clicking, making it easy for even those without a professional programming background to build and modify flash vaporization calculation models. The system also integrates multiple modules, such as thermodynamics and reaction kinetics, allowing users to freely combine these modules to create complex models that align with real-world scenarios. This significantly reduces modeling time and lowers the barrier to entry.
[0087] Example 2
[0088] Gasifier reactor modeling.
[0089] In the coal chemical industry, gasifiers are widely used to convert solid fuels (such as coal) into synthesis gas (a gas containing a certain proportion of carbon monoxide and hydrogen). The coal gasification process involves complex chemical reactions, including coal oxidation, gasification and water vapor conversion. For these reactions, it is necessary to establish appropriate chemical kinetic models. There is currently no universal model in common process simulation software, and users need to model independently. Using the present invention, users can easily write coal gasification reaction kinetic models through the custom modeling platform, and easily adjust the model to adapt to different gasifier reactor designs and process requirements. The use of graphical modeling reduces the difficulty of writing modeling language files, reduces development costs, and shortens modeling time by at least 50%. At the same time, the modeling method based on simultaneous equations allows the model to switch seamlessly in different scenarios, meeting user simulation, optimization, parameter setting and other needs.
[0090] Coal gasification is the process by which solid fuels such as coal, coke, and semi-coke react with a gasifying agent under high temperature, atmospheric pressure, or pressurized conditions, converting them into gaseous products (synthesis gas) and a small amount of residue (slag). Taking the Texaco downflow entrained flow gasifier as an example, its schematic diagram is shown in Figure 4. The gasifier is primarily divided into two sections: the top section for coal gasification and the bottom section for quenching (water reservoir, quench vessel, soot water, and cooling water). When coal, oxygen, and steam are simultaneously introduced into the gasifier, several reactions occur sequentially: coal pyrolysis, volatile combustion, and coke gasification. These reactions require appropriate chemical kinetic models. Currently, common process simulation software lacks universal models, requiring users to develop their own models.
[0091] This example primarily involves a coal chemical gasifier model and its construction method, breaking through the constraints of traditional modeling approaches. Based on a proposed method for building a compilable custom module, it aims to improve model visualization, accessibility, and ease of practical application. This model integrates thermodynamics and reaction kinetics, simplifying the construction of the complex physical and chemical processes of the gasifier through a graphical user interface. Users can intuitively set parameters, build models, and apply them by defining variables, parameters, and equations, writing residual equations, and seamlessly switching between models, resulting in a more effective simulation of the coal gasification process.
[0092] FIG1 is a flow chart of a coal chemical gasifier model and its construction method in Example 2 of the present invention. The construction method of the compilable custom module in this embodiment includes:
[0093] S1: Customize the module according to the process, set the modeling language syntax, and use text modeling combined with graphical modeling to generate the modeling language file corresponding to the custom module.
[0094] In this embodiment, the modeling language syntax includes: equations, data involved in the equations, control flow statements and data structures, and the data involved in the equations include variables and parameters.
[0095] The equations involved in the gasifier model include: unreacted core shrinkage reaction kinetics model equation, flash calculation equation, pressure drop calculation equation, discretization equation, and reactor parameter calculation equation.
[0096] The kinetic model equations of the unreacted core shrinkage reaction mainly include the equation for calculating the gas film diffusion constant, the equation for calculating the gray film diffusion coefficient, the equation for calculating the surface reaction rate, the equation for calculating the effective concentration term, etc.
[0097] The pressure drop calculation equations mainly include Ergun equation, Darcy equation, etc.
[0098] The discretized equations mainly include the node pressure gradient equation, the node flow gradient equation, etc.
[0099] The flash evaporation calculation equations mainly include viscosity calculation equation, density calculation equation, molar enthalpy calculation equation, etc.
[0100] The calculation equations of reactor parameters mainly include the calculation equation of reactor reaction volume, the calculation equation of reactor cross-sectional area, etc.
[0101] Variables are used to describe the calculation quantities in the equations. The gasifier variables involved include: reactor-related variables, unreacted core shrinkage reaction kinetic variables, flash variables, pressure drop calculation variables, and discretization variables.
[0102] Reactor-related variables include: reactor volume, reactor length, reactor inner diameter, reactor cross-sectional area, number of reactor tubes, total reactor residence time, etc.
[0103] The kinetic variables of the unreacted core shrinkage reaction include: gas film diffusion constant, gray film diffusion coefficient, surface reaction rate, effective concentration term, reaction rate, component reaction rate, etc.
[0104] Flash evaporation variables include: viscosity, density, molar flow rate, temperature, pressure, molar enthalpy, composition, etc.
[0105] Parameters are used to describe fixed values or invariants in a system and include real numbers, integers, Boolean values, and strings.
[0106] Parameter variables include: flash type, reactor type, effective phase, whether it is a multi-tube reactor, whether there is a catalyst, number of model segments, discretization method, etc.
[0107] Control flow statements include conditional statements and loop structures, which are used to perform different operations or repeatedly perform operations based on conditions;
[0108] Data structures are used to organize data with set logic.
[0109] Use text modeling combined with graphical modeling to generate the modeling language file corresponding to the custom module, including:
[0110] According to the process, a graphical interface is used to provide a user-defined configuration interface; the configuration interface includes: preset common tables, drop-down boxes and input boxes. The schematic diagram (partial) of the graphical definition of variables in this embodiment is shown in Figure 5.
[0111] Preview the customized configuration interface and generate the corresponding modeling language file;
[0112] In the equation configuration interface, configure the expressions and corresponding declarations of the equations that represent the relationship between parameters and variables, and generate the modeling language into the modeling language file. See Table 3 for the variables involved in the custom gasifier model.
[0113] Table 3 Variables involved in the custom gasifier model
[0114] In this embodiment, the expressions and corresponding statements of the equations for configuring the relationship between parameters and variables in the configuration interface, and the equations involved in the custom gasifier model are shown in Table 4.
[0115] Table 4 Equations involved in the custom gasifier model
[0116] In a second aspect, an embodiment of the present invention provides a construction system capable of compiling a custom module, characterized by comprising:
[0117] Modeling language writing module, used to customize modules according to process, set modeling language syntax, and generate modeling language files corresponding to customized modules by combining text modeling with graphical modeling;
[0118] The parser creation module is used to create text matching rules and grammar matching rules, and use flex to generate the source program file of the lexical analyzer from the text matching rules, and use bison to generate the source program file of the syntax analyzer from the grammar matching rules;
[0119] A syntax tree generation module is used to analyze the lexical structure of the modeling language file using a lexical analyzer, and based on the analyzed lexical structure, analyze the grammar of the code text of the modeling language using a syntax analyzer to generate an abstract syntax tree;
[0120] The translation C++ file generation module is used to traverse the syntax tree, generate the translation C++ file of the modeling language according to the translation configuration file of the syntax, and compile the C++ file into an executable binary file;
[0121] The process simulation module is used to import the constructed custom modules and executable binary files into the simulation platform to perform process simulation of different scenarios for flash tank simulation, optimization and parameter adjustment.
[0122] In a third aspect, an embodiment of the present invention further provides a computer system comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of any of the above methods when executing the computer program.
[0123] In summary, the compilable custom module construction method and system of the present invention first allows the user to complete the writing of the modeling language file through a graphical interface by dragging and dropping and table input; then uses Flex and Bison tools to quickly build an abstract syntax tree of the modeling language, converts the abstract syntax tree into C++ language through syntax translation, and finally compiles the C++ source code into an executable binary file.
[0124] In the description of the present invention, it should be understood that the terms "first" and "second" are used for descriptive purposes only and should not be understood to indicate or imply relative importance or implicitly specify the number of the technical features indicated. Therefore, a feature specified as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of the present invention, "plurality" means two or more, unless otherwise specifically defined.
[0125] In the present invention, unless otherwise expressly specified or limited, the terms "mounted," "connected," "connect," "fixed," etc. should be understood broadly. For example, they may refer to fixed connection, detachable connection, or integration; mechanical connection or electrical connection; direct connection or indirect connection through an intermediate medium; and internal communication between two components or interaction between two components. Those skilled in the art will understand the specific meanings of the above terms in the present invention based on specific circumstances.
[0126] In the present invention, unless otherwise expressly specified or limited, when a first feature is "above" or "below" a second feature, it may mean that the first and second features are in direct contact, or that the first and second features are in indirect contact through an intermediate medium. Furthermore, when a first feature is "above," "above," or "above" a second feature, it may mean that the first feature is directly above or obliquely above the second feature, or simply means that the first feature is at a higher level than the second feature. When a first feature is "below," "below," or "below" a second feature, it may mean that the first feature is directly below or obliquely below the second feature, or simply means that the first feature is at a lower level than the second feature.
[0127] In the description of this specification, the terms "one embodiment", "some embodiments", "embodiments", "examples", "specific examples" or "some examples" refer to the specific features, structures, materials or characteristics described in conjunction with the embodiment or example and included in at least one embodiment or example of the present invention. In this specification, the schematic expressions of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine different embodiments or examples described in this specification and features of different embodiments or examples, unless they are mutually inconsistent.
[0128] Although the embodiments of the present invention have been shown and described above, it will be understood that the above embodiments are illustrative and are not to be construed as limitations on the present invention. A person skilled in the art may alter, modify, replace and modify the above embodiments within the scope of the present invention.
Claims
1. A construction method for a compilable custom module, characterized in that, Including: Customize the module according to the process, set the grammar of the modeling language, and generate the modeling language file corresponding to the customized module by combining text modeling and graphical modeling; Establish text matching rules and grammar matching rules, use flex to generate the source program file of the lexical analyzer based on the text matching rules, and use bison to generate the source program file of the syntax analyzer based on the grammar matching rules; Use the lexical analyzer to analyze the lexicon of the modeling language file, and use the syntax analyzer to analyze the syntax of the code text of the modeling language based on the analyzed lexicon to generate an abstract syntax tree; Traverse the syntax tree, generate a translated C++ file for the modeling language according to the syntax, and compile the C++ file into an executable binary file; Import the constructed custom module and the executable binary file into the simulation platform to perform process simulation for different scenarios of simulating, optimizing, and tuning parameters of the process.
2. The construction method of a customizable module that can be compiled according to claim 1, characterized in that: The grammar of the modeling language includes: equations, data involved in the equations, control flow statements, and data structures. The data involved in the equations include variables and parameters.
3. The construction method of a customizable module that can be compiled according to claim 2, characterized in that: The equations are used to describe the basic framework of the model behavior; the expressions of the equations support basic arithmetic operators, exponential functions, logarithmic functions, trigonometric functions, and mathematical and physical function libraries; The variables are used to describe the calculated quantities in the equations; The parameters are used to describe the fixed values or invariants in the system, including real numbers, integers, boolean values, and strings; The control flow statements include conditional statements and loop structures, which are used to perform different operations or repeat operations according to conditions; The data structures are used to organize the set logic data.
4. The construction method of the compilable custom module according to claim 3, characterized in that: The generation of the modeling language file corresponding to the customized module by combining text modeling and graphical modeling includes: According to the process, provide a user-defined configuration interface using a graphical interface; the configuration interface includes: preset common tables, dropdown boxes, and input boxes; Preview the user-defined configuration interface and generate the corresponding modeling language file; Configure the expressions and corresponding declarations of the equations for the parameter and variable relationships in the equation configuration interface in sequence, and generate the modeling language into the modeling language file.
5. The construction method of a customizable module that can be compiled according to claim 4, characterized in that: The dropdown box includes: according to the configuration characteristics of the process, including flash types, and the flash types include pressure-temperature, pressure-heat load, pressure-phase fraction, temperature-heat load, temperature-phase fraction, and effective phase states; the effective phase states include: gas-liquid, only gas phase, only liquid phase, gas-liquid-free water, gas-liquid-sewage, and gas-liquid-liquid; The input boxes include: numeric input boxes and text input boxes; the text input boxes include: name / identifier input boxes, description / comment input boxes, unit input boxes, data range / limit input boxes, file path input boxes, code / script input boxes, and custom information input boxes; The digital input boxes include: temperature, pressure, gas phase fraction, heat load, composition, volume, etc.; The preset common tables include: preset port types, preset parameters, and preset variables; the preset port types include fluid ports, conventional solid ports, unconventional solid ports, polymer ports, and heat stream ports; the preset parameters include start state, string identifier, and enumeration; the preset variables include temperature, pressure, molar flow rate, molar mass, molar volume, gas phase fraction, volume, composition, concentration, volume flow rate, and mass flow rate.
6. The construction method of the compilable custom module according to claim 5, characterized in that: The establishment of the text matching rule and the grammar matching rule includes: The text matching rule is used to illustrate that Flex recognizes the strings in the modeling language file as corresponding tokens when reading the file, and the strings include: syntax keywords, logical keywords, delimiters, and data types; The grammar matching rule is used to illustrate the rule according to which Bison combines the tokens to form corresponding relationships when reading the tokens; the grammar matching rule includes: Define the token values of the read tokens, and read the syntax keywords, the delimiters, and the data types according to the definition; Define the identifier expression relationship and the statement syntax description. In generating the structured data based on the identifier expression relationship and the nested hierarchy of the statements depending on the syntax statements: define the identifier as a class, and use the content of the identifier as an object; define different expressions as different classes, with the identifier as a member; define different statement syntaxes as a class, with the expression and the identifier as members; use pointers to point to the target for storage according to the nested hierarchy of the statement syntax.
7. The construction method of the compilable custom module according to claim 4, characterized in that: Using the lexical analyzer to analyze the lexicon of the modeling language file, including: checking the syntax errors of the syntax tree including declarations and definitions, identifier types, control flow, and uniqueness, and if there are errors, feedback them to the user interface, and if there are no errors, proceed to the next step.
8. The construction method of the compilable custom module according to claim 4, characterized in that: Traverse the syntax tree, including: for each leaf node traversed, if there is configuration information in the translation configuration file of the syntax for the syntax type of the current leaf node, then take out the configuration information, and generate the translated C++ text according to the configuration in the configuration information for the translation result of the subtree.
9. A build system for compiling custom modules, characterized in that, Including: A modeling language writing module, used to customize the module according to the process, set the modeling language syntax, and generate a modeling language file corresponding to the custom module by using text modeling combined with graphical modeling; A parser establishment module, used to establish text matching rules and grammar matching rules, and use flex to generate the source program file of the lexical analyzer according to the text matching rules, and use bison to generate the source program file of the syntax analyzer according to the grammar matching rules; A syntax tree generation module, which is used to analyze the lexical grammar of a modeling language file by using the lexical analyzer, and based on the analyzed lexical grammar, analyze the syntax of the code text of the modeling language by using the syntax analyzer to generate an abstract syntax tree; A translated C++ file generation module, which is used to traverse the syntax tree, generate a translated C++ file for the modeling language according to the syntax, and compile the C++ file into an executable binary file; A process simulation module, which is used to import the constructed custom module and the executable binary file into a simulation platform to perform process simulations of different scenarios for simulating, optimizing, and tuning parameters of a flash tank.
10. A computer system, characterized in that, It includes a memory, a processor, and a computer program stored on the memory and executable on the processor. It is characterized in that when the processor executes the computer program, the steps of any one of the above claims 1 to 8 are implemented.
Citation Information
Patent Citations
Soft PLC configuration software generation system based on FPGA platform
CN110376959A
Compiling method and system for mechanical arm program development programming language
CN111580825A
Method, device and equipment for automatically generating Modelica model file of discrete system
CN115525264A
Multi-output compiling method and system based on flex and Bison syntax analysis
CN116257245A
Construction method and system of compilable custom module
CN117806649A
Cited By
Multi-level hybrid model flattening compiling method and system for X language
CN120560666A
Prompt word compiling and generating method and system for large language model
CN120848895A
Equipment state analysis method and system based on DSL (Digital Subscriber Line) and dynamic compiling technology
CN121233116A
Cross-normal-form automatic conversion method and system for parameterized geometric modeling script and medium
CN122020760A
A cross-paradigm automatic conversion method, system and medium for a parameterized geometry modeling script
CN122020760B