﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
4865	Issue with scalar*array products in functions with NF	Francesco Casella	Per Östlund	"Please check [https://libraries.openmodelica.org/branches/newInst/Modelica_3.2.2/files/Modelica_3.2.2_Modelica.Blocks.Examples.Filter.err Modelica.Blocks.Examples.Filter]. The following error is reported:
{{{
Modelica_3.2.2_Modelica.Blocks.Examples.Filter_functions.c:3071:18: error: 
invalid operands to binary expression ('modelica_real' (aka 'double')
and 'real_array' (aka 'struct base_array_s'))
  _cr = (_w_cut) * (_cr_in);
        ~~~~~~~~ ^ ~~~~~~~~
}}}
This expression is found in function {{{Modelica.Blocks.Continuous.Internal.Filter.coefficients.lowPass}}}. When flattening the model with the NF, the function is
{{{
function Modelica.Blocks.Continuous.Internal.Filter.coefficients.lowPass ""Return low pass filter coefficients at given cut-off frequency""
  input Real[:] cr_in ""Coefficients of real poles"";
  input Real[:] c0_in ""Coefficients of s^0 term if conjugate complex pole"";
  input Real[size(c0_in, 1)] c1_in ""Coefficients of s^1 term if conjugate complex pole"";
  input Real f_cut(quantity = ""Frequency"", unit = ""Hz"") ""Cut-off frequency"";
  output Real[size(cr_in, 1)] cr ""Coefficient of real pole"";
  output Real[size(c0_in, 1)] c0 ""Coefficients of s^0 term if conjugate complex pole"";
  output Real[size(c0_in, 1)] c1 ""Coefficients of s^1 term if conjugate complex pole"";
  protected Real w_cut(quantity = ""AngularVelocity"", unit = ""rad/s"") = 2.0 * 3.141592653589793 * f_cut ""Cut-off angular frequency"";
  protected Real w_cut2 = w_cut * w_cut;
algorithm
  assert(f_cut > 0.0, ""Cut-off frequency f_cut must be positive"");
  cr := w_cut * cr_in;
  c1 := w_cut * c1_in;
  c0 := w_cut2 * c0_in;
end Modelica.Blocks.Continuous.Internal.Filter.coefficients.lowPass;
}}}
while the old FE gives
{{{
function Modelica.Blocks.Continuous.Internal.Filter.coefficients.lowPass ""Return low pass filter coefficients at given cut-off frequency""
  input Real[:] cr_in ""Coefficients of real poles"";
  input Real[:] c0_in ""Coefficients of s^0 term if conjugate complex pole"";
  input Real[size(c0_in, 1)] c1_in ""Coefficients of s^1 term if conjugate complex pole"";
  input Real f_cut(quantity = ""Frequency"", unit = ""Hz"") ""Cut-off frequency"";
  output Real[size(cr_in, 1)] cr ""Coefficient of real pole"";
  output Real[size(c0_in, 1)] c0 ""Coefficients of s^0 term if conjugate complex pole"";
  output Real[size(c0_in, 1)] c1 ""Coefficients of s^1 term if conjugate complex pole"";
  protected Real w_cut(quantity = ""AngularVelocity"", unit = ""rad/s"") = 6.283185307179586 * f_cut ""Cut-off angular frequency"";
  protected Real w_cut2 = w_cut ^ 2.0;
algorithm
  assert(f_cut > 0.0, ""Cut-off frequency f_cut must be positive"");
  cr := cr_in * w_cut;
  c1 := c1_in * w_cut;
  c0 := c0_in * w_cut2;
end Modelica.Blocks.Continuous.Internal.Filter.coefficients.lowPass;
}}}
All variable declarationa are equivalent. For some reason, the old FE swaps the order of the scalar*array product to an array*scalar product, while the NF keeps the expression as in the source code. Both expressions are allowed by the specification and should give the same result. 

Maybe the current code generation assumes to only array*scalar? In that case, when creating the DAE structure we should swap those products as in the old FE."	defect	closed	high	2.0.0	New Instantiation		fixed		
