Opened 4 years ago

Last modified 3 years ago

#6293 new defect

Function non-inputs are initialized in the wrong order

Reported by: perost Owned by: perost
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)

comment:1 in reply to: ↑ description ; follow-up: Changed 4 years ago by casella

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?

comment:2 in reply to: ↑ 1 Changed 4 years ago by perost

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 Changed 4 years ago by casella

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

comment:4 Changed 4 years ago by perost

  • Priority changed from high to low

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 Changed 4 years ago by casella

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

comment:6 Changed 3 years ago by casella

  • Milestone 1.18.0 deleted

Ticket retargeted after milestone closed

Note: See TracTickets for help on using tickets.