Callbacks
| Do not confuse the callbacks described in this article with library callbacks. DiffEqCallbacks.jl. Read more about working with them in Event Handling and Callback Functions. |
Model Callbacks — these are functions that are called automatically in response to certain events in the model. Callbacks Engee created in a programming language Julia.
To open callbacks, go to the settings window
and click Edit source code
:

All callbacks are available in the menu that opens. Engee. They are empty by default and do not contain any code.:

All callbacks Engee It can be roughly divided into 4 groups:
|
|
|
|
Description of callbacks
Opening the model
They are used to adjust the behavior of the model before and after opening.
_ Learn more about model opening callbacks_
Callbacks used: PreLoadFunc (opening) and PostLoadFunc (closing).
Description:
-
PreLoadFunc— runs before loading the model.Software control methods cannot be used in the callback of this model, because the model has not yet been loaded. -
PostLoadFunc— performed after loading the model. You can use the model parameters in it, since they are already loaded.
|
Callbacks based on the model opening condition allow:
|
Model Execution
They are used in the simulation process.
_ Learn more about model execution callbacks_
Callbacks used: InitFunc (initialization), StartFunc (launch), PauseFunc (pause), ContinueFunc (execution), StopFunc (stop).
When you start the model and stop the simulation process at least once, all these functions will work.
Description:
-
InitFunc— performed after the compilation stage of the model; -
StartFunc— runs until the first step of the simulation; -
PauseFunc— called in case of a pause during the simulation; -
ContinueFunc— runs in one step when starting the model after a pause; -
StopFunc— it is performed during the shutdown of the simulation process.
Saving the model
Used when saving the model.
_ Learn more about model save callbacks_
Callbacks used: PreSave (before saving), PostSave (after saving)
Description:
-
PreSave— performed before saving the model; -
PostSave— executed after saving the model.
Closing the model
Used when closing the model.
_ Learn more about model closure callbacks_
Callbacks used: CloseFunc (closing)
Description:
-
CloseFunc— executed after the model is closed.
|
Callbacks based on the closure condition of the model allow:
|
Messages in the diagnostic window
In the callback code of the model, you can send messages to model diagnostic window
using the functions:
-
engee.info(msg)— information message; -
engee.warning(msg)— warning message;
These functions only work inside callbacks (masks and models). Collect text through interpolation ("Value = $(x)") or string(…).
|
examples by callback groups
Opening the model (PreLoadFunc, PostLoadFunc):
PreLoadFunc() = begin
engee.info("Открываю модель")
end
PostLoadFunc() = begin
engee.info("Модель загружена")
end
Model execution (InitFunc, StartFunc, PauseFunc, ContinueFunc, StopFunc):
InitFunc() = engee.info("Инициализация завершена")
StartFunc() = engee.info("Симуляция запущена")
PauseFunc() = engee.warning("Симуляция на паузе")
ContinueFunc() = engee.info("Продолжаю после паузы")
StopFunc() = engee.info("Симуляция остановлена")
Saving the model (PreSave, PostSave):
PreSave() = engee.info("Сохраняю модель…")
PostSave() = engee.info("Модель сохранена")
Closing the model (CloseFunc):
CloseFunc() = begin
try
# освобождение временных ресурсов
engee.info("Ресурсы освобождены, модель закрыта")
catch e
engee.warning("Не удалось корректно закрыть модель: $(e)")
end
end
| Also see the section about messages in block masks.: Messages in the diagnostic window. |
Example of work
To see an example of how callbacks work, go to link.
For each callback in Engee you can assign a variable. This is convenient to track the triggering depending on the simulation condition, for example, inside the model opening call. PreLoadFunc 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 initializes variables with null values. Variable PreL, associated with opening the model, is equal to one, since its parameters are loaded before and after loading the model (they are always executed). For example, in the model execution callbacks StartFunc you can set a variable Start = 1. If this callback is successful, the value of the variable will change from 0 (not completed) on 1 (completed). You can monitor the execution of callbacks using the variables window.:

Each time the callback is triggered, the variables are updated, and then their values are output for analysis and debugging of the simulation process.