FMU encapsulation method and device based on C language and FORTRAN hybrid modeling

By using a hybrid modeling approach combining C language and FORTRAN, the RinSim simulation model file is automatically parsed and packaged into an FMU, solving the problem of low efficiency in traditional FMU packaging. This enables efficient model exchange and integration, improving reusability and portability.

CN121807296APending Publication Date: 2026-04-07CHINA NUCLEAR POWER OPERATION TECH CORP
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-19
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

Traditional FMU encapsulation processes rely on manual operation, which is inefficient and error-prone, and cannot achieve efficient model exchange and integration.

Method used

A hybrid modeling approach based on C language and FORTRAN is adopted to automatically parse RinSim simulation model files, generate model description files, simulation source program files and variable initial value files, and encapsulate the model into an FMU file through a compilation process.

Benefits of technology

It achieves automated and standardized encapsulation of FMU models, improves the reusability and portability of models in different simulation tools and platforms, and supports model sharing and collaboration.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121807296A_ABST
    Figure CN121807296A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of nuclear power, and particularly relates to an FMU encapsulation method and device based on C language and FORTRAN hybrid modeling. According to the FMU packaging method based on C language and FORTRAN hybrid modeling, key information can be automatically extracted by deeply analyzing the RinSim simulation model file, and corresponding C and Fortran codes are generated. And then, through a compiling process, the model is packaged into an FMU, so that automation and standardization of model packaging are realized. According to the implementation of the method, the FMU model generated by the RinSim simulation platform not only can be reused in different simulation tools or simulation platforms, but also can be subjected to joint simulation with models from different sources in a unified simulation environment, so that the portability and reusability of the model are improved, and convenience is provided for sharing and collaboration of the model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of nuclear power technology, specifically relating to an FMU encapsulation method and apparatus based on hybrid modeling using C language and FORTRAN. Background Technology

[0002] In modern engineering and scientific research, complex system modeling and simulation have become indispensable tools. To achieve efficient model exchange and integration, Functional Mock-up Units (FMUs), as a standardized encapsulation method, are increasingly important. FMU encapsulation technology allows complex system models to be packaged into independent, reusable components that can be integrated and simulated in different simulation environments. However, traditional FMU encapsulation processes often rely on manual operation, which is inefficient and prone to errors. Summary of the Invention

[0003] To overcome the problems existing in related technologies, an FMU encapsulation method and device based on hybrid modeling using C language and FORTRAN is provided.

[0004] According to one aspect of the embodiments of this disclosure, an FMU encapsulation method based on hybrid modeling using C language and FORTRAN is provided, the method comprising:

[0005] Step 1: Parse the system files generated by compiling the RinSim simulation model and identify the interface variables of the RinSim simulation platform model. The interface variables include input variables, output variables, state variables, and parameters.

[0006] Step 2: Based on the identified interface variables, generate the model description file and the model simulation source program file;

[0007] Step 3: Generate the initial value file for the model variables and the header file for the model variables;

[0008] Step 4: Based on the interface variables, use connection statements to establish the connection relationships between the input ports, output ports, and inter-system variables within the model, in order to complete the encapsulation of the model file;

[0009] Step 5: Compile the generated model simulation source program file into a dynamic link library, and package all related files into an FMU file.

[0010] In one possible implementation, step 1 includes:

[0011] Step 11: For the standard graphical interface, parse the RTT files of each system compiled by the RinSim simulation platform, identify the variables in the RTT files that are not defined in this system as input variables of this system, and identify the variables as output variables of the system.

[0012] Step 12: For the interface between the process and the electrical system, iterate through the variables with the attribute Entry=DEMARCATE in the RTT file to obtain the interface variables between the process system and the electrical system; if the CONST attribute of the interface variable is 1, then the variable is determined to be an input variable of the system; if the CONST attribute of the interface variable is not 1, then the variable is determined to be an output variable of the system.

[0013] Step 13: For non-standard interfaces, read the predefined interface list, record the variables in the input interface list as output variables of the system, and record the variables in the output interface list as input variables of the system; and / or, by compiling the interface program of the instrumentation and control system and traversing the generated header files, record the variables in the s._input header file that do not belong to the instrumentation and control system as input variables of the instrumentation and control system, record the variables in the s._output header file that do not belong to the instrumentation and control system as output variables of the instrumentation and control system, and record the corresponding variables as output and input interface variables of the process system.

[0014] In one possible implementation, in step 2, the model description file includes: FMI version, model name, GUID basic information, definitions and attributes of each interface variable, model structure and variable relationships, and default simulation settings information;

[0015] The model simulation source code file includes: header file inclusion declaration, data structure definition, model initialization function, state update function, output calculation function, and FMU standard interface function.

[0016] In one possible implementation, step 3, generating the initial value file for the model variables, includes:

[0017] Step 31: Select the appropriate IC file based on the specific operating conditions and system.

[0018] Step 32: Compile the header file generated by the simulation system using the RinSim simulation platform, and retrieve variable-related information from the database;

[0019] Step 33: Unpack the binary data to obtain the value of the variable under the current operating conditions;

[0020] Step 34: Organize the values ​​according to the FMU standard format to obtain the initial value file of the model variables.

[0021] In one possible implementation, in step 5, the variables are compiled using the ifort, link, and cl commands in the order of input variables, output variables, and inter-system variables.

[0022] According to another aspect of the embodiments of this disclosure, an FMU packaging device based on hybrid modeling using C language and FORTRAN is provided, the device comprising:

[0023] The identification module is used to parse the system files generated by compiling the RinSim simulation model and identify the interface variables of the RinSim simulation platform model. The interface variables include input variables, output variables, state variables, and parameters.

[0024] The first generation module is used to generate model description files and model simulation source program files based on the identified interface variables;

[0025] The second generation module is used to generate initial value files for model variables and header files for model variables.

[0026] The model encapsulation module is used to establish the connection relationships between the input ports, output ports, and inter-system variables within the model based on the interface variables using connection statements, so as to complete the encapsulation of the model file.

[0027] The compilation and compression module is used to compile the generated model simulation source program files into dynamic link libraries and package all related files into an FMU file.

[0028] According to another aspect of the embodiments of this disclosure, an FMU packaging device based on hybrid modeling using C language and FORTRAN is provided, the device comprising:

[0029] processor;

[0030] Memory used to store processor-executable instructions;

[0031] The processor is configured to execute the above-described method.

[0032] According to another aspect of the present disclosure, a non-volatile computer-readable storage medium is provided, on which computer program instructions are stored, which, when executed by a processor, implement the above-described method.

[0033] The beneficial effects of this disclosure are as follows: The FMU encapsulation method based on hybrid C and FORTRAN modeling provided in this disclosure can automatically extract key information and generate corresponding C and Fortran code through in-depth analysis of RinSim simulation model files. Subsequently, the model is encapsulated into an FMU through a compilation process, realizing the automation and standardization of model encapsulation. This method enables FMU models generated by the RinSim simulation platform to be reused in different simulation tools or platforms, and can also be co-simulated with models from different sources in a unified simulation environment, improving the portability and reusability of the model, and facilitating model sharing and collaboration. Attached Figure Description

[0034] Figure 1 This is a flowchart illustrating an FMU encapsulation method based on hybrid modeling using C language and FORTRAN, according to an exemplary embodiment.

[0035] Figure 2 This is a block diagram illustrating an FMU package device based on hybrid modeling using C language and FORTRAN, according to an exemplary embodiment. Detailed Implementation

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

[0037] Figure 1 This is a flowchart illustrating an FMU encapsulation method based on hybrid modeling using C language and FORTRAN, according to an exemplary embodiment. This method can be executed by a terminal device, which can be a computer, such as a server, desktop computer, laptop computer, etc. This disclosure does not limit the type of terminal device. Figure 1 As shown, the method includes:

[0038] Step 1: Parse the system files generated by compiling the RinSim simulation model and identify the interface variables of the RinSim simulation platform model. The interface variables include input variables, output variables, state variables, and parameters.

[0039] In this disclosure, interface variables define the interfaces through which the model interacts with the external environment or other models. By looking up interface variables, the model's inputs, outputs, and internal states can be clearly identified, ensuring that the model can correctly exchange data and integrate functions with external systems.

[0040] As an example of this embodiment, step 1 may include:

[0041] Step 11: For interface variables generated by standard graphical connections, when a graphical component is connected, downstream variables are replaced by upstream variables. The variable that actually participates in the calculation downstream is the upstream variable. The RTT files for each system are compiled and generated by traversing the RinSim simulation platform. Variables not defined in the RTT files for this system are defined as input variables for this system, and these variables are also recorded as the output of the system to which they belong.

[0042] Step 12: For the interface variables between the process system and the electrical system, according to the RinSim platform rules, data interaction between the electrical system and the process system models is achieved by matching power supply index numbers. The electrical system stores the corresponding voltage and frequency in a specific bit of the electrical array. The process system retrieves values ​​from the array using the index number stored in the electrical system's data array and stores the active and reactive currents in the array. Therefore, the interface variable between the process system and the electrical system can be defined as "electrical array (power supply index number)".

[0043] When searching for interface variables between a process system and an electrical system, the variables with "Entry="DEMARCATE" in the RTT file are traversed to obtain all interface variables of the process electrical system and electrical system. Based on whether the "CONST" attribute of the variable in the RTT file is 1, it is determined whether the variable is an input variable or an output variable of the system.

[0044] Step 13: For non-standard interface variables, the corresponding interface variables are found by reading the interface list and header file of the interface program provided by the model engineer.

[0045] The interface variables of the thermal system are determined by reading the list of input and output interface variables provided by the model engineer. Variables in the input list are denoted as output variables of the system in which they reside, and vice versa.

[0046] The interface variable rules for the process and instrumentation / control systems are as follows: The point-to-point program is reorganized using the instrumentation / control simulation system as a unit. An interface program for an instrumentation / control simulation system is divided into "s.*_input" and "s.*_output" according to the data transmission direction. "s.*_input" is the interface program from the process system to the instrumentation / control system, and "s.*_output" is the interface program from the instrumentation / control system to the process system. By compiling the interface program, the generated header files are traversed. Variables in the "s.*_input" header file that do not belong to the instrumentation / control system are recorded as input variables of the instrumentation / control system, and variables in the "s.*_output" header file that do not belong to the instrumentation / control system are recorded as output variables of the instrumentation / control system. Simultaneously, the corresponding variables are recorded as the output and input interface variables of the process system.

[0047] Step 2: Based on the identified interface variables, generate the model description file and the model simulation source program file.

[0048] In the Functional Model Unit (FMU), the model description file (usually named modelDescription.xml) contains all the important information about the model.

[0049] Parsing this file guides the use and integration of the model. This encapsulation method generates the file by parsing the interface variable results and their definitions in the database. The model description file includes: Basic information: including FMI version, model name, GUID, etc. Model structure: including the definitions and attributes of all interface variables. Model equations and relationships: including the model's equation structure and the relationships between variables. Instantiation and simulation settings: including default simulation settings.

[0050] Based on the modeling rules of the RinSim simulation platform, and according to the parsed model information and interface variable information, corresponding C code files are generated. These files include: Header file inclusion declarations: used to include necessary libraries and header files to ensure correct compilation and execution of the program. Data structure definitions: used to define the data structures required by the model. These typically include the model's state variables, parameters, inputs, and outputs. Initialization functions: used to initialize the model's state variables and parameters, setting initial conditions. State update functions: used to update state variables according to the model's dynamic equations. This function is typically called in each simulation step. Output calculation functions: used to calculate the model's output based on the current state. FMU interface functions: these are interface functions defined by the FMU standard for interacting with the simulation platform. They mainly include initialization, simulation step, and termination functions.

[0051] Step 3: Generate the initial value file for model variables and the header file for model variables. The initial value file provides the initial data required for the model to run, and the header file provides the structural definitions required for the model to run.

[0052] As an example of this embodiment, step 3 may include:

[0053] Step 31: Select the appropriate IC file based on the specific operating conditions and system.

[0054] Step 32: Compile the header file generated by the simulation system using the RinSim simulation platform, and retrieve variable-related information from the database;

[0055] Step 33: Unpack the binary data to obtain the value of the variable under the current operating conditions;

[0056] Step 34: Organize the values ​​according to the FMU standard format to obtain the initial value file of the model variables.

[0057] In step 3, the model variable header file is used to declare all variables and related data structures in the model. It organizes all variables in the model, provides declarations of interface functions, and lays the foundation for model initialization, simulation, and output calculation. The model variable header file declares all input, output, and state variables of the model, mainly including the variable's name, type, and its default or initial value. The purpose of defining data structures is to organize and manage these variables, grouping or classifying them for easy access and manipulation during simulation.

[0058] Step 4: Based on the interface variables, use connection statements to establish the connection relationships between the input ports, output ports, and inter-system variables within the model, in order to complete the encapsulation of the model file.

[0059] The model file contains the model definition, parameters, variables, and equations. To establish the signal and physical quantity transmission relationships between components and connect the input and output ports in the model, the `connect` statement is used to connect the interfaces between model components. In this method, the `connect` statements are divided into three parts: input variables, output variables, and variables between systems.

[0060] Step 5 involves compiling the generated model simulation source code files into a dynamic link library (DLL) and packaging all related files into an FMU file. In step 5, a C / C++ compiler can be used to compile the generated code into a DLL or SO library and package all related files into an FMU file. Compilation is performed using commands such as ifort, link, and cl, following the order of compiling input variables, output variables, and inter-system variables.

[0061] Figure 2 This is a block diagram illustrating an FMU-encapsulated device based on hybrid C and FORTRAN modeling, according to an exemplary embodiment. For example, device 1900 can be provided as a server. (See also...) Figure 2 The apparatus 1900 includes a processing component 1922, which further includes one or more processors, and memory resources represented by memory 1932 for storing instructions, such as application programs, that can be executed by the processing component 1922. The application programs stored in memory 1932 may include one or more modules, each corresponding to a set of instructions. Furthermore, the processing component 1922 is configured to execute instructions to perform the methods described above.

[0062] Device 1900 may also include a power supply component 1926 configured to perform power management of device 1900, a wired or wireless network interface 1950 configured to connect device 1900 to a network, and an input / output (I / O) interface 1958. Device 1900 can operate on an operating system stored in memory 1932, such as Windows Server™, MacOS X™, Unix™, Linux™, FreeBSD™, or similar.

[0063] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 1932 including computer program instructions that can be executed by a processing component 1922 of the device 1900 to perform the above-described method.

[0064] This disclosure can be a system, method, and / or computer program product. A computer program product may include a computer-readable storage medium having computer-readable program instructions loaded thereon for causing a processor to implement various aspects of this disclosure.

[0065] Computer-readable storage media can be tangible devices capable of holding and storing instructions for use by an instruction execution device. Computer-readable storage media can be, for example—but not limited to—electrical storage devices, magnetic storage devices, optical storage devices, electromagnetic storage devices, semiconductor storage devices, or any suitable combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), static random access memory (SRAM), portable compact disc read-only memory (CD-ROM), digital multifunction disc (DVD), memory sticks, floppy disks, mechanical encoding devices, such as punch cards or recessed protrusions storing instructions thereon, and any suitable combination thereof. The computer-readable storage media used herein are not to be construed as transient signals themselves, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through waveguides or other transmission media (e.g., light pulses through fiber optic cables), or electrical signals transmitted through wires.

[0066] The computer-readable program instructions described herein can be downloaded from computer-readable storage media to various computing / processing devices, or downloaded via a network, such as the Internet, local area network, wide area network, and / or wireless network, to an external computer or external storage device. The network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge servers. A network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards them to the computer-readable storage media in the respective computing / processing device.

[0067] Computer program instructions used to perform the operations of this disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, status setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Smalltalk, C++, etc., and conventional procedural programming languages ​​such as the "C" language or similar programming languages. The computer-readable program instructions may execute entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or may be connected to an external computer (e.g., via the Internet using an Internet service provider). In some embodiments, electronic circuitry, such as programmable logic circuitry, field-programmable gate arrays (FPGAs), or programmable logic arrays (PLAs), is personalized by utilizing the status information of the computer-readable program instructions to implement various aspects of this disclosure.

[0068] Various aspects of this disclosure are described herein with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this disclosure. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer-readable program instructions.

[0069] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that, when executed by the processor of the computer or other programmable data processing apparatus, they create means for implementing the functions / actions specified in one or more blocks of the flowchart and / or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium that causes a computer, programmable data processing apparatus, and / or other device to operate in a particular manner; thus, the computer-readable medium storing the instructions comprises an article of manufacture that includes instructions for implementing aspects of the functions / actions specified in one or more blocks of the flowchart and / or block diagram.

[0070] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to perform the functions / actions specified in one or more boxes of a flowchart and / or block diagram.

[0071] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of an instruction containing one or more executable instructions for implementing a specified logical function. In some alternative implementations, the functions marked in the blocks may occur in a different order than those shown in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0072] The various embodiments of this disclosure have been described above. These descriptions are exemplary and not exhaustive, nor are they limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen to best explain the principles, practical application, or improvement of the technology in the market, or to enable others skilled in the art to understand the embodiments disclosed herein.

Claims

1. An FMU encapsulation method based on hybrid modeling using C language and FORTRAN, characterized in that, The method includes: Step 1: Parse the system files generated by compiling the RinSim simulation model and identify the interface variables of the RinSim simulation platform model. The interface variables include input variables, output variables, state variables, and parameters. Step 2: Based on the identified interface variables, generate the model description file and the model simulation source program file; Step 3: Generate the initial value file for the model variables and the header file for the model variables; Step 4: Based on the interface variables, use connection statements to establish the connection relationships between the input ports, output ports, and inter-system variables within the model, in order to complete the encapsulation of the model file; Step 5: Compile the generated model simulation source program file into a dynamic link library, and package all related files into an FMU file.

2. The method according to claim 1, characterized in that, Step 1 includes: Step 11: For the standard graphical interface, parse the RTT files of each system compiled by the RinSim simulation platform, identify the variables in the RTT files that are not defined in this system as input variables of this system, and identify the variables as output variables of the system. Step 12: For the interface between the process and the electrical system, iterate through the variables with the attribute Entry=DEMARCATE in the RTT file to obtain the interface variables between the process system and the electrical system; if the CONST attribute of the interface variable is 1, then the variable is determined to be an input variable of the system; if the CONST attribute of the interface variable is not 1, then the variable is determined to be an output variable of the system. Step 13: For non-standard interfaces, read the predefined interface list, record the variables in the input interface list as output variables of the system, and record the variables in the output interface list as input variables of the system; and / or, by compiling the interface program of the instrumentation and control system and traversing the generated header files, record the variables in the s._input header file that do not belong to the instrumentation and control system as input variables of the instrumentation and control system, record the variables in the s._output header file that do not belong to the instrumentation and control system as output variables of the instrumentation and control system, and record the corresponding variables as output and input interface variables of the process system.

3. The method according to claim 1, characterized in that, In step 2, the model description file includes: FMI version, model name, GUID basic information, definition and attributes of each interface variable, model structure and variable relationships, and default simulation settings information; The model simulation source code file includes: header file inclusion declaration, data structure definition, model initialization function, state update function, output calculation function, and FMU standard interface function.

4. The method according to claim 1, characterized in that, Step 3, generating the initial value file for the model variables includes: Step 31: Select the appropriate IC file based on the specific operating conditions and system. Step 32: Compile the header file generated by the simulation system using the RinSim simulation platform, and retrieve variable-related information from the database; Step 33: Unpack the binary data to obtain the value of the variable under the current operating conditions; Step 34: Organize the values ​​according to the FMU standard format to obtain the initial value file of the model variables.

5. The method according to claim 1, characterized in that, In step 5, the input variables, output variables, and inter-system variables are compiled using the ifort, link, and cl commands respectively.

6. An FMU packaging device based on hybrid modeling using C language and FORTRAN, characterized in that, The device includes: The identification module is used to parse the system files generated by compiling the RinSim simulation model and identify the interface variables of the RinSim simulation platform model. The interface variables include input variables, output variables, state variables, and parameters. The first generation module is used to generate model description files and model simulation source program files based on the identified interface variables; The second generation module is used to generate initial value files for model variables and header files for model variables. The model encapsulation module is used to establish the connection relationships between the input ports, output ports, and inter-system variables within the model based on the interface variables using connection statements, so as to complete the encapsulation of the model file. The compilation and compression module is used to compile the generated model simulation source program files into dynamic link libraries and package all related files into an FMU file.

7. An FMU packaging device based on hybrid modeling using C language and FORTRAN, characterized in that, The device includes: processor; Memory used to store processor-executable instructions; The processor is configured to perform the method according to any one of claims 1 to 5.

8. A non-volatile computer-readable storage medium storing computer program instructions thereon, characterized in that, When the computer program instructions are executed by the processor, they implement the method described in any one of claims 1 to 5.