FMI standard-based joint simulation method between cloud chain tool one-dimensional models
Through the cloud-based chain tool based on FMI standards, one-dimensional joint simulation integration and collaboration between different fields or different systems has been achieved, the problem of simulation integration and collaboration in the existing technology has been solved, and the precise control and standardization of simulation tasks has been achieved, which has improved the improvement of simulation tasks. The accuracy of the simulation results is achieved.
Patent Information
- Application Number
- CN202411530940.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-30
- Publication Date
- 2025-02-18
AI Technical Summary
The existing technology is difficult to achieve simulation integration and collaboration between different fields or systems, and it is difficult to build a general simulation integration framework, which makes it a major problem to establish data exchange and interface standardization between simulation software.
Using the cloud-based chaining tool based on the FMI standard, the internal parameters and operations of each instantiated FMU are accurately controlled to achieve accurate synchronization of simulation time, and the simulation task is realized through global state control and data control between multiple FMUs. control functions such as configuration, start, pause, continue and stop.
One-dimensional joint simulation integration and collaboration between different fields or systems is realized, which reduces the difficulty of simulation, standardizes the one-dimensional joint simulation process, and the simulation results are closer to real-world results, and supports the integration and data exchange of different simulation software.
Smart Images

Figure CN119475734A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of joint simulation technology, and in particular to a joint simulation method between one-dimensional models of cloud chain tools based on the FMI standard. Background Art
[0002] In recent years, with the development and maturity of a series of emerging technologies such as cloud computing, Internet of Things, big data, artificial intelligence, 5G, etc., products have become more and more complex, and the speed of replacement is getting faster and faster, which makes enterprises face unprecedented pressure for product innovation. As the best way to optimize product design, ensure product performance, shorten the R&D cycle, and verify complex working conditions, simulation is becoming more and more widely used and has become the cornerstone and catalyst of enterprise innovation. At present, in the field of simulation, all walks of life are more focused on single discipline and single physical field for simulation applications. Due to technical barriers, multi-disciplinary and multi-physical field joint simulation is difficult, but in the real world, any object exists in multiple physical fields, so single physical field simulation is obviously far from meeting the requirements of real-world scenarios. Therefore, in order to make the simulation results closer to the real-world results, multi-physical field and multi-disciplinary joint simulation research and application are imminent.
[0003] For joint simulation, the known technical contents include:
[0004] 1. Simulation is divided into different directions: structure, fluid, dynamics, electronic control, etc.; according to the dimension, it can be divided into one-dimensional and three-dimensional;
[0005] 2. The simulation models in different directions are completely different, and the simulation models in the same direction cannot be reused due to differences in keywords, languages, programming logic, etc.;
[0006] 3. For the FMI protocol proposed by EU Modelisar, although the co-simulation and exchange-model interfaces are defined, a feasible framework method is still needed if these interfaces are to be connected.
[0007] For joint simulation, the industry currently faces the following challenges:
[0008] 1. It is difficult to realize simulation integration and collaboration between different fields or systems;
[0009] 2. It is difficult to build a general simulation integration framework;
[0010] 3. Different simulation software architectures are different, which makes data exchange and interface standardization between simulation software a major challenge;
[0011] 4. During the simulation process, different simulation software need to maintain a time synchronization mechanism;
[0012] 5. There are many kinds of simulation software with the same functions, and their architectures are very different. Therefore, it is extremely difficult to build simulation process management tools and implement control functions such as configuration, start, pause, continue and stop of simulation tasks.
[0013] Based on this technical background, the present invention studies a joint simulation method between one-dimensional models of cloud-based chain tools based on the FMI standard. Summary of the invention
[0014] In view of the shortcomings of the prior art, the present invention provides a joint simulation method between one-dimensional models of cloud-based chain tools based on the FMI standard. By accurately controlling the internal parameters and operations of each instantiated FMU, accurate synchronization of simulation time is achieved, including fixed-step synchronization and event-driven synchronization mechanisms, to meet the needs of different simulation tasks; through global state control and data control between multiple FMUs, control functions such as configuration, start, pause, continue and stop of simulation tasks, as well as monitoring and logging of the simulation process are achieved.
[0015] In order to achieve the above object, the present invention provides a joint simulation method between one-dimensional models of cloud chain tools based on the FMI standard, including:
[0016] Initialization phase: read all FMU description XML files and global coupling configuration files, parse the FMU model that meets the FMI standard, instantiate and initialize the FMU, and configure the simulation;
[0017] Simulation phase: Each instantiated FMU performs operations such as obtaining continuous state variable derivatives, time synchronization, setting input vectors, updating continuous state variables, obtaining event monitoring vectors, re-obtaining continuous state vectors, and updating output vectors. At the same time, global state control and data control are performed between multiple FMUs, time series data is acquired and saved in real time, and generated data is saved. For incompatible FMUs, distributed joint simulation is performed;
[0018] End phase: terminate the simulation, destroy the model instance and release the memory.
[0019] The beneficial effects of the present invention include:
[0020] (1) The joint simulation method between one-dimensional models of cloud-based chain tools based on the FMI standard proposed in the present invention realizes precise synchronization of simulation time by accurately controlling the internal parameters and operations of each instantiated FMU, including fixed-step synchronization and event-driven synchronization mechanisms, to meet the needs of different simulation tasks; through global state control and data control between multiple FMUs, control functions such as configuration, start, pause, continue and stop of simulation tasks, as well as monitoring and logging of the simulation process are realized.
[0021] (2) The joint simulation method between one-dimensional models of cloud-based chain tools based on the FMI standard proposed in the present invention realizes the integration and coordination of one-dimensional joint simulation between different fields or different systems, and manages the one-dimensional joint simulation process, thereby standardizing the one-dimensional joint simulation process, thereby reducing the difficulty of simulation, making one-dimensional joint simulation widely used in the simulation industry, and making the simulation results closer to the real-world results.
[0022] (3) The joint simulation method between one-dimensional models of cloud-based chain tools based on the FMI standard proposed in the present invention can support the integration of different simulation software by establishing a general simulation integration framework method; standardize data exchange and interfaces, and define a unified data exchange format and interface protocol to achieve efficient and accurate data exchange between different simulation models.
[0023] Other features and advantages of the present invention will be described in detail in the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] The above and other objects, features and advantages of the present invention will become more apparent through a more detailed description of exemplary embodiments of the present invention with reference to the accompanying drawings.
[0025] Figure 1 This is a flow chart of the joint simulation method between one-dimensional models of cloud-based chain tools based on the FMI standard proposed in the present invention.
[0026] Figure 2 This is a schematic diagram of a one-dimensional joint simulation system in a specific implementation of the joint simulation method between one-dimensional models of cloud-based chain tools based on the FMI standard proposed by the present invention.
[0027] Figure 3 This is an interface / class diagram of a specific implementation of the joint simulation method between one-dimensional models of cloud-based chain tools based on the FMI standard proposed by the present invention. DETAILED DESCRIPTION
[0028] The preferred embodiments of the present invention will be described in more detail below. Although the preferred embodiments of the present invention are described below, it should be understood that the present invention can be implemented in various forms and should not be limited to the embodiments set forth herein.
[0029] The present invention provides a joint simulation method between one-dimensional models of cloud chain tools based on the FMI standard, such as Figure 1 As shown, including:
[0030] Initialization phase: read all FMU description XML files and global coupling configuration files, parse the FMU model that meets the FMI standard, instantiate and initialize the FMU, and configure the simulation;
[0031] Simulation phase: Each instantiated FMU performs operations such as obtaining continuous state variable derivatives, time synchronization, setting input vectors, updating continuous state variables, obtaining event monitoring vectors, re-obtaining continuous state vectors, and updating output vectors. At the same time, global state control and data control are performed between multiple FMUs, time series data is acquired and saved in real time, and generated data is saved. For incompatible FMUs, distributed joint simulation is performed;
[0032] End phase: terminate the simulation, destroy the model instance and release the memory.
[0033] In the present invention, accurate synchronization of simulation time is achieved by accurately controlling the internal parameters and operations of each instantiated FMU, including fixed-step synchronization and event-driven synchronization mechanisms, to meet the needs of different simulation tasks; through global state control and data control between multiple FMUs, control functions such as configuration, start, pause, continue and stop of simulation tasks, as well as monitoring and logging of the simulation process are achieved.
[0034] According to the present invention, all FMU description xml files are read through the cosim::model_description interface;
[0035] The global coupling configuration file is read through the cosim::system_structure interface;
[0036] The interface used for model parsing is the fmi::glue interface;
[0037] FMI compliance means compliance with FMI 1.0 / 2.0 protocols;
[0038] The interfaces used for instantiation are slave_instance::fmiInstantiateModel interfaces;
[0039] The interface used for initialization is slave_instance::fmiInitialize interface;
[0040] The system used for one-dimensional co-simulation includes a coupling controller and at least two FMU models;
[0041] Each FMU model communicates with the coupling controller via the FMU standard interface;
[0042] Each FMU model includes a solver, a simulation parameter module, an input parameter module, and an output parameter module;
[0043] Each FMU model performs parameter mapping with adjacent FMU models through its own input parameter module and output parameter module;
[0044] The coupling controller includes a global simulation control module, a coupling mode module, a simulation step time control module, a communication control module and a simulation parameter control module.
[0045] According to the present invention, the FMU description XML file is to save the description information related to the model in the FMU in the modelDescription.xml file in the XML format;
[0046] The operation process of model parsing the FMU that meets the FMI standard includes:
[0047] Three variable enumeration types are defined: variable_type, variable_causality, and variable_variability:
[0048] variable_type: defines the possible types of variables;
[0049] real, integer, boolean, string, enumeration;
[0050] variable_causality: defines the role of the variable in the model;
[0051] parameter, calculated_parameter, input, output, local;
[0052] variable_variability: defines how the value of a variable changes over time;
[0053] constant, fixed, tunable, discrete, continuous;
[0054] Two structures are designed: model_description and variable_description. A model_description instance contains multiple variable_description instances:
[0055] model_description describes an FMU model;
[0056] name: model name;
[0057] uuid: unique identifier;
[0058] description: FMU description;
[0059] author: author information;
[0060] version: version information;
[0061] variables: list of variables;
[0062] variable_description describes a model variable in FMU;
[0063] name: unique identifier;
[0064] reference: a numerical identifier;
[0065] type: data type;
[0066] causality: causality;
[0067] variability: variability;
[0068] start: Optional starting value.
[0069] According to the present invention, the simulation configuration includes:
[0070] Design the cosim::system_structure interface;
[0071] Design two structures, entity and connection, to handle the management of entities and variables in the simulation system and ensure that the connections and value assignments between variables are valid;
[0072] Define the function_io_description structure to support efficient variable management and connection verification;
[0073] Structure entity: describes the information of the simulation FMU instance;
[0074] name: instance name;
[0075] type: instance type is FMU or function;
[0076] step_size_hint: recommended step size is only valid for FMU;
[0077] parameter_values: Function parameter values are only valid for functions;
[0078] Structure connection: describes the connection between variables;
[0079] source: source variable;
[0080] target: target variable;
[0081] Structure function_io_description: describes the input and output of function variables, including group index and variable index;
[0082] group_index: variable group index;
[0083] io_index: variable index;
[0084] description: function I / O description;
[0085] The cosim::model_description interface is used to instantiate multiple entities of the read FMU to form the variable entities_, and is also used to instantiate multiple connection structures to establish variable connections between the variables of multiple FMUs.
[0086] According to the present invention, obtaining the continuous state variable derivative is completed through the slave_instance::fmiGetDerivatives interface;
[0087] Time synchronization is true. The time synchronization between the platform and the model itself is completed through the slave_instance::fmiSetTime interface;
[0088] Setting the input vector is done through the slave_instance::fmiSetReal interface;
[0089] Updating continuous state variables is done through the slave_instance::fmiSetContinuousStates interface;
[0090] Obtaining the event monitoring vector is done through the slave_instance::fmiGetEventIndicators interface;
[0091] Re-acquiring the continuous state vector includes re-acquiring the continuous state vector when the judgment event is triggered, which is completed through the slave_instance::fmiGetContinuousStates interface;
[0092] Update the output vector through the slave_instance::fmiGetReal interface;
[0093] Perform global state control and data control between multiple FMUs, acquire and save time series data in real time, and save the generated data including:
[0094] During the simulation process, global state control and data control between multiple FMUs are implemented through the slave_simulator class. The coupler monitors the state changes of each FMU instance through the observer::last_value_observer interface and records the last observed value. The time series data generated by the simulation process is acquired and saved in real time through observer::time_series_observer, and the generated data is saved locally in csv format in real time through observer::file_observer.
[0095] Preferably, the overall process of performing simulation operation in the simulation phase includes:
[0096] Define the execution structure. In the execution class, define the cosim namespace through forward declaration and add declarations of four interface classes: algorithm, observer, manipulator, and simulator. These four interfaces represent the simulation algorithm, simulation observer, simulation operator, and FMU simulator respectively.
[0097] Call algorithm_->setup through the execution class constructor to set the algorithm and initialize the current time, algorithm and other internal states;
[0098] When initialization is complete, proceed to add components and execute the following functions:
[0099] add_slave: add a slave simulator and notify observers and operators;
[0100] add_function: add a function to execution;
[0101] add_observer: adds an observer and notifies the simulation initialization when necessary;
[0102] add_manipulator: add an operator;
[0103] Before the simulation starts, set initial values for different types of variables and expose them before the simulation starts;
[0104] When running the simulation, current_time is used to return the current logical time, the simulation starts, a step of simulation is performed using the step function, the time and step count are updated, and the observer is notified;
[0105] Use the get_model_description function to get the model description of the specified simulator, and use the simulate_until or simulate_until_async function to simulate to the specified time according to whether synchronous simulation or asynchronous simulation is used;
[0106] Use the is_running function to check whether the simulation is running. If it is running, use the get_real_time_config and get_real_time_metrics functions to get the real-time configuration and metrics, and use the get_modified_variables function to get the modified variables;
[0107] When you need to end the simulation, call stop_simulation to stop the simulation.
[0108] In the present invention, by establishing a general simulation integration framework method, it is possible to support the integration of different simulation software; standardize data exchange and interfaces, define a unified data exchange format and interface protocol, so as to achieve efficient and accurate data exchange between different simulation models.
[0109] According to the present invention, the simulation algorithm is a fixed_step_algorithm algorithm, which inherits the algorithm class;
[0110] The pseudo code of the fixed_step_algorithm algorithm includes:
[0111] 1. Initialization:
[0112] a. Initialize internal data structures;
[0113] b. Initialize each simulator;
[0114] c. Initialize each function;
[0115] d. Set the initial value of the connection variable;
[0116] e. Optionally perform iterative initialization to reach a steady-state value;
[0117] 2. Settings:
[0118] a. Record the start time and optional end time;
[0119] b. Make sure all simulators and functions are configured correctly;
[0120] c. Establish variable connections according to regulations;
[0121] d. Set the step size factor;
[0122] e. Add simulator;
[0123] f. Add function;
[0124] g. Connection variables;
[0125] 3. Execution:
[0126] a. Determine the current simulation time;
[0127] b. For each emulator:
[0128] i. Calculate the next step size of the simulator based on the base step size and any allocation factors;
[0129] ii. Execute the simulator's step function;
[0130] iii. Collect the output values of the simulator;
[0131] c. For each function:
[0132] i. Collect input values from connected simulators;
[0133] ii. Execute the function;
[0134] iii. Update the output variables of the connection;
[0135] d. Pass the output value to the connected input variable at the communication point;
[0136] e. Update the simulation time according to the basic step size or the minimum step size in the simulator;
[0137] 4. Remove the emulator:
[0138] a. Unregister the emulator by index;
[0139] 5. Disconnect variables:
[0140] a. Disconnect any previously established connection to the specified input variable;
[0141] End the algorithm.
[0142] According to the present invention, the simulation observer records a specific signal through an XML file, and the implementation process includes:
[0143] Use the slave_value_provider class to manage and provide access to different types of variable samples, and directly obtain FMU data and provide it to the last_value_observer class;
[0144] Use the last_value_observer class to track and obtain the latest value of each simulator during the simulation process;
[0145] Through the collaborative work of file_observer class, file_observer class and slave_value_writer class, the data is recorded in parallel and the real-time detected FMU data is saved in csv format;
[0146] Use the simulator_added and simulator_removed methods in the time_series_observer class to dynamically add and remove simulators, monitor the output variables of multiple simulators in real time, and record their changes;
[0147] Use the observe method to record the data of the current time step and time point, use the get_real_samples and get_integer_samples methods to obtain the real and integer samples of the specified time period, use the get_synchronized_real_series method to obtain the synchronized real sequence samples of the two simulators, use the start_observing and stop_observing methods to start and stop observing the variables of the specified type and reference during the simulation, and control the number of monitored variables;
[0148] The simulation operator uses the override_manipulator class to add and remove FMU simulators, overwrite and reset variables. The implementation process includes:
[0149] Before the simulation starts, the internal function find_variable_causality is used to find the matching variable in the variable list and return its causal relationship. If it is not found, an exception is thrown. The internal function is_input is used to determine whether the variable is an input type. If the type is not supported, an exception is thrown.
[0150] At the beginning of the simulation, the simulator is added to the simulators_map using the simulator_added method. During the running of the FMU simulator, the step_commencing method is used to lock the operation, traverse all pending operations, apply modifiers according to the variable type, and according to the results of the FMU simulator running, the add_action method is used to add an action for the specified FMU simulator, including variable references, types and modifiers;
[0151] During simulation, override_real_variable, override_integer_variable, override_boolean_variable, and override_string_variable are used to override real, integer, Boolean, and string variables.
[0152] Use reset_variable to reset the variable according to the variable type, set its modifier to nullptr, and refresh the state.
[0153] According to the present invention, the FMU simulator has automatic state management, variable caching and management, modifier support, and simulation control functions, and its implementation process includes:
[0154] Use the state_guard class to manage the slave_state type value of the FMU instantiation object. The slave_state contains the following states:
[0155] created: indicates that the slave simulator has been created but has not yet been initialized or simulated;
[0156] indeterminate: indicates an uncertain state, usually used to temporarily set the state during state transition;
[0157] initialisation: indicates that the slave simulator is in the initialization process;
[0158] simulation: indicates that the slave simulator is in simulation running state;
[0159] error: indicates that an error occurred during the operation and the simulator entered an error state;
[0160] Use the slave_simulator class to provide an external interface for execution and manipulator interfaces to call, which is used to implement state management, expose and access variables, and simulate operation functions. The calling process includes setup, iteration, startup, and execution steps.
[0161] Use the impl class to implement specific logic, including exposing variables, getting and setting variable values, setting modifiers, and iteration and simulation;
[0162] In the process of initializing variable management, expose_for_getting and expose_for_setting methods are used to expose different types of variables, and the exposed variables are used in two template classes, get_variable_cache and set_variable_cache, to manage and cache two different types of variables in the simulator;
[0163] For the simulation control of a single FMU, use the setup method to set up the simulation, use the start_simulation method to start the simulation, use the do_step method to execute the simulation step, and use the do_iteration method to iterate. During the simulation process, use state_guard to automatically manage the state based on the simulation results.
[0164] According to the present invention, the distributed co-simulation is implemented by setting up a proxy function, including three processes: URI resolution and model search, model resolution and creation, and remote proxy unit initialization, which are respectively implemented through the three interfaces proxy::proxy_uri_sub_resolver, proxy::remote_fmu, and proxy::remote_slave;
[0165] The URI parsing and model lookup process includes:
[0166] Use the proxy::proxy_uri_sub_resolver interface to parse and process the uniform resource identifier and find the model through the proxy to solve the problem of finding and loading FMU on the remote server;
[0167] Use the parse_authority function to parse the authority part of the URI and return the host and port. The specific logic is: look for the position of :. If not found, return the host name and port -1; if found, extract the part before as the host name, and convert the part after to an integer as the port;
[0168] The query part is parsed using the lookup_model function. The function has two overloads. The first overload looks up the model based on the base URI and model URI reference, and the second overload looks up the model based on the model URI. If the first overload is used, the second overload type will be recursively called during the parsing process. The specific logic includes:
[0169] The lookup_model function is the first overload;
[0170] Check the query part of the URI. If it contains file=file: / / / , construct a new query string and recursively call lookup_model.
[0171] If the query part contains file=, construct a new query string and recursively call lookup_model;
[0172] The lookup_model function is the second overload;
[0173] Check if the scheme part of the URI exists and check if it is proxyfmu;
[0174] Use parse_authority to parse the authority part;
[0175] Check if the query part starts with file=, extract the file path and check if the file exists;
[0176] If the host is localhost and the port is -1, create a remote_fmu object;
[0177] Otherwise, create a remote_fmu object using the host and port information;
[0178] Parsing and creating models includes:
[0179] Use the proxy::remote_fmu interface to read the model description information from the proxyfmu library and convert it into a format that can be used by the one-dimensional co-simulation coupler. It also provides methods to instantiate slave objects.
[0180] Use parse_model_description to parse the proxyfmu::fmi::model_description type object into cosim::model_description type, traverse the model variable list, set the name, reference, type, causality and mutability of each variable, set the starting value according to the variable type, and finally return a cosim::model_description smart pointer;
[0181] Through the constructor of the remote_fmu class, the proxy_fmu object is initialized with the given FMU path and remote information, and the model description is parsed and assigned to modelDescription_.
[0182] Remote agent unit initialization includes:
[0183] Provides an interface for remote slave unit interaction, using the proxy::remote_slave interface to support simulation setup, startup, termination, and variable acquisition and setting, and ensures clear error information is provided when the state is abnormal through exception handling;
[0184] Initialize the remote_slave object using the remote_slave constructor, receive an exclusive pointer to the slave object and a shared pointer to modelDescription, and return the value of modelDescription through model_description;
[0185] The simulation control of remote FMU is realized through the four methods of setup, start_simulation, end_simulation and do_step.
[0186] In the present invention, one-dimensional joint simulation integration and collaboration between different fields or different systems are realized, and the one-dimensional joint simulation process is managed, so that the one-dimensional joint simulation process is standardized, thereby reducing the simulation difficulty, making the one-dimensional joint simulation widely used in the simulation industry, and making the simulation results closer to the real-world results.
[0187] The present invention will be described in more detail below by way of examples.
[0188] Embodiment 1:
[0189] This embodiment proposes a joint simulation method between one-dimensional models of cloud chain tools based on the FMI standard, which includes the following three stages:
[0190] 1. Initialization phase: The coupler reads all FMU description xml files through the cosim::model_description interface, uses the cosim::system_structure interface to read the global coupling configuration file, uses the fmi::glue interface to convert the FMU that complies with the FMI 1.0 / 2.0 protocol to generate a data structure that the coupler can read. The FMU model object is instantiated through the slave_instance::fmiInstantiateModel interface, and the slave_instance::fmiInitialize interface is responsible for model initialization. Simulation and scene settings also need to be configured, and the specific configuration is detailed below;
[0191] 2. Simulation phase: As the simulation step length advances, the following operations will be performed inside each instantiated FMU: the slave_instance::fmiGetDerivatives interface is responsible for obtaining the derivatives of continuous state variables, the slave_instance::fmiSetTime interface is responsible for synchronizing the time between the simulation platform and the model itself, the slave_instance::fmiSetReal interface is responsible for setting the input vector, the slave_instance::fmiSetContinuousStates interface is responsible for updating the continuous state variables, the slave_instance::fmiGetEventIndicators interface is responsible for obtaining the event monitoring vector, and when the event is judged to be triggered, the slave_instance::fmiGetContinuousStates interface is responsible for The slave_instance::fmiGetReal interface is responsible for reacquiring the continuous state vector, and the slave_instance::fmiGetReal interface is responsible for updating the output vector; during the simulation process, the global state control and data control process between multiple FMUs are implemented through the slave_simulator class, and the coupler monitors the state changes of each FMU instance through the observer::last_value_observer interface and records the last observed value; the time series data generated by the simulation process is acquired and saved in real time through the observer::time_series_observer, and the generated data is saved locally in csv format in real time through the observer::file_observer; at the same time, for distributed HPC with proxy enabled, the coupler can call remote resources to instantiate FMU through IP and port to realize distributed joint simulation;
[0192] 3. Ending stage: slave_instance::fmiTerminate interface is responsible for terminating the simulation, and slave_instance::fmiFreeModelInstance interface is responsible for destructing the model instance and releasing the memory;
[0193] In this embodiment, the schematic diagram of the one-dimensional joint simulation system is as follows: Figure 2 As shown;
[0194] In this embodiment, the joint simulation method between one-dimensional models of cloud chain tools based on the FMI standard is described through the following steps:
[0195] Step 1 Model parsing: The one-dimensional simulation model is uploaded to the joint simulation coupler in the form of FMU. The FMU saves the model-related description information in XML format in a file such as modelDescription.xml. The configuration information of the FMU simulation model can be obtained by parsing the XML file. This information is the basis for realizing joint simulation parameter configuration, simulation intermediate data transmission and other functions. Therefore, we developed an FMU parsing component based on the FMI protocol and integrated it into the chain tool platform. The FMU parsing component can parse the uploaded model that complies with the FMI 1.0 / 2.0 standard, read the model configuration file, and identify the input and output parameters of the model, laying a foundation for subsequent parameter mapping, as shown in Table 1.
[0196] Table 1 Simulation system structural elements
[0197]
[0198]
[0199] In order to parse the FMU modelDescription.xml model description file and obtain different types of model variables, the 1D-1D co-simulation coupler implements the cosim::model_description interface; this interface provides a structured way to describe the model, covering various variable types, causality and variability; it implements utility functions such as text conversion and stream insertion, and uses robust type handling of variants and enumerations; it designs two data structures, model_description and variable_description, and provides a detailed schema to facilitate the integration and manipulation of data in the co-simulation environment;
[0200] Three variable enumeration types are defined: variable_type, variable_causality, and variable_variability:
[0201] variable_type: defines the possible types of variables;
[0202] real, integer, boolean, string, enumeration;
[0203] variable_causality: defines the role of the variable in the model;
[0204] parameter, calculated_parameter, input, output, local;
[0205] variable_variability: defines how the value of a variable changes over time;
[0206] constant, fixed, tunable, discrete, continuous;
[0207] Two structures are designed: model_description and variable_description. A model_description instance can contain multiple variable_description instances:
[0208] model_description describes an FMU model;
[0209] name: model name;
[0210] uuid: unique identifier;
[0211] description: FMU description;
[0212] author: author information;
[0213] version: version information;
[0214] variables: list of variables;
[0215] variable_description describes a model variable in FMU;
[0216] name: unique identifier;
[0217] reference: a numerical identifier;
[0218] type: data type;
[0219] causality: causality;
[0220] variability: variability;
[0221] start: optional starting value;
[0222] Step 2 Simulation configuration: After parsing the uploaded FMU, the joint simulation environment needs to configure the simulation system; the system structure configuration format is based on the OSP interface specification (OSP-IS), which is used to configure the simulation system structure, including the connection between FMUs and the initial value setting of input and parameter variables. The configuration file format is XML; in order to realize the configuration of the joint simulation system and achieve the purpose of joint simulation of multiple FMUs, the cosim::system_structure interface is designed; the entity and connection structures are designed to handle the management of entities and variables in the simulation system to ensure that the connection and value allocation between variables are valid; the function_io_description structure contains a detailed description of the function variable and the position index of the variable in the function, supporting efficient variable management and connection verification;
[0223] Structure entity: describes the information of the simulation FMU instance;
[0224] name: instance name;
[0225] type: instance type (FMU or function);
[0226] step_size_hint: recommended step size (valid only for FMU);
[0227] parameter_values: function parameter values (valid only for functions);
[0228] Structure connection: describes the connection between variables;
[0229] source: source variable;
[0230] target: target variable;
[0231] Structure function_io_description: describes the input and output of function variables, including group index and variable index;
[0232] group_index: variable group index;
[0233] io_index: variable index;
[0234] description: function I / O description;
[0235] In the scenario of multiple FMU joint simulation, after the cosim::structure interface reads the simulation configuration XML file, the FMU read by the cosim::model_description interface can be instantiated into multiple entities to form the variable entities_, and multiple connection structures can be instantiated to establish the variable connection_ between the variables of multiple FMUs; the functions get_variable_description and get_function_io_description respectively obtain the simulator variable description and function variable description according to the full name of the variable; the single variable value first needs to be checked for validity by the is_valid_variable_value function, and then the is_valid_connection function is used to check whether the connection between the variables is valid with other variables. After passing the two validity checks, the add_variable_value function is used to add it to the variable_value_map; during the above process, cosim::structure will save the cache of model information modelCache_ and function information functionCache_ for fast search; at the same time, boost::hash_combine is used to hash the member variables, and indexes are established on frequently accessed data structures (entity, connection) to improve the search speed and data access efficiency;
[0236] Step 3 Simulation execution: After the simulation configuration phase is completed, multiple FMU models and variables and functions in the FMU models have been loaded into the simulation system. In order to facilitate the management of simulation operations and coordinate the operation of multiple FMUs and functions, a structure execution is designed for the one-dimensional one-dimensional joint simulation coupler. The simulation performance and efficiency are improved by optimizing simulation steps, managing time steps, and coordinating data transmission between simulators. At the same time, the execution class ensures the accuracy and consistency of data transmission during the simulation process through strict variable connection and verification mechanisms, reducing potential simulation errors. The execution class supports both synchronous and asynchronous simulation operation modes, providing flexible simulation control options to meet different application requirements.
[0237] In the execution class, the cosim namespace is further defined through forward declaration, and the declarations of four interface classes, algorithm, observer, manipulator, and simulator, are added. These four interfaces represent the simulation algorithm, simulation observer, simulation operator, and FMU simulator, respectively, and will be described in detail in the following subsections; the execution class constructor calls algorithm_->setup to set up the algorithm and initialize the current time, algorithm, and other internal states; after the initialization is completed, the component adding process is carried out, and the following functions are executed:
[0238] add_slave: add a slave simulator (FMU) and notify observers and operators;
[0239] add_function: add a function to execution;
[0240] add_observer: adds an observer and notifies the simulation initialization when necessary;
[0241] add_manipulator: add an operator;
[0242] Before the simulation starts, set initial values for different types of variables and expose them before the simulation starts; when running real-time simulation, use current_time to return the current logical time; when the simulation starts, use the step function to perform a step of simulation, update the time and step count, and notify the observer; the get_model_description function obtains the model description of the specified simulator, and uses the simulate_until or simulate_until_async function to simulate to the specified time according to whether synchronous simulation or asynchronous simulation is used, and the is_running function is used to check whether the simulation is running; if it is still running, use the get_real_time_config and get_real_time_metrics functions to obtain the real-time configuration and indicators, and use the get_modified_variables function to obtain the modified variables; when you need to end the simulation, call stop_simulation to stop the simulation;
[0243] Step 4 simulation algorithm: The cosim::algorithm interface defines a base class and provides a series of virtual functions for managing the connection, initialization and execution steps of simulators and functions, which is convenient for the inheritance and implementation of various specific algorithms; currently the fixed_step_algorithm algorithm is used, which inherits the algorithm class, indicating that the one-dimensional one-dimensional joint simulator adopts a fixed-step collaborative simulation algorithm; the constructor of the fixed_step_algorithm class accepts baseStepSize and optional workerThreadCount parameters; rewrite the main method functions: methods add_simulator(), remove_simulator(), add_function() for managing simulators and functions; methods connect_variables() and disconnect_variable() for connecting and disconnecting variables; methods setup(), initialize() and do_step() for setting, initializing and executing simulation steps; the following is the pseudo code of the fixed_step_algorithm algorithm:
[0244] 1. Initialization:
[0245] a. Initialize internal data structures;
[0246] b. Initialize each simulator;
[0247] c. Initialize each function;
[0248] d. Set the initial value of the connection variable;
[0249] e. Optionally perform iterative initialization to reach a steady-state value;
[0250] 2. Settings:
[0251] a. Record the start time and optional end time;
[0252] b. Make sure all simulators and functions are configured correctly;
[0253] c. Establish variable connections according to regulations;
[0254] d. Set the step size factor;
[0255] e. Add simulator;
[0256] f. Add function;
[0257] g. Connection variables;
[0258] 3. Execute (for each time step):
[0259] a. Determine the current simulation time (currentT);
[0260] b. For each emulator:
[0261] i. Calculate the next step size of the simulator based on the base step size and any allocation factors;
[0262] ii. Execute the simulator's step function;
[0263] iii. Collect the output values of the simulator;
[0264] c. For each function:
[0265] i. Collect input values from connected simulators;
[0266] ii. Execute the function;
[0267] iii. Update the output variables of the connection;
[0268] d. Pass the output value to the connected input variable at the communication point;
[0269] e. Update the simulation time according to the basic step size or the minimum step size in the simulator;
[0270] 4. Remove the emulator:
[0271] a. Unregister the emulator by index;
[0272] 5. Disconnect variables:
[0273] a. Disconnect any previously established connection (whether simulator or function) to the specified input variable;
[0274] End the algorithm;
[0275] Step 5 Simulation observer: During the 1D-1D co-simulation process, users have the need to monitor various parameters of FMU in real time. The cosim::observer interface can meet the user's needs for real-time monitoring and recording of simulation data by implementing four classes: file_observer, last_value_observer, slave_value_provider, and time_series_observer. It can trigger event responses, support debugging and optimization of the simulation process, and provide result visualization and system integration functions, thereby helping users to fully control and improve the collaborative simulation effect;
[0276] By default, all signal changes at each instant are logged; one file will be generated for each simulator; this can quickly lead to a large amount of data being generated, to avoid this, we use a configurable log format to specify which signals to log; the 1D-1D co-simulation coupler supports basic configuration for logging specific signals for any simulator through an XML file, as shown in Table 2;
[0277] Table 2 Simulator element table
[0278]
[0279]
[0280] Among these four classes, slave_value_provider is the lowest level class, which manages and provides access to samples of different types of variables: real numbers, integers, Boolean values, and strings. It directly obtains the data of FMU and provides it to the last_value_observer class. The last_value_observer class implements an observer mode, and its main function is to track and obtain the latest values of each simulator during the simulation process.
[0281] The file_observer class supports parallel data recording of multiple simulators through the collaboration of the file_observer and slave_value_writer classes. It can flexibly select the variables to be recorded and control the recording frequency according to the configuration, and implement a powerful logging mechanism that can save the real-time detected FMU data in csv format. The definitions of the two classes are as follows:
[0282] slave_value_writer class:
[0283] Responsible for recording data obtained from observable objects;
[0284] Constructor:
[0285] Initialize default records or configuration-based records;
[0286] Observation method:
[0287] observe method: record variable values according to step length;
[0288] To start and stop logging:
[0289] start_recording and stop_recording methods: control the start and stop of recording;
[0290] Internal initialization method:
[0291] initialize_default and initialize_config methods: initialize the variables to be recorded, respectively, by default and according to external configuration;
[0292] Create log files and metadata files:
[0293] create_log_file and create_metadata_file methods: create log files and corresponding metadata files;
[0294] Data persistence:
[0295] persist method: write the sampled data into the log file;
[0296] file_observer class:
[0297] Manage recording operations for multiple emulators;
[0298] Constructor:
[0299] Accepts a log directory and optional configuration parameters;
[0300] Emulator Management:
[0301] simulator_added and simulator_removed methods: manage the addition and removal of simulators;
[0302] Record Control:
[0303] start_recording and stop_recording methods: control the global switch of recording;
[0304] Configuration analysis:
[0305] parse_config method: parses the record configuration of the specified simulator;
[0306] Utility functions:
[0307] find_simulator and get_log_path methods: assist in finding the simulator and obtaining the log path;
[0308] The time_series_observer class that manages time series observers can dynamically add and remove simulators through simulator_added and simulator_removed methods, monitor the output variables of multiple simulators in real time, and record their changes; each simulator has an independent single_slave_observer instance to record the time series data of the simulator; it can obtain the synchronized data of multiple simulators at the same time step for analysis and comparison; the observe method is used to record the data of the current time step and time point; use the get_real_samples and get_integer_samples methods to obtain real and integer samples of the specified time period;
[0309] At the same time, the get_synchronized_real_series method is used to obtain synchronized real sequence samples of the two simulators; the variables that need to be monitored can be dynamically added and removed to improve the flexibility and efficiency of the simulation; the start_observing and stop_observing methods are used to start and stop observing variables of specified types and references during the simulation, and the number of monitored variables can be controlled;
[0310] Step 6 Simulation operator: The one-dimensional one-dimensional joint simulation coupler provides functions such as adding and removing FMU simulators, overwriting and resetting variables by designing a simulator operator class override_manipulator; under the coupler architecture, all FMU simulators are at the same level, and the simulator operator controls the interaction of FMU simulator variables;
[0311] Before the simulation starts, two internal functions are used to check the validity of parameters. The internal function find_variable_causality searches for matching variables in the variable list and returns their causal relationship. If not found, an exception is thrown. The internal function is_input determines whether the variable is of input type. If the type is not supported, an exception is thrown. At the beginning of the simulation, the simulator_added method adds the simulator to the simulators_map. During the operation of the FMU simulator, the step_commencing method locks the operation, traverses all pending operations, and applies modifiers according to the variable type. According to the results of the simulator operation, the add_action method adds an operation to the specified FMU simulator, including variable references, types, and modifiers. During the joint simulation operation, override_real_variable, override_integer_variable, override_boolean_variable, and override_string_variable will perform operations to override real, integer, Boolean, and string type variables. At the same time, the simulator operator also allows reset operations, which is equivalent to refreshing the current state in some application scenarios. reset_variable resets the variable according to the variable type and sets its modifier to nullptr.
[0312] Step 7 FMU simulator: In addition to the operator, the one-dimensional one-dimensional joint simulation system also needs to be equipped with an FMU simulator; it needs to have functions such as automatic state management, variable caching and management, modifier support, simulation control, etc., and is suitable for simulation scenarios with multiple types of variables;
[0313] During the operation of FMU, state management is required. The automatic state management of FMU is realized through the state_guard class, which mainly manages the slave_state type value of the FMU instantiation object. The slave_state contains the following states:
[0314] created: indicates that the slave simulator has been created but has not yet been initialized or simulated;
[0315] indeterminate: indicates an uncertain state, usually used to temporarily set the state during state transition;
[0316] initialisation: indicates that the slave simulator is in the initialization process;
[0317] simulation: indicates that the slave simulator is in simulation running state;
[0318] error: indicates that an error occurred during the operation and the simulator entered an error state;
[0319] The slave_simulator class provides external interfaces for execution, manipulator and other interfaces to call, mainly realizing functions such as state management, exposing and accessing variables, simulation operations, including setting, iteration, starting and execution steps; internally, the specific logic is implemented through the impl class, which is divided into four categories: exposing variables, getting and setting variable values, setting modifiers, and iteration and simulation;
[0320] During the initialization of variable management, expose_for_getting and expose_for_setting methods are provided to expose different types of variables; the exposed variables are used in two template classes, get_variable_cache and set_variable_cache, to manage and cache two different types of variables in the simulator; for the simulation control of a single FMU, the setup method is used to set up the simulation, the start_simulation method is used to start the simulation, the do_step method is used to execute the simulation step, and the do_iteration method is used to iterate; during the simulation process, state_guard is used to automatically manage the state according to the simulation results, and the appropriate state is set during construction and destruction;
[0321] Step 8 Distributed co-simulation proxy: This is achieved by setting up a proxy function, which can call and run FMUs that are incompatible with the operating system or bit number of the main computing node, greatly enhancing the compatibility of co-simulation;
[0322] The implementation of distributed co-simulation requires three processes: URI resolution and model search, model parsing and creation, and remote proxy unit initialization, which are implemented through the three interfaces proxy::proxy_uri_sub_resolver, proxy::remote_fmu, and proxy::remote_slave respectively;
[0323] The main function of proxy::proxy_uri_sub_resolver is to parse and process the Uniform Resource Identifier (URI), and to find the model through the proxy, which can solve the problem of finding and loading FMU on the remote server; the parts that need to be parsed include parsing the authority part (host and port) and the query part (file path); the parse_authority function is used to parse the authority part of the URI and return the host and port; the specific logic is to find the location of :, if not found, return the host name and port -1; if found, extract the part before : as the host name, and convert the part after : into an integer as the port; the query part is parsed using the lookup_model function, which has two overloads, the first overload finds the model based on the base URI and model URI reference, and the second overload finds the model based on the model URI; if the first overload is used, the second overload type will be recursively called during the parsing process; the specific logic is as follows:
[0324] lookup_model function (first overload)
[0325] Check the query part of the URI. If it contains file=file: / / / , construct a new query string and recursively call lookup_model.
[0326] If the query part contains file=, construct a new query string and recursively call lookup_model;
[0327] lookup_model function (second overload)
[0328] Check if the scheme part of the URI exists and check if it is proxyfmu;
[0329] Use parse_authority to parse the authority part;
[0330] Check if the query part starts with file=, extract the file path and check if the file exists;
[0331] If the host is localhost and the port is -1, create a remote_fmu object;
[0332] Otherwise, create a remote_fmu object using the host and port information;
[0333] proxy::remote_fmu is mainly responsible for reading model description information from the proxyfmu library and converting it into a format that can be used by the one-dimensional one-dimensional co-simulation coupler. It also provides methods for instantiating subordinate objects; using parse_model_description, objects of type proxyfmu::fmi::model_description are parsed into cosim::model_description types; traversing the model variable list, setting the name, reference, type, causality, and variability of each variable, and setting the starting value according to the variable type; finally returning a smart pointer to cosim::model_description; the constructor of the remote_fmu class initializes the proxy_fmu object with the given FMU path and remote information, and parses the model description and assigns it to modelDescription_;
[0334] In order to realize remote distributed co-simulation, similar to the setting of local co-simulation, it is necessary to provide an interface for remote slave unit interaction. Proxy::remote_slave supports simulation setting, startup, termination, and variable acquisition and setting; and can ensure clear error information when the state is abnormal through exception handling; remote_slave constructor initializes remote_slave object, receives an exclusive pointer to slave object and shared pointer to modelDescription; model_description returns the value of modelDescription; remote FMU simulation control is implemented through four methods: setup, start_simulation, end_simulation, and do_step;
[0335] Step 9 interface / class diagram as follows Figure 3 shown.
[0336] The embodiment of the present invention proposes a joint simulation method between one-dimensional models of cloud-based chain tools based on the FMI standard, which realizes precise synchronization of simulation time by precisely controlling the internal parameters and operations of each instantiated FMU, including fixed-step synchronization and event-driven synchronization mechanisms, to meet the needs of different simulation tasks; through global state control and data control between multiple FMUs, control functions such as configuration, start, pause, continue and stop of simulation tasks, as well as monitoring and logging of the simulation process are realized.
[0337] The embodiments of the present invention have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments.
Claims
1. A joint simulation method between one-dimensional models of cloud-based chain tools based on the FMI standard, characterized in that: include: Initialization phase: read all FMU description XML files and global coupling configuration files, parse the FMU model that meets the FMI standard, instantiate and initialize the FMU, and configure the simulation; Simulation phase: Each instantiated FMU performs operations such as obtaining continuous state variable derivatives, time synchronization, setting input vectors, updating continuous state variables, obtaining event monitoring vectors, re-obtaining continuous state vectors, and updating output vectors. At the same time, global state control and data control are performed between multiple FMUs, time series data is acquired and saved in real time, and generated data is saved. For incompatible FMUs, distributed joint simulation is performed; End phase: terminate the simulation, destroy the model instance and release the memory.
2. The method according to claim 1, characterized in that: All FMU description XML files are read through the cosim::model_description interface; The global coupling configuration file is read via the cosim::system_structure interface; The interface used for model parsing is the fmi::glue interface; The FMI standard is in compliance with the FMI 1.0 / 2.0 protocol; The interfaces used for the instantiation are slave_instance::fmiInstantiateModel interfaces; The interface used for the initialization is the slave_instance::fmiInitialize interface; The system used for the one-dimensional joint simulation includes a coupling controller and at least two FMU models; Each FMU model communicates with the coupling controller via an FMU standard interface; Each FMU model includes a solver, a simulation parameter module, an input parameter module, and an output parameter module; Each FMU model performs parameter mapping with adjacent FMU models through its own input parameter module and output parameter module; The coupling controller comprises a global simulation control module, a coupling mode module, a simulation step time control module, a communication control module and a simulation parameter control module.
3. The method according to claim 1, characterized in that The FMU description XML file is to save the description information related to the model in the FMU in the modelDescription.xml file in XML format; The operation process of model parsing the FMU that meets the FMI standard includes: Three variable enumeration types are defined: variable_type, variable_causality, and variable_variability: variable_type: defines the possible types of variables; real, integer, boolean, string, enumeration; variable_causality: defines the role of the variable in the model; parameter, calculated_parameter, input, output, local; variable_variability: defines how the value of a variable changes over time; constant, fixed, tunable, discrete, continuous; Two structures are designed: model_description and variable_description. A model_description instance contains multiple variable_description instances: model_description describes an FMU model; name: model name; uuid: unique identifier; description: FMU description; author: author information; version: version information; variables: list of variables; variable_description describes a model variable in FMU; name: unique identifier; reference: a numerical identifier; type: data type; causality: causality; variability: variability; start: Optional starting value.
4. The method according to claim 1, characterized in that The simulation configuration includes: Design the cosim::system_structure interface; Design two structures, entity and connection, to handle the management of entities and variables in the simulation system and ensure that the connections and value assignments between variables are valid; Define the function_io_description structure to support efficient variable management and connection verification; Structure entity: describes the information of the simulation FMU instance; name: instance name; type: instance type is FMU or function; step_size_hint: recommended step size is only valid for FMU; parameter_values: Function parameter values are only valid for functions; Structure connection: describes the connection between variables; source: source variable; target: target variable; Structure function_io_description: describes the input and output of function variables, including group index and variable index; group_index: variable group index; io_index: variable index; description: function I / O description; The cosim::model_description interface is used to instantiate multiple entities of the read FMU to form the variable entities_, and is also used to instantiate multiple connection structures to establish variable connections between the variables of multiple FMUs.
5. The method according to claim 1, characterized in that The acquisition of continuous state variable derivatives is completed through the slave_instance::fmiGetDerivatives interface; The time synchronization is the time synchronization between the real platform and the model itself, which is completed through the slave_instance::fmiSetTime interface; The setting of the input vector is completed through the slave_instance::fmiSetReal interface; The updating of the continuous state variable is completed through the slave_instance::fmiSetContinuousStates interface; The acquisition of the event monitoring vector is completed through the slave_instance::fmiGetEventIndicators interface; The re-acquiring the continuous state vector includes re-acquiring the continuous state vector when the judgment event is triggered, which is completed through the slave_instance::fmiGetContinuousStates interface; The updating output vector is completed through the slave_instance::fmiGetReal interface; Perform global state control and data control between multiple FMUs, acquire and save time series data in real time, and save the generated data including: During the simulation process, global state control and data control between multiple FMUs are implemented through the slave_simulator class. The coupler monitors the state changes of each FMU instance through the observer::last_value_observer interface and records the last observed value. The time series data generated by the simulation process is acquired and saved in real time through observer::time_series_observer, and the generated data is saved locally in csv format in real time through observer::file_observer.
6. The method according to claim 1, characterized in that The overall process of performing simulation operation in the simulation phase includes: Define the execution structure. In the execution class, define the cosim namespace through forward declaration and add declarations of four interface classes: algorithm, observer, manipulator, and simulator. These four interfaces represent the simulation algorithm, simulation observer, simulation operator, and FMU simulator respectively. Call algorithm_->setup through the execution class constructor to set the algorithm and initialize the current time, algorithm and other internal states; When initialization is complete, proceed to add components and execute the following functions: add_slave: add a slave simulator and notify observers and operators; add_function: add a function to execution; add_observer: adds an observer and notifies the simulation initialization when necessary; add_manipulator: add an operator; Before the simulation starts, set initial values for different types of variables and expose them before the simulation starts; When running the simulation, current_time is used to return the current logical time, the simulation starts, a step of simulation is performed using the step function, the time and step count are updated, and the observer is notified; Use the get_model_description function to get the model description of the specified simulator, and use the simulate_until or simulate_until_async function to simulate to the specified time according to whether synchronous simulation or asynchronous simulation is used; Use the is_running function to check whether the simulation is running. If it is running, use the get_real_time_config and get_real_time_metrics functions to get the real-time configuration and metrics, and use the get_modified_variables function to get the modified variables; When you need to end the simulation, call stop_simulation to stop the simulation.
7. The method according to claim 6, characterized in that The simulation algorithm is the fixed_step_algorithm algorithm, which inherits the algorithm class; The pseudo code of the fixed_step_algorithm algorithm includes:
1. Initialization: a. Initialize internal data structures; b. Initialize each simulator; c. Initialize each function; d. Set the initial value of the connection variable; e. Optionally perform iterative initialization to reach a steady-state value; 2. Settings: a. Record the start time and optional end time; b. Make sure all simulators and functions are configured correctly; c. Establish variable connections according to regulations; d. Set the step size factor; e. Add simulator; f. Add function; g. Connection variables; 3. Execution: a. Determine the current simulation time; b. For each emulator: i. Calculate the next step size of the simulator based on the base step size and any allocation factors; ii. Execute the simulator's step function; iii. Collect the output values of the simulator; c. For each function: i. Collect input values from connected simulators; ii. Execute the function; iii. Update the output variables of the connection; d. Pass the output value to the connected input variable at the communication point; e. Update the simulation time according to the basic step size or the minimum step size in the simulator; 4. Remove the emulator: a. Unregister the emulator by index; 5. Disconnect variables: a. Disconnect any previously established connection to the specified input variable; End the algorithm.
8. The method according to claim 6, characterized in that The simulation observer records specific signals through an XML file, and the implementation process includes: Use the slave_value_provider class to manage and provide access to different types of variable samples, and directly obtain FMU data and provide it to the last_value_observer class; Use the last_value_observer class to track and obtain the latest value of each simulator during the simulation process; Through the collaborative work of file_observer class, file_observer class and slave_value_writer class, the data is recorded in parallel and the real-time detected FMU data is saved in csv format; Use the simulator_added and simulator_removed methods in the time_series_observer class to dynamically add and remove simulators, monitor the output variables of multiple simulators in real time, and record their changes; Use the observe method to record the data of the current time step and time point, use the get_real_samples and get_integer_samples methods to obtain the real and integer samples of the specified time period, use the get_synchronized_real_series method to obtain the synchronized real sequence samples of the two simulators, use the start_observing and stop_observing methods to start and stop observing the variables of the specified type and reference during the simulation, and control the number of monitored variables; The simulation operator provides the ability to add and remove FMU simulators, overwrite and reset variables through the override_manipulator class. The implementation process includes: Before the simulation starts, the internal function find_variable_causality is used to find the matching variable in the variable list and return its causal relationship. If it is not found, an exception is thrown. The internal function is_input is used to determine whether the variable is an input type. If the type is not supported, an exception is thrown. At the beginning of the simulation, add the simulator to the simulators_map using the simulator_added method. During the running of the FMU simulator, lock the operation using the step_commencing method, traverse all pending operations, apply modifiers according to the variable type, and according to the results of the running of the FMU simulator, add an operation for the specified FMU simulator using the add_action method, including variable references, types and modifiers. During simulation, override_real_variable, override_integer_variable, override_boolean_variable, and override_string_variable are used to override real, integer, Boolean, and string variables. Use reset_variable to reset the variable according to the variable type, set its modifier to nullptr, and refresh the state.
9. The method according to claim 6, characterized in that The FMU simulator has automatic state management, variable caching and management, modifier support, and simulation control functions, and its implementation process includes: The state_guard class is used to manage the slave_state type value of the FMU instantiation object. The slave_state contains the following states: created: indicates that the slave simulator has been created but has not yet been initialized or simulated; indeterminate: indicates an uncertain state, usually used to temporarily set the state during state transition; initialisation: indicates that the slave simulator is in the initialization process; simulation: indicates that the slave simulator is in simulation running state; error: indicates that an error occurred during the operation and the simulator entered an error state; Use the slave_simulator class to provide an external interface for execution and manipulator interfaces to call, which is used to implement state management, expose and access variables, and simulate operation functions. The calling process includes setup, iteration, startup, and execution steps. Use the impl class to implement specific logic, including exposing variables, getting and setting variable values, setting modifiers, and iteration and simulation; In the process of initializing variable management, expose_for_getting and expose_for_setting methods are used to expose different types of variables, and the exposed variables are used in two template classes, get_variable_cache and set_variable_cache, to manage and cache two different types of variables in the simulator; For the simulation control of a single FMU, use the setup method to set up the simulation, use the start_simulation method to start the simulation, use the do_step method to execute the simulation step, and use the do_iteration method to iterate. During the simulation process, use state_guard to automatically manage the state based on the simulation results.
10. The method according to claim 6, characterized in that The distributed joint simulation is implemented by setting up a proxy function, including three processes: URI resolution and model search, model resolution and creation, and remote proxy unit initialization, which are respectively implemented through the three interfaces proxy::proxy_uri_sub_resolver, proxy::remote_fmu, and proxy::remote_slave; The URI parsing and model search process includes: Use the proxy::proxy_uri_sub_resolver interface to parse and process the uniform resource identifier and find the model through the proxy to solve the problem of finding and loading FMU on the remote server; Use the parse_authority function to parse the authority part of the URI and return the host and port. The specific logic is: look for the position of :. If not found, return the host name and port -1; if found, extract the part before as the host name, and convert the part after to an integer as the port; The query part is parsed using the lookup_model function. The function has two overloads. The first overload looks up the model based on the base URI and model URI reference, and the second overload looks up the model based on the model URI. If the first overload is used, the second overload type will be recursively called during the parsing process. The specific logic includes: The lookup_model function is the first overload; Check the query part of the URI. If it contains file=file: / / / , construct a new query string and recursively call lookup_model. If the query part contains file=, construct a new query string and recursively call lookup_model; The lookup_model function is the second overload; Check if the scheme part of the URI exists and check if it is proxyfmu; Use parse_authority to parse the authority part; Check if the query part starts with file=, extract the file path and check if the file exists; If the host is localhost and the port is -1, create a remote_fmu object; Otherwise, create a remote_fmu object using the host and port information; The parsing and model creation includes: Use the proxy::remote_fmu interface to read the model description information from the proxyfmu library and convert it into a format that can be used by the one-dimensional co-simulation coupler. It also provides methods to instantiate slave objects. Use parse_model_description to parse the proxyfmu::fmi::model_description type object into cosim::model_description type, traverse the model variable list, set the name, reference, type, causality and mutability of each variable, set the starting value according to the variable type, and finally return a cosim::model_description smart pointer; Through the constructor of the remote_fmu class, the proxy_fmu object is initialized with the given FMU path and remote information, and the model description is parsed and assigned to modelDescription_. The remote agent unit initialization includes: Provides an interface for remote slave unit interaction, using the proxy::remote_slave interface to support simulation setup, startup, termination, and variable acquisition and setting, and ensures clear error information is provided when the state is abnormal through exception handling; Initialize the remote_slave object using the remote_slave constructor, receive an exclusive pointer to the slave object and a shared pointer to modelDescription, and return the value of modelDescription through model_description; The simulation control of remote FMU is realized through the four methods of setup, start_simulation, end_simulation and do_step.