-
Notifications
You must be signed in to change notification settings - Fork 44
Description
I have a modeling problem where I need to detect changes in a Real
variable that is discrete-time by construction, without being assigned in a when
-clause. This captures what I'd like the specification to allow:
model M
discrete Real x(start = 0.0, fixed = true);
discrete Real y = x + floor(time); /* Currently not allowed */
Integer count(start = 0);
equation
when time > 0.5 then
x = 0.1;
end when;
when change(y) then
count = pre(count) + 1;
end when;
end M;
This would only require minor changes in the specification:
- Don't require that a
Real
variable declareddiscrete
be assigned in awhen
-clause. - Make all variables declared
discrete
have discrete-time component variability. - (Make sure we use the term discrete-time states (or some other terminology) is used instead of discrete-time variables when referring to a variable assigned in a
when
-clause.) - (For backwards compatibility, allow variables assigned in
when
-clauses to be implicitly discrete-time, just like today.)
Note that the following existing rule is key to the semantics of the new discrete-time Real
variables:
When determining whether an equation can contribute to solving for a variable v (for instance, when applying the perfect matching rule, see section 8.4), the equation can only be considered contributing if the resulting solution would be at most as variable as v.
Also note that existing variability rules also disallow bad non-sensical things like this:
discrete Real y = x + time; /* Variability error: RHS has higher variability than declared component. */
This has been test-implemented with good results in System Modeler.