Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variability of record instances #1832

Closed
modelica-trac-importer opened this issue Nov 4, 2018 · 8 comments
Closed

Variability of record instances #1832

modelica-trac-importer opened this issue Nov 4, 2018 · 8 comments
Labels
bug Something isn't working worksforme
Milestone

Comments

@modelica-trac-importer
Copy link
Collaborator

Reported by stefanv on 11 Nov 2015 15:34 UTC
If all of the members of a record are declared constant or parameter, is an instance of the record itself automatically considered a constant or parameter, even if it is not explicitly declared as such?

record Rec
    constant Real x = 1;
    constant Real y = 2;
end Rec;

function Func
    input Rec r;
    output Real z;
algorithm
    z := r.x + r.y;
    annotation (Inline=false);
end Func;

model Main
    Real Rec rec; // Notice that rec is not declared constant.
    constant Real K = Func(rec); // Here rec is used as if it were constant.
end Main;

Is the definition of Main.K legal? Its value depends on rec, which is not declared as a constant.

[Note that if the function were inlined, the resulting expression would be constant, and I could envision a tool failing to notice that rec itself is not constant. Hence, I added the Inline=false annotation to Func, although it shouldn't actually make a difference to the legality of the declaration of K.]


Migrated-From: https://trac.modelica.org/Modelica/ticket/1832

@modelica-trac-importer
Copy link
Collaborator Author

Comment by hansolsson on 16 Dec 2015 09:19 UTC
Example is slightly syntactically wrong and should be:

record Rec
    constant Real x = 1;
    constant Real y = 2;
end Rec;

function Func
    input Rec r;
    output Real z;
algorithm
    z := r.x + r.y;
    annotation (Inline=false);
end Func;

model Main
    Rec rec; // Notice that rec is not declared constant.
    constant Real K = Func(rec); // Here rec is used as if it were constant.
end Main;

@modelica-trac-importer
Copy link
Collaborator Author

Comment by jmattsson on 16 Dec 2015 09:56 UTC
I'd say that this boils down to if you consider a record to be just a collection of values or a value in its own right.

There is a related issue:

record Rec
    Real x;
    Real y;
end Rec;

model A
    Rec r;
end A;

model B
    A a(r = Rec(1, 2));
end B;

model Test
    B b(a(r(x = 3)));
end Test;

Is the modification in Test allowed?

I think these issues are closely related, and should be resolved together.

@modelica-trac-importer
Copy link
Collaborator Author

Comment by dietmarw on 8 Jan 2016 19:07 UTC
Ticket retargeted after milestone closed

@modelica-trac-importer modelica-trac-importer removed this from the Design88 milestone Nov 4, 2018
@modelica-trac-importer
Copy link
Collaborator Author

Modified by stefanv on 3 Mar 2016 16:50 UTC

@modelica-trac-importer
Copy link
Collaborator Author

Comment by hansolsson on 9 Mar 2016 14:34 UTC
Design group:
That "rec" is constant has been used in e.g. MSL.
If the intent is to get parameter-dialog for "rec", then that can be done by using annotation(Dialog(...)). A possibility would be some variant of "constant record Rec ..." declaring that "Rec" is constant-record class - even when extending it.

@modelica-trac-importer
Copy link
Collaborator Author

Modified by otter on 5 Aug 2016 05:58 UTC

@modelica-trac-importer modelica-trac-importer added this to the Design91 milestone Nov 4, 2018
@modelica-trac-importer
Copy link
Collaborator Author

Comment by hansolsson on 13 Sep 2016 12:49 UTC
Replying to [comment:5 hansolsson]:

Design group:
That "rec" is constant has been used in e.g. MSL.

Should investigate if this is still the case - possibly in Spice3.
OpenModelica doesn't view it as constant; so generates an error for the model above.

If the intent is to get parameter-dialog for "rec", then that can be done by using annotation(Dialog(...)). A possibility would be some variant of "constant record Rec ..." declaring that "Rec" is constant-record class - even when extending it.

Unclear if "rec" should be seen as constant or not - depends on whether viewing "rec" as a collection of components, or as the whole record.

@modelica-trac-importer
Copy link
Collaborator Author

Comment by hansolsson on 14 Sep 2016 12:49 UTC
It seems that the 'SpiceConstants' components in Spice3 are now declared as 'constant'.

The most correct case seems to be require 'rec' to be declared as constant to treat it as constant (according to 3.8.1).
Will test-implement whether that breaks any user models in Dymola.
--
Seems that no change of specification is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment