Opened 10 years ago

Closed 10 years ago

#3168 closed defect (fixed)

Wrong type or wrong number of arguments

Reported by: Rüdiger Franke Owned by: Rüdiger Franke
Priority: high Milestone: 1.9.2
Component: Frontend Version: trunk
Keywords: Cc:

Description

The following three models of the PowerSystems library fail with the error reported here, using OpenModelica r24644:
PowerSystems.Examples.Spot.AC3ph.Machines
PowerSystems.Examples.Spot.TransmissionAC3ph.DoublePIlineTG
PowerSystems.Examples.Spot.TransmissionAC3ph.DoubleRXlineTG

The following model reproduces the problem:

package WrongDiagonal
  function f
    input Real[:] a;
    output Real[size(a,1) - 1, size(a,1) - 1] T;
  protected
    parameter Integer n = size(a,1);
  algorithm
    T := diagonal(ones(n-1));
  end f;

  model M
    parameter Real[:,:] T = f({1,2,3});
  end M;
end WrongDiagonal;

Checking or attempting to simulate WrongDiagonal.M gives:

[1] 13:55:10 Translation Error
Error occurred while flattening model WrongDiagonal.M

[2] 13:55:10 Translation Error
[/home/user/work/WrongDiagonal.mo: 8:5-8:29]: Wrong type or wrong number of arguments to diagonal(ones(n - 1)). (in component ).

Change History (3)

comment:1 by Rüdiger Franke, 10 years ago

The example works if the parameter qualifier is removed from n and if the nested function call is avoided:

package WrongDiagonal
  function f
    input Real[:] a;
    output Real[size(a,1) - 1, size(a,1) - 1] T;
  protected
    Integer n = size(a,1);
  algorithm
    //T := diagonal(ones(n-1));
    T := identity(n-1);
  end f;

  model M
    parameter Real[:,:] T = f({1,2,3});
  end M;
end WrongDiagonal;

It's fine to not use parameters inside functions. But the nested function call should work (it's generally not that trivial to avoid them).

comment:2 by Rüdiger Franke, 10 years ago

Owner: changed from somebody to Rüdiger Franke
Status: newassigned

The problem is caused by the function Static.elabBuiltinDiagonal that forces known dimensions. The implementation of dimensionKnown does not cover functions with variable array sizes.

Note that dimensionKnown is hardly used anywhere else in Static. Only Static.elabBuiltinScalar and Static.elabSubscriptsDims2 call it to exploit known dimensions, but they do not require it.

The call to dimensionKnown is removed from Static.elabBuiltinDiagonal in r24849.

comment:3 by Rüdiger Franke, 10 years ago

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.