Approximation model (TL)#
Appearance of the approximation model launching block#
Approximation model (TL) block is intended for use within the library Thermohydraulics of the set approximation models:
Neural networks, which are part of the algorithms of machine learning;
Gaussian processes;
Linear and nonlinear regression models.
Approximation Models can contain any nonlinear relations between the input parameters of the Model and calculation results that are difficult to describe by a software algorithm and require modern approaches such as neural networks and other machine learning methods.
The block is designed to call ((Inference)) approximation model and enable communication with other blocks of library Thermohydraulics.
Approximation model (TL) block loads the model from the neutral format ONNX.
Note
The External models library contains the Approximation model block, which is used to call ML models during modeling and exchange data with the Automation library blocks and other blocks containing the port type Automation.
1. Requirements for an approximation model interacting with Thermohydraulics library blocks#
Important
The basic requirements for the approximation model are presented in the description of a similar block of the library External models.
1.1. Requirements for formulating an approximation problem#
The approximation model must describe the following physical processes in the modeled system:
The process of fluid movement;
Heat exchange process.
A node must be a constituent element of the approximation model. Each node \(i\) in the model must include the following parameters:
Pressure \(\mathbf P_{i}\),
Temperature \(\mathbf T_{i}\).
Mass flow rate \(\dot{\mathbf m_i}\),
Enthalpy flow \(\mathbf H_i\).
At each node \(i\) of the approximation model, the dependences of the mass flow \( \dot{\mathbf m_i}\) and the enthalpy flow \(\mathbf H_i\) (1) on the pressure \(\mathbf P_{i}\) and temperature \(\mathbf T_{i}\) must be calculated.
in the (1) dependency, the index \(i\) denotes the ordinal number of the model node.
The approximation model must contain at least one node with the pressure parameter \(\mathbf P_1\) and temperature \(\mathbf T_1\) and the calculated values of mass flow \( \dot{\mathbf m_1}\) and enthalpy flow \(\mathbf H_1\).
Sign convention for calculating enthalpy flow and flow rate#
Positive direction of mass flow and enthalpy flow is accepted in the node of the approximation model.
The flow rate and enthalpy flux directed out of a model node are considered negative.
The diagram below shows two nodes of the approximation model with positive directions of the calculated values of mass flow rate and enthalpy flow.
Sign rule for calculating mass flow rate and enthalpy flux for an approximation model with two nodes.#
The diagram above uses the following notations.
Designations |
Description |
|---|---|
Blue circles |
Model nodes with temperature \(\mathbf T_i\) and pressure \(\mathbf P_{i}\) parameters |
Orange vectors |
Positive directions of mass flow \(\dot{\mathbf m_i}\) and enthalpy flow \(\mathbf H_i\) of the model |
Option for calculating the enthalpy flow and mass flow from one node to another#
The approximation model may contain two nodes, calculating one value of the enthalpy flow \(\mathbf H\) and one value of the mass flow \(\dot{\mathbf m}\), directed from node 1 to node 2 according to the diagram given below.
Calculation of enthalpy flow and mass flow rate directed from node 1 to node 2 of an approximation model with two nodes.#
In the case given above, the enthalpy flow towards node 2 is \(\mathbf H\), and the enthalpy flow of node 1 is \( - \mathbf H\). The mass flow rate \(\dot{\mathbf m}\) is determined similarly.
Option for calculating the enthalpy flow and mass flow rate at three nodes#
The approximation model can contain three or more nodes, calculating the values of enthalpy flows \(\mathbf H_i = g(\mathbf P_{i}, \mathbf T_{i})\) and mass flows \(\dot{\mathbf m_i} = f(\mathbf P_{i}, \mathbf T_{i})\) in each of the model nodes.
Calculation of enthalpy flows and mass flow rates at three nodes of the approximation model.#
1.2. Requirements for the parameters of the approximation model#
An approximation model that interacts with the blocks of the Thermohydraulics library must:
The input parameters to be taken are the values of pressures (P₁,P₂,Pₙ in the figure below) and temperatures (T₁,T₂,Tₙ) at the nodes of the modeled system element;
As a result of the calculation, the model should provide values of liquid mass flow rates (m₁, m₂, mₙ in the figure below) and enthalpy flows (H₁, H₂, Hₙ) at each node of the modeled system.
Исходные данные и результаты расчёта Аппроксимационной модели (ТГ)#
The following notations are used in the figure above.
Designation |
Dimension |
Description |
|---|---|---|
P₁, … , Pₙ |
Па |
Initial values of pressures in the nodes of the approximation model |
T₁, … , Tₙ |
\(^{\circ}C\) |
Initial temperature values of the approximation model |
m₁, … , mₙ |
kg/s |
Results of calculation of liquid mass flow rates |
H₁, … , Hₙ |
W |
Results of enthalpy flow calculations |
The physical quantities of the initial data and the results of the approximation model calculations must be presented in the SI system of units.
1.3. Requirements for additional description of the model#
The ML file of the ONNX model must contain additional description that allows the Approximation model (TL) block to unambiguously associate model nodes with pressures and temperatures, and to obtain the flow rate and enthalpy flux for each node in the calculation results.
Hint
To simplify the process of preparing an additional description of the ML thermal hydraulics model in the Python programming language, use the repeat_onnx module, reference to which is provided in the section Tools for interacting with ML models in Python.
Requirements for the content of the model description#
The additional description of the ML model must be a JSON string with the following keys.
Key - string type |
Meaning |
Description of value |
Value type |
|---|---|---|---|
|
|
The scientific direction of the developed model. For the |
Line |
|
|
List of model nodes |
List |
Each model node included in the [ ] list by the "nodes" key must have the following description of potentials and flows.
Key - string type |
Description of value |
|---|---|
|
The name of the model node to display on the ports of the |
|
Name of the pressure input parameter of this node |
|
Name of the temperature input parameter of this node |
|
The name of the output parameter with the result of the mass flow calculation in the node model |
|
The name of the output parameter with the result of calculating the enthalpy flow in the node model |
Below is a description of a model with a single node named "Output unit", in which the input parameters of the ML model are two potentials: "pressure_1" and "temperature_1", for pressure and temperature, respectively. The output parameters of the model node are two flows: "flowrate_1" and "enthalpy_flux_1", for the flow rate and enthalpy flux, respectively. The description is performed in the Python programming language.
1import json
2
3
4model_structure = {
5 "discipline" : "thermohydraulics",
6 "nodes" : [
7 {
8 "name" : "Output unit",
9 "pressure" : "pressure_1",
10 "temperature" : "temperature_1",
11 "flowrate" : "flowrate_1",
12 "enthalpy_flux" : "enthalpy_flux_1"
13 }
14 ]
15}
16model_structure_serialized = json.dumps(model_structure)
Requirements for posting additional description of the model#
An additional description of the ML model should be located in the metadata_props structure under the "repeat_contract" key.
Below is an example in which, for a pre-prepared ML model saved in the neutral ONNX format at path, an additional description of the model is written, which is necessary for use by the Approximation model (TL) block.
1import onnx
2
3
4description = onnx.StringStringEntryProto()
5description.key = "repeat_contract"
6description.value = model_structure_serialized
7model = onnx.load(path)
8model.metadata_props.append(description)
9onnx.save(model, path)
2. Properties#
No
3. Inputs and outputs#
Parameters |
Input/Output |
Description |
Units of measurement |
Port type |
|---|---|---|---|---|
Node names models |
Input |
The list of node names is generated based on the information about the nodes of the model from the ONNX file |
- |
Thermohydraulics |
Expenses |
Output |
The list of output ports is generated based on information about the set of output parameters (calculation results) of the model from the ONNX file |
kg/s |
Automation |
Enthalpy flows |
Output |
The list of output ports is generated based on information about the set of output parameters (calculation results) of the model from the ONNX file |
W |
Automation |
The block output ports are required to obtain the results of calculations of mass flow rates and enthalpy flows in the model nodes, as well as to transfer the calculation results to the Outport block.
Important
The Meter block does not support displaying the calculation results of the Approximation model (TL) block.
In order to see the connection capabilities of the block, you need to go to page Description of block ports