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. Engee callbacks are created in a programming language Julia.
To open callbacks, go to the settings window. and click Edit source code
:
All Engee callbacks are available in the menu that opens. They are empty by default and do not contain any code.:
All Engee callbacks 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' — is performed 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' — is 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
(start), 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' — is executed after the compilation stage of the model.;
-
'startFunc' — runs until the first step of the simulation;
-
`PauseFunc' — called in case of a pause during simulation;
-
'ContinueFunc' — runs in one step when starting the model after a pause;
-
'StopFunc' — is executed during the shutdown of the simulation process.
Saving the model
Used when saving the model.
_ Learn more about model saving callbacks_
Callbacks used: PreSave
(before saving), postSave
(after saving)
Description:
-
`PreSave' — is performed before saving the model.;
-
'postSave' — is performed after saving the model.
Closing the model
Used when closing the model.
_ Learn more about model closure callbacks_
Callbacks used: `CloseFunc' (closure)
Description:
-
'CloseFunc' — is executed after the model is closed.
Callbacks based on the closure condition of the model allow:
|
Example of work
To see an example of how callbacks work, go to link.
You can assign a variable to Engee for each callback. This is convenient to track the triggering depending on the simulation condition, for example, the code can be used inside the model opening call PreLoadFunc
:
# model opening variables
PreL = 1 # performed before loading the model
PostL = 0 # performed after loading the model
# model execution variables
Init = 0 # it is executed after the model is compiled
Start = 0 # runs until the first step of the simulation
Pause = 0 # called when the simulation is paused
Continue = 0 # it is performed in one step when the model is started after a pause
Stop = 0 # it is performed during the stop of the simulation
# model retention variables
PreS = 0 # performed before saving the model
PostS = 0 # performed after saving the model
# model closure variables
Close = 0 # performed after the model is closed
This code initializes variables with null values. The PreL
variable associated with opening the model is one, since its parameters are loaded before and after loading the model (they are always executed). For example, in the execution callbacks of the startFunc
model, you can set the variable Start = 1
. If this callback is successful, the value of the variable will change from 0
(failed) to 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.