Compiling Models

Navigation:  Editor > Compiling >

Compiling Models

Previous pageReturn to chapter overviewNext page

When you enter a model and open the Simulator or when you select the Check Complete Model command of the Model menu, the model will be compiled. During compilation, 20-sim will perform a number of tasks.

Error Checking

Type checking: 20-sim will search for illegal type conversion and possible loss of data.
Unit Checking: Many models in 20-sim use units and quantities. 20-sim will check for a proper use of these units and quantities.

Optimizing Model Structure

Analyze causality: determine the causal order of equations.
Integral Form: Equations are changed to integral form as much as possible.
Solving differential equations: Differential equations are solved directly if possible.
Solving Algebraic Loops: Algebraic loops are solved to their analytical solution, where possible.
Optimizing Equation Structure: Some equations have to be calculated only once during each simulation step, because they do not influence the model dynamics. Depending on their relation to the model dynamics (needed for or a result of) these equations are calculated before the model dynamics (input equations) or after the model dynamics (output equations)
Remove redundant equations: A lot of model equations are just assignments like var1 = var2, where one variable is already known. 20-sim reduces these equations from the model and maps the unknown variables to known variables.

After these tasks a complete equation model is created, which can be inspected using the Show Equations command of the Model menu. After the complete equation model has been created the following tasks are applied:

Compiling

Find the correct order of execution: All equations will split up into their most simple form and rewritten into the correct order of execution.
Interpreter Code: Create interpreter like code out of the equations. This is low level code that can be understood by the simulation algorithms.
Machine Code: When you have the Built-In compiler option selected, the interpreter code is compiled into platform specific 32-bit machine code. This code uses the full power of native Pentium and 486 instructions. The result is a dramatic increase of simulation speed: 100% to 400 %, depending on the kind of model used!

Simulation Code

The resulting code, either interpreter code or machine code, is used in the Simulator to perform simulation runs with and therefore also know as simulation code. As we have learned, the simulation code can be quite different from the original model equations. To denote the function of each original model variable in the simulation code, 20-sim uses the following names:

independent rate
independent state
dependent rate
dependent state
algebraic loop in
algebraic loop out
interesting variable
hidden variable