Modelica-based two-fluid six-equation and differential algebraic equation coupling system compiling and solving device and method

By generating the topological structure and coefficient matrix information of the two-fluid hexa equation system, and combining the syntax and semantic inspection of the differential algebraic equation system, the stable and efficient solution of the Modelica compilation and solution device under unified solution sequence planning is realized, which solves the problem that the existing technology is difficult to be applied to the two-fluid hexa equation system, and improves the data read and write efficiency.

CN120492771APending Publication Date: 2025-08-15NUCLEAR POWER INSTITUTE OF CHINA +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510469782.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-15
Publication Date
2025-08-15

AI Technical Summary

Technical Problem

The existing Modelica compilation and solution devices are difficult to be applied to two-fluid hexa equation systems, making it difficult to find a system-wide multi-professional coupling model for decompressed water reactor nuclear power units, thermal power units and other energy systems.

Method used

It provides a compilation and solution device for the coupling system of two-fluid hexa equations and differential algebraic equations based on Modelica, including the functional system of the compilation stage and solution stage, generates the topological structure, coefficient matrix, time step control and other information of the two-fluid hexa equation system, and realizes the syntax semantic inspection and planarization of the differential algebraic equation system, ensuring that the two types of equation systems interact with data under unified solution sequence planning.

Benefits of technology

The stable and efficient coupling solution between the two-fluid hexa equation system and the differential algebraic equation system is realized, which improves the solution efficiency and stores parameter information through binary files, which improves the data reading and writing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120492771A_ABST
    Figure CN120492771A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of thermal hydraulics, and particularly relates to a Modelica-based two-fluid six-equation and differential algebraic equation coupling system compiling and solving device and a Modelica-based two-fluid six-equation and differential algebraic equation coupling system compiling and solving method. Comprising a compiling stage function system and a solving stage function system. The method has the beneficial effects that the problem of coupling, compiling and solving of a two-fluid six-equation system and a differential algebraic equation system under a unified modeling framework based on Modelica is solved, and a compiling and solving device with complete functions is provided; the whole process compiling solution from topological structure generation, coefficient matrix assembly, time step size control, source term function calculation, matrix equation solution to convergence judgment based on the quality error of the two-fluid six-equation system is realized; the whole-process compilation solution from grammar semantic check, planarization processing, compilation analysis to nonlinear solution of the differential algebraic equation system is realized, and the real-time data communication and interaction of the two-fluid six-equation system and the differential algebraic equation system under the unified solution sequence planning are realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of thermal hydraulic technology, and in particular relates to a device and method for compiling and solving a coupled system of two-fluid six equations and differential algebraic equations based on Modelica. Background Art

[0002] For pressurized water reactor nuclear power plants, thermal power plants, and other energy systems, the mathematical physics equation system based on the full-system, multi-disciplinary coupled model in Modelica is a heterogeneous system of equations formed by coupling the two-fluid six-equation system corresponding to the thermal hydraulics discipline with the differential-algebraic equation systems corresponding to the control, electrical, mechanical, and pneumatic disciplines. The two-fluid six-equation system is a typical spatial partial differential equation, characterized by strong spatial coupling and source closure. This requires the construction of a discrete grid with control volumes and nozzles as basic node elements, with strong constraints on the variables and parameters between adjacent node elements. Furthermore, mathematically, the two-fluid six-equation system must be completed using complex source closure functions to ensure its closure. However, differential-algebraic equation systems lack these strong spatial coupling and source closure characteristics and are generally calculated using algebraic equations or time-based differential equations. Therefore, there are significant differences in the configuration and solution logic between the two-fluid six-equation system and the differential-algebraic equation system. Since the current Modelica compilation and solving device is mainly used for differential algebraic equation systems, it is difficult to apply it to two-fluid six-equation systems. As a result, it is also difficult to solve the full-system multi-disciplinary coupling models of pressurized water reactor nuclear power units, thermal power units and other energy systems based on Modelica. Summary of the Invention

[0003] The purpose of the present invention is to provide a device and method for compiling and solving a coupled system of two-fluid six-equations and differential-algebraic equations based on Modelica, realizing the whole process of compiling and solving the two-fluid six-equation system, including topological structure generation, coefficient matrix assembly, time step control, source function calculation, matrix equation solving, and convergence judgment based on mass error, and realizing the whole process of compiling and solving the differential-algebraic equation system, including syntax and semantic checking, flattening processing, compilation analysis, and nonlinear solution, and realizing real-time data communication and interaction between the two-fluid six-equation system and the differential-algebraic equation system under a unified solution sequence planning, thereby ensuring stable and efficient solution of the heterogeneous equation system formed by the coupling of the two-fluid six-equation system and the differential-algebraic equation system.

[0004] The technical solution of the present invention is as follows: a device for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica, comprising a compiling stage functional system and a solving stage functional system;

[0005] The compilation phase functional system is used to generate a two-fluid six-equation system data information binary file TpfNetwork.bin and a model compilation analysis C code file momodel.c, including a two-fluid six-equation solution information generation module and a two-fluid six-equation model merging and packaging module for the two-fluid six-equation, a native Modelica syntax semantic analysis module and a model flattening module for differential algebraic equations, and an equation system integration analysis module and a simulation C code generation module for the coupled system of the two-fluid six-equation and differential algebraic equations;

[0006] The solution phase functional system takes the two-fluid six-equation system data information binary file TpfNetwork.bin and the model compilation analysis C code file momodel.c output by the compilation phase functional system as input, solves the two-fluid six-equation and differential-algebraic equation coupling system according to the orderly solution plan, and outputs the simulation solution results of the two-fluid six-equation and differential-algebraic equation coupling system advancing along time. The solution phase functional system includes an initialization assignment module, a simulation control module, a Courant number check and time step control module for solving the two-fluid six-equation, a two-fluid six-equation single-step solution module, a mass error check and time step control module, an integral advancement and differential-algebraic continuity equation single-step solution module for solving differential-algebraic equations, a discrete event detection and processing module, and an FMU data communication module for coupling the two-fluid six-equation and differential-algebraic equations.

[0007] The two-fluid six-equation solution information generation module includes:

[0008] Input: A Modelica model with a two-fluid six-equation specific model annotation. The model annotation is used to determine the type of the Modelica model. If this annotation is present, it indicates that the Modelica model is a two-fluid six-equation based Modelica model. If this annotation is absent, it indicates that the Modelica model is a differential-algebraic equation based Modelica model.

[0009] Output: TpfNetwork.bin file containing the topological structure of the thermal-hydraulic system and the parameters, variables, interfaces, source functions, and coefficient matrix information of the two-fluid six-equation of each basic node unit, for use by the two-fluid six-equation solving module;

[0010] Function: The two-fluid six-equation solution information generation module generates all the information required for solving the two-fluid six-equation system, including parameters, variables, interfaces, source term functions, and coefficient matrices, based on the modeling information of the thermal-hydraulic system based on the two-fluid six-equation. It includes a topology information generation submodule, a basic parameter collection submodule, a variable interface collection submodule, a source term function automatic association submodule, a coefficient matrix assembly submodule, and an information printing submodule. Specifically:

[0011] 1) Topology information generation submodule

[0012] Input: Modelica model with annotations for the specific model of two fluids and six equations;

[0013] Output: Flattened topological structure connection diagram of the thermal-hydraulic system consisting entirely of basic node units and their directed connection edges, as well as topological information such as the basic node unit number, type, model component name, and upstream and downstream information of the basic node unit. The basic node units include control body v, takeover j, time-dependent control body tdv, and time-dependent takeover tdj. The basic node unit model corresponds to the discrete nodes of the thermal-hydraulic system based on a staggered grid.

[0014] Function: First, through flattening, the thermal-hydraulic system model built on the Modelica model of two fluids and six equations is converted and restored into a system model consisting entirely of orderly connected basic node unit models. Then, according to the direction, branches, and loops of the orderly connection in the topological structure diagram, the control body type basic node units and the pipe type basic node units are uniformly numbered. Finally, the topological information of the basic node unit number, type, model component name, and upstream and downstream information of the basic node unit on the flattened topological structure diagram of the thermal-hydraulic system is obtained.

[0015] 2) Basic parameter collection submodule

[0016] Input: Modelica model with annotations for the two-fluid six-equation model, as well as the flattened topology connection diagram and topology information of the thermal-hydraulic system;

[0017] Output: basic node unit parameter information data container;

[0018] Function: The basic node unit parameter information data container traverses the basic node units of the flattened topology connection diagram of the thermal hydraulic system, and collects and stores the parameter information corresponding to the basic node unit, including the number, type, model component name, upstream and downstream information of the basic node unit, structural parameters, characteristic parameters, and initial parameters, into the basic node unit parameter information data container;

[0019] 3) Variable interface collection submodule

[0020] Input: Modelica model with annotations for the specific model of two fluids and six equations and the flattened topology connection diagram of the thermal-hydraulic system;

[0021] Output: basic node unit interface information data container;

[0022] Function: The Modelica model based on two fluids and six equations has other types of data interfaces besides flow interfaces, including control interfaces, mechanical interfaces, thermal interfaces, and electrical interfaces. The variable interface collection submodule traverses the basic node units of the flattened topology connection diagram of the thermal-hydraulic system and collects the corresponding numbers, types, data interface types, interface variable types, interface variable names, and serial numbers of the interface variables in the control body or takeover variable enumeration table of the basic node units as an array with corresponding relationships into the basic node unit interface information data container. The control body or takeover variable enumeration table refers to an array in which all variables and parameters of the basic node units are stored according to a certain data structure.

[0023] 4) Source function automatically associates submodules

[0024] Input: Modelica model with annotations for the specific model of two fluids and six equations and the flattened topology connection diagram of the thermal-hydraulic system;

[0025] Output: basic node unit source function information data container;

[0026] Function: The source function automatic association submodule traverses the basic units of the flattened topology connection diagram of the thermal hydraulic system, and collects the basic node unit number, type, source function type, and expression name used by the source function as an array with corresponding relationships into the basic node unit source function information data container. The source function enumeration table is an array that stores all source function types of the two-fluid six-equation system according to a certain data structure. The position number in the enumeration table represents the execution order of the source function;

[0027] 5) Coefficient matrix assembly submodule

[0028] Input: Flattened topology connection diagram of thermal hydraulic system, basic node unit parameter information data container, basic node unit source function information data container;

[0029] Output: storage container for the coefficient matrix of the two-fluid six-equation equation;

[0030] Function: The coefficient matrix assembly submodule applies for memory and stores the assembled two-fluid six-equation coefficient matrix in the form of a row-compressed format array. The coefficient matrix assembly submodule traverses the basic units of the flattened topology connection diagram of the thermal-hydraulic system, organizes the variable coefficients of the basic solution variables and archives similar terms, calculates the non-zero variable coefficients and equation constants of the control body mass and energy conservation discrete equations about the seven basic solution variables of pressure, cavitation fraction, vapor phase relative internal energy, liquid phase relative internal energy, non-condensable gas fraction, vapor phase flow rate, and liquid phase flow rate, and calculates the non-zero coefficients and equation constants of the takeover momentum conservation discrete equation about the three basic solution variables of vapor phase flow rate, liquid phase flow rate, and pressure, confirms the row and column information of each non-zero variable coefficient in the corresponding coefficient matrix, and stores the value of the variable coefficient in the row-compressed format array of the coefficient matrix according to the row and column information.

[0031] 6) Information printing submodule

[0032] Input: basic node unit parameter information data container, basic node unit interface information data container, basic node unit source term function information data container, two-fluid six-equation coefficient matrix storage container;

[0033] Output: A binary file TpfNetwork.bin file containing the topological structure of the thermal-hydraulic system and the parameters, variables, interfaces, source functions, and coefficient matrix information of the two-fluid six-equation of each basic node unit, which is called by the two-fluid six-equation solving module;

[0034] Function: The information printing submodule integrates the topological structure information and basic parameter information stored in the basic node unit parameter information data container, the variable interface information stored in the basic node unit interface information data container, the source function information stored in the basic node unit source function information data container, and the coefficient matrix stored in the two-fluid six-equation coefficient matrix storage container, and prints them into the binary file TpfNetwork.bin for the two-fluid six-equation solving module to call.

[0035] The two-fluid six-equation model merging and encapsulating module includes:

[0036] Input: basic node unit interface information data container.

[0037] Output: Two-fluid six-equation encapsulation function TpfFun based on the FMU model framework;

[0038] Function: Based on the FMU model framework, the two-fluid six-equation model merging module encapsulates the two-fluid six-equation system into a function TpfFun with input variables and output variables. This function is coupled with other non-two-fluid six-equation equation subsets as an independent equation subset. The two-fluid six-equation model merging module uses the input type data interface variables of the basic node unit interface information data container as the input variables of the function TpfFun, and the output type data interface variables as the output variables of TpfFun.

[0039] The grammatical semantic analysis module includes:

[0040] Input: Modelica model based on differential algebraic equations;

[0041] Output: Model text information data structure symbol table that complies with Modelica specifications;

[0042] Function: The syntax and semantic analysis module analyzes and checks the code of the Modelica model based on differential algebraic equations based on the syntax and semantic specifications of the Modelica language. Syntax checking refers to checking whether the combination of model code keywords, identifiers, operators, strings, numbers, comments, etc. conforms to the grammatical form of Modelica. Semantic checking refers to type and variable search, type compatibility checking, and complex semantics checking such as restricted classes, objects, inheritance, variants, and redeclarations according to the Modelica semantic specifications. Finally, it generates a model text information data structure symbol table that conforms to the Modelica specifications. When there are syntax or semantic errors in the model, the syntax and semantic analysis module can accurately locate the error location and assist engineers in completing the modeling work.

[0043] The model flattening module includes:

[0044] Input: Model text information data structure symbol table that complies with Modelica specifications and Modelica model based on differential algebraic equations;

[0045] Output: Flattened continuous-discrete mixed differential algebraic equation system;

[0046] Function: Based on the model text information data structure symbol table, the Model Flattening module maps the declarative, object-oriented, hierarchical Modelica model based on differential algebraic equations into a flattened continuous-discrete mixed differential algebraic equation system consisting of a flattened equation subset and a flattened variable set.

[0047] The equation system integrated analysis module includes:

[0048] Input: A coupled system consisting of a set of flattened subsets based on differential algebraic equations and a wrapper function TpfFun based on the two-fluid six-equation system.

[0049] Output: The encapsulated function TpfFun of the two-fluid six-equation system and the ordered solution plan of the flattened differential-algebraic equation system;

[0050] Function: Treat the two-fluid six-equation encapsulation function TpfFun as an independent equation subset and integrate it with the differential-algebraic equation flattening system for compilation and analysis. Generate a unified solution sequence plan for the coupled system of the two-fluid six-equation and differential-algebraic equations. The solution sequence plan expresses the solution order of the two-fluid six-equation encapsulation function TpfFun equation subset and the differential-algebraic equation flattening system under the unified solution framework, as well as the input-output relationship between each equation subset.

[0051] The simulation C code generation module includes:

[0052] Input: Two-fluid six-equation encapsulation function TpfFun and the ordered solution plan of the flattened differential-algebraic equation system;

[0053] Output: model compiled C code file momodel.c;

[0054] Function: Based on the orderly solution plan of the function equation TpfFun and the coupled system of differential algebraic equations and the model code information, a C code file momodel.c is generated that can be integrated and compiled with the solver C code and library files. Under the C code compiler, momodel.c is integrated with the solver and compiled into an executable program, ultimately realizing the conversion of the model file described in the Modelica language into a model file described in C code. In the momodel.c file, the C code describing the two-fluid six-equation encapsulation function TpfFun is a C code in the form of fmu. The fmu internally calls the two-fluid six-equation solving module, and the fmu externally calls the differential algebraic equation system solving module.

[0055] The initialization assignment module includes:

[0056] Input: binary file TpfNetwork.bin of the two-fluid six-equation system data information and C code file momodel.c for model compilation and analysis;

[0057] Output: Memory space and initial values of variable parameters required to solve the two-fluid six-equation system and the differential-algebraic equation system;

[0058] Function: For the two-fluid six-equation system, apply for the solution memory of the two-fluid six-equation system according to the basic node unit type and number of the thermal-hydraulic system topology information in the binary file TpfNetwork.bin, and store the type, number, model component information, upstream and downstream node information, variable parameter information, source function information, and coefficient matrix data information of each basic node unit.

[0059] The simulation control module includes:

[0060] Input: User settings of simulation control panel;

[0061] Output: upper and lower limits of mass error, maximum time step, minimum time step, simulation time, simulation result output interval for two-fluid six-equation simulation control, and FMU data communication mode and communication time interval for two-fluid six-equation and differential-algebraic equation coupled control;

[0062] Function: The simulation control module writes the simulation control parameters set by the user into the solver, and reads the simulation control parameters during the simulation process to control the convergence, time advancement, and result output of the simulation.

[0063] The Courant number checking and time step control module includes:

[0064] Input: pre-used time step;

[0065] Output: time step based on Courant limit correction;

[0066] Function: The Courant number check module is used to check and correct the time step for solving the two-fluid six equations to ensure that the Courant number of each basic node unit of the thermal-hydraulic system is not greater than 1. The Courant number check module uses the calculated Courant limit as the standard and requires that the pre-used time step must be less than or equal to the Courant limit. If the pre-used time step is greater than the Courant limit, the time step is changed to the Courant limit.

[0067] The Courant limit is calculated as follows:

[0068]

[0069] Where M is the total number of non-boundary pipes in the thermal hydraulic system, Δt upc,m and Δt downc,m V is the upstream upwind Courant time and downstream upwind Courant time of the mth junction, K,m is the volume of the upstream control volume of the mth takeover, A m is the flow channel area of the mth connection, v g,m and v f,m is the vapor and liquid flow rate of the mth connection, Δx K,m and ΔxL,m is the length of the upstream and downstream control bodies of the mth takeover; v f,L,m and v g,L,m are the liquid and vapor flow rates at the center of the downstream control body of the mth pipe.

[0070] The two-fluid six-equation single-step solution module includes:

[0071] Input: binary file TpfNetwork.bin, t n Simulation results of basic solution variables at time instants, and time step corrected based on Courant limit;

[0072] Output: t n+1 Simulation results of basic solution variables at time;

[0073] Function: According to the topological structure information and source function information of the binary file TpfNetwork.bin and t n The seven basic solution variables, namely, momentary pressure, cavitation fraction, vapor phase relative internal energy, liquid phase relative internal energy, non-condensable gas fraction, vapor phase flow rate, and liquid phase flow rate, are combined with the time step based on the Courant limit correction to calculate the source function value of the basic node unit of the thermal-hydraulic system. Based on the coefficient matrix data information of the binary file TpfNetwork.bin, the coefficient matrix of the scalar equation and the coefficient matrix of the vector equation of the two-fluid six equations are refreshed. The global pressure matrix equation of the thermal-hydraulic system is obtained by the inversion operation of the coefficient matrix, and the direct solution method based on the LU decomposition method is used to solve the global pressure matrix equation to obtain t n+1 The pressure value of each control body of the thermal hydraulic system at the moment, and finally obtain t according to the vector equation coefficient matrix n+1 The steam and liquid flow rate of each pipe in the thermal hydraulic system at time t is obtained according to the scalar equation coefficient matrix. n+1 The cavitation fraction, vapor phase internal energy, liquid phase internal energy and non-condensable gas fraction of each control body in the thermal-hydraulic system at any moment.

[0074] The quality error checking and time step control module includes:

[0075] Input: t n+1 Control the equation solution results at all times and set the upper and lower limits of mass error;

[0076] Output: t n+1 Moment quality error, and based on the quality error, determine whether to recalculate and adjust the time step;

[0077] Function: The quality error check module is used to calculate t n+1 The mass error at the moment is compared with the set upper and lower limits of the mass error. If t n+1If the quality error at a certain moment is greater than the set quality error upper limit, the time step is reduced and the time step is returned to the previous moment t n , recalculate t n+1 Thermal hydraulic variable parameters at time t n+1 If the mass error at a certain moment is less than the set mass error lower limit, the time step is increased and the calculation of t is continued along the time. n+2 Thermal hydraulic variable parameters at time t n+1 When the mass error is between the upper and lower limits of the set mass error, the time step is kept unchanged and t is calculated as time advances. n+2 The mass error refers to the maximum deviation between the vapor-liquid mixture density obtained by the first-order Taylor expansion of each control body of the thermal-hydraulic system and the vapor-liquid mixture density calculated by the physical state equation.

[0078] The integral advancement and differential algebraic continuous equation single-step solution module includes:

[0079] Input: continuous variable true solution x(t n-i ) approximate value x n-i , C code file momodel.c;

[0080] Output: t of the system of differential-algebraic continuity equations n+1 The continuous variable approximate solution x at time n+1 ;

[0081] Function: Based on the differential algebraic equation system solution sequence planning in the C code file momodel.c, it solves continuous differential algebraic equation subsets and transfers input and output data between equation subsets. For a single continuous differential algebraic equation subset, the DASSL algorithm, which takes both solution accuracy and efficiency into consideration, is used as the solution algorithm for the continuous differential algebraic equation system.

[0082] The discrete event detection and processing module includes:

[0083] Input: t n+1 Simulation results of differential algebraic equation systems and discrete event triggering conditions;

[0084] Output: t n+1 The state condition variable c at the moment, and based on the state condition variable c, determine whether the discrete event occurs and perform corresponding processing;

[0085] Function: Calculate t according to the state condition variable relationship n+1 The state condition variable c at the moment detects whether the discrete event occurs. If it does not occur, the integration continues. If it occurs, since the time step may be large, there may be several discrete events, and it is necessary to go back to t nThe integral advances to the time point t at which the first discrete event occurs e1 , and calculate the continuous variable x at t e1 The right derivative x′ at the moment is obtained to obtain the influence of the first discrete event on the continuous variable x, and then the integration is continued.

[0086] The FMU data communication module includes:

[0087] Input: t n+1 Simulation results of the six equations of two fluids at time t n+1 Simulation calculation results of differential algebraic equation system, communication mode and communication time step;

[0088] Output: t n+1 Input variable data and output variable data of the two-fluid six-equation FMU package function TpfFun at the moment;

[0089] Function: Based on the ordered solution sequence planning, FMU communication mode, and communication time step, the FMU communication module reads and refreshes the FMU package function TpfFun input variable data from the simulation calculation results of the differential algebraic equation system for use by the two-fluid six-equation solution module; and extracts and refreshes the FMU package function TpfFun output variable data from the two-fluid six-equation simulation calculation results for use by the differential algebraic equation solution module.

[0090] A method for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica includes the following steps:

[0091] Step 1: Identify the two-fluid six-equation model and the differential-algebraic equation model based on the model annotation. If the two-fluid six-equation model is annotated, it is marked as the two-fluid six-equation model. If there is no such model annotation, it is marked as the differential-algebraic equation model.

[0092] Step 2: Compile the two-fluid six-equation model and the differential-algebraic equation model respectively to generate a subset of equations that can be solved in a unified and orderly manner;

[0093] Step 3: Perform integrated compilation and analysis on the two-fluid six-equation encapsulation function TpfFun equation subset and the differential-algebraic equation subset to generate a unified solution sequence plan for the coupled system of the two-fluid six-equation and differential-algebraic equations. This plan expresses the solution order of the two-fluid six-equation encapsulation function TpfFun equation subset and the differential-algebraic flattened equation subset under the unified solution framework, as well as the input-output relationship between each equation subset.

[0094] Step 4: Based on the orderly solution plan and model code information of the coupled system of functional equations TpfFun and differential algebraic equations, generate a C code file momodel.c that can be integrated and compiled with the solver C code and library files. In the momodel.c file, the C code describing the equation subset of the two-fluid six-equation encapsulation function TpfFun is in the fmu form, while the C code other than the fmu form is a subset of the differential algebraic equations.

[0095] Step 5: Based on the binary file TpfNetwork.bin for the two-fluid six-equation system data and the C code file momodel.c for model compilation and analysis, apply for the memory space required to solve the two-fluid six-equation system and the differential-algebraic equation system. Calculate the initial values of each variable parameter based on the model component settings or default initial parameters and store them in the corresponding storage units.

[0096] Step 6: Write the simulation control parameters set by the user, such as the upper and lower limits of mass error, maximum time step, minimum time step, simulation time, simulation result output interval, and FMU data communication mode and communication time interval for the coupled control of the two-fluid six equations and differential-algebraic equations, into the solver;

[0097] Step 7: According to the ordered solution sequence planning, the two-fluid six-equation system and the differential-algebraic equation system are solved in single steps respectively. The two types of equations exchange data through the FMU data communication mechanism. The FMU data communication mechanism reads and refreshes the input variable data of the FMU package function TpfFun from the simulation calculation results of the differential-algebraic equation system according to the FMU data communication mode and communication time interval set by the user for use in solving the two-fluid six-equation system; and extracts and refreshes the output variable data of the FMU package function TpfFun from the simulation calculation results of the two-fluid six-equation system for use in solving the differential-algebraic equation system;

[0098] Step 8: Determine whether the simulation time has reached the simulation termination time. If not, jump to step 7 and continue to advance along the time to carry out single-step solution and data communication of the two-fluid six-equation system and the differential algebraic equation system; if the simulation termination time is reached, the simulation ends and the simulation result file is output.

[0099] The step 2 includes:

[0100] In terms of the two-fluid six-equation model,

[0101] Step 211: Generate a flattened topology diagram of the thermal-hydraulic system and assemble a coefficient matrix for the two-fluid six-equation model, traverse the basic node units of the flattened topology diagram of the thermal-hydraulic system, collect and organize the topological information, variable parameters, data interface information, source function information, coefficient matrix information, etc. of the basic node units, and generate a binary file TpfNetwork.bin containing the above data information for calling by the two-fluid six-equation solving module. The data interface information is other types of data interface information other than the flow interface, including control interface, mechanical interface, thermal interface, and electrical interface. These interfaces use specific value functions or assignment functions to establish variable parameter constraint relationships between the Modelica model based on the two-fluid six-equation model and other types of Modelica models;

[0102] Step 212: Traverse the data interface of the binary file TpfNetwork.bin, and based on the FMU model framework, encapsulate the two-fluid six-equation system into a function TpfFun with input variables and output variables. The input variable of the function is the input type data interface of the binary file TpfNetwork.bin, and the output variable is the output type data interface of the binary file TpfNetwork.bin. The encapsulated function TpfFun can be used as an independent equation subset to be jointly coupled with other equation subsets other than the two-fluid six-equation.

[0103] The step 2 includes:

[0104] In terms of differential algebraic equation models,

[0105] Step 221: Analyze and check the code of the Modelica model based on differential algebraic equations based on the syntax and semantic specifications of the Modelica language to obtain a model text information data structure symbol table that complies with the Modelica specifications;

[0106] Step 222: Based on the model text information data structure symbol table, eliminate the hierarchical structure of the differential algebraic equation model and the value-transfer functions and intermediate variables related to the multi-disciplinary coupling interface, and map the declarative, object-oriented, hierarchical differential algebraic equation-based Modelica model into a flattened continuous-discrete mixed differential algebraic equation system consisting of a flattened equation subset and a flattened variable set.

[0107] The step 7 includes:

[0108] Single-step solution of the six-equation system for two fluids:

[0109] Step 711: Check and correct the Courant number of the pre-used time step for solving the two-fluid six-equation solution to ensure that the Courant number of each basic node unit of the thermal-hydraulic system is not greater than 1;

[0110] Step 712: Based on the topological structure information, basic variable parameter information, source function information, coefficient matrix information and t n The seven basic solution variables, namely, momentary pressure, cavity fraction, vapor phase internal energy, liquid phase internal energy, non-condensable gas fraction, vapor phase velocity, and liquid phase velocity, are combined with the time step corrected based on the Courant number to carry out the source function calculation of the basic node unit of the thermal hydraulic system, the coefficient matrix of the two-fluid six equations is updated, and the global pressure matrix equation is updated and solved. n+1 Calculation of steam and liquid flow rate of each pipe in the thermal hydraulic system at time t n+1 Calculation of cavitation fraction, vapor phase internal energy, liquid phase internal energy and non-condensable gas fraction of each control volume in the thermal hydraulic system at any time;

[0111] Step 713: According to t n+1 Simulation results of the two-fluid six-equation system at time t n+1 The maximum deviation between the vapor-liquid mixture density obtained by the first-order Taylor expansion of each control body of the thermal hydraulic system at the moment and the vapor-liquid mixture density calculated by the physical state equation is the mass error, and is compared with the set upper and lower limits of the mass error. If t n+1 If the quality error at a certain moment is greater than the set quality error upper limit, the time step is reduced and the time step is returned to the previous moment t n , recalculate t n+1 Thermal hydraulic variable parameters at time t n+1 If the mass error at a certain moment is less than the set mass error lower limit, the time step is increased and the calculation of t is continued along the time. n+2 Thermal hydraulic variable parameters at time t n+1 When the mass error is between the upper and lower limits of the set mass error, the time step is kept unchanged and t is continued to be calculated as time advances. n+2 Thermal hydraulic variable parameters at each moment.

[0112] The step 7 includes:

[0113] Single-step solution of differential algebraic equation systems,

[0114] Step 721: According to the differential algebraic equation system solution sequence planning in the C code file momodel.c, the differential algebraic continuous equation subsets are solved and the input and output data between the equation subsets are transferred. The single differential algebraic continuous equation subset adopts the DASSL algorithm that takes both solution accuracy and efficiency into consideration as the solution algorithm for the continuous differential algebraic equation system, and obtains t n+1 Simulation results of differential algebraic equation system at time;

[0115] Step 722: Calculate t according to the state condition variable relationship n+1 The state condition variable c at the moment detects whether the discrete event occurs. If it does not occur, the integral continues to advance; if it occurs, it falls back to t n The integral advances to the time point t at which the first discrete event occurs e1 , and calculate the continuous variable x at t e1 The right derivative x′ at the moment is obtained to obtain the influence of the first discrete event on the continuous variable x, and then the integration is continued.

[0116] The beneficial effects of the present invention are:

[0117] (1) The present invention solves the problem of coupled compilation and solution of a two-fluid six-equation system and a differential-algebraic equation system under a unified modeling framework based on Modelica, and provides a fully functional compilation and solution device, which not only realizes the compilation and solution of the two-fluid six-equation system from topological structure generation, coefficient matrix assembly, time step control, source function calculation, matrix equation solution to convergence judgment based on mass error, but also realizes the compilation and solution of the differential-algebraic equation system from syntax and semantic checking, flattening processing, compilation analysis to nonlinear solution, and realizes real-time data communication and interaction between the two-fluid six-equation system and the differential-algebraic equation system under a unified solution sequence planning, ensuring stable and efficient solution of the heterogeneous equation system formed by the coupling of the two-fluid six-equation system and the differential-algebraic equation system.

[0118] (2) The present invention uses binary files to store and read and write information such as parameters, variables, interfaces, source term functions, and coefficient matrices of the two-fluid six-equation system. It has the compactness, security, and friendliness of complex data structures of data storage, and has the high-speed reading and writing capabilities of large-scale data. The reading and writing efficiency far exceeds that of text files. It is very suitable for reading and writing large-scale variable parameters in the process of solving the two-fluid six-equation system, thereby improving the solution efficiency of the two-fluid six-equation system. BRIEF DESCRIPTION OF THE DRAWINGS

[0119] Figure 1 This is a logic diagram of a method for compiling and solving a coupled system of two-fluid six equations and differential algebraic equations based on Modelica provided by the present invention. DETAILED DESCRIPTION

[0120] The present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0121] A device for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica comprises a compiling stage functional system and a solving stage functional system.

[0122] The compilation phase functional system converts the full-system multi-disciplinary coupling model of pressurized water reactor nuclear power units, thermal power units, and other energy systems into a two-fluid six-equation system data information file TpfNetwork.bin and a model compilation analysis C code file momodel.c. The data information file TpfNetwork.bin describes the topological structure of the thermal-hydraulic system based on the two-fluid six-equation, the thermal-hydraulic variable parameters of each basic node unit, the data interface, the source term closure function, the two-fluid six-equation coefficient matrix, and other information, providing input for memory allocation, data reading and writing, and error locating in the solution phase. The C code file momodel.c describes the orderly solution plan and information for the two-fluid six-equation and differential-algebraic equation coupling system, and can be integrated with the solver's C code and compiled as a whole into an executable program under a C code compiler.

[0123] Specifically, the compilation stage functional system is used to generate a two-fluid six-equation system data information binary file TpfNetwork.bin and a model compilation analysis C code file momodel.c, including a two-fluid six-equation solution information generation module and a two-fluid six-equation model merging and encapsulation module for the two-fluid six-equation, a native Modelica syntax semantic analysis module and a model flattening module for differential algebraic equations, and an equation system integration analysis module and a simulation C code generation module for the coupled system of two-fluid six-equations and differential algebraic equations.

[0124] The two-fluid six-equation solution information generation module includes:

[0125] a. Input: A Modelica model with a two-fluid six-equation specific model annotation. The model annotation is used to determine the type of Modelica model. If this annotation is present, it indicates that the Modelica model is a two-fluid six-equation based Modelica model. If this annotation is absent, it indicates that the Modelica model is a differential algebraic equation based Modelica model.

[0126] b. Output: The TpfNetwork.bin file contains the topological structure of the thermal-hydraulic system and the parameters, variables, interfaces, source functions, coefficient matrices of the two-fluid six-equation equations of each basic node unit, etc., which can be called by the two-fluid six-equation solving module.

[0127] c. Function: The two-fluid six-equation solution information generation module generates all the information required for solving the two-fluid six-equation system, including parameters, variables, interfaces, source term functions, coefficient matrices, etc., based on the thermal-hydraulic system modeling information based on the two-fluid six-equation system. It includes a topology information generation submodule, a basic parameter collection submodule, a variable interface collection submodule, a source term function automatic association submodule, a coefficient matrix assembly submodule, and an information printing submodule. Specifically:

[0128] 1) Topology information generation submodule

[0129] a. Input: Modelica model with two-fluid six-equation model-specific annotations.

[0130] b. Output: A flattened topological connection diagram of the thermal-hydraulic system consisting entirely of basic node units and their directed edges, along with topological information such as the basic node unit number, type, model component name, and upstream and downstream information. The basic node units include control volume v, nozzle j, time-dependent control volume tdv, and time-dependent nozzle tdj. The basic node unit model corresponds to the discrete nodes of the thermal-hydraulic system based on a staggered grid.

[0131] c. Function: First, through flattening processing, the thermal-hydraulic system model built based on the Modelica model of two fluids and six equations is converted and restored into a system model composed entirely of orderly connected basic node unit models; then, according to the direction, branches and loops of the orderly connection in the topological structure diagram, the basic node units of the control body type and the basic node units of the takeover type are uniformly numbered respectively; finally, the topological information such as the basic node unit number, type, model component name, upstream and downstream information of the basic node unit on the flattened topological structure diagram of the thermal-hydraulic system is obtained.

[0132] 2) Basic parameter collection submodule

[0133] a. Input: Modelica model with annotations for the two-fluid six-equation model, as well as the flattened topology connection diagram and topology information of the thermal-hydraulic system.

[0134] b. Output: basic node unit parameter information data container.

[0135] c. Function: The basic node unit parameter information data container traverses the basic node units of the flattened topology connection diagram of the thermal-hydraulic system, and collects and stores the parameter information corresponding to the basic node unit, such as the number, type, model component name, upstream and downstream information of the basic node unit, structural parameters, characteristic parameters, initial parameters, etc., into the basic node unit parameter information data container.

[0136] 3) Variable interface collection submodule

[0137] a. Input: Modelica model with annotations for the specific model of two fluids and six equations and the flattened topology connection diagram of the thermal-hydraulic system.

[0138] b. Output: basic node unit interface information data container.

[0139] c. Function: The Modelica model based on two-fluid six-equation has other types of data interfaces besides flow interfaces, including control interfaces, mechanical interfaces, thermal interfaces, electrical interfaces, etc. These interfaces use specific value functions or assignment functions to establish variable parameter constraint relationships between the Modelica model based on two-fluid six-equation and other types of Modelica models. The variable interface collection submodule traverses the basic node units of the flattened topology structure connection diagram of the thermal hydraulic system, and collects the corresponding numbers, types (control body or takeover), data interface types (input or output), interface variable types (variable or parameter), interface variable names, and the serial numbers of the interface variables in the control body or takeover variable enumeration table as arrays with corresponding relationships into the basic node unit interface information data container. The control body or takeover variable enumeration table refers to an array in which all variables and parameters of the basic node units are stored according to a certain data structure.

[0140] 4) Source function automatically associates submodules

[0141] a. Input: Modelica model with annotations for the specific model of two fluids and six equations and a flattened topology connection diagram of the thermal-hydraulic system;

[0142] b. Output: basic node unit source function information data container;

[0143] c. Function: The source function automatic association submodule traverses the basic units of the flattened topology connection diagram of the thermal-hydraulic system and collects the basic node unit number, type (control body or takeover), source function type (the source function's sequence number in the source function enumeration table), and the expression name used by the source function as an array with corresponding relationships into the basic node unit source function information data container. The source function enumeration table stores all source function types of the two-fluid six-equation system according to a specific data structure. The position number in the enumeration table represents the execution order of the source function.

[0144] 5) Coefficient matrix assembly submodule

[0145] a. Input: flattened topology connection diagram of the thermal-hydraulic system, basic node unit parameter information data container, and basic node unit source function information data container.

[0146] b. Output: Storage container for the coefficient matrix of the two-fluid six-equation equation.

[0147] c. Function: The coefficient matrix assembly submodule allocates memory and stores the assembled two-fluid six-equation coefficient matrix in a row-compressed array format. The coefficient matrix assembly submodule traverses the basic units of the flattened topology connection diagram of the thermal-hydraulic system, organizes the variable coefficients of the basic solution variables, and files similar terms. It calculates the non-zero variable coefficients and equation constants for the discrete equations for conservation of control volume mass and energy with respect to seven basic solution variables: pressure, cavitation fraction, vapor phase relative internal energy, liquid phase relative internal energy, non-condensable gas fraction, vapor phase flow rate, and liquid phase flow rate. It also calculates the non-zero coefficients and equation constants for the discrete equation for conservation of takeover momentum with respect to three basic solution variables: vapor phase flow rate, liquid phase flow rate, and pressure. It confirms the row and column information of each non-zero variable coefficient in the corresponding coefficient matrix and stores the numerical value of the variable coefficient in the row-compressed array of the coefficient matrix based on the row and column information.

[0148] The row-compressed format array is stored as follows: first, all non-zero elements are loaded into a one-dimensional array, row first, then column second, as the constitutive data data. The length of data, nnz, is then recorded, and the colIndex array is used to record the column number of each data item in data. Finally, the rowIndex array is used to record the index of the first non-zero element in each row in data, and the number of non-zero elements plus 1 is added to the end. nnz, colIndex, rowIndex, and the number of matrix rows, N, are called the structural parameters of the matrix. Combined with the data array, they provide complete information about large sparse matrices.

[0149] 6) Information printing submodule

[0150] a. Input: basic node unit parameter information data container, basic node unit interface information data container, basic node unit source term function information data container, two-fluid six-equation coefficient matrix storage container.

[0151] b. Output: A binary file TpfNetwork.bin containing the topological structure of the thermal-hydraulic system and the parameters, variables, interfaces, source functions, coefficient matrices of the two-fluid six-equation equations of each basic node unit, etc., which can be called by the two-fluid six-equation solving module.

[0152] Function: The information printing submodule integrates the topology and basic parameter information stored in the basic node unit parameter information data container, the variable interface information stored in the basic node unit interface information data container, the source function information stored in the basic node unit source term function information data container, and the coefficient matrix stored in the two-fluid six-equation coefficient matrix storage container, and prints it to the binary file TpfNetwork.bin for use by the two-fluid six-equation solver module. This binary file offers compact and secure data storage, is user-friendly for complex data structures, and offers significantly higher read and write efficiency than text files.

[0153] The two-fluid six-equation model merging and encapsulating module includes:

[0154] Input: basic node unit interface information data container.

[0155] Output: Two-fluid six-equation encapsulation function TpfFun based on the FMU model framework.

[0156] Function: Based on the FMU model framework, the Two-Fluid Six-Equation Model Merger module encapsulates the two-fluid six-equation system into a function TpfFun with input and output variables. This function can be used as an independent equation subset to simultaneously couple with other equation subsets other than the two-fluid six-equation system. The Two-Fluid Six-Equation Model Merger module uses the input-type data interface variables of the basic node unit interface information data container as the input variables of the function TpfFun, and the output-type data interface variables as the output variables of TpfFun.

[0157] The grammatical semantic analysis module includes:

[0158] a. Input: Modelica model based on differential algebraic equations.

[0159] b. Output: Model text information data structure symbol table that complies with the Modelica specification.

[0160] c. Function: The Syntax and Semantic Analysis module analyzes and checks the code of Modelica models based on differential algebraic equations (DAEs) based on the syntax and semantics of the Modelica language. Syntax checking verifies that the combination of model code keywords, identifiers, operators, strings, numbers, and comments conforms to the Modelica syntax. Semantic checking involves type and variable lookup, type compatibility checks, and checks for complex semantics such as restricted classes, objects, inheritance, variants, and redeclarations, all based on the Modelica semantics specification. Ultimately, it generates a symbol table of the model's text information data structure that conforms to the Modelica specification. When syntactic or semantic errors are found in the model, the Syntax and Semantic Analysis module accurately locates the error, assisting engineers in completing the modeling process.

[0161] The model flattening module includes:

[0162] a. Input: Model text information data structure symbol table that complies with the Modelica specification and Modelica model based on differential algebraic equations.

[0163] b. Output: Flattened continuous-discrete mixed differential algebraic equation system.

[0164] c. Function: Based on the symbol table of the model text information data structure, the model flattening module maps the declarative, object-oriented, hierarchical Modelica model based on differential algebraic equations into a flattened continuous-discrete mixed differential algebraic equation system consisting of a flattened equation subset and a flattened variable set. Therefore, the model flattening module eliminates the value-transfer functions and intermediate variables related to the model hierarchy and multi-disciplinary coupling interface, and also eliminates the model component information corresponding to the equation. The flattened equation refers to: for a differential algebraic equation system (where t is the time variable, x is the state vector involved in the derivative operation about t, is the derivative of x with respect to t, y is an algebraic variable not involved in the derivative operation with respect to t), if there exists a set of variables z = (z1, z2, z3, ..., z m ) (called the flattened variable set), so that all variables x and y of the equation system and their derivatives can be expressed as algebraic expressions of z and its derivatives (called the flattened equation subset), then the flattening treatment.

[0165] The equation system integrated analysis module includes:

[0166] Input: A coupled system consisting of a set of flattened subsets based on differential algebraic equations and a wrapper function TpfFun based on the two-fluid six-equation system.

[0167] Output: The encapsulated function TpfFun of the two-fluid six-equation system and the ordered solution plan of the flattened differential-algebraic equation system;

[0168] Function: Treat the two-fluid six-equation encapsulation function TpfFun as an independent equation subset and integrate it with the differential-algebraic equation flattening system for compilation and analysis. Generate a unified solution sequence plan for the coupled system of the two-fluid six-equation and differential-algebraic equations. The solution sequence plan expresses the solution order of the two-fluid six-equation encapsulation function TpfFun equation subset and the differential-algebraic equation flattening system under the unified solution framework, as well as the input-output relationship between each equation subset.

[0169] The simulation C code generation module includes:

[0170] a. Input: Two-fluid six-equation encapsulation function TpfFun and the ordered solution plan for the flattened differential-algebraic equation system;

[0171] b. Output: Model compiled C code file momodel.c;

[0172] c. Function: Based on the ordered solution plan for the coupled system of differential-algebraic equations (DAEs) and the model code information, the program generates a C code file, momodel.c, that can be integrated with the solver's C code and library files. Using a C code compiler, momodel.c is integrated with the solver into an executable program, ultimately converting the Modelica-based model file into a C-based one. In momodel.c, the C code describing the two-fluid six-equation encapsulation function, TpfFun, is in the form of an FMU. The FMU internally calls the two-fluid six-equation solver module and externally calls the DAE system solver module.

[0173] The function of the functional system in the solution stage is to take the data information file TpfNetwork.bin and the C code file momodel.c as input, call the two-fluid six-equation solution algorithm, the differential-algebraic equation solution algorithm, and the two-fluid six-equation and differential-algebraic equation data communication algorithm based on the FMU framework, and output the simulation solution results of the two-fluid six-equation and differential-algebraic equation coupling system advancing along time.

[0174] Specifically, the solution phase functional system takes the binary file TpfNetwork.bin of the two-fluid six-equation system data information and the model compilation analysis C code file momodel.c output by the compilation phase functional system as input, solves the two-fluid six-equation coupled system and the differential-algebraic equation according to the ordered solution plan, and outputs the simulation solution results of the two-fluid six-equation coupled system and the differential-algebraic equation coupled system as it advances along time. The solution phase functional system includes an initialization assignment module, a simulation control module, a Courant number check and time step control module for solving the two-fluid six-equation, a two-fluid six-equation single-step solution module, a mass error check and time step control module, an integral advancement and differential-algebraic continuity equation single-step solution module for solving the differential-algebraic equation, a discrete event detection and processing module, and an FMU data communication module for the coupling of the two-fluid six-equation and the differential-algebraic equation.

[0175] The initialization assignment module includes:

[0176] a. Input: Two-fluid six-equation system data information binary file TpfNetwork.bin and model compilation analysis C code file momodel.c.

[0177] b. Output: Memory space and initial values of variable parameters required to solve the two-fluid six-equation system and the differential-algebraic equation system.

[0178] c. Function: For the two-fluid six-equation system, memory is requested for solving the two-fluid six-equation system based on the type and number of basic node units in the thermal-hydraulic system topology information in the binary file TpfNetwork.bin. This memory stores the type, number, model component information, upstream and downstream node information, variable parameter information, source function information, coefficient matrix data, and other data information for each basic node unit. Furthermore, based on the initial value settings of the thermal-hydraulic model components, the initial values of the variable parameters of each basic node unit are calculated and stored in the corresponding storage units. For the differential-algebraic equation system, memory is requested for solving the system based on the type and number of variable parameters in the C code file momodel.c, excluding the fmu-form C code, and the set or default model variable parameter initial values are stored in the corresponding storage units.

[0179] The simulation control module includes:

[0180] a. Input: Simulate the user settings on the control panel.

[0181] b. Output: upper and lower limits of mass error, maximum time step, minimum time step, simulation time, simulation result output interval for two-fluid six-equation simulation control, and FMU data communication mode and communication time interval for the coupled control of two-fluid six-equation and differential-algebraic equations.

[0182] c. Function: The simulation control module writes the simulation control parameters set by the user into the solver, and reads the simulation control parameters during the simulation process to control the convergence, time advancement, result output, etc. of the simulation.

[0183] The Courant number checking and time step control module includes:

[0184] a. Input: The pre-used time step, such as the maximum time step initially set by the user or the time step of the previous calculation.

[0185] b. Output: Time step based on Courant limit correction.

[0186] c. Function: The Courant number check module is used to check and correct the time step for solving the two-fluid six equations, ensuring that the Courant number of each basic node element in the thermal-hydraulic system is no greater than 1. The Courant number check module uses the calculated Courant limit as the standard and requires that the pre-used time step be less than or equal to the Courant limit. If the pre-used time step is greater than the Courant limit, the time step is changed to the Courant limit.

[0187] The Courant limit is calculated as follows:

[0188]

[0189] Where M is the total number of non-boundary pipes in the thermal hydraulic system, Δt upc,m and Δt downc,m V is the upstream upwind Courant time and downstream upwind Courant time of the mth junction, K,m is the volume of the upstream control volume of the mth takeover, A m is the flow channel area of the mth connection, v g,m and v f,m is the vapor and liquid flow rate of the mth connection, Δx K,m and Δx L,m is the length of the upstream and downstream control bodies of the mth takeover; v f,L,m and v g,L,m are the liquid and vapor flow rates at the center of the downstream control body of the mth pipe.

[0190] The two-fluid six-equation single-step solution module includes:

[0191] a. Input: binary file TpfNetwork.bin, t n The simulation results of the basic solution variables at time and the time step corrected based on the Courant limit.

[0192] b. Output: t n+1 Simulation results of basic solution variables at time.

[0193] c. Function: According to the topological structure information and source function information of the binary file TpfNetwork.bin and t n The seven basic solution variables, including momentary pressure, cavitation fraction, vapor phase relative internal energy, liquid phase relative internal energy, non-condensable gas fraction, vapor phase flow rate, and liquid phase flow rate, are combined with the time step based on the Courant limit correction to calculate the source function value of the basic node unit of the thermal-hydraulic system. Based on the coefficient matrix data information of the binary file TpfNetwork.bin, the coefficient matrix of the scalar equation and the coefficient matrix of the vector equation of the two-fluid six equations are refreshed. The global pressure matrix equation of the thermal-hydraulic system is obtained by the inversion operation of the coefficient matrix, and the direct solution method based on the LU decomposition method is used to solve the global pressure matrix equation to obtain t n+1 The pressure value of each control body of the thermal hydraulic system at the moment, and finally obtain t according to the vector equation coefficient matrix n+1 The steam and liquid flow rate of each pipe in the thermal hydraulic system at time t is obtained according to the scalar equation coefficient matrix. n+1 The cavitation fraction, vapor phase internal energy, liquid phase internal energy and non-condensable gas fraction of each control body in the thermal-hydraulic system at any moment.

[0194] The quality error checking and time step control module includes:

[0195] a. Input: t n+1 The results of the equation solution are controlled at all times, and the upper and lower limits of the quality error are set.

[0196] b. Output: t n+1 The moment quality error is determined, and based on the quality error, it is determined whether to recalculate and adjust the time step.

[0197] c. Function: The quality error check module is used to calculate t n+1 The mass error at the moment is compared with the set upper and lower limits of the mass error. If t n+1 If the quality error at a certain moment is greater than the set quality error upper limit, the time step is reduced and the time step is returned to the previous moment t n , recalculate t n+1 Thermal hydraulic variable parameters at time t n+1 If the mass error at a certain moment is less than the set mass error lower limit, the time step is increased (but not greater than the maximum time step set by the user), and t is continued to be calculated along the time. n+2 Thermal hydraulic variable parameters at time t n+1 When the mass error is between the upper and lower limits of the set mass error, the time step is kept unchanged and t is calculated as time advances. n+2 The mass error refers to the maximum deviation between the vapor-liquid mixture density obtained by the first-order Taylor expansion of each control volume of the thermal-hydraulic system and the vapor-liquid mixture density calculated by the physical state equation.

[0198] The integral advancement and differential algebraic continuous equation single-step solution module includes:

[0199] a. Input: continuous variable true solution x(t n-i ) approximate value x n-i (i=0, 1, 2, ..., k), C code file momodel.c.

[0200] b. Output: t of the system of differential-algebraic continuity equations n+1 The continuous variable approximate solution x at time n+1 .

[0201] c. Function: Based on the DAE system solution sequence planning in the C code file momodel.c, this program solves subsets of continuous DAEs and transfers input and output data between these subsets. For each subset of continuous DAEs, the DASSL algorithm, designed to balance accuracy and efficiency, is used as the solution algorithm for continuous DAE systems. The DASSL algorithm, based on a variable-order, variable-step-size, multi-step backward difference scheme, can solve stiff DAEs and is widely used in various DAE solvers.

[0202] The discrete event detection and processing module includes:

[0203] a. Input: t n+1 Simulation results of differential algebraic equation system at time instants and trigger conditions of discrete events.

[0204] b. Output: t n+1 The state condition variable c at the moment is used to determine whether a discrete event occurs and perform corresponding processing based on the state condition variable c.

[0205] c. Function: Calculate t according to the state condition variable relationship n+1 The state condition variable c at the moment detects whether the discrete event occurs. If it does not occur, the integration continues. If it occurs, since the time step may be large, there may be several discrete events, and it is necessary to go back to t n The integral advances to the time point t at which the first discrete event occurs e1 , and calculate the continuous variable x at t e1 The right derivative x′ at the moment is obtained to obtain the influence of the first discrete event on the continuous variable x, and then the integration is continued.

[0206] The FMU data communication module includes:

[0207] Input: t n+1 Simulation results of the six equations of two fluids at time t n+1 Simulation results of differential algebraic equation systems, communication modes, and communication time steps

[0208] Output: t n+1 Input variable data and output variable data of the two-fluid six-equation FMU package function TpfFun at this moment

[0209] Function: Based on the ordered solution sequence planning, FMU communication mode, and communication time step, the FMU communication module reads and refreshes the FMU package function TpfFun input variable data from the simulation calculation results of the differential algebraic equation system for use by the two-fluid six-equation solution module; and extracts and refreshes the FMU package function TpfFun output variable data from the two-fluid six-equation simulation calculation results for use by the differential algebraic equation solution module.

[0210] A method for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica includes the following steps:

[0211] Step 1: Identify the two-fluid six-equation model and the differential-algebraic equation model according to the model annotation. If there is a two-fluid six-equation model, it will be marked as a two-fluid six-equation model. If there is no such model annotation, it will be marked as a differential-algebraic equation model.

[0212] Step 2: Compile the two-fluid six-equation model and the differential-algebraic equation model separately to generate a subset of equations that can be solved in a unified and orderly manner, including:

[0213] In terms of the two-fluid six-equation model,

[0214] Step 211: Generate a flattened topology diagram for the thermal-hydraulic system and assemble the coefficient matrix for the two-fluid six-equation model. The basic node units of the flattened topology diagram are traversed, and the topological information, variable parameters, data interface information, source function information, coefficient matrix information, etc. of the basic node units are collected and organized. A binary file TpfNetwork.bin containing the above data information is generated for invocation by the two-fluid six-equation solver module. The data interface information includes other types of data interfaces besides flow interfaces, including control interfaces, mechanical interfaces, thermal interfaces, and electrical interfaces. These interfaces use specific value functions or assignment functions to establish variable parameter constraint relationships between the Modelica model based on the two-fluid six-equation model and other types of Modelica models.

[0215] Step 212: Traverse the data interface of the binary file TpfNetwork.bin and, based on the FMU model framework, encapsulate the two-fluid six-equation system into a function TpfFun with input variables and output variables. The input variables of this function are the input-type data interface of the binary file TpfNetwork.bin, and the output variables are the output-type data interface of the binary file TpfNetwork.bin. The encapsulated function TpfFun can be used as an independent equation subset to be simultaneously coupled with other equation subsets other than the two-fluid six-equation system.

[0216] In terms of differential algebraic equation models,

[0217] Step 221: Analyze and check the code of the Modelica model based on differential algebraic equations based on the syntax and semantic specifications of the Modelica language to obtain a model text information data structure symbol table that complies with the Modelica specifications.

[0218] Step 222: Based on the model text information data structure symbol table, eliminate the hierarchical structure of the differential algebraic equation model and the value-transfer functions and intermediate variables related to the multi-disciplinary coupling interface, and map the declarative, object-oriented, hierarchical differential algebraic equation-based Modelica model into a flattened continuous-discrete mixed differential algebraic equation system consisting of a flattened equation subset and a flattened variable set.

[0219] Step 3: Perform integrated compilation and analysis on the equation subset of the two-fluid six-equation encapsulation function TpfFun and the differential-algebraic equation subset to generate a unified solution sequence plan for the coupled system of the two-fluid six-equation and differential-algebraic equations. This expresses the solution order of the equation subset of the two-fluid six-equation encapsulation function TpfFun and the differential-algebraic flattening equation subset under the unified solution framework, as well as the input-output relationship between each equation subset.

[0220] Step 4: Based on the ordered solution plan for the coupled system of functional equations TpfFun and differential-algebraic equations and the model code information, generate the C code file momodel.c, which can be integrated and compiled with the solver C code and library files. In the momodel.c file, the C code describing the equation subset of the two-fluid six-equation encapsulation function TpfFun is in fmu form, while the C code in fmu form is for the differential-algebraic equation subset.

[0221] Step 5: Based on the binary file TpfNetwork.bin of the two-fluid six-equation system data information and the model compilation and analysis C code file momodel.c, apply for the memory space required to solve the two-fluid six-equation system and the differential-algebraic equation system, and calculate the initial values of each variable parameter based on the model component settings or default initial parameters, and store them in the corresponding storage units.

[0222] Step 6: Write the simulation control parameters set by the user, such as the upper and lower limits of mass error, maximum time step, minimum time step, simulation time, simulation result output interval, and FMU data communication mode and communication time interval for the coupled control of the two-fluid six equations and differential algebraic equations, into the solver.

[0223] Step 7: Based on the ordered solution sequence plan, single-step solutions are performed for the two-fluid six-equation system and the differential-algebraic equation system, respectively. Data exchange between the two types of equations is performed via the FMU data communication mechanism. The FMU data communication mechanism reads and refreshes the input variable data of the FMU encapsulated function TpfFun from the simulation calculation results of the differential-algebraic equation system based on the FMU data communication mode and communication time interval set by the user, for use in solving the two-fluid six-equation system; and extracts and refreshes the output variable data of the FMU encapsulated function TpfFun from the simulation calculation results of the two-fluid six-equation system for use in solving the differential-algebraic equation system.

[0224] Single-step solution of the six-equation system for two fluids:

[0225] Step 711: Check and correct the Courant number of the pre-used time step for solving the two-fluid six-equation solution to ensure that the Courant number of each basic node unit of the thermal-hydraulic system is not greater than 1.

[0226] Step 712: Based on the topological structure information, basic variable parameter information, source function information, coefficient matrix information and t n The seven basic solution variables, including momentary pressure, cavity fraction, vapor phase internal energy, liquid phase internal energy, non-condensable gas fraction, vapor phase velocity, and liquid phase velocity, are combined with the time step corrected based on the Courant number to carry out the source function calculation of the basic node unit of the thermal hydraulic system, the coefficient matrix of the two-fluid six equations is updated, and the global pressure matrix equation is updated and solved. n+1 Calculation of steam and liquid flow rate of each pipe in the thermal hydraulic system at time t n+1 Calculate the cavitation fraction, vapor phase internal energy, liquid phase internal energy and non-condensable gas fraction of each control volume in the thermal-hydraulic system at any time.

[0227] Step 713: According to t n+1 Simulation results of the two-fluid six-equation system at time t n+1 The maximum deviation between the vapor-liquid mixture density obtained by the first-order Taylor expansion of each control body of the thermal hydraulic system at the moment and the vapor-liquid mixture density calculated by the physical state equation is the mass error, and is compared with the set upper and lower limits of the mass error. If t n+1 If the quality error at a certain moment is greater than the set quality error upper limit, the time step is reduced and the time step is returned to the previous moment t n , recalculate t n+1 Thermal hydraulic variable parameters at time t n+1 If the mass error at a certain moment is less than the set mass error lower limit, the time step is increased (but not greater than the maximum time step set by the user), and t is continued to be calculated along the time. n+2 Thermal hydraulic variable parameters at time t n+1When the mass error is between the upper and lower limits of the set mass error, the time step is kept unchanged and t is calculated as time advances. n+2 Thermal hydraulic variable parameters at each moment.

[0228] Single-step solution of differential algebraic equation systems,

[0229] Step 721: According to the differential algebraic equation system solution sequence planning in the C code file momodel.c, the differential algebraic continuous equation subsets are solved and the input and output data between the equation subsets are transferred. The single differential algebraic continuous equation subset adopts the DASSL algorithm that takes both solution accuracy and efficiency into consideration as the solution algorithm for the continuous differential algebraic equation system, and obtains t n+1 Simulation results of the differential algebraic equation system at time.

[0230] Step 722: Calculate t according to the state condition variable relationship n+1 The state condition variable c at the moment detects whether the discrete event occurs. If it does not occur, the integration continues. If it occurs, since the time step may be large, there may be several discrete events, and it is necessary to go back to t n The integral advances to the time point t at which the first discrete event occurs e1 , and calculate the continuous variable x at t e1 The right derivative x′ at the moment is obtained to obtain the influence of the first discrete event on the continuous variable x, and then the integration is continued.

[0231] Step 8: Determine whether the simulation time has reached the simulation termination time. If not, jump to step 7 and continue to advance along the time to carry out single-step solution and data communication of the two-fluid six-equation system and the differential algebraic equation system; if the simulation termination time is reached, the simulation ends and the simulation result file is output.

Claims

1. A device for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica, characterized by: It includes two parts: the compilation phase function system and the solution phase function system; The compilation phase functional system is used to generate a two-fluid six-equation system data information binary file TpfNetwork.bin and a model compilation analysis C code file momodel.c, including a two-fluid six-equation solution information generation module and a two-fluid six-equation model merging and packaging module for the two-fluid six-equation, a native Modelica syntax semantic analysis module and a model flattening module for differential algebraic equations, and an equation system integration analysis module and a simulation C code generation module for the coupled system of the two-fluid six-equation and differential algebraic equations; The solution phase functional system takes the two-fluid six-equation system data information binary file TpfNetwork.bin and the model compilation analysis C code file momodel.c output by the compilation phase functional system as input, solves the two-fluid six-equation and differential-algebraic equation coupling system according to the orderly solution plan, and outputs the simulation solution results of the two-fluid six-equation and differential-algebraic equation coupling system advancing along time. The solution phase functional system includes an initialization assignment module, a simulation control module, a Courant number check and time step control module for solving the two-fluid six-equation, a two-fluid six-equation single-step solution module, a mass error check and time step control module, an integral advancement and differential-algebraic continuity equation single-step solution module for solving differential-algebraic equations, a discrete event detection and processing module, and an FMU data communication module for coupling the two-fluid six-equation and differential-algebraic equations.

2. The device for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica as claimed in claim 1, characterized in that: The two-fluid six-equation solution information generation module includes: Input: A Modelica model with a two-fluid six-equation specific model annotation. The model annotation is used to determine the type of the Modelica model. If this annotation is present, it indicates that the Modelica model is a two-fluid six-equation based Modelica model. If this annotation is absent, it indicates that the Modelica model is a differential-algebraic equation based Modelica model. Output: TpfNetwork.bin file containing the topological structure of the thermal-hydraulic system and the parameters, variables, interfaces, source functions, and coefficient matrix information of the two-fluid six-equation of each basic node unit, for use by the two-fluid six-equation solving module; Function: The two-fluid six-equation solution information generation module generates all the information required for solving the two-fluid six-equation system, including parameters, variables, interfaces, source term functions, and coefficient matrices, based on the modeling information of the thermal-hydraulic system based on the two-fluid six-equation. It includes a topology information generation submodule, a basic parameter collection submodule, a variable interface collection submodule, a source term function automatic association submodule, a coefficient matrix assembly submodule, and an information printing submodule. Specifically: 1) Topology information generation submodule Input: Modelica model with annotations for the specific model of two fluids and six equations; Output: Flattened topological structure connection diagram of the thermal-hydraulic system consisting entirely of basic node units and their directed connection edges, as well as topological information such as the basic node unit number, type, model component name, and upstream and downstream information of the basic node unit. The basic node units include control body v, takeover j, time-dependent control body tdv, and time-dependent takeover tdj. The basic node unit model corresponds to the discrete nodes of the thermal-hydraulic system based on a staggered grid. Function: First, through flattening, the thermal-hydraulic system model built on the Modelica model of two fluids and six equations is converted and restored into a system model consisting entirely of orderly connected basic node unit models. Then, according to the direction, branches, and loops of the orderly connection in the topological structure diagram, the control body type basic node units and the pipe type basic node units are uniformly numbered. Finally, the topological information of the basic node unit number, type, model component name, and upstream and downstream information of the basic node unit on the flattened topological structure diagram of the thermal-hydraulic system is obtained. 2) Basic parameter collection submodule Input: Modelica model with annotations for the two-fluid six-equation model, as well as the flattened topology connection diagram and topology information of the thermal-hydraulic system; Output: basic node unit parameter information data container; Function: The basic node unit parameter information data container traverses the basic node units of the flattened topology connection diagram of the thermal hydraulic system, and collects and stores the parameter information corresponding to the basic node unit, including the number, type, model component name, upstream and downstream information of the basic node unit, structural parameters, characteristic parameters, and initial parameters, into the basic node unit parameter information data container; 3) Variable interface collection submodule Input: Modelica model with annotations for the specific model of two fluids and six equations and the flattened topology connection diagram of the thermal-hydraulic system; Output: basic node unit interface information data container; Function: The Modelica model based on two fluids and six equations has other types of data interfaces besides flow interfaces, including control interfaces, mechanical interfaces, thermal interfaces, and electrical interfaces. The variable interface collection submodule traverses the basic node units of the flattened topology connection diagram of the thermal-hydraulic system and collects the corresponding numbers, types, data interface types, interface variable types, interface variable names, and serial numbers of the interface variables in the control body or takeover variable enumeration table of the basic node units as an array with corresponding relationships into the basic node unit interface information data container. The control body or takeover variable enumeration table refers to an array in which all variables and parameters of the basic node units are stored according to a certain data structure. 4) Source function automatically associates submodules Input: Modelica model with annotations for the specific model of two fluids and six equations and the flattened topology connection diagram of the thermal-hydraulic system; Output: basic node unit source function information data container; Function: The source function automatic association submodule traverses the basic units of the flattened topology connection diagram of the thermal hydraulic system, and collects the basic node unit number, type, source function type, and expression name used by the source function as an array with corresponding relationships into the basic node unit source function information data container. The source function enumeration table is an array that stores all source function types of the two-fluid six-equation system according to a certain data structure. The position number in the enumeration table represents the execution order of the source function; 5) Coefficient matrix assembly submodule Input: Flattened topology connection diagram of thermal hydraulic system, basic node unit parameter information data container, basic node unit source function information data container; Output: storage container for the coefficient matrix of the two-fluid six-equation equation; Function: The coefficient matrix assembly submodule applies for memory and stores the assembled two-fluid six-equation coefficient matrix in the form of a row-compressed format array. The coefficient matrix assembly submodule traverses the basic units of the flattened topology connection diagram of the thermal-hydraulic system, organizes the variable coefficients of the basic solution variables and archives similar terms, calculates the non-zero variable coefficients and equation constants of the control volume mass and energy conservation discrete equations for the seven basic solution variables of pressure, cavitation fraction, vapor phase relative internal energy, liquid phase relative internal energy, non-condensable gas fraction, vapor phase flow rate, and liquid phase flow rate, and calculates the non-zero coefficients and equation constants of the takeover momentum conservation discrete equation for the three basic solution variables of vapor phase flow rate, liquid phase flow rate, and pressure, confirms the row and column information of each non-zero variable coefficient in the corresponding coefficient matrix, and stores the value of the variable coefficient in the row-compressed format array of the coefficient matrix according to the row and column information; 6) Information printing submodule Input: basic node unit parameter information data container, basic node unit interface information data container, basic node unit source term function information data container, two-fluid six-equation coefficient matrix storage container; Output: A binary file TpfNetwork.bin file containing the topological structure of the thermal-hydraulic system and the parameters, variables, interfaces, source functions, and coefficient matrix information of the two-fluid six-equation of each basic node unit, which is called by the two-fluid six-equation solving module; Function: The information printing submodule integrates the topological structure information and basic parameter information stored in the basic node unit parameter information data container, the variable interface information stored in the basic node unit interface information data container, the source function information stored in the basic node unit source function information data container, and the coefficient matrix stored in the two-fluid six-equation coefficient matrix storage container, and prints them into the binary file TpfNetwork.bin for the two-fluid six-equation solving module to call.

3. The device for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica as claimed in claim 1, characterized in that: The two-fluid six-equation model merging and encapsulating module includes: Input: basic node unit interface information data container; Output: Two-fluid six-equation encapsulation function TpfFun based on the FMU model framework; Function: Based on the FMU model framework, the two-fluid six-equation model merging module encapsulates the two-fluid six-equation system into a function TpfFun with input variables and output variables. This function is coupled with other non-two-fluid six-equation equation subsets as an independent equation subset. The two-fluid six-equation model merging module uses the input type data interface variables of the basic node unit interface information data container as the input variables of the function TpfFun, and the output type data interface variables as the output variables of TpfFun.

4. The device for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica as claimed in claim 1, characterized in that: The grammatical semantic analysis module includes: Input: Modelica model based on differential algebraic equations; Output: Model text information data structure symbol table that complies with Modelica specifications; Function: The syntax and semantic analysis module analyzes and checks the code of the Modelica model based on differential algebraic equations based on the syntax and semantic specifications of the Modelica language. Syntax checking refers to checking whether the combination of model code keywords, identifiers, operators, strings, numbers, and comments conforms to the grammatical form of Modelica. Semantic checking refers to type and variable search, type compatibility checking, and complex semantics checks such as restricted classes, objects, inheritance, variants, and redeclarations based on the Modelica semantic specifications. Finally, it generates a model text information data structure symbol table that conforms to the Modelica specifications. When there are syntax or semantic errors in the model, the syntax and semantic analysis module can accurately locate the error location and assist engineers in completing the modeling work.

5. The device for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica as claimed in claim 1, characterized in that: The model flattening module includes: Input: Model text information data structure symbol table that complies with Modelica specifications and Modelica model based on differential algebraic equations; Output: Flattened continuous-discrete mixed differential algebraic equation system; Function: Based on the model text information data structure symbol table, the Model Flattening module maps the declarative, object-oriented, hierarchical Modelica model based on differential algebraic equations into a flattened continuous-discrete mixed differential algebraic equation system consisting of a flattened equation subset and a flattened variable set.

6. The device for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica as claimed in claim 1, characterized in that: The equation system integrated analysis module includes: Input: A coupled system consisting of a set of flattened subsets based on differential algebraic equations and a wrapper function TpfFun based on the two-fluid six-equation system. Output: The encapsulated function TpfFun of the two-fluid six-equation system and the ordered solution plan of the flattened differential-algebraic equation system; Function: Treat the two-fluid six-equation encapsulation function TpfFun as an independent equation subset and integrate it with the differential-algebraic equation flattening system for compilation and analysis. Generate a unified solution sequence plan for the coupled system of the two-fluid six-equation and differential-algebraic equations. The solution sequence plan expresses the solution order of the two-fluid six-equation encapsulation function TpfFun equation subset and the differential-algebraic equation flattening system under the unified solution framework, as well as the input-output relationship between each equation subset.

7. The device for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica as claimed in claim 1, characterized in that: The simulation C code generation module includes: Input: Two-fluid six-equation encapsulation function TpfFun and the ordered solution plan of the flattened differential-algebraic equation system; Output: model compiled C code file momodel.c; Function: Based on the orderly solution plan of the function equation TpfFun and the coupled system of differential algebraic equations and the model code information, a C code file momodel.c is generated that can be integrated and compiled with the solver C code and library files. Under the C code compiler, momodel.c is integrated with the solver and compiled into an executable program, ultimately realizing the conversion of the model file described in the Modelica language into a model file described in C code. In the momodel.c file, the C code describing the two-fluid six-equation encapsulation function TpfFun is a C code in the form of fmu. The fmu internally calls the two-fluid six-equation solving module, and the fmu externally calls the differential algebraic equation system solving module.

8. The device for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica as claimed in claim 1, characterized in that: The initialization assignment module includes: Input: binary file TpfNetwork.bin of the two-fluid six-equation system data information and C code file momodel.c for model compilation and analysis; Output: Memory space and initial values of variable parameters required to solve the two-fluid six-equation system and the differential-algebraic equation system; Function: For the two-fluid six-equation system, apply for the solution memory of the two-fluid six-equation system according to the basic node unit type and number of the thermal-hydraulic system topology information in the binary file TpfNetwork.bin, and store the type, number, model component information, upstream and downstream node information, variable parameter information, source function information, and coefficient matrix data information of each basic node unit.

9. The device for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica as claimed in claim 1, characterized in that: The simulation control module includes: Input: User settings of simulation control panel; Output: upper and lower limits of mass error, maximum time step, minimum time step, simulation time, simulation result output interval for two-fluid six-equation simulation control, and FMU data communication mode and communication time interval for two-fluid six-equation and differential-algebraic equation coupled control; Function: The simulation control module writes the simulation control parameters set by the user into the solver, and reads the simulation control parameters during the simulation process to control the convergence, time advancement, and result output of the simulation.

10. The device for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica as claimed in claim 1, characterized in that: The Courant number checking and time step control module includes: Input: pre-used time step; Output: time step based on Courant limit correction; Function: The Courant number check module is used to check and correct the time step for solving the two-fluid six equations to ensure that the Courant number of each basic node unit of the thermal hydraulic system is not greater than 1. The Courant number check module uses the calculated Courant limit as the standard and requires that the pre-used time step must be less than or equal to the Courant limit. If the pre-used time step is greater than the Courant limit, the time step is changed to the Courant limit. The Courant limit is calculated as follows: Where M is the total number of non-boundary pipes in the thermal hydraulic system, Δt upc,m and Δt downc,m V is the upstream upwind Courant time and downstream upwind Courant time of the mth junction, K,m is the volume of the upstream control volume of the mth takeover, A m is the flow channel area of the mth connection, v g,m and v f,m is the vapor and liquid flow rate of the mth connection, Δx K,m and Δx L,m is the length of the upstream and downstream control bodies of the mth takeover; v f,L,m and v g,L,m are the liquid and vapor flow rates at the center of the downstream control body of the mth pipe.

11. The device for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica according to claim 1, characterized in that: The two-fluid six-equation single-step solution module includes: Input: binary file TpfNetwork.bin, t n Simulation results of basic solution variables at time instants, and time step corrected based on Courant limit; Output: t n+1 Simulation results of basic solution variables at time; Function: According to the topological structure information and source function information of the binary file TpfNetwork.bin and t n The seven basic solution variables, namely, momentary pressure, cavitation fraction, vapor phase relative internal energy, liquid phase relative internal energy, non-condensable gas fraction, vapor phase flow rate, and liquid phase flow rate, are combined with the time step based on the Courant limit correction to calculate the source function value of the basic node unit of the thermal-hydraulic system. Based on the coefficient matrix data information of the binary file TpfNetwork.bin, the coefficient matrix of the scalar equation and the coefficient matrix of the vector equation of the two-fluid six equations are refreshed. The global pressure matrix equation of the thermal-hydraulic system is obtained by the inversion operation of the coefficient matrix, and the direct solution method based on the LU decomposition method is used to solve the global pressure matrix equation to obtain t n+1 The pressure value of each control body of the thermal hydraulic system at the moment, and finally obtain t according to the vector equation coefficient matrix n+ The steam and liquid flow rate of each pipe in the thermal hydraulic system at time x is obtained according to the scalar equation coefficient matrix. n+1 The cavitation fraction, vapor phase internal energy, liquid phase internal energy and non-condensable gas fraction of each control body in the thermal-hydraulic system at any moment.

12. The device for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica as claimed in claim 1, characterized in that: The quality error checking and time step control module includes: Input: t n+1 Control the equation solution results at all times and set the upper and lower limits of mass error; Output: t n+1 Moment quality error, and based on the quality error, determine whether to recalculate and adjust the time step; Function: The quality error check module is used to calculate t n+1 The mass error at the moment is compared with the set upper and lower limits of the mass error. If t n+1 If the quality error at a certain moment is greater than the set quality error upper limit, the time step is reduced and the time step is returned to the previous moment t n , recalculate t n+1 Thermal hydraulic variable parameters at time t n+1 If the mass error at a certain moment is less than the set mass error lower limit, the time step is increased and the calculation of t is continued along the time. n+2 Thermal hydraulic variable parameters at time t n+1 When the mass error is between the upper and lower limits of the set mass error, the time step is kept unchanged and t is calculated as time advances. n+2 The mass error refers to the maximum deviation between the vapor-liquid mixture density obtained by the first-order Taylor expansion of each control body of the thermal-hydraulic system and the vapor-liquid mixture density calculated by the physical state equation.

13. The device for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica as claimed in claim 1, characterized in that: The integral advancement and differential algebraic continuous equation single-step solution module includes: Input: continuous variable true solution x(t n-i ) approximate value x n-i , C code file momodel.c; Output: t of the system of differential-algebraic continuity equations n+1 The continuous variable approximate solution x at time n+1 ; Function: Based on the differential algebraic equation system solution sequence planning in the C code file momodel.c, it solves continuous differential algebraic equation subsets and transfers input and output data between equation subsets. For a single continuous differential algebraic equation subset, the DASSL algorithm, which takes both solution accuracy and efficiency into consideration, is used as the solution algorithm for the continuous differential algebraic equation system.

14. The device for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica as claimed in claim 1, characterized in that: The discrete event detection and processing module includes: Input: t n+1 Simulation results of differential algebraic equation systems and discrete event triggering conditions; Output: t n+1 The state condition variable c at the moment, and based on the state condition variable c, determine whether the discrete event occurs and perform corresponding processing; Function: Calculate t according to the state condition variable relationship n+1 The state condition variable c at the moment detects whether the discrete event occurs. If it does not occur, the integration continues. If it occurs, since the time step may be large, there may be several discrete events, and it is necessary to go back to t n The integral advances to the time point t at which the first discrete event occurs e1 , and calculate the continuous variable x at t e1 The right derivative x′ at the moment is obtained to obtain the influence of the first discrete event on the continuous variable x, and then the integration is continued.

15. The device for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica as claimed in claim 1, characterized in that: The FMU data communication module includes: Input: t n+1 Simulation results of the six equations of two fluids at time t n+1 Simulation calculation results of differential algebraic equation system, communication mode and communication time step; Output: t n+1 Input variable data and output variable data of the two-fluid six-equation FMU package function TpfFun at the moment; Function: Based on the ordered solution sequence planning, FMU communication mode, and communication time step, the FMU communication module reads and refreshes the FMU package function TpfFun input variable data from the simulation calculation results of the differential algebraic equation system for use by the two-fluid six-equation solution module; and extracts and refreshes the FMU package function TpfFun output variable data from the two-fluid six-equation simulation calculation results for use by the differential algebraic equation solution module.

16. A method for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica, characterized by: The steps include: Step 1: Identify the two-fluid six-equation model and the differential-algebraic equation model based on the model annotation. If the two-fluid six-equation model is annotated, it is marked as the two-fluid six-equation model. If there is no such model annotation, it is marked as the differential-algebraic equation model. Step 2: Compile the two-fluid six-equation model and the differential-algebraic equation model respectively to generate a subset of equations that can be solved in a unified and orderly manner; Step 3: Perform integrated compilation and analysis on the two-fluid six-equation encapsulation function TpfFun equation subset and the differential-algebraic equation subset to generate a unified solution sequence plan for the coupled system of the two-fluid six-equation and differential-algebraic equations. This plan expresses the solution order of the two-fluid six-equation encapsulation function TpfFun equation subset and the differential-algebraic flattened equation subset under the unified solution framework, as well as the input-output relationship between each equation subset. Step 4: Based on the orderly solution plan and model code information of the coupled system of functional equations TpfFun and differential algebraic equations, generate a C code file momodel.c that can be integrated and compiled with the solver C code and library files. In the momodel.c file, the C code describing the equation subset of the two-fluid six-equation encapsulation function TpfFun is in the fmu form, while the C code other than the fmu form is a subset of the differential algebraic equations. Step 5: Based on the binary file TpfNetwork.bin for the two-fluid six-equation system data and the C code file momodel.c for model compilation and analysis, apply for the memory space required to solve the two-fluid six-equation system and the differential-algebraic equation system. Calculate the initial values of each variable parameter based on the model component settings or default initial parameters and store them in the corresponding storage units. Step 6: Write the simulation control parameters set by the user, such as the upper and lower limits of mass error, maximum time step, minimum time step, simulation time, simulation result output interval, and FMU data communication mode and communication time interval for the coupled control of the two-fluid six equations and differential-algebraic equations, into the solver; Step 7: According to the ordered solution sequence planning, the two-fluid six-equation system and the differential-algebraic equation system are solved in single steps respectively. The two types of equations exchange data through the FMU data communication mechanism. The FMU data communication mechanism reads and refreshes the input variable data of the FMU package function TpfFun from the simulation calculation results of the differential-algebraic equation system according to the FMU data communication mode and communication time interval set by the user for use in solving the two-fluid six-equation system; and extracts and refreshes the output variable data of the FMU package function TpfFun from the simulation calculation results of the two-fluid six-equation system for use in solving the differential-algebraic equation system; Step 8: Determine whether the simulation time has reached the simulation termination time. If not, jump to step 7 and continue to advance along the time to carry out single-step solution and data communication of the two-fluid six-equation system and the differential-algebraic equation system; If the simulation end time is reached, the simulation ends and the simulation result file is output.

17. The method for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica according to claim 16, characterized in that: The step 2 includes: In terms of the two-fluid six-equation model, Step 211: Generate a flattened topology diagram of the thermal-hydraulic system and assemble a coefficient matrix for the two-fluid six-equation model, traverse the basic node units of the flattened topology diagram of the thermal-hydraulic system, collect and organize the topological information, variable parameters, data interface information, source function information, and coefficient matrix information of the basic node units, and generate a binary file TpfNetwork.bin containing the above data information for calling by the two-fluid six-equation solving module. The data interface information is data interface information of other types besides flow interfaces, including control interfaces, mechanical interfaces, thermal interfaces, and electrical interfaces. These interfaces use specific value functions or assignment functions to establish variable parameter constraint relationships between the Modelica model based on the two-fluid six-equation model and other types of Modelica models. Step 212: Traverse the data interface of the binary file TpfNetwork.bin, and based on the FMU model framework, encapsulate the two-fluid six-equation system into a function TpfFun with input variables and output variables. The input variable of the function is the input type data interface of the binary file TpfNetwork.bin, and the output variable is the output type data interface of the binary file TpfNetwork.bin. The encapsulated function TpfFun can be used as an independent equation subset to be jointly coupled with other equation subsets other than the two-fluid six-equation.

18. The method for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica according to claim 16, characterized in that: The step 2 includes: In terms of differential algebraic equation models, Step 221: Analyze and check the code of the Modelica model based on differential algebraic equations based on the syntax and semantic specifications of the Modelica language to obtain a model text information data structure symbol table that complies with the Modelica specifications; Step 222: Based on the model text information data structure symbol table, eliminate the hierarchical structure of the differential algebraic equation model and the value-transfer functions and intermediate variables related to the multi-disciplinary coupling interface, and map the declarative, object-oriented, hierarchical differential algebraic equation-based Modelica model into a flattened continuous-discrete mixed differential algebraic equation system consisting of a flattened equation subset and a flattened variable set.

19. The method for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica according to claim 16, characterized in that: The step 7 includes: Single-step solution of the six-equation system for two fluids: Step 711: Check and correct the Courant number of the pre-used time step for solving the two-fluid six-equation solution to ensure that the Courant number of each basic node unit of the thermal-hydraulic system is not greater than 1; Step 712: Based on the topological structure information, basic variable parameter information, source function information, coefficient matrix information and t n The seven basic solution variables, namely, momentary pressure, cavity fraction, vapor phase internal energy, liquid phase internal energy, non-condensable gas fraction, vapor phase velocity, and liquid phase velocity, are combined with the time step corrected based on the Courant number to carry out the source function calculation of the basic node unit of the thermal hydraulic system, the coefficient matrix of the two-fluid six equations is updated, and the global pressure matrix equation is updated and solved. n+1 Calculation of steam and liquid flow rate of each pipe in the thermal hydraulic system at time t n+1 Calculation of cavitation fraction, vapor phase internal energy, liquid phase internal energy and non-condensable gas fraction of each control volume in the thermal hydraulic system at any time; Step 713: According to t n+1 Simulation results of the two-fluid six-equation system at time t n+1 The maximum deviation between the vapor-liquid mixture density obtained by the first-order Taylor expansion of each control body of the thermal hydraulic system at the moment and the vapor-liquid mixture density calculated by the physical state equation is the mass error, and is compared with the set upper and lower limits of the mass error. If t n+1 If the quality error at a certain moment is greater than the set quality error upper limit, the time step is reduced and the time step is returned to the previous moment t n , recalculate t n+1 Thermal hydraulic variable parameters at time t n+1 If the mass error at a certain moment is less than the set mass error lower limit, the time step is increased and the calculation of t is continued along the time. n+2 Thermal hydraulic variable parameters at time t n+1 When the mass error is between the upper and lower limits of the set mass error, the time step is kept unchanged and t is continued to be calculated as time advances. n+2 Thermal hydraulic variable parameters at each moment.

20. The method for compiling and solving a coupled system of two-fluid six-equation and differential-algebraic equations based on Modelica as claimed in claim 16, characterized in that: The step 7 includes: Single-step solution of differential algebraic equation systems, Step 721: According to the differential algebraic equation system solution sequence planning in the C code file momodel.c, the differential algebraic continuous equation subsets are solved and the input and output data between the equation subsets are transferred. The single differential algebraic continuous equation subset adopts the DASSL algorithm that takes both solution accuracy and efficiency into consideration as the solution algorithm for the continuous differential algebraic equation system, and obtains t n+1 Simulation results of differential algebraic equation system at time; Step 722: Calculate t according to the state condition variable relationship n+1 The state condition variable c at the moment detects whether the discrete event occurs. If it does not occur, the integral continues to advance; if it occurs, it falls back to t n The integral advances to the time point t at which the first discrete event occurs e1 , and calculate the continuous variable x at t e1 The right derivative x′ at the moment is obtained to obtain the influence of the first discrete event on the continuous variable x, and then the integration is continued.