Opened 10 years ago

Last modified 10 years ago

#3182 new defect

dimension size of function calls

Reported by: vwaurich Owned by: somebody
Priority: high Milestone: Future
Component: Frontend Version: trunk
Keywords: functions, array dimension Cc: perost, sjoelund.se, adrpo, niklwors

Description

Hi,

The dimension of an array-equation with (external) functions can occasionally be evaluated. See example model:

package funcTest
  
  function func
    input Real[n] arrIn;
    input Integer n;
    output Real[n] arrOut;
  external "C" foo(arrIn,arrOut);
  end func;

  model funcDimension
    parameter Integer n1 = 2;
    Real x[n1], x1[n1];
    Real y;
  equation 
    for i in 1:n1 loop
      x1[i] = time;
    end for;
    x = func(x1,n1);
    der(y) = x[1];
  end funcDimension;

end funcTest;

+d=dumpSimCode tells us that

8: x=funcTest.func(x1, 2)[Real[:] ]

the dimension of the arrayequation is unknown but actually, this could be evaluated with the help of the function declaration to n i.e. n1 and even 2 (if we evaluate parameter).

Change History (2)

comment:1 follow-up: Changed 10 years ago by rfranke

How do you use dumpSimCode? Can you post a command line call? I tried

$  omc +d=dumpSimCode -i=funcTest.funcDimension funcTest.mo

and got nothing but the regular flattened model.

Btw. Modelica libraries typically use the size operator. Some even overuse the size operator (maybe hoping for better tool support); see e.g. Modelica.Math.Matrices.continuousLyapunov. The best practice seems to be to use the size operator for I/O arguments, but not for internal variables, see e.g. Modelica.Math.Matrices.exp.

  function func
    input Real[:] arrIn;
    output Real[size(arrIn,1)] arrOut;
  external "C" foo(arrIn,arrOut);
  end func;

comment:2 in reply to: ↑ 1 Changed 10 years ago by vwaurich

Replying to rfranke:

How do you use dumpSimCode? Can you post a command line call? I tried

$  omc +d=dumpSimCode -i=funcTest.funcDimension funcTest.mo

and got nothing but the regular flattened model.

Btw. Modelica libraries typically use the size operator. Some even overuse the size operator (maybe hoping for better tool support); see e.g. Modelica.Math.Matrices.continuousLyapunov. The best practice seems to be to use the size operator for I/O arguments, but not for internal variables, see e.g. Modelica.Math.Matrices.exp.

  function func
    input Real[:] arrIn;
    output Real[size(arrIn,1)] arrOut;
  external "C" foo(arrIn,arrOut);
  end func;

+d=dumpSimCode outputs the objects used for the templates. If you only instantiate your class with -i then the Compiler will not generate the simCode structure.
You could activate the simulation codegen. Add -s to your command line call.

Note: See TracTickets for help on using tickets.