Callbacks
Do not confuse the callbacks described in this article with the callbacks of the link:https://docs.sciml.ai/DiffEqCallbacks/stable/ library [DiffEqCallbacks.jl]. Read more about working with them in Event Handling and Callback Functions. |
Model Callbacks - are functions that are called automatically in response to certain events in the model. Callbacks Engee are created in the programming language Julia.
To open callbacks, go to the settings window and press Edit source code
:
In the menu that opens, all Engee callbacks are available. They are empty by default and contain no code:
All Engee callbacks can be roughly divided into 4 groups:
|
|
|
|
Description of callbacks
Model opening
Used to configure the behaviour of the model before and after opening.
For more information about model opening callbacks.
*Useful callbacks: PreLoadFunc
(opening) and PostLoadFunc
(closing).
Description:
-
PreLoadFunc
- executed before the model is loaded.Program control methods cannot be used in this model callback because the model has not yet had time to load. -
PostLoadFunc
- is executed after the model has been loaded. You can use parameters of the model in it, because they have already been loaded.
Callbacks on the condition of opening the model allow:
|
Model Execution
Used during the simulation process.
For more information about model execution callbacks.
*Useful callbacks: InitFunc
(initialisation), StartFunc
(start), PauseFunc
(pause), ContinueFunc
(execute), StopFunc
(stop).
When the model is started and the simulation process is stopped at least once, all these functions will be triggered.
*Description:
-
InitFunc
- executed after the model compilation step; -
StartFunc
- executed before the first simulation step; -
PauseFunc
- called in case of a pause during the simulation; -
ContinueFunc
- executed one step at a time when the model is started after a pause; -
StopFunc
- executed when the simulation process is stopped.
Saving the model
Used when saving the model.
For more information about model saving callbacks.
*Used callbacks: PreSave
(before saving), PostSave
(after saving)
Description:
-
PreSave
- executed before saving the model; -
PostSave
- is executed after saving the model.
Close model
Used when closing the model.
For more information about model closure callbacks.
*Used callbacks: CloseFunc
(closing)
Description:
-
CloseFunc
- executed after the model is closed.
Callbacks on the model closing condition allow:
|
Example of operation
For an example of how callbacks work, go to link.
You can assign a variable to each callback in Engee. This is useful to keep track of the triggering depending on the simulation condition, for example inside the PreLoadFunc
model opening callback you can use the code:
#переменные открытия модели
PreL = 1 #выполняется до загрузки модели
PostL = 0 #выполняется после загрузки модели
# переменные выполнения модели
Init = 0 #выполняется после компиляции модели
Start = 0 #выполняется до первого шага симуляции
Pause = 0 #вызывается в случае паузы симуляции
Continue = 0 #выполняется на одном шаге при запуске модели после паузы
Stop = 0 #выполняется во время остановки симуляции
#переменные сохранения модели
PreS = 0 #выполняется перед сохранением модели
PostS = 0 #выполняется после сохранения модели
#переменные закрытия модели
Close = 0 #выполняется после закрытия модели
This code initialises variables with null values. The PreL
variable associated with model opening is equal to one because its parameters are loaded before and after the model is loaded (always executed). For example, in StartFunc
model execution callbacks, you can set the Start = 1
variable. If this callback is successfully executed, the value of the variable will change from 0
(not executed) to 1
(executed). You can monitor the execution of callbacks using the variable window:
Each time a callback is triggered, the variables are updated and then their values are displayed for analysing and debugging the simulation process.