Practical work with model architecture in Engee
Page in progress. |
The theory of building model architecture in Engee is described in the article Model Architecture in Engee. It is recommended to read it before starting to study the current article. |
Subsystems and submodels are used to group blocks. A subsystem can be thought of as a function and a submodel as a plug-in file. In Engee they are implemented as follows:
Types of subsystems | Submodels | Other blocks for implementing subsystem behaviour | |
---|---|---|---|
Classic |
Block Subsystem |
Block Model (submodel) |
Block Chart |
Conditionally triggered |
Enabled Subsystem (Enabled Subsystem) Triggered (Triggered Subsystem) Triggered & Enabled Subsystem (Triggered & Enabled Subsystem) Resettable Subsystem (Resettable Subsystem) Function-Call (Function-Call) |
||
Control logics |
Action |
||
Multiple execution (computational cycles) |
For Each For Iterator |
For an example implementation of the various subsystems, go to link. |
Any Engee subsystem can be customised with masks (see Masks at Engee). |
Classic Subsystem
A Classical Subsystem is a block Subsystem, used to divide a model into modules without additional conditions or the need to control an external signal.
When to use a classic subsystem:
-
To simplify large models by breaking them into smaller modules;
-
To improve the structuring and readability of the model;
-
To transfer ready-made modules between models (copying subsystems).
For more information about the classical subsystem.
A block Subsystem contains a subset of blocks within a model or system and can be a non-virtual or virtual subsystem:
-
A non-virtual subsystem executes as a unit and can be configured to execute only on certain events.
-
A virtual subsystem does not execute as a unit and is independent of events. This subsystem helps to make the model more understandable without affecting its operation.
To switch the virtual subsystem to a non-virtual subsystem, set the Treat as atomic unit parameters to `true'.
*The *Classical subsystem has the following features:
-
Is not a managed subsystem;
-
Allows for a hierarchical model structure where one subsystem may contain another;
-
Cannot be saved as a separate file or subsystem. To save a subsystem as a separate model, the block Model (submodel) is used;
-
Does not affect the functionality and logic of the model.
How to use the classic subsystem:
-
Add the Subsystem block to the canvas and add the desired blocks to the subsystem;
or
-
Combine blocks into a subsystem with the key combination Shift+ЛКМ and select Subsystem:
Conditionally triggered
Enabled Subsystem (Enabled Subsystem)
Enabled Subsystem - is a block type Subsystem whose execution is controlled by an external signal. An Enabled Subsystem is executed once for each main time step as long as the control signal is positive.
When to use an activatable subsystem:
-
To perform operations that depend on external conditions or signals.
-
To realise complex control logic where model execution is only necessary when certain conditions are met.
For more information about the activatable subsystem.
Activated subsystem has the following features:
-
Is a controlled subsystem;
-
The Enable block adds an external signal to control the execution of the subsystem;
-
The control signal can be a scalar or a vector:
-
If the scalar value is greater than zero, the subsystem is executed;
-
If at least one of the vector values is greater than zero, the subsystem is executed;
-
-
If the control signal crosses zero during a smaller time step, the subsystem is not switched on or off until the next major time step.
How to use an activatable subsystem:
-
Add the Subsystem block to the canvas and add the Enable block to the subsystem. If Enable is used at the root level of the model referenced by the Model block, the following is required:
-
For multirate models, set the solver to single-task mode.
-
For fixed step size models, at least one block in the model must run at the specified fixed step size speed
or
-
-
Combine the desired blocks into a subsystem with the key combination Shift+ЛКМ and select Enabled Subsystem:
In case of merging into an activatable subsystem with a key combination, the block Enable will be added automatically.
Triggered Subsystem (Triggered Subsystem)
Triggered Subsystem - is a type of block Subsystem whose execution is initiated by an external trigger signal. A Triggered Subsystem will be executed once per step when the value of the control signal changes in the specified manner.
For more information about the triggered subsystem
Triggered subsystem has the following features:
-
Is a controlled subsystem;
-
The Trigger block adds an external signal to control the execution of the subsystem;
-
Unlike an activated subsystem, which executes when the control signal is positive, a triggered subsystem holds its output parameters at the last value between triggers;
-
The states of discrete blocks within the subsystem are retained between triggers.
*When to use the triggered subsystem:
-
To implement operations that must be triggered by certain events;
-
To implement systems where certain actions must be performed in response to interrupts or other asynchronous events;
-
To implement tasks that must be executed at a specified frequency determined by an external trigger signal.
*How to use a triggered subsystem:
-
Add the Subsystem block to the canvas and add the Trigger block to the subsystem;
or
-
Combine the desired blocks into a subsystem with the key combination Shift+ЛКМ and select Triggered Subsystem:
In case of merging into a triggered subsystem using a key combination, the block Trigger will be added automatically.
Triggered & Enabled Subsystem (Triggered & Enabled Subsystem)
Triggered and Enabled Subsystem - is the combination of the functionality of two subsystems (Triggered & Enabled) into one subsystem. This subsystem will only be executed when the activation control signal has a positive value and a trigger event occurs.
When to use triggered and activated subsystem:
-
To perform operations that depend on both activation and a trigger event;
-
To implement systems in which the subsystem is executed only when both conditions are true (signals from the Trigger and Enable blocks).
-
To realise complex control logic where activation under certain conditions and execution at a trigger event are required.
For more information about the triggered and activated subsystem
The Trigger block can be added to the Enable block to obtain a triggerable and activatable subsystem. |
The Triggerable and activatable subsystem has the following features:
-
Is a controlled subsystem;
-
The execution of the subsystem is controlled by two external signals simultaneously: a trigger signal and an activation signal;
-
The subsystem must be activated by a positive value of a scalar or vector signal. If the scalar value is greater than zero or any of the vector values is greater than zero, the subsystem is activated.
-
The subsystem is executed once in each step when the value of the control signal changes in the specified manner. The Trigger block controls the execution of the subsystem.
-
The subsystem holds its output parameters at the last value between triggers.
-
The states of the discrete blocks within the subsystem are retained between triggers.
How to use a triggered and activated subsystem:
Resettable Subsystem (Resettable Subsystem)
Resettable Subsystem - is a block type Subsystem whose block states can be reset by an external trigger. This subsystem is executed at each time step, but the states of all blocks within it are reset to their initial state when a trigger event occurs on the Reset port.
*When to use the resettable subsystem:
-
To perform operations that require resetting the states of all blocks within a subsystem under certain conditions;
-
To reset the subsystem to its initial state in response to external events (such as a system restart or error);
-
To manage the state of the system by ensuring that the subsystem is reset at specific points in time.
For more information about the subsystem to be reset.
*The resettable subsystem has the following features:
-
Is a controlled subsystem;
-
The Reset block adds an external signal to control the execution of the subsystem;
-
The states of all blocks within the subsystem are reset to the initial state when a trigger on the Reset port occurs;
-
The subsystem is executed at each time step, but resets the block states only when the trigger on the Reset port is actuated;
-
Similar to the behaviour of resetting blocks with Reset ports, except that the subsystem being reset resets the states of all blocks within itself.
How to use the resettable subsystem:
-
Add a Subsystem block to the canvas and add a Reset block to the subsystem;
or
-
Combine the desired blocks into a subsystem with the key combination Shift+ЛКМ and select Resettable Subsystem:
If merged into a resettable subsystem using a key combination, the Reset block will be added automatically.
Function-Call (function call subsystem)
Function-Call (function-call subsystem) is a block type Subsystem. The subsystem is started whenever the control port receives a function call event. These events can come from the Chart block, the Function-Call Generator block, or the Engee Function block.
*When to use the Function-Call subsystem:
-
To create functionality similar to procedures in programming languages where execution is only required when a function call occurs.
-
To realise complex control logic where certain actions must be performed on request.
For more information about Function-Call subsystem.
*The *Function-Call subsystem has the following features:
-
Is a managed subsystem;
-
The Trigger block with the Trigger Type parameters of
function-call
turns into a Function block and adds an external signal to control the execution of the subsystem; -
The subsystem is executed only when a function call event is received on the control port;
-
A call to a subsystem initiates the execution of all blocks within it in a given order, similar to a function in a procedural programming language.
How to use Function-Call subsystem:
-
Add the Subsystem block to the canvas and add the Trigger block to the subsystem. Set the Trigger Type parameters to
function-call
. The Trigger block will change its view to Function.or
-
Combine the desired blocks into a subsystem by using the key combination Shift+ЛКМ and selecting Function-call Subsystem:
In case of merging into a Function-Call subsystem using a key combination, the Function block will be added automatically.
Control logic
Action
An Action subsystem is a subsystem whose execution is controlled by an action signal from a block Action Port. The subsystem is used in models containing the blocks If and Switch Case.
When to use the Action subsystem:
-
To implement models with If and Switch-Case logic;
-
To realise conditional execution of parts of the model based on action signals (from the Action Port block);
-
To create complex branching logic where the execution of blocks depends on conditions determined by external signals.
For more information about the Action subsystem
*Action subsystem has the following features:
-
Is a managed subsystem;
-
Block If implements If-Else logic to control the execution of the Action Subsystem;
-
Block Switch Case implements switching logic to control the execution of Action Subsystem;
-
The action signal controls the execution of blocks within the subsystem, similar to the If and Switch-Case constructs in programming languages.
How to use the Action Subsystem:
-
Add the Subsystem block to the canvas and add the Action Port block to the subsystem. The block adds an external Action input port to the subsystem.
Multiple execution
For Each (for each item)
For Each subsystem is a subsystem that allows processing each element of the input signal. The control block for such a subsystem is the block For Each.
When to use the For Each subsystem:
-
To process input signals for each element, such as in filtering or data transformation tasks;
-
To perform parallel calculations over elements or subarrays of input signals;
-
To implement complex processing logic that requires separate state accounting for each data element.
For More About For Each Subsystem
For Each subsystem has the following features:
-
Is a controlled subsystem;
-
The subsystem processes each element of the input signals;
-
Each block within the subsystem maintains a separate set of states for each element or subarray it processes;
-
As the elements or subarrays are processed, the subsystem combines the results to form output signals;
-
The block allows indices to be formed for input data and output as a port.
*How to use the For Each subsystem:
For Iterator (iterative subsystem)
The For Iterator subsystem is an iterative subsystem with programmable For logic. It represents a subsystem that repeats execution during the current time step until the iteration variable exceeds a given iteration limit. This allows you to implement logic equivalent to the For loop in Engee using the block For Iterator.
When to use the iterative subsystem:
-
In models where you need to accumulate or summarise data over a single time step;
-
To implement complex data processing algorithms that require the same operation to be performed multiple times;
-
In tasks requiring multiple calculations over elements of a data array.
For more information about For Iterator subsystem
The Iterator subsystem has the following features:
-
Is a controlled subsystem;
-
The subsystem is executed repeatedly during the current time step based on an iteration variable;
-
The For Iterator block controls the number of iterations (Iteration limit parameters), similar to a For loop;
-
The output of the For Iterator block cannot be a function call signal, and Engee will generate an error when updating the model if this condition is violated.
How to use the iterative subsystem:
-
Add the Subsystem block to the canvas and add the For Iterator block to the subsystem.
-
Enable the Show iteration variable parameters to make the output port appear. Enable the Set next i (iteration variable externally) parameters to make the input port appear. Define the number of iterations of the subsystem in the Iteration limit parameters. Use the Index mode parameters to specify the initial iteration number.
Model (submodel)
Model is a block that refers to a separate model file. It can be embedded in other models using the block Model.
When to use a submodel:
-
To create a system model hierarchy;
-
To reuse and distribute modules between projects;
-
To develop complex systems with many interrelated components;
-
To divide a project into independent parts that can be developed and tested separately.
For more information about submodels.
*The submodel has the following features:
-
Unlike a classic subsystem, a submodel must already be in the file system on the search path in order to be used in other models;
-
Displays input and output ports corresponding to the top-level input and output ports of the submodel. These ports allow the submodel to connect to other blocks in the parent model;
-
A submodel can reference another submodel and supports multi-level nesting of any subsystems and other submodels;
|
*How to use a submodel:
-
Add the Model block to the canvas.
-
In the block settings, specify which model the submodel will refer to by pressing Select model.
-
To make input/output ports appear on the Model block, add Input and Output blocks to the referenced model and select the option Refresh connectors:
To see an example of submodels implementation, please go to link. |
Chart
Chart is a graphical representation of finite automaton. The Chart block is used to model the control logic of a finite automaton, a mathematical device model that describes a system with a finite number of states.
When to use Chart:
-
To implement finite automaton logic.
-
To implement state and flow charts.
-
For modelling systems with explicit control logic and events.
-
For visual representation of states and transitions in the system.
-
For realisation of complex control algorithms.
-
To implement Julia language constructs using code generation.
For more information about Chart
*Chart has the following features:
-
The library consists of unique components:
-
You can only work with those internal variables that have been declared in the signal addition menu (in the Chart block).
-
To make input/output ports appear, the corresponding local variables must be set.
How to use Chart:
Read more about finite automata in Engee at State machines. |