constant
Define a model constant
Syntax
constant <variable name> = <value>, <variable name> = <value>, ...
Description
Model quantities which are defined using the CONSTANT statement do not change over the course of the simulation. Sometimes these types of quantities are referred to as model parameters. They are distinct from ordinary model variables in that their values may be externally from the model code itself (e.g., in script files, sliders on interactive plots, etc). Any variable data type (e.g., floating point, integer, etc) may be declared as a constant, as can arrays.
It's important to note the difference between the following two statements, which would otherwise seem similar:
constant x = 1.0
x = 1.0
The first statement declares "x" as a model constant and sets its default value to one. If this value is modified before running the simulation, the new value will used in any subsequent model calculations involving the constant. By contrast, the second statement overwrites any value of "x" set from outside the model code when that statement is executed. Another way of thinking about this is that the CONSTANT statement reserves a place in memory for the associated quantity and initializes its value, while the second statement above is an executable instruction to replace the value in memory. Note that an attempt to overwrite the value of a constant in CSL code will result in a warning at translation time, as this is usually unintended and likely a source of model errors.
Example
constant g = 9.8
dimension c[3]
constant c = 1.2, 3.2, 5.1