Opened 10 years ago

Closed 8 years ago

#3211 closed defect (fixed)

Inconsistent handling of final attribute

Reported by: crupp@… Owned by: Patrick Täuber
Priority: high Milestone: Future
Component: *unknown* Version: trunk
Keywords: Cc: Martin Sjölund, Lennart Ochel

Description

In the following example, the protected parameter b does not get updated when parameter a is updated.

My interpretation of the Modelica spec is that protected variables are like local variables and can only be modified/accessed locally but shouldn't prevent the intended behavior here (correct me if I'm wrong).

loadString("
model protectedbug
parameter Real a = 0.24;
Real x(start = 1.0, fixed = true);
protected
parameter Real b = 2.0 * a;
equation
der(x)=-b*x;
end protectedbug;
");

// Value of b is 0.48, x is 0.61878
simulate(protectedbug);
val(b,1.0);
val(x,1.0);

// Override of a does not change b, value of b should b 1.0, x should be 0.13534
simulate(protectedbug, simflags="-override a=1.0");
val(b,1.0);
val(x,1.0);

Tested in r24986.

Change History (10)

comment:1 by Lennart Ochel, 10 years ago

This happens in pre-optimization module evaluateReplaceProtectedFinalEvaluateParameters.

comment:2 by Lennart Ochel, 10 years ago

Owner: changed from somebody to Lennart Ochel
Status: newaccepted

It should work now (r25012). Not sure if my fix breaks anything … we will see.

comment:3 by crupp@…, 10 years ago

18 minutes to fix this, impressive!!!

in reply to:  3 comment:4 by Lennart Ochel, 10 years ago

Replying to crupp@…:

18 minutes to fix this, impressive!!!

Well, not really. It broke some models. I will have a closer look tomorrow.

comment:5 by Lennart Ochel, 10 years ago

Cc: Martin Sjölund added

Evaluation of protected parameters was introduced in r20675. Martin, why get those parameters evaluated during compilation?

comment:6 by Martin Sjölund, 10 years ago

Probably the correct properties is sent somewhere which causes a parameter to be evaluated

comment:7 by Patrick Täuber, 8 years ago

Cc: Lennart Ochel added
Owner: changed from Lennart Ochel to Patrick Täuber
Status: acceptedassigned

The problem is the inconsistent handling of the final attribute. The protected parameter "b" which is considered to be final is dependent on "a", which is not declared to be final but used to evaluate "b". So if you change "a" after compilation "b" is not evaluated again.

Things to discuss about are:

Should protected parameters be considered as final?

How to handle the final attribute? Is "a" implicitly final? Then it must not be possible to change "a" after compilation. Or is only the binding of a parameter "final". In this case you could change the value of "a" after compilation and "b" would always be "2*a".

I will open a ticket at the Modelica trac about this to get to know how to handle the latter.

comment:8 by Patrick Täuber, 8 years ago

Summary: Protected secondary parameters don't get updatedInconsistent handling of final attribute

comment:9 by Rüdiger Franke, 8 years ago

The attribute final primarily means that the parameter must not be modified anymore. This is of interest during flattening in the frontend. The backend should consider final parameters like bound parameters.

comment:10 by Patrick Täuber, 8 years ago

Resolution: fixed
Status: assignedclosed

Since d75f648 parameters are handled in a consistent way.

Note: See TracTickets for help on using tickets.