Simulation Phases

The process of simulating a model occurs in three phases: Evaluation, Compilation and Simulation. The Evaluation and Compilation phases occur first generating a structure that is processed during the Simulation phase.

Evaluation

The Evaluation phase is the first phase of the simulation process and produces a hierarchical data structure required for the Compilation phase.

New Data Structure

During Evaluation, the software creates a new data structure based on the model structure defined in the .scm file. This new data structure is hierarchical as the original model structure, but the new data structure can contain more blocks because the Evaluation process retrieves and includes the content of referenced library blocks into the new structure. This inlining action increases the level of hierarchy when an inlined reference block is a super block. The same occurs for programmable super blocks which are expanded and inlined during Evaluation. The new data structure may also lose some of the blocks of the original structure, in particular, some virtual blocks that are treated during this phase. At the end of Evaluation, the data structure contains no outside references.

Computation

During Evaluation, the software also computes all the numerical values of the block parameters and stores them in the data structure for later use during the Simulation phase. The block parameter values are in general given as OML expressions that need to be evaluated in a proper workspace. The computation of the proper workspaces and the evaluation of the block parameter expressions occur during the Evaluation phase. Following the scoping rules used in the software, the software computes the workspace of each diagram by executing first the model initialization script followed by the diagram contexts of all diagrams in the lineage of the current diagram, top to bottom, ending with the context of the current diagram itself. The block parameter values of the blocks in the current diagram are then evaluated in this workspace. This scoping rule lets you parameterize your models and diagrams. For example, by changing the value of a variable defined in the initialization script or a diagram context, the behavior of multiple blocks can be changed at once. Such variables, called model parameters and diagram parameters, respectively, can be used not only to update the value of an OML variable used in multiple places but also to construct generic models. For example, a unique diagram can be used to realize an LQG controller feedback system for all linear systems, parameterizing even the number of inputs and outputs of the controlled system.

Compilation

The Compilation phase computes the order for the data structure produced during the Evaluation phase.

The hierarchical data structure provided during the Evaluation phase contains all the numerical values of block parameters, and therefore contains the necessary information for the block simulation functions to be called during the Simulation phase. But this data structure is not yet ready for simulation. The Simulation phase requires the order in which the block simulation functions should be called. The computation of this order, or more precisely computation of orders for different modes, is the main purpose of the Compilation phase.

The Compilation is done in two stages. First the hierarchical data structure provided from the Evaluation phase is flattened. The inheritance mechanism and the Set and Get blocks are also treated in this stage. At the end, the model is reduced to a single diagram containing basic blocks connected with links. Note that Atomic Super Blocks are seen as basic blocks in this stage and their contents are treated separately.

The second stage of the Compilation computes the scheduling tables that are later used in the Simulation phase. For each simulation mode, a table is constructed that contains the list of blocks and the order in which the blocks should be called during Simulation phase. These scheduling tables enable the Simulation phase to run extremely efficiently and eliminate the need for scheduling during the Simulation phase at run time.

Simulation

The Simulation phase runs a simulation based on the scheduling tables and other information generated during the Compilation phase.