Opened 4 years ago

Last modified 3 years ago

#6293 new defect

Function non-inputs are initialized in the wrong order

Reported by: Per Östlund Owned by: Per Östlund
Priority: low Milestone:
Component: New Instantiation Version: v1.17.0-dev
Keywords: Cc:

Description

Non-input components in functions should according to 12.4.4 be initialized in an order such that a variable isn't used before it has been initialized. The NF does not yet do this, which causes e.g. ModelicaTest.Fluid.Dissipation.Verifications.HeatTransfer.HeatExchanger.kc_flatTube to fail during simulation due to using uninitialized variables.

The old frontend handles this by reordering the protecteds component according to their dependencies, but obviously it can't do that with the output components which means it has issues with something like:

function f
  input Real x;
  output Real y = z; // OF assigns z to y before z has been initialized
  output Real z = x;
end f;

model M
  Real x, y;
equation
  (x, y) = f(time);
end M;

We should investigate whether there's some way to specify the initialization order without actually reordering the components so we can handle both protected and output components in the NF.

Change History (6)

in reply to:  description ; comment:1 by Francesco Casella, 4 years ago

Replying to perost:

We should investigate whether there's some way to specify the initialization order without actually reordering the components so we can handle both protected and output components in the NF.

In the meantime, I understand @perost can port the current OF solution, which works fine in most cases.

BTW, Section 12.4.4 mentions declaration assignments :=expression, not equations, but then nobody uses the semicolon. Not the MSL, not any Modelica tool. Should we fix Modelica 3.5 accordingly, before it is released?

in reply to:  1 comment:2 by Per Östlund, 4 years ago

Replying to casella:

BTW, Section 12.4.4 mentions declaration assignments :=expression, not equations, but then nobody uses the semicolon. Not the MSL, not any Modelica tool. Should we fix Modelica 3.5 accordingly, before it is released?

It's already been fixed in 3.5, see 12.4.4 in master.

comment:3 by Francesco Casella, 4 years ago

Aha, I had a recollection of working on that, I should have checked. Very good.

comment:4 by Per Östlund, 4 years ago

Priority: highlow

Fixed for local components in 14d191b, which should fix most models affected by this issue. I'll leave this ticket open since it's still an issue for outputs, but with low priority since I don't know of any models where that's an issue.

comment:5 by Francesco Casella, 4 years ago

Good! I'm curious to see how many models in the library testsuite are affected by this fix.

comment:6 by Francesco Casella, 3 years ago

Milestone: 1.18.0

Ticket retargeted after milestone closed

Note: See TracTickets for help on using tickets.