﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
5116	The NF does not constant-evaluate parameter binding equations in the MSL	Francesco Casella	Per Östlund	"Please consider [https://libraries.openmodelica.org/branches/newInst/Modelica_trunk/files/Modelica_trunk_Modelica.Magnetic.FundamentalWave.Examples.BasicMachines.AIMC_Conveyor.err Modelica.Magnetic.FundamentalWave.Examples.BasicMachines.AIMC_Conveyor]. When using the NF, the compilation of the C code fails with errors on expressions involving sine and cosine function calls on temp variables. One of them is
{{{
  tmp6._re = (cos(tmp7)) * (tmp8._re) - ((sin(tmp12)) * (tmp13._im));
}}}

The root cause of the problem are these [https://github.com/modelica/ModelicaStandardLibrary/blob/31b9ea837782d4d8aecedff2e9a6535c659061ba/Modelica/Magnetic/FundamentalWave.mo#L6142 binding equations]:
{{{
  final parameter Complex N=effectiveTurns*Modelica.ComplexMath.exp(Complex(
      0, orientation)) ""Complex number of turns"";
}}}
with both {{{effectiveTurns}}} and {{{orientation}}} having {{{Evaluate=true}}}. The old FE correctly constant-evaluates them, producing
{{{
  final parameter Real aimc.rotorCage.electroMagneticConverter.singlePhaseElectroMagneticConverter[3].N.re = -0.5000000000000004 ""Real part of complex number"";
  final parameter Real aimc.rotorCage.electroMagneticConverter.singlePhaseElectroMagneticConverter[3].N.im = -0.8660254037844384 ""Imaginary part of complex number"";
  final parameter Real aimc.rotorCage.electroMagneticConverter.singlePhaseElectroMagneticConverter[2].N.re = -0.4999999999999998 ""Real part of complex number"";
  final parameter Real aimc.rotorCage.electroMagneticConverter.singlePhaseElectroMagneticConverter[2].N.im = 0.8660254037844387 ""Imaginary part of complex number"";
  final parameter Real aimc.rotorCage.electroMagneticConverter.singlePhaseElectroMagneticConverter[1].N.re = 1.0 ""Real part of complex number"";
  final parameter Real aimc.rotorCage.electroMagneticConverter.singlePhaseElectroMagneticConverter[1].N.im = 0.0 ""Imaginary part of complex number"";
}}}

The NF instead does not recognize that these binding equations should be constant-evaluated, so it adds {{{fixed = false}}} to the parameter declaration and moves the binding equations to the initial equation section
{{{
  aimc.rotorCage.electroMagneticConverter.singlePhaseElectroMagneticConverter[3].N = Complex.'*'.multiply(array(Modelica.SIunits.ComplexMagneticFlux.'constructor'.fromReal({1.0, 1.0, 1.0}[$i1], 0.0) for $i1 in 1:3), Modelica.ComplexMath.exp(Modelica.SIunits.ComplexMagneticFlux.'constructor'.fromReal(0.0, {0.0, 2.094395102393195, 4.188790204786391})));
  aimc.rotorCage.electroMagneticConverter.singlePhaseElectroMagneticConverter[2].N = Complex.'*'.multiply(array(Modelica.SIunits.ComplexMagneticFlux.'constructor'.fromReal({1.0, 1.0, 1.0}[$i1], 0.0) for $i1 in 1:3), Modelica.ComplexMath.exp(Modelica.SIunits.ComplexMagneticFlux.'constructor'.fromReal(0.0, {0.0, 2.094395102393195, 4.188790204786391})));
  aimc.rotorCage.electroMagneticConverter.singlePhaseElectroMagneticConverter[1].N = Complex.'*'.multiply(array(Modelica.SIunits.ComplexMagneticFlux.'constructor'.fromReal({1.0, 1.0, 1.0}[$i1], 0.0) for $i1 in 1:3), Modelica.ComplexMath.exp(Modelica.SIunits.ComplexMagneticFlux.'constructor'.fromReal(0.0, {0.0, 2.094395102393195, 4.188790204786391})));
}}}
Then, they ride through the whole back-end as 
{{{
10/18 (2): aimc.stator.electroMagneticConverter.singlePhaseElectroMagneticConverter[3].N = Complex(cos({0.0, 2.094395102393195, 4.188790204786391}) * {Complex(1.0, 0.0), Complex(1.0, 0.0), Complex(1.0, 0.0)}.re - sin({0.0, 2.094395102393195, 4.188790204786391}) * {Complex(1.0, 0.0), Complex(1.0, 0.0), Complex(1.0, 0.0)}.im, sin({0.0, 2.094395102393195, 4.188790204786391}) * {Complex(1.0, 0.0), Complex(1.0, 0.0), Complex(1.0, 0.0)}.re + cos({0.0, 2.094395102393195, 4.188790204786391}) * {Complex(1.0, 0.0), Complex(1.0, 0.0), Complex(1.0, 0.0)}.im)   [dynamic |0|0|0|0|] 
11/20 (2): aimc.stator.electroMagneticConverter.singlePhaseElectroMagneticConverter[2].N = Complex(cos({0.0, 2.094395102393195, 4.188790204786391}) * {Complex(1.0, 0.0), Complex(1.0, 0.0), Complex(1.0, 0.0)}.re - sin({0.0, 2.094395102393195, 4.188790204786391}) * {Complex(1.0, 0.0), Complex(1.0, 0.0), Complex(1.0, 0.0)}.im, sin({0.0, 2.094395102393195, 4.188790204786391}) * {Complex(1.0, 0.0), Complex(1.0, 0.0), Complex(1.0, 0.0)}.re + cos({0.0, 2.094395102393195, 4.188790204786391}) * {Complex(1.0, 0.0), Complex(1.0, 0.0), Complex(1.0, 0.0)}.im)   [dynamic |0|0|0|0|] 
12/22 (2): aimc.stator.electroMagneticConverter.singlePhaseElectroMagneticConverter[1].N = Complex(cos({0.0, 2.094395102393195, 4.188790204786391}) * {Complex(1.0, 0.0), Complex(1.0, 0.0), Complex(1.0, 0.0)}.re - sin({0.0, 2.094395102393195, 4.188790204786391}) * {Complex(1.0, 0.0), Complex(1.0, 0.0), Complex(1.0, 0.0)}.im, sin({0.0, 2.094395102393195, 4.188790204786391}) * {Complex(1.0, 0.0), Complex(1.0, 0.0), Complex(1.0, 0.0)}.re + cos({0.0, 2.094395102393195, 4.188790204786391}) * {Complex(1.0, 0.0), Complex(1.0, 0.0), Complex(1.0, 0.0)}.im)   [dynamic |0|0|0|0|] 
}}}
without being expanded, ultimately leading to the generation of wrong code.

Contrary to #5115, my understanding is that the NF should indeed constant-evaluate those binding equations because the parameter is final and it only depends on literal constants and parameters with {{{Evaluate = true}}} "	task	closed	high	2.0.0	New Instantiation		fixed		
