Opened 7 years ago

Closed 7 years ago

#4862 closed defect (fixed)

The NF does not evaluate expressions with Integer indeces

Reported by: Francesco Casella Owned by: Martin Sjölund
Priority: high Milestone: 2.0.0
Component: New Instantiation Version:
Keywords: Cc:

Description

Please check the ScalableTestSuite.Power.ConceptualPowerSystem.Verification.TwoGeneratorsStepLoad model. It currently fails during C code compilation.

Flattening the model with the NF leads to equations such as

generator[2].T_s[2] = 
  (generator[2].T_s[2 - 1] + generator[2].NTU / 4.0 * generator[2].T_source) /
  (1.0 + generator[2].NTU / 4.0);

and

  if 1 == 1 then
    P_diss[1,1] = 0.0;
    P_ex[1,1] = 0.0;
  else
    P_diss[1,1] = P_d * (generator[1].omega - generator[1].omega);
    P_ex[1,1] = P_f / /*Real*/(abs(1 - 1)) * sin(generator[1].theta - generator[1].theta);
  end if;

In the first case, the indeces of the array elements should be evaluated to literal constants (as with the old FE).

In the second case, the condition should be evaluated and only the first branch should be included in the flat code.

Change History (4)

comment:1 by Francesco Casella, 7 years ago

Something similar happens in Modelica.Blocks.Examples.PID_Controller. The flattened code contains the follwing lines

protected parameter Real kinematicPTP.p_deltaq[1] = 
  (if 1 == 1 then {1.0} * kinematicPTP.deltaq[1] else kinematicPTP.deltaq)[1];
kinematicPTP.sd_max = 1.0 / max(array(abs(kinematicPTP.aux1[$i1]) for $i1 in 1:1));

instead of

protected parameter Real kinematicPTP.p_deltaq[1] = kinematicPTP.deltaq[1];
kinematicPTP.sd_max = 1.0 / abs(kinematicPTP.aux1[1]);

comment:2 by Martin Sjölund, 7 years ago

Owner: changed from Per Östlund to Martin Sjölund
Status: newaccepted

This does not seem to be the current error. Instead it is that scalar*array and array*scalar is translated to scalar*scalar. Note also that the old FE does not have scalar*array (it swaps the arguments to only implement one operator).

comment:4 by Francesco Casella, 7 years ago

Resolution: fixed
Status: acceptedclosed

After PR #2350, the model now simulates

Note: See TracTickets for help on using tickets.