Practical work with model architecture in Engee
Page in progress. |
The theory of model architecture construction in Engee is described in the article Model Architecture in Engee. We recommend that you read it before starting to study the current article. |
Subsystems and submodels are used to group blocks. A subsystem can be considered as a function, and a submodel as a pluggable file. In Engee they are implemented as follows:
Types of subsystems | Submodels | Other blocks of subsystem behavior implementation | |
---|---|---|---|
Classic |
Block Subsystem |
Block Model (submodel) |
Block Chart |
Triggered by a condition |
Activated Subsystem Triggered Subsystem Triggered and Activated Subsystem Resettable Subsystem Function-Call (function call) |
||
Control logic |
Action |
||
Multiple execution (computational cycles) |
For Each For Iterator |
To see an example of the implementation of various subsystems, go to link. |
Any subsystem of Engee can be configured using masks (for more information, see Masks in Engee). |
Classical subsystem
The classical subsystem — this is a block Subsystem, used to divide the model into modules without additional conditions or the need to control an external signal.
When to use the classic subsystem:
-
To simplify large models by breaking them down into smaller modules;
-
To improve the structuring and readability of the model;
-
To transfer ready-made modules between models (copying subsystems).
_ Learn more about the classical subsystem_
Block Subsystem It contains a subset of blocks within a model or system and can be a non-virtual or virtual subsystem.:
-
The non-virtual subsystem runs as a single unit and can be configured to run only under certain events.
-
The virtual subsystem does not run as a single unit and does not depend on events. Such a subsystem helps to make the model more understandable without affecting its operation.
To switch a virtual subsystem to a non-virtual one, set the Treat as atomic unit parameter to true
.
The classical subsystem has the following features:
-
It is not a managed subsystem;
-
Allows you to create a hierarchical structure of models where one subsystem can contain another;
-
It cannot be saved as a separate file or subsystem. To save the subsystem as a separate model, the block is used Model (submodel);
-
It does not affect the functionality and logic of the model.
How to use the classical subsystem:
-
Add a block Subsystem to the canvas and add the desired blocks to the subsystem;
or
-
Combine blocks into a subsystem using a keyboard shortcut Shift+LKM and choose Subsystem:
Triggered by a condition
The Activated Subsystem
Enabled Subsystem — this is a type of block Subsystem, the execution of which is controlled by an external signal. The activated subsystem is executed once at each main time step, as long as the control signal has a positive value.
When to use the activated subsystem:
-
To perform operations that depend on external conditions or signals.
-
To implement complex control logic, where the execution of the model is necessary only if certain conditions are met.
_ Learn more about the subsystem being activated_
The activated subsystem has the following features:
-
It is a managed subsystem;
-
Block Enable adds an external signal to control subsystem execution;
-
The control signal can be a scalar or a vector:
-
If the scalar value is greater than zero, then the subsystem executes;
-
If at least one of the vector values is greater than zero, then the subsystem executes;
-
-
If the control signal crosses zero during a smaller time step, the subsystem does not turn on or off until the next major time step.
How to use the activated subsystem:
-
Add a block Subsystem to the canvas and add a block Enable into the subsystem. If Enable used at the root level of the model referenced by the block Model, then you need to do the following:
-
For multi-speed models, set the solver to single-task mode.
-
For models with a fixed step size, at least one block in the model must operate at a given fixed step size speed.
or
-
-
Combine the necessary blocks into a subsystem using a keyboard shortcut Shift+LKM and choose Enabled Subsystem:
If combined into an activated subsystem using a key combination, the block Enable it will be added automatically.
Triggered Subsystem
Triggered Subsystem — this is a type of block Subsystem, the execution of which is initiated by an external trigger signal. The triggered subsystem will be executed once at each step when the value of the control signal is changed in the specified way.
_ Learn more about the triggered subsystem_
The triggered subsystem has the following features:
-
It is a managed subsystem;
-
Block Trigger adds an external signal to control subsystem execution;
-
Unlike the activated subsystem, which runs at a positive value of the control signal, the triggered subsystem keeps its output parameters at the last value between triggers.;
-
The states of discrete blocks within the subsystem are stored between triggers.
When to use the triggered subsystem:
-
To perform operations that should 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 performed at a specified frequency, determined by an external trigger signal.
How to use the triggered subsystem:
-
Add a block Subsystem to the canvas and add a block Trigger to the subsystem;
or
-
Combine the necessary blocks into a subsystem using a keyboard shortcut Shift+LKM and choose Triggered Subsystem:
If combined into a triggered subsystem using a key combination, the block Trigger it will be added automatically.
Triggered and Activated Subsystem
Triggered and Enabled Subsystem — this is the integration of the functionality of two subsystems (triggered and activated) into one subsystem. Such a subsystem will be executed only when the activation control signal has a positive value and a trigger event occurs.
When to use the triggered and activated subsystem:
-
To perform operations that depend on both activation and trigger events.;
-
For the implementation of systems in which the subsystem is executed only when both conditions are true (signals from the blocks Trigger and Enable).
-
To implement complex control logic that requires activation under certain conditions and execution upon a trigger event.
_ Learn more about the triggered and activated subsystem_
The triggered and activated subsystem has the following features:
-
It is a managed subsystem;
-
The subsystem is controlled simultaneously by two external signals: 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, then the subsystem is activated.
-
The subsystem is executed once at each step when the value of the control signal is changed in the specified way. Block Trigger controls the execution of the subsystem.
-
The subsystem keeps its output parameters at the last value between triggers.
-
The states of discrete blocks within the subsystem are stored between triggers.
How to use the triggered and activated subsystem:
Resettable Subsystem
Resettable Subsystem — this is a type of block Subsystem, the state of the blocks of which can be reset by an external trigger. This subsystem is executed at each time step, but the states of all the blocks inside it are reset to their initial state when on the port Reset a trigger event occurs.
When to use the resettable subsystem:
-
To perform operations that require resetting the states of all blocks inside the subsystem under certain conditions;
-
To reset the subsystem to its initial state in response to external events (for example, system restart or error);
-
To manage the state of the system, ensuring that the subsystem is reset at certain points in time.
_ Learn more about the subsystem being reset_
The resettable subsystem has the following features:
-
It is a managed subsystem;
-
The Reset block adds an external signal to control the subsystem execution.;
-
The states of all blocks inside the subsystem are reset to the initial state when a trigger is triggered on the Reset port.;
-
The subsystem is executed at each time step, but resets the block states only if a trigger is triggered on the Reset port.;
-
It is similar to the behavior of resetting blocks with Reset ports, except that the subsystem being reset resets the states of all blocks inside itself.
How to use the resettable subsystem:
-
Add a block Subsystem to the canvas and add the Reset block to the subsystem;
or
-
Combine the necessary blocks into a subsystem using a keyboard shortcut Shift+LKM and choose Resettable Subsystem:
If combined into a resettable subsystem using a key combination, the Reset block will be added automatically.
Function-Call (subsystem of function call)
Function-Call (function call subsystem) — this is a type of block Subsystem. The subsystem is started every time the control port receives a function call event. These events can come from the block Chart, the Function-Call Generator block or the Engee Function.
When to use the Function-Call subsystem:
-
To create functionality similar to procedures in programming languages, where execution is only necessary when calling a function.
-
To implement complex control logic, where certain actions must be performed on request.
_ Learn more about the Function-Call subsystem_
The Function-Call subsystem has the following features:
-
It is a managed subsystem;
-
Block Trigger with the Trigger Type parameter in the value
function-call
, it 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;
-
Calling a subsystem initiates the execution of all the blocks inside it in a given order, similar to a function in a procedural programming language.
How to use the Function-Call subsystem:
-
Add a block Subsystem to the canvas and add a block Trigger into the subsystem. Set the value of the Trigger Type parameter to
function-call
. Block Trigger changes the view to Function.or
-
Combine the necessary blocks into a subsystem using a keyboard shortcut Shift+LKM and choose Function-call Subsystem:
If combined into a Function-Call subsystem using a keyboard shortcut, the Function block will be added automatically.
Control logic
Action (action)
The Action subsystem is a subsystem whose execution is controlled by the block action signal Action Port. The subsystem is used in models containing blocks If and Switch Case.
When to use the Action subsystem:
-
To implement models with If and Switch-Case logic;
-
To implement conditional execution of parts of the model based on action signals (from the Action Port block);
-
To create a complex branching logic, where the execution of blocks depends on conditions determined by external signals.
_ Learn more about the Action subsystem_
The Action subsystem has the following features:
-
It 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 the 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 a block Subsystem 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 element)
For Each subsystem is a subsystem that allows processing of each element of the input signal. The control unit for such a subsystem is the block For Each.
When to use For Each subsystem:
-
For processing input signals for each element, for example, in data filtering or transformation tasks.;
-
To perform parallel calculations on elements or subarrays of input signals;
-
To implement complex processing logic that requires separate accounting of states for each data element.
_ Learn more about For Each subsystem_
For Each subsystem has the following features:
-
It is a managed 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 that it processes.;
-
As the elements or subarrays are processed, the subsystem combines the results to form output signals.;
-
The block allows you to create indexes for input data and output them as a port.
How to use For Each subsystem:
For Iterator (iterative subsystem)
The For Iterator subsystem is an iterative subsystem with programmable For logic. It is a subsystem that repeats execution during the current time step until the iteration variable exceeds the specified iteration limit. This allows you to implement the logic equivalent to the For loop in Engee using the block For Iterator.
When to use the iterative subsystem:
-
In models where it is necessary to accumulate or summarize data within a single time step.;
-
To implement complex data processing algorithms that require multiple execution of the same operation.;
-
In tasks that require performing multiple calculations on elements of a data array.
_ Learn more about the For Iterator subsystem_
The iterative subsystem has the following features:
-
It is a managed subsystem;
-
The subsystem is executed repeatedly during the current time step based on the iteration variable;
-
Block For Iterator controls the number of iterations (the Iteration limit parameter), similar to the For loop;
-
Block output For Iterator it cannot be a function call signal, and Engee will issue an error when updating the model if this condition is violated.
How to use the iterative subsystem:
-
Add a block Subsystem to the canvas and add a block For Iterator into the subsystem.
-
Enable the Show iteration variable parameter to display the output port. Enable the Set next i (iteration variable externally) parameter to display the input port. Determine the number of subsystem iterations in the Iteration limit parameter. Use the Index mode parameter to specify the initial iteration number.
Model (submodel)
Model — this is a block that links to a separate model file. It can be integrated into other models using the block Model.
When to use a submodel:
-
To create a hierarchy of the system model;
-
For reuse and distribution of modules between projects;
-
To develop complex systems with multiple interconnected components;
-
To divide the project into independent parts that can be developed and tested separately.
_ Learn more about the submodel_
The submodel has the following features:
-
Unlike the classical subsystem, the submodel must already be in the file system along the search path so that it can be used in other models.;
-
Displays the input and output ports corresponding to the top-level input and output ports of the submodel. These ports allow you to connect the submodel to other blocks of the parent model.;
-
A submodel can refer to another submodel and supports multi-level embedding of any subsystems and other submodels.;
|
How to use a submodel:
-
Add a block Model on the canvas.
-
In the block settings, specify which model the submodel will refer to by clicking Select model.
-
To make the input/output ports appear in the Model block, add the Input and Output blocks to the referenced model and select the option Refresh connectors:
To view an example of implementing submodels, go to link. |
Chart (Chart)
Chart — this is a graphical representation a finite state machine. Block Chart It is used to model the control logic of a finite state machine, a mathematical model of a device that describes a system with a finite number of states.
When to use Chart:
-
For implementation logic of finite automata.
-
To implement diagrams states and flowcharts.
-
For modeling systems with explicit control logic and events.
-
For visual representation of states and transitions in the system.
-
To implement complex control algorithms.
-
To implement Julia language constructs using code generation.
_ Learn more about Chart_
Chart has the following features:
-
The library consists of unique components:
-
You can only work with those internal variables that were declared in the add signals menu (in the block Chart).
-
For the input/output ports to appear, the appropriate local variables must be set.
How to use Chart:
Read more about finite automata in Engee in State Machines. |