86 Modelica Language Specification 3.1
slowSample := pre(ticks) == 0;
end when;
algorithm
when fastSample then // fast sampling
...
end when;
algorithm
when slowSample then // slow sampling (5-times slower)
...
end when;
The slowSample when-clause is evaluated at every 5th occurrence of the fastSample when-clause.
]
[The single assignment rule and the requirement to explicitly program the synchronization of events allow a
certain degree of model verification already at compile time.]
8.6 Initialization, initial equation, and initial algorithm
Before any operation is carried out with a Modelica model [e.g., simulation or linearization], initialization takes
place to assign consistent values for all variables present in the model. During this phase, also the derivatives,
der(..), and the pre-variables, pre(..), are interpreted as unknown algebraic variables. The initialization uses
all equations and algorithms that are utilized in the intended operation [such as simulation or linearization]. The
equations of a when-clause are active during initialization, if and only if they are explicitly enabled with the
“
initial()” operator. In this case, the when-clause equations remain active during the whole initialization
phase. [If a when-clause equation
v = expr; is not active during the initialization phase, the equation v =
pre(v) is added for initialization. This follows from the mapping rule of when-clause equations].
Further constraints, necessary to determine the initial values of all variables, can be defined in the following two
ways:
1) As equations in an
initial equation section or as assignments in an initial algorithm section. The
equations and assignments in these initial sections are purely algebraic, stating constraints between the variables at
the initial time instant. It is not allowed to use when-clauses in these sections.
2) Implicitly by using the attributes
start=value and fixed=true in the declaration of variables:
• For all non-discrete Real variables
v, the equation “v = startExpression” is added to the initialization
equations, if “
start = startExpression” and “fixed = true”.
• For all discrete variables
vd, the equation “pre(vd) = startExpression” is added to the initialization
equations, if “
start = startExpression” and “fixed = true.
• For constants and parameters, the attribute fixed is by default true. For other variables fixed is by default
false.
[A Modelica translator may first transform the continuous equations of a model, at least conceptually, to state
space form. This may require to differentiate equations for index reduction, i.e., additional equations and, in some
cases, additional unknown variables are introduced. This whole set of equations, together with the additional
constraints defined above, should lead to an algebraic system of equations where the number of equations and the
number of all variables (including
der(..) and pre(..) variables) is equal. Often, this is a nonlinear system
of equations and therefore it may be necessary to provide appropriate guess values (i.e., start values and
fixed=false) in order to compute a solution numerically.
It may be difficult for a user to figure out how many initial equations have to be added, especially if the system
has a higher index. A tool may add or remove initial equations automatically such that the resulting system is
structurally nonsingular. In these cases diagnostics are appropriate since the result is not unique and may not be
what the user expects. A missing initial value of a discrete variable which does not influence the simulation
result, may be automatically set to the start value or its default without informing the user. For example, variables