Skip to content

What is the semantics of binding equations in records? #2757

@casella

Description

@casella

Consider the following models

package P
  record R
    Real x;
    Real y = 1/x;
  end R;

  function f
    input Real t;
    output R r;
  algorithm
    r.x = t;
    r.y = 1;
  end f;

  function g
     input R r;
     output Real y;
   algorithm
     y := r.x + r.y;
  end g;

model M1
  R r1(x = 2);
  R r2;
equation
  r2.x = 1 + time;
end M1;

model M2
  R r3;
equation
  r3 = f(time);
end M2;

model M3
  Real y;
equation
  y = g(f(0));
end M3;
end P;
  • It seems quite clear to me that M1 is valid and gives r1.x = 2, and r2.y = 1/(1+time)
  • It is not clear to me if M2 is valid.
    Q1: can the algorithm in f override the binding of r.y? (A1:probably not)
    Q2: is it possible to assign the whole record in an equation, given that one element of the record has a binding? (A2: probably not)
  • It is even less clear to me if M3 is valid. Dymola compiles it, even though the binding in the record is overridden by the assignment in the algorithm. But then it fails at runtime because of a division by zero.

This discussion is motivated by some issues we're having with the HelmholtzMedia library, see OpenModelica PR 7023.

IMHO if we allow to assign records (or parts thereof) that have binding equations within function algorithms, we need to make exceptions to the fundamental idea that a binding equation is an equation by definition, not an assignment that can be overridden. Then, we would probably get down a rabbit hole of infinite discussions that may never end.

Personally, I would simply suggest to forbid doing that.

What do you think?

Metadata

Metadata

Labels

clarificationSpecification of feature is unclear, but not incorrect

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions