﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
5283	Issue with function with multiple outputs and arrays in the NF	Francesco Casella	Per Östlund	"Please check [https://libraries.openmodelica.org/branches/newInst/Modelica_trunk/files/Modelica_trunk_Modelica.Electrical.Machines.Examples.AsynchronousInductionMachines.AIMC_withLosses.err Modelica.Electrical.Machines.Examples.AsynchronousInductionMachines.AIMC_withLosses]. The C-code compilation fails with
{{{
Modelica_trunk_Modelica.Electrical.Machines.Examples.AsynchronousInductionMachines.AIMC_withLosses.c:282:49: error: cannot take the address of an rvalue of type 'modelica_real' (aka 'double')
  real_array_create(&tmp14, ((modelica_real*)&((&-(data->localData[0]->realVars[167] /* sineVoltage.i[1] variable */))[calc_base_index_dims_subs(1, 3, ((modelica_integer) 1))])), 1, 3);
                                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}}}
Some analysis reveals that the following line of code:
{{{
  i_ = Machines.SpacePhasors.Functions.ToSpacePhasor(plug_p.pin.i);
}}}
whereas {{{ToSpacePhasor}}} is defined as
{{{
function Modelica.Electrical.Machines.SpacePhasors.Functions.ToSpacePhasor ""Inline before index reduction"" ""Conversion from multi phase input to space phasor and zero sequence component""
  input Real[:] x ""Multi phase (voltage or current) input"";
  output Real[2] y ""Space phasor"";
  output Real y0 ""Zero sequence component (of voltage or current)"";
...
}}}

is flattened by the OF as
{{{
(electricalPowerSensor.i_, _) = 
  Modelica.Electrical.Machines.SpacePhasors.Functions.ToSpacePhasor(
   {electricalPowerSensor.plug_p.pin[1].i, 
    electricalPowerSensor.plug_p.pin[2].i, 
    electricalPowerSensor.plug_p.pin[3].i});
}}}
but is instead flattened by the NF as
{{{
electricalPowerSensor.i_ = 
  Modelica.Electrical.Machines.SpacePhasors.Functions.ToSpacePhasor(
    electricalPowerSensor.plug_p.pin.i)[1];
}}}
which has the following issues:
- the second output arguent was skipped on the left-hand side
- the array input was not flattened (I'm unsure if the backend can handle that)
- only the first scalar element of the function output is assigned to the left-hand side, which has type {{{Real[2]}}}"	defect	closed	high	2.0.0	New Instantiation		duplicate		
