Parameters are symbolic representations of numerical quantities which can only be changed after simulation has been stopped. They can therefore be changed in between of simulation runs, or after the user has (temporarily) stopped the simulation.
Parameters must be defined in 20-sim, using the parameters keyword. After the keyword, lines with parameter declarations can be entered. Every line must be finished by a semicolon (;) and may be followed by comment with a description of the parameter. An example is given below:
parameters
real V = 1 {volume, m3}; // the volume of barrel 1
real hidden D = 0.5 {length, m}; // the length of part 1
real x (range=<-1,1>) = 0.1 {m}; // the position of part x with a min-max range
real global L = 3.1 {m}; // A global parameter, can be used in other models, but should be assigned a value only once
real favorite P = 1.1 {V}; // A parameter, that is made favorite: it will appear in the favorites list for quick selection
...
Parameters can be assigned default values. These values can be changed in the code. However, a quicker way to change parameter values is to open the Parameters/Initial Values Editor.This editor will allow you to quickly changes parameter values and run a simulation.
20-sim currently supports four types of parameters: boolean, integer, real and string. These types must be specified explicitly. The use of the type real is shown in the example above.
To prevent users from inspecting parameters or decreasing the list of parameters, the keyword hidden can be applied. This keyword should follow the data type.
To use the same parameter in other submodels, the keyword global can be applied. This keyword should follow the data type. Note that the keywords oneup and global are mutually exclusive. Only one can be used.
The keyword oneup should be used after the type (real, boolean, integer) and keyword hidden and before the name of the parameter. It is used to limit the scope of a parameter. Note that the keywords oneup and global are mutually exclusive. Only one can be used.
To quickly find a parameter in the Parameters/Initial Values Editor the keyword favorite can be applied. This keyword should follow the data type.
Parameter names can consist of characters and underscores. A parameter name must always start with a character. Parameter names are case-sensitive. No reserved words may be used for parameters. If a reserved word is used, an error message will pop-up while checking the model. In the example above the names V and D are used.
Right after a parameter name you can enter annotations for the minimum value, range etc. Examples:
parameters
real V (min=0.1) = 1 {volume, m3}; // the volume of barrel 1, minimum volume = 0.1 m3
real R (max=100) = 20 {ohm}; // the resistance, maximum value = 100 ohm
real x (range=<-10,10>) = 0.5 {length, m}; // the position of part x, range from -10 to 10 m
real D (readonly=true) = 0.1 {m}; // the diameter of the the tube, readonly
If a parameter is known to represent a physical value, you can define the corresponding quantity and unit. 20-sim will use this information to do a unit check on equations. The use of quantities and units is optional. In the example above the quantities volume and length are used with the units m3 and m.
If comment is added at the end of the parameter declaration, it is shown in the Variable Chooser to facilitate the selection between variables.
parameters
real p1 = 12, p2, state = 1.1;
integer i = 10 {length,m}; // vehicle length
integer j = 1 {time,s};
parameters
string filename = 'data.txt'; // This comment appears as a description in the Parameters/Initial values editor.
integer i = 1; // Just a parameter
real state; // Initial velocity [m/s]
boolean t = true; // T = true
• | You can easily enter parameters by using the Add button in the Equation Editor Taskbar. |
• | You can easily select quantities and units by using the Units button of the Equation Editor Taskbar. |
• | Use the 20-sim naming convention for parameter names. |