﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
5947	Backend cannot solve for variable indexed array elements	Karim Adbdelhak	Karim Adbdelhak	"Indexing an array with non constant expressions is allowed due to modelica specification. Our current backend is only able to have these variable indices as part of the right hand side and can never solve for these variables. This is a basic matching problem and can not be done, since we cannot evaluate during compilation what values the index can take.

This is a problem that was identified in ticket #4120

Consider the following model:
{{{
model testArr
  Boolean x(start = false);
  Integer y[2];
  Real z[2];
equation
  when sample(0.0, 0.1) then
    x = not pre(x);
  end when;
  y[1] = if x then 1 else 2;
  y[2] = if x then 2 else 1;
  z[y[1]] = sin(time);
  z[y[2]] = cos(time);
end testArr;
}}}

The indexing of `z` is not constant and therefore our current backend cannot solve for these variables (in this example it could be done, but there can be an example where it depends on a state). Equation 4 and 5 have to be solved for either z[1] or z[2] and if correctly processed it would work, but it fails. 

Dymola is able to solve this and i suppose they re-formulate them to be residuals. There is a way i could implement this in the backend (i need to adapt the adjacency matrix) but that would also allow a lot of stuff that is not valid to pass. We would only be able to recognize that during runtime and that could be a headache.

Q: Is this relevant for real models?
Q: Should we only care for special cases?
Q: Should we care for invalid models failing with bad or unrelated error messages?"	discussion	new	high	Future	Backend			variable index, residual	Francesco Casella Per Östlund Philip Hannebohm Bernhard Bachmann Lennart Ochel massimo ceraolo adrien.guironnet@…
