Opened 6 years ago

Closed 6 years ago

#5249 closed defect (fixed)

[NF] Issues with variable scalarization

Reported by: Adrian Pop Owned by: Per Östlund
Priority: high Milestone: 1.14.0
Component: New Instantiation Version:
Keywords: Cc:

Description

Flattening ThermalSeparation.Examples.Absorption_IdealGases from:
https://github.com/adrpo/ThermalSeparation gives you:

"[C:/home/adrpo33/dev/OpenModelica/OMCompiler/Compiler/NFFrontEnd/NFExpression.mo:1296:7-1297:111:writable] Error: Internal error NFExpression.makeSubscriptedExp: too few dimensions in 
MediumLiquid.ThermodynamicProperties(
 column1.mediumLiquid[1].properties.T, 
 column1.mediumLiquid[1].properties.sigma, 
 column1.mediumLiquid[1].properties.eta, 
 column1.mediumLiquid[1].properties.eta_comp, 
 column1.mediumLiquid[1].properties.rho, 
 column1.mediumLiquid[1].properties.MM, 
 column1.mediumLiquid[1].properties.v, 
 column1.mediumLiquid[1].properties.x, 
 column1.mediumLiquid[1].properties.d, 
 column1.mediumLiquid[1].properties.h, 
 column1.mediumLiquid[1].properties.lambda, 
 column1.mediumLiquid[1].properties.cp, 
 column1.mediumLiquid[1].properties.u, 
 column1.mediumLiquid[1].properties.p, 
 column1.mediumLiquid[1].properties.c) 
to apply subscripts [1]

This happens during flattening, so typing went fine.
On the way to this error the NF does NFBinding.setTypedExp with an record expression that is not an array even if the bindingType of that binding is an array. I added a check in setTypedExp to check if the dimensions of the expression and the bindingType agree. I get:

bindingExp type: ThermodynamicProperties binding type: ThermodynamicProperties[10]

Change History (6)

comment:1 by Adrian Pop, 6 years ago

As far as I can tell this happens if you have a pattern like this:

  Record x[n];
  Type a[n](record = x);

I found a minimal example:

model M

  record X
    Real a;
  Real b;
  end X;
  constant Integer n = 2;
  X x[n] = {X(1, 2), X(2, 3)};
  
  model H
    X x;
  end H;
  
  H h[n](x = x);
end M;

This gives me the same error:

adrpo33@ida-0030 MINGW64 /c/home/adrpo33/dev/OMTesting/thermal
$ time ~/dev/OpenModelica/build/bin/omc -d=newInst --showAnnotations m.mo
bindingExp type: X binding type: X[2]
Error processing file: m.mo
[C:/home/adrpo33/dev/OpenModelica/OMCompiler/Compiler/NFFrontEnd/NFExpression.mo:1296:7-1297:111:writable] 
Error: Internal error NFExpression.makeSubscriptedExp: too few dimensions in 
X(x[1].a, x[1].b) to apply subscripts [1]

comment:2 by Adrian Pop, 6 years ago

Milestone: Future1.14.0

comment:3 by Adrian Pop, 6 years ago

Should be fixed by PR: https://github.com/OpenModelica/OMCompiler/pull/2836
@perost: please check.

// $ omc -d=newInst m.mo
class M
  constant Integer n = 2;
  Real x[1].a = 1.0;
  Real x[1].b = 2.0;
  Real x[2].a = 2.0;
  Real x[2].b = 3.0;
  Real h[1].x.a = x[1].a;
  Real h[1].x.b = x[1].b;
  Real h[2].x.a = x[2].a;
  Real h[2].x.b = x[2].b;
end M;

comment:4 by Adrian Pop, 6 years ago

The first part of this ticket is done, but the models are failing in NFScalarize.scalarizeVariable on a really involved if expression:

final parameter SI.Temperature T_v_start[n] = if (T_v_profile and not n==1) then linspace(T_vap_start_bottom, T_vap_start_top, n) else (if (T_v_profile and n==1) then ones(n)*(T_vap_start_bottom+ T_vap_start_top)/2 else ones(n)*T_vapour_start);

comment:5 by Adrian Pop, 6 years ago

Summary: [NF] Issues with flattening of array bindings[NF] Issues with variable scalarization

comment:6 by Per Östlund, 6 years ago

Resolution: fixed
Status: newclosed

Fixed in 2ae95cf. The linspace in the if-expression was turned into an array constructor of size 1:n. But when the n was evaluated to 10 later on we didn't update the type of the array constructor, causing the scalarization to fail.

The model now passes the frontend, but fails in the backend for some reason.

Note: See TracTickets for help on using tickets.