The modeling and simulation process using Xcos is done in several steps. First, the model design should be completed. This means that all blocks in the Xcos diagram should be connected, there should be no port left “in air”. If we don’t connect all ports, when we start the simulation, Xcos will throw a warning without completing the simulation.
After the model design (block diagram) is complete, we need to make sure that all the parameters used in the model are defined in the Scilab workspace or in the context of simulation. How to define variables in Scilab is explained in detail in the article Scilab Variables – naming, real numbers, constants.
The last step, before launching the simulation, is the simulation parameters setup. This is done through the Set Parameters menu. To launch it, click on the menu bar: Simulation -> Setup.
Final integration time
This is the total duration of the simulation. The value is in exponential form, 1.0E05
which means 1.0 · 105
, which is equal to 100000
seconds. Make sure that you put the right value for you model. The value doesn’t necessarily needs to be in exponential format, it can be in decimal format (e.g. 30
).
Take into account that the simulation will always start from 0
s, it is not possible to change the simulation start time.
Real time scaling
This setting takes integer values, 0
, 1
, 2
, etc.. The values are written in exponential form by default, but, when changed, can be set in decimal format.
The value 0
means that there is no real-time scaling. This means that the actual duration of the simulation (how long it takes to calculate the model) is only dependent on the speed of the numerical solver. In this case, even is the simulation is set to 10
s (final integration time), the actual duration of the simulation is much shorter (depending on the model complexity), can be run in 0.001 - 0.1
s. With this setting (0
) you will notice that, when using a Scope to plot data, the values will be plotted very fast, as soon as they are available.
If the value is set to 1
, the simulation will be run in real-time. This means that the actual duration of the simulation (how long it takes to calculate the model) is equal to the final integration time. In this case, if the simulation is set to 10
s (final integration time), the actual duration of the simulation will be also 10
s. With this setting (1) you will notice that, when using a Scope to plot data, the values will be plotted in real-time.
If set to 2
the simulation will be run 1/2 slower than real-time. Example, to run 10
s (final integration time), the user will have to wait 20
s. The same principle applies for higher values, 3
, 4
, etc.
Integrator absolute tolerance
Specify the largest acceptable error of the numerical solver, as the value of the measured state approaches zero. If the absolute error exceeds this tolerance, the solver will reduce the time step size. The default value is 1.0E-06
. In order to improve the accuracy of the simulation results, this value can be decreased (e.g. 1.0E-08
) but this will increase the duration of the simulation.
Integrator relative tolerance
Specifies the largest acceptable error of the numerical solver, relative to the size of each state during each time step. If the relative error exceeds this tolerance, the solver will reduce the time step size. The default value is 1.0E-06
. In order to improve the accuracy of the simulation results, this value can be decreased (e.g. 1.0E-08
) but this will increase the duration of the simulation.
Tolerance on time
This value represents the smallest interval of time for which the ODE (Ordinary Differential Equation) solver is used to update continuous states. The default value is 1.0E-10
.
Max integration time interval
This is the maximum interval of time for each call to solver. It must be reduced if the error message “Too many calls” is encountered during a simulation. The default value is 1.00001E05
.
Solver kind
Using the drop-sown menu, the user can select the which numerical solver should be used for the model integration. The default solever is Sundials/CVODE - BDF - NEWTON
.
Depending on the type of differential equation contained in the model, Xcos can automatically select the appropriate solver for the user. The solver selection is communicated through a text message displayed in the Scilab console.
Detailed description of the characteristics of each solver will be provided in a future article.
Maximum step size (0 means no limit)
With this parameter set to 0
(default value), the numerical solver can increase automatically the integration step size (time) without any limit, with the purpose to decrease to simulation time. Be setting this parameter to a particular value (e.g. 0.1
) we constrain the numerical solver to adjust the integration time step as it needs but not above this value.
Set Context
By clicking this button a new menu dialog appears.
In this editable window the user can enter Scilab instructions, in order to define the symbolic Xcos parameters (e.g. A
, B
, C
) used in block definitions. The user can insert any Scilab instructions. These are going to be evaluated each time the diagram is loaded. If the value of a symbolic Xcos parameters is changed in the context, all the blocks that contains this symbolic parameter are updated when the Ok button is clicked.
After all the simulation parameters are set, the user must click the Ok button to save them. In order to revert to the initial parameter settings (default values), the user must click on the Default button.
For any questions, observations and queries regarding this article, use the comment form below.
Don’t forget to Like, Share and Subscribe!
shivam mishra
sir, I m getting error max step taken before reaching tout