Approximation model (P)#
Appearance of the approximation model launching block#
Approximation model (P) block is intended for use within the library Pneumatics 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 Pneumatics.
Approximation model (P) block loads the model from the neutral format ONNX.
See also
Check out the how-to on using the Approximation model (P) block to integrate ML models into the REPEAT VISION platform.
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 Pneumatics 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 gas 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}\),
Energy flow \(\mathbf H_i\).
At each node \(i\) of the approximation model, the dependences of the mass flow rate \( \dot{\mathbf m_i}\) and the energy 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 energy flow \(\mathbf H_1\).
Sign convention for calculating energy consumption and flow#
Positive direction of mass flow and energy flow is accepted in the node of the approximation model.
Energy consumption and flow directed from a model node are considered negative.
The diagram below shows two nodes of the approximation model with positive direction of the calculated values of mass flow and energy flow.
Sign rule for calculating mass flow and energy 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 |
|
Positive directions of mass flow \(\dot{\mathbf m_i}\) and energy flow \(\mathbf H_i\) of the model |
Option for calculating the flow of energy and gas consumption from one node to another#
The approximation model may contain two nodes, calculating one value of energy flow \(\mathbf H\) and one value of mass flow \(\dot{\mathbf m}\), directed from node 1 to node 2 according to the diagram given below.
Calculation of energy 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 energy flow towards node 2 is \(\mathbf H\), and the energy flow of node 1 is \( - \mathbf H\). The mass flow rate \(\dot{\mathbf m}\) is determined similarly.
Option for calculating energy flow and gas consumption in three nodes#
The approximation model can contain three or more nodes, calculating the values of energy 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 energy flows and mass flow rates in 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 Pneumatics 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 gas mass flow rates (m₁, m₂, mₙ in the figure below) and energy flows (H₁, H₂, Hₙ) at each node of the modeled system.
Исходные данные и результаты расчёта Аппроксимационной модели (П) / Initial data and calculation results of the Approximation Model (P)#
The following notations are used in the figure above.
Designation |
Dimension |
Description |
|---|---|---|
P₁, … , Pₙ |
Pa |
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 gas mass flow rates |
H₁, … , Hₙ |
W |
Results of energy 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 (P) 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
Use the Python repeat_onnx package to simplify the preparation of additional ML description of the pneumatics model.
[An example](../../../../../howto/ml_approximation/orifice_gas_flow/index.md #prepare-ml-model-info) of preparing an additional description of the ML model is given in the practical guide to creating an approximation model of gas flow through a nozzle.
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 energy 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" : "pneumatics",
6 "nodes" : [
7 {
8 "name" : "Output unit",
9 "pressure" : "pressure_1",
10 "temperature" : "temperature_1",
11 "flowrate" : "flowrate_1",
12 "energy" : "energy_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 (P) 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 |
- |
Pneumatics |
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 |
Flows of energy |
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’s output ports are required to obtain the results of calculations of mass flow rates and energy 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 (P) block.
In order to see the connection capabilities of the block, you need to go to page Description of block ports.
4. Examples of use#
Examples of using this block can be found in the following sections:
Tutorials;
Description of Demo.
How-to guides
Section |
Guide name |
|---|---|
Machine learning approximation |