Callbacks¶
In this demonstration, we will show the possibilities of calling functions from the model based on conditions executed inside the model.
The model itself is a logged sinusoid. The scheme of work, when in the process of modelling there is a possibility to include callbacks, is shown in the figure below.
This demonstration will be a set of tests, which can be conditionally divided into 4 groups:
- functions on the condition of opening the model,
- functions on the condition of model execution,
- functions on the condition of saving the model,
- functions on the condition of closing the model.
To open the callbacks window, open "Model Settings" -> "Edit Source Code".
To trigger the tests described below, you need to run model_callback.engee.
The first test is triggering of callbacks when opening a model.
PreL = 0
PostL = 0
Init = 0
Start = 0
Pause = 0
Continue = 0
Stop = 0
PreS = 0
PostS = 0
Close = 0
As we can see, two variables are initialised at the time of opening:
- before the model is opened,
- after the model is opened.
print("PreLoad: " * string(PreL) * " / PostLoad: " * string(PostL) *
" / PreSave: " * string(PreS) * " / PostSave: " * string(PostS) *
" / Close: " * string(Close))
The second test is actions when saving the model.
Similar to the previous embodiment, two functions with conditions before saving and after saving are provided.
print("PreLoad: " * string(PreL) * " / PostLoad: " * string(PostL) *
" / PreSave: " * string(PreS) * " / PostSave: " * string(PostS) *
" / Close: " * string(Close))
The third test is to close the model.
From it we can see that in case the model is closed, it is this function that is triggered.
print("Close: " * string(Close))
The last group of callbacks are functions that occur by actions during modelling. There are 5 of them, as shown in the figure below.
Now let's consider the cases when each of these functions is called. As you can see at the stage before opening the model, we initialised all variables, which we later change depending on the condition.
- The initialisation function is called after the compilation stage of the model.
- The start function is executed in the first step of the simulation.
- The pause function is called if there is a pause during the simulation.
- Function executed at all steps of the simulation.
- Function to stop the modelling process.
Accordingly, if we run the model and pause the process at least once during the simulation, all the above functions will be executed. In the figure below we can see that after running our tests in the workspace all variables are equal to 1.
Conclusion¶
In this demonstration we have shown how to use callbacks. This tool is designed to automate modelling processes, as well as to save and analyse modelling results. With the help of callbacks we can completely get rid of scripting and implement our entire project exclusively in models, from the parameter declaration stage to the stage of analysing the results.