﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
2690	Problems with functions returning multi-dimensional arrays in when statements	Francesco Casella	Per Östlund	"Please consider the following test cases:

{{{
package TestFunctionArray
  function getVal
    input Integer nx, ny;
    output Real val[nx, ny];
  algorithm
    for i in 1:nx loop
      for j in 1:ny loop
        val[i, j] := i * j;
      end for;
    end for;
  end getVal;

  model TestOnes
    parameter Integer N = 2;
    parameter Real Ts = 0.0001;
    discrete Real v[N, N];
  equation
    when sample(0, Ts) then
      v = ones(N, N);
    end when;
    annotation(experiment(StartTime = 0, StopTime = 0.1, Tolerance = 1e-006, Interval = 0.0002));
  end TestOnes;

  model TestOnesLarge
    extends TestOnes(N = 50);
     annotation(experiment(StartTime = 0, StopTime = 0.1, Tolerance = 1e-006, Interval = 0.0002));
  end TestOnesLarge;

  model TestVal
    parameter Integer N = 2;
    parameter Real Ts = 0.0001;
    discrete Real v[N, N];
  equation
    when sample(0, Ts) then
      v = getVal(N, N);
    end when;
    annotation(experiment(StartTime = 0, StopTime = 0.1, Tolerance = 1e-006, Interval = 0.0002));
  end TestVal;

  model TestValLarge
    extends TestVal(N = 50);
    annotation(experiment(StartTime = 0, StopTime = 0.1, Tolerance = 1e-006, Interval = 0.0002));
  end TestValLarge;

  model TestAlgorithm
    parameter Integer N = 2;
    parameter Real Ts = 0.0001;
    discrete Real v[N, N];
  algorithm
    when sample(0, Ts) then
      v := getVal(N, N);
    end when;
    annotation(experiment(StartTime = 0, StopTime = 0.1, Tolerance = 1e-006, Interval = 0.0002));
  end TestAlgorithm;

  model TestAlgorithmLarge
    extends TestAlgorithm(N = 50);
    annotation(experiment(StartTime = 0, StopTime = 0.1, Tolerance = 1e-006, Interval = 0.0002));
  end TestAlgorithmLarge;
end TestFunctionArray;
}}}

- TestOnes works fine
- TestOnesLarge requires to kill the omc.exe process, otherwise
  it goes on forever in the compiling phase
- TestVal generates incorrect C-code
- TestValLarge again requires to kill the omc.exe process
- TestAlgorithm works fine
- TestAlgorithmLarge works fine, although it takes about 30 seconds to compile

Apparently there is something wrong with functions returning multi-dimensional arrays within when-statements in the back-end, but only if the when statement is used in the equation section. Note that such models are quite common when modelling 2D and 3D thermal systems.

I reckon there is not much testing involving multi-dimensional arrays in the testsuite, so maybe these cases reveal some design flaw in the back-end."	defect	closed	high	1.9.4	Backend	trunk	fixed		federico.terraneo@… alberto.leva@…
