Execution Stages
Execution Stages
It was explained in an earlier section that, at the element level, the model executes one of four stages. These stages are:
Execution Stage | Code to Use in JFunction Template |
---|---|
Initialisation | initialise |
Trigger evaluation | triggers |
Increment (if no treatment) | increment |
Reset (if treated) | resets |
Maintenance | maintenance |
When you define your Domain Model, you must assign each JFunction to one of the above execution stages, so that JCass will know which functions to evaluate depending on whether it is busy performing initialisation, trigger evaluation, incrementing etc.
In addition to the above main stages, you may want some JFunctions to always execute regardless of which of the above stages the model is executing. For example, if you have a set of model constants that are used by various JFunctions, you will want the JFunctions that pertain to these constants to be always loaded at the start of the current execution stage.
Another example of a JFunction that you may want to always evaluate is the calculation of an Index or Objective Function that is dependent on other model parameters, and that you always want to evaluate when all other functions in the current stage have finished evaluating.
To avoid a situation where you need to replicate such JFunctions in each of the above noted stages, you can allocate such JFunctions to one of the following two stages:
- Pre-Calculations: assign execution stage as ‘precalcs’
- Post-Calculations: assign execution stage as ‘postcalcs’
Order of Execution
The JCass Framework model will automatically cycle through the above-mentioned execution stages, using decision logic to determine which stages to execute or skip. When the model is executing one specific stage (e.g.’initialise’), it will automatically select from the overal JFunction Set only those JFunctions that pertain to the stage that is being executed.
As noted above, JFunctions allocated to the stages ‘precalcs’ or ‘postcalcs’ will always be selected in addition to the JFunctions that pertain only to the current stage.
The figure below shows a simplified example of a JFunction Set definition. Here we are only showing some columns of the template, and we have simplified function_type and setup_code using the dummy code ‘etc.’.
The figure above shows which of the JFunctions will be selected for the ‘initialisation’ stage, and also the order in which they will be executed. As shown by the figure, JCass will first select all JFunctions pertaining to stage ‘precalcs’ - in the order in which they are defined.
Next, all JFunctions pertaining to the ‘initialisation’ stage are selected, again in the order in which they are defined. Finally, all functions pertaining to the ‘postcalcs’ stage are selected in the order in which they are defined.