Predefined Variables

Navigation:  Language Reference > Keywords >

Predefined Variables

Previous pageReturn to chapter overviewNext page

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


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);



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


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




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


         // simulation is slower that real time




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.



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.


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


u = random;



The variable true will return the boolean value true.


The variable false will return the boolean value false.


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.




if major then

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