Ticket #37 (closed defect: invalid)

Opened 10 months ago

Last modified 9 months ago

Clarify execution order of statements in an algorithm

Reported by: mauss Owned by: otter
Priority: normal Milestone:
Component: --Modelica Specification-- Version: 3.0
Severity: Keywords:
Cc: Hide ticket:

Description (last modified by dietmarw) (diff)

The following model contains an algorithm with three
statements a,b,c. These seem to be executed in the
order a,c,b, which I find not completely obvious when
reading the specification.

model A
  Real x;
  Real y;
algorithm
  when time>0.5 then
    x := 1;
  end when;
  y := x;
  when time>0.5 then
    x := 2;
  end when;
end A;

When running this, y jumps from 0 to 2 at time=0.5,
not from 0 to 1 as one might expect.
Dynasim confirmed that this is the intended behaviour.

Proposal: In section 11.2.7 of the Modelica Spec 3.0,
clarify that all activated when statements of an algorithm
section are executed in their order of occurrence in the
algorithm section, but BEFORE all other statements
of the algorithm section.

Attachments

Change History

Changed 10 months ago by dietmarw

  • description modified (diff)

Changed 9 months ago by HansOlsson

  • status changed from new to closed
  • resolution set to invalid
  • milestone 3.1 deleted

The description is incorrect.

The actual execution order is not a,c,b but a,b,c,b or in more detail:

first event iteration: a,b,c,
following event iterations: (skip a), b, (skip c)
(this can be repeated several times and the result is the same - as defined for event iterations)

This can be confirmed by changing this to:

when time>0.5 then

x := 1;

end when;
y := 1/(1-x);
when time>0.5 then

x := 2;

end when;

The proposed change would cause a change in semantics for algorithms - with unknown consequences.

However, a tool may often perform it as an optimization according to the general rule allowing optimizations.
---
Basically when the algorithm is executed once again during the event iteration y := 2 according to the algorithm. Thus y has several values at t=0.5, but you do not see the value y = 1.

Add/Change #37 (Clarify execution order of statements in an algorithm)

Author



Action
as closed
Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.