-
Notifications
You must be signed in to change notification settings - Fork 43
Description
Reported by otter on 29 Jun 2011 09:02 UTC
It is not obvious how to handle reinit(..) in a tool. It seems therefore useful to add a comment in section 8.3.6 of the Modelica specification:
[A reinit(..) clause should be sorted together with all other equations. This can be performed in the following way:
A statement of the form:
when condition then
reinit(x, expr)
end when;
is mapped to the following equation:
b = condition
x = if edge(b) then expr else fromIntegrator(id_x);
_where fromIntegrator(..) is a known tool specific function and id_x is the known identifier to identify "x" (e.g., the index of x in the state vector). This mapped equation can be sorted with all other equations under the assumption that the state x is an "unknown" and no longer a "known". As for all when-equations, it is an error if an algebraic loop contains equations from when-clauses with different when-conditions.
Examples:
_
algorithm
when z > 0 then
reinit(x, 2*y)
reinit(y, 2*x)
end when;
_
this is o.k., since mapped to:_
algorithm
x := pre(x)
y := pre(y)
b := z > 0
x := if b and not pre(b) then 2*y else fromIntegrator(id_x);
y := if b and not pre(b) then 2*x else fromIntegrator(id_x);
_
On the other hand:_
equation
when y > 0 then
reinit(x, 2*y);
end when;
when x > 0 then
reinit(y, 2*x)
end when;
is an error, since mapped to an algebraic loop with equations from two when clauses:
equation
x = if edge(y>0) then 2*y else fromIntegrator(id_x);
y = if edge(x>0) then 2*x else fromIntegrator(id_y);
/* These are two equations in two unknowns
0 = f1(x,y) // when-condition y > 0
0 = f2(x,y) // when-condition x > 0
*/
]
Migrated-From: https://trac.modelica.org/Modelica/ticket/578