﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
6089	Evaluate reductions only involving literal constants in the NF	Francesco Casella	Per Östlund	"@perost, please check out the FEMBody package from https://github.com/looms-polimi/FEMPackage. I just re-sent you an invitation to access the repo.

Please open the FemPackage3.2.mo file and flatten the model {{{ExamplesFEM.PendulumBody}}}. 

The FEMBody model which is instantiated in this example contains code such as
{{{
  transpose(Cr) = data.inv4 + sum(data.inv5[i, :, :] * q[i] for i in 1:M);
  Jbar = data.inv7 - sum((transpose(data.inv8[i, :, :]) + data.inv8[i, :, :]) * q[i] for i in 1:M) - sum(sum(data.inv9[i, j, :, :] * q[j] for j in i:M) * q[i] for i in 1:M);
  [mDcbartilde, Jbar, transpose(Cr)] * [aa_a - g_0; za_a; ddq] = h_w_theta + h_e_theta;
  [data.Ct, Cr, Me] * [aa_a - g_0; za_a; ddq] = h_w_f + h_e_f - matrix(data.Ke * q) - matrix(d / 100 * (alpha * Me + beta * data.Ke) * dq);
}}}
which comes straight from tensor equations describing the multibody FEM model of a flexible link, see [https://dx.doi.org/10.1080/13873954.2013.807433 paper].

The parameter record {{{data}}}, which has {{{Evaluate = true}}} contains multi-dimensional arrays (tensors) of structural parameters of the flexible body, which come from modal analysis of the original FEM model. Most of the elements of those arrays are zero, so for efficient and robust handling of the model equations by the backend it is absolutely essential that the NF reduces the complexity of the model as much as possible without passing it over to the backend, by fully evaluating those expressions.

After fixing #6067, I don't see any surviving parameter name in the flat code, which is good. However, there are several huge reduction expressions, involving the sum operator and literal constant arrays, that are not evaluated and passed straight to the backend. The backend can eventually handle the test case in question, but it produces numerically unreliable code for larger examples.

@perost, could you make sure that these reduction are properly evaluated, so that the backend receives simplified code for further processing?"	defect	closed	high	1.16.0	New Instantiation		fixed		Martin Sjölund Karim Adbdelhak Philip Hannebohm
