﻿ 20-sim webhelp > Language Reference > Keywords > Predefined Variables

# Predefined Variables

Some variables in 20-sim have a predefined value. These variables do not have to be declared in the variables section of a model.

## time

The variable time is equal to the simulated time. It can for example be used in functions such as:

u = sin(time*f*2*3.1415);

## starttime

The variable starttime is equal to the Start value of the Simulator Run Properties (typically 0.0 {s}).

## finishtime

The variable finishtime is equal to the Finish value of the Simulator Run Properties (e.g. 10.0 {s}). It can be used for example to execute some actions just before finishing the simulation:

if (time >= finishtime - 1.0) then

// do some action

end;

realtime

The variable realtime contains the elapsed wall-clock time (in seconds) from the start of the simulation. It can be used to monitor if the simulation runs slower, equally fast or faster than real time.

if (time >= realtime) then

// simulation is realtime or faster than realtime

else

// simulation is slower that real time

end;

## sampletime

The variable sampletime is equal to the sampletime. It is only meaningful when it is used in an equation model that is part of a discrete loop in your model. 20-sim will automatically detect, which loop the model belongs to and assign the proper value to the variable sampletime.

## stepsize

The variable stepsize contains the actual stepsize of the integration routine. It can be used to monitor the variable step sizes of methods like BDF and Vode Adams.

## random

The variable random will yield a random variable uniformly distributed in the interval [-1,1]. E.g.:

u = random;

## true

The variable true will return the boolean value true.

## false

The variable false will return the boolean value false.

## major

Some integration algorithms, will perform model calculations at one or more intermediate points before calculating the next output value. To prevent equations being calculated, at these intermediate steps, you can use the variable major. This variable will return the boolean false when calculations are performed for an intermediate step and will return true when calculations are performed for the output values.

## Example

....

if major then

sim_steps = sim_steps + 1;     // this equation is not evaluated at intermediate points

end;

....