Skip to content

Don't require discrete-time Real variables to be assigned in when-clauses #3247

@henrikt-ma

Description

@henrikt-ma

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 declared discrete be assigned in a when-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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionIndicates that there's a discussion; not clear if bug, enhancement, or working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions