Available 20-sim Tokens

Navigation:  Toolboxes > Real-Time Toolbox > C-Code Generation >

Available 20-sim Tokens

Previous pageReturn to chapter overviewNext page

Both the target configuration file and the code generation dialog revealed the most important part of the 20-sim code generation process, the use of tokens!

 

A token is a placeholder for model-dependent information. For instance in the code generation dialog, the target destination directory contains the name of the selected submodel by default. Since this information is not yet known when the targets.ini file is created, a specific token that refers to this name is used instead.

 

The idea is to create targets from template source files that contain tokens instead of actual model-dependent information (like equations, names, parameters, inputs etc). The files that are specified in a target section will be scanned for these tokens and tokens will be replaced by the corresponding model-dependent information.

Predefined variable names

The following variables should be declared in the C-Code template, because 20-sim uses these names in the generation of the equations:

 

c: constant array

P: parameters array

V: variables array

s: states array

R: rates array

M: matrix array

U: unnamed variables array

F: favorite variables array

f: favorite parameters array

 

 

Note that these parameters are case-sensitive!

Model Data

The following tokens will be replaced by numbers indicating the number of model parameters etc., typically used in memory allocation parts and loops.

%NUMBER_CONSTANTS%

%NUMBER_PARAMETERS%

%NUMBER_VARIABLES%

%NUMBER_STATES%

%NUMBER_INPUTS%

%NUMBER_OUTPUTS%

%NUMBER_MATRICES%

%NUMBER_UNNAMED%

%NUMBER_FAVORITE_PARAMETERS%

%NUMBER_FAVORITE_VARIABLES%

%WORK_ARRAY_SIZE%

The number of constants in the model

The number of parameters in the model

The number of variables in the model

The number of states in the model

The number of inputs of the model

The number of outputs of the model

The number of matrices used in the model

The number of unnamed variables in the model

The number of favorite parameters in the model

The number of favorite variables in the model

The size of the largest workarray necessary in calculating some matrix functions

 

The following tokens are already reserved for future use:

%NUMBER_DEPSTATES%

%NUMBER_ALGLOOPS%

%NUMBER_CONSTRAINTS%

%NUMBER_IMPORTS%

%NUMBER_EXPORTS%

The number of dependent states in the model

The number of algebraic loop variables pairs in the model

The number of constraint variable pairs in the model

The number of import variables in the model

The number of export variables in the model

 

Example

Variable name arrays

If you want to use parameters etc. that are specific to a model you can use arrays of names using the following tokens:

 

%CONSTANT_NAMES%

%PARAMETER_NAMES%

%VARIABLE_NAMES%

%STATE_NAMES%

%RATE_NAMES%

%DEPSTATE_NAMES%

%DEPRATE_NAMES%

%ALGLOOP_NAMES%

%CONSTRAINT_NAMES%

%INPUT_NAMES%

%OUTPUT_NAMES%

%MATRIX_NAMES%

%FAVORITE_PARAMETER_NAMES%

%FAVORITE_VARIABLE_NAMES%

All the constants used in the model.

All the parameters used in the model.

All the variables used in the model.

All the states used in the model.

All the rates used in the model.

All the dependent states used in the model.

All the dependent rates used in the model.

All the algebraic loop variables used in the model.

All the constraint variables used in the model.

All the inputs used in the model.

All the outputs used in the model.

All the matrices used in the model.

All the favorite parameters used in the model.

All the favorite variables used in the model.

Example

Initialization code

An important part of a model are the parameters, initial values states etc. To match these with the generated model code and use the correct values the following tokens can be used:

 

%INITIALIZE_CONSTANTS%

%INITIALIZE_PARAMETERS%

%INITIALIZE_MATRICES%

%INITIALIZE_STATES%

%INITIALIZE_DEPSTATES%

%INITIALIZE_ALGLOOPS%

%INITIALIZE_CONSTRAINTS%

%INITIALIZE_INPUTS%

%INITIALIZE_OUTPUTS%

%INITIALIZE_FAVORITE_PARS%

%INITIALIZE_FAVORITE_VARS%

 

Example

Equations

The following tokens can be used to place 20-sim simulation model equations into the C-Code:

 

%INITIAL_EQUATIONS%

Equations that should be calculated once for initialization of the model

%STATIC_EQUATIONS%

Equations that should be calculated once

%INPUT_EQUATIONS%

Equations that should be calculated once at the beginning of every simulation step

%DYNAMIC_EQUATIONS%

Equations that calculates the dynamic part of the model, calculates the rates

%OUTPUT_EQUATIONS%

Equations that should be calculated once at the end of every simulation step

%OUTPUT2_EQUATIONS%

Reduced set of equations that should be calculated at the end of every simulation step

%FINAL_EQUATIONS%

Equations that should be calculated once for termination of the model

Inputs/Outputs

To match model inputs and model outputs to for example sensor signals and actuator signals you can use:

 

%INPUT_TO_VARIABLE_EQUATIONS%

%VARIABLE_TO_OUTPUT_EQUATIONS%

%ALIAS_EQUATIONS%

%FAVORITE_PARS_EQUATIONS%

%FAVORITE_VARS_EQUATIONS%

 

Example

Additional tokens

%INTEGRATION_METHOD_NAME%

A string representing the name of the selected integration method, for now only Euler, RungeKutta4 and Discrete are available.

%XX_TIME%

%XX_INITIALIZE%

The name of the simulation time variable (combined with %VARPREFIX%)

The name of the variable that indicates the initialization phase(combined with %VARPREFIX%).

%START_TIME%

%FINISH_TIME%

%TIME_STEP_SIZE%

%MODEL_IS_DISCRETE%

Start time of the simulation (floating point notation).

Finish time of the simulation (floating point notation).

Step size of the simulation (floating point notation).

Either TRUE or FALSE, depending if the model is discrete in time or continuous in time.

Experiment Tokens

Tokens which hold information about the model, experiment, user and system:

%FILE_NAME%

%MODEL_FILE%

%MODEL_NAME%

%SUBMODEL_NAME%

%EXPERIMENT_NAME%

%GENERATION_TIME%

%GENERATION_DATE%

%GENERATION_BUILD%

%GENERATION_DIR%

%USER_NAME%

%COMPANY_NAME%

%20SIM_DIR%

 

The file name of the generated C-Code.

The complete path and file name of the original 20-sim model.

The name of the 20-sim model out of which C-Code was generated.

The name of the 20-sim submodel out of which C-Code was generated.

The experiment name accompanying the 20-sim (sub)model.

The time of C-Code generation.

The date of C-Code generation.

The 20-sim version and build number.

The directory where the generated C-Code files are stored.

The user name given in the 20-sim license.

The company name given in the 20-sim license.

The directory where 20-sim is installed.