Ticket #103 (closed enhancement: fixed)

Opened 3 months ago

Last modified 2 weeks ago

Specification of reinit (was: Two reinits in Translational.Stop)

Reported by: otter Owned by: HansOlsson
Priority: normal Milestone: ModelicaSpec3.1
Component: --Modelica Specification-- Version: Spec3.0
Severity: normal Keywords:
Cc: Hide ticket: no

Description

Modelica.Mechanics.Translational.Stop has the following code fragment:

     when not (s < smax - L/2) then
        reinit(s, smax - L/2);
        if (not initial() or v>0) then
          reinit(v, 0);
        end if;
      end when;
 
      when not (s > smin + L/2) then
        reinit(s, smin + L/2);
        if (not initial() or v<0) then
          reinit(v, 0);
        end if;
      end when;

This is not correct Modelica according to Modelica 3.0, page 24:

reinit(x,expr): In the body of a when clause, reinitializes x with expr at an event instant. x is a Real variable (resp. an array of Real variables, in which case vectorization applies according to Section 12.4.5) that must be selected as a state (resp., states) at least when the enclosing when clause becomes active. expr needs to be type-compatible with x. The reinit operator can only be applied once for the same variable (resp. array of variables). It can only be applied in the body of a when clause. See also Section 8.3.6 .

The model should be corrected to follow the specification (so, to have only one reinit(..) call). It might be possible and useful to extend Modelica so that the reinit(..) operator can be applied to the same variable several times, in the same algorithm section, but this requires an enhancement of the Modelica language.

Attachments

Change History

Changed 3 weeks ago by AHaumer

  • owner changed from AHaumer to HansOlsson
  • status changed from new to assigned
  • version changed from trunk(dev) to Spec3.0
  • component changed from Mechanics.Translational to --Modelica Specification--
  • type changed from defect to enhancement

r1194 (trunk) and r1195 (maintenance 2.2.2, 3.0 and 3.0_ImprovedFriction) replaces the 2 x reinit by a much clearer formulation:

  Integer stopped = if s <= smin + L/2 then -1 else if s >= smax - L/2 then +1 else 0;
  when stopped <> 0 then
    reinit(s, if stopped < 0 then smin + L/2 else smax - L/2);
    if (not initial() or stopped*v>0) then
      reinit(v, 0);
    end if;
  end when;

However, Hans considers reformulating the spec for reinit.

Changed 2 weeks ago by AHaumer

  • summary changed from Two reinits in Translational.Stop to Specifiaction of reinit (was: Two reinits in Translational.Stop)

Changed 2 weeks ago by dietmarw

  • summary changed from Specifiaction of reinit (was: Two reinits in Translational.Stop) to Specification of reinit (was: Two reinits in Translational.Stop)

typo in new title fixed

Changed 2 weeks ago by HansOlsson

  • milestone changed from MSL3.0.1 to ModelicaSpec3.1

Proposed change from group - this can be corrected in the specification in a natural way:

The reinit operator can for the same variable (resp. array of variables) only be applied either in one equation (having reinit of the same variable in when and else-when of the same variable is allowed) or one or more times in one algorithm section. It can only be applied in the body of a when-equation or when-statement.

The reinit operator does not break the single assignment rule, because reinit(x,expr) in equations evaluates expr to a value (value), then makes the previously known variable x unknown and introduces the equation “x = value”. In algorithms reinit(x,expr) evaluates expr to a value (value), and then performs the assignment “x := value”.

Changed 2 weeks ago by HansOlsson

  • status changed from assigned to closed
  • resolution set to fixed

Decided to change spec.

Add/Change #103 (Specification of reinit (was: Two reinits in Translational.Stop))

Author



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