## 'reinit()'reinit() |

This information is part of the Modelica Standard Library maintained by the Modelica Association.

Reinitialize state variable

reinit(x, expr)

The operator reinitializes `x`

with expr at an event instant. `x`

is a Real variable
(or an array of Real variables) that must be selected as a state (resp., states), that is
reinit on `x`

implies `stateSelect = StateSelect.always`

on `x`

.
`expr`

needs to be type-compatible with `x`

. The reinit operator can for the same variable
(resp. array of variables) only be applied (either as an individual variable or as part
of an array of variables) in one equation (having reinit of the same variable in when and
else-when of the same variable is allowed).
The reinit operator can only be used in the body of a when-equation. It cannot be used
in an algorithm section.

The reinit operator does not break the single assignment rule, because reinit(x,expr) in equations evaluates expr to a value (value), then at the end of the current event iteration step it assigns this value to x (this copying from values to reinitialized state(s) is done after all other evaluations of the model and before copying x to pre(x)).

*
[If a higher index system is present, that is constraints between state variables,
some state variables need to be redefined to non-state variables. During simulation,
non-state variables should be chosen in such a way that variables with an applied reinit
operator are selected as states at least when the corresponding when-clauses become active.
If this is not possible, an error occurs, since otherwise the reinit operator would be applied
on a non-state variable.]
*

// Bouncing ballparameterReal e=0.5 "Coefficient of restitution" Real h, v; Boolean flying;equationder(h) = v;der(v) =ifflyingthen-gelse0; flying =not(h<=0andv<=0);whenh < 0thenreinit(v, -e*pre(v));end when;