Skip to content

Clarification on fixed point iterations for pre() #3909

@PeterMeisrimelModelon

Description

@PeterMeisrimelModelon

Consider the following model:

model min_ex
    Real x(start = 3);
    Real z(start = 0);
    Real t;
    Boolean b;
    discrete Real output_state(start = 0);
equation
    b = x < 2;
    x + t + z = 3;
    if b then
        t = 2*time;
    else
        t = time;
    end if;
    if x < 1.9 then
        z = 1;
    else
        z = 0;
    end if;
    when b then
        output_state = x;
    end when;
end min_ex;
  • Initial solution for x is 3, and decreases as time increases as per t = time.
  • At time = 1 (x = 2), there will be an event:
    • first: b becomes true => t becomes 2, new solution: x = 1
    • second: x < 1.9 becomes false => z becomes 1, new solution: x = 0
    • Note: This example can be expanded to make this an N step process.
  • The when construct is to capture the value of x with the change in b (which was also the intention of the modeller), but what is the expected value?
    • 1 as the value of the iteration when b first becomes true?
    • 0 as the final value after the value for x has been fully resolved? (which was what the modeller expected)
    • Something else?
    • The modeler expected this value to be 0 in this reproducer
  • The example can simplified by replacing the use of b with x < 2. This gives fewer dependencies, while effectively being the same model.

What should be the correct solution here and more importantly: why?

Disclaimer: OCT currently yields output_state = 1 for this model. We suspect this is not the correct result, but it is not evident to us from the specification.

Specification for pre()
Chapter 3 Operators and Expressions ‣ Modelica® Language Specification version 3.7 states a lot of things, but it is still not quite clear:

  • What does “mask event iteration“ mean to begin with?
  • Is this type of example the non-normative text refers to with “global fix point iteration scheme, similarly to the event iteration“?
    • I.e., a fixed point iteration that resolves the chain of “if” evaluations required to compute “x“, before evaluating the when block for the first time.

Edit: fixed mistake pointed out in comment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clarificationSpecification of feature is unclear, but not incorrect

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions