Opened 7 years ago

Closed 6 years ago

#5010 closed defect (fixed)

Issue with NFRangeIterator.fromDim

Reported by: Francesco Casella Owned by: Per Östlund
Priority: high Milestone: 2.0.0
Component: New Instantiation Version:
Keywords: Cc:

Description

Please check Modelica_trunk_Modelica.Media.Examples.MoistAir. The following error is reported:

[PpenModelica/OMCompiler/Compiler/NFFrontEnd/NFRangeIterator.mo:164:11-164:87:writable]
Error: Internal error NFRangeIterator.fromDim got unknown dim

This also affects other Media examples.

Change History (6)

comment:1 by Per Östlund, 7 years ago

Resolution: fixed
Status: newclosed

Already fixed in 5615485, it just hasn't had time to show up in the test results yet.

comment:2 by Francesco Casella, 7 years ago

Resolution: fixed
Status: closedreopened

There are still test cases showing the same problem, see e.g. ThermoPower.Examples.HRB.Simulators.ClosedLoopDigitalSimulator.

in reply to:  2 comment:3 by Per Östlund, 6 years ago

Resolution: fixed
Status: reopenedclosed

Replying to casella:

There are still test cases showing the same problem, see e.g. ThermoPower.Examples.HRB.Simulators.ClosedLoopDigitalSimulator.

It seems like c41a2f16 accidentally fixed that issue, and with some other minor fixes in d680f89 that model now flattens but doesn't pass the backend yet.

comment:4 by Francesco Casella, 6 years ago

Resolution: fixed
Status: closedreopened

There are still prolems with NFRangeIterator.fromDim in NFScalarize.scalarize if you try the test model of #2858

model TestMixture
  package Medium = Modelica.Media.IdealGases.MixtureGases.FlueGasSixComponents;
  Medium.BaseProperties medium;
  Medium.MolarMass MM[:] = Medium.data.MM;
equation 
  medium.p = 1e5;
  medium.T = 300;
  medium.X[1] = time;
  medium.X[2] = 1 - time;
  medium.X[3:6] = zeros(4);
end TestMixture;

which fails with

Translation Error
[OMCompiler/Compiler/NFFrontEnd/NFRangeIterator.mo: 164:11-164:87]:
Internal error NFRangeIterator.fromDim got unknown dim

I hope fixing this issue finally resolves #2858 for good.

Last edited 6 years ago by Francesco Casella (previous) (diff)

in reply to:  4 comment:5 by Per Östlund, 6 years ago

Replying to casella:

There are still prolems with NFRangeIterator.fromDim in NFScalarize.scalarize if you try the test model of #2858

Fixed in ab87884, although now the model gets a division by zero in the call to molarMass:

assert            | debug   | division by zero at time 0, (a=1) / (b=0), where divisor b expression is: sum(medium.state.X[j] / ({0.0280134, 0.00201588, 0.0280101, 0.0319988, 0.01801528, 0.0440095})[j] for j in 1:6)

I'm not yet sure if that's due to the NF flattening the model incorrectly somehow, or due to some backend issue (or maybe even a model issue?). As #2858 says the old frontend flattens molarMass incorrectly to:

function TestMixture.Medium.molarMass
  input TestMixture.Medium.ThermodynamicState state;
  output Real MM(quantity = "MolarMass", unit = "kg/mol", min = 0.001, max = 0.25, nominal = 0.032);
algorithm
  MM := 0.0280134 / (state.X[1] + state.X[2] + state.X[3] + state.X[4] + state.X[5] + state.X[6]);
end TestMixture.Medium.molarMass;

while the new flattens it to:

function TestMixture.Medium.molarMass
  input Medium.ThermodynamicState state;
  output Real MM(quantity = "MolarMass", unit = "kg/mol", min = 0.001, max = 0.25, nominal = 0.032);
algorithm
  MM := 1.0 / sum(state.X[j] / {0.0280134, 0.00201588, 0.0280101, 0.0319988, 0.01801528, 0.0440095}[j] for j in 1:6);
end TestMixture.Medium.molarMass;

comment:6 by Francesco Casella, 6 years ago

Resolution: fixed
Status: reopenedclosed

The body of the Modelica.Media.IdealGases.Common.MixtureGasNasa.molarMass function is

    MM := 1/sum(state.X[j]/data[j].MM for j in 1:size(state.X, 1));

so the old front-end was definitely not flattening it correctly, while the new front-end apparently does.

However, the reduction expression is found in a function body, so it is not evaluated by the front end. When the back-end inlines it, it does not process it correctly, causing a runtime error.

I'm closing the ticket because this is no longer a NF issue, please see #5200

Note: See TracTickets for help on using tickets.