﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
1329	Wrong prefixing of array indexes in the DAE.	Adrian Pop	Adrian Pop	"This model cannot be simulated. It was reported here: [https://openmodelica.org/index.php/forum/topic?id=91]
{{{
model jktest 
  annotation(Diagram(coordinateSystem(extent = {{ -100, -100},{100,100}}))); 
  annotation(uses(Modelica(version = ""3.1"")), Diagram(graphics)); 
  Modelica.Electrical.Digital.Examples.Utilities.JKFF jKFF annotation(Placement(transformation(origin = { -36.0,44.0}, extent = {{ -46.0,34.0},{ -26.0,54.0}}), iconTransformation(origin = { -36.0,44.0}, extent = {{ -46.0,34.0},{ -26.0,54.0}}))); 
  Modelica.Electrical.Digital.Sources.Set set(x = Modelica.Electrical.Digital.Interfaces.Logic.'1') annotation(Placement(transformation(origin = { -96.0,50.0}, extent = {{ -106.0,40.0},{ -86.0,60.0}}), iconTransformation(origin = { -96.0,50.0}, extent = {{ -106.0,40.0},{ -86.0,60.0}}))); 
  Modelica.Electrical.Digital.Sources.Clock clock(period = 0.4) annotation(Placement(transformation(origin = { -96.0,20.0}, extent = {{ -106.0,10.0},{ -86.0,30.0}}), iconTransformation(origin = { -96.0,20.0}, extent = {{ -106.0,10.0},{ -86.0,30.0}}))); 

equation 
  connect(jKFF.j,set.y) annotation(Line(points = {{ -46.0,51.0},{ -70.0,51.0},{ -70.0,50.0},{ -86.0,50.0}}, color = {127,0,127})); 
  connect(jKFF.k,set.y) annotation(Line(points = {{ -46.0,37.0},{ -70.0,37.0},{ -70.0,50.0},{ -86.0,50.0}}, color = {127,0,127})); 
  connect(clock.y,jKFF.clk) annotation(Line(points = {{ -86.0,20.0},{ -68.0,20.0},{ -68.0,44.0},{ -46.0,44.0}}, color = {127,0,127})); 
end jktest; 
}}}

The flattening and checking works fine:

{{{
Class jktest has 70 equation(s) and 70 variable(s).
66 of these are trivial equation(s).
}}}

But the code generation fails with: 

{{{
Too few equations, underdetermined system. The model has 4 equation(s) and 12 variable(s)
}}}

The problem is that the prefixing of array indexes is not correct. Equation:
{{{
  jKFF.And2.auxiliary[2] = D.Tables.AndTable[auxiliary[1],x[2]];
}}}
uses array indexes {{{auxiliary[1],x[2]}}} that DO NOT EXIST in the model (they exist, but have an extra prefix).\\
See in the flatten model below:
{{{
class jktest
  parameter Real jKFF.delayTime(quantity = ""Time"", unit = ""s"") = 0.001 ""delay time"";
  parameter enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.q0 = Modelica.Electrical.Digital.Interfaces.Logic.'0' ""initial value"";
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.j;
  output enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.q;
  output enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.qn ""not Q"";
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.clk;
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.k;
  parameter Real jKFF.RS1.delayTime(quantity = ""Time"", unit = ""s"") = jKFF.delayTime ""delay time"";
  parameter enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS1.q0 = jKFF.q0 ""initial value of output"";
  parameter Integer jKFF.RS1.Nor1.n(min = 2) = 2 ""Number of inputs"";
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS1.Nor1.x[1] ""Connector of Digital input signal vector"";
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS1.Nor1.x[2] ""Connector of Digital input signal vector"";
  output enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS1.Nor1.y ""Connector of Digital output signal"";
  protected enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS1.Nor1.auxiliary[1](start = Modelica.Electrical.Digital.Interfaces.Logic.'U', fixed = true);
  protected enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS1.Nor1.auxiliary[2](start = Modelica.Electrical.Digital.Interfaces.Logic.'U', fixed = true);
  parameter Integer jKFF.RS1.Nor2.n(min = 2) = 2 ""Number of inputs"";
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS1.Nor2.x[1] ""Connector of Digital input signal vector"";
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS1.Nor2.x[2] ""Connector of Digital input signal vector"";
  output enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS1.Nor2.y ""Connector of Digital output signal"";
  protected enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS1.Nor2.auxiliary[1](start = Modelica.Electrical.Digital.Interfaces.Logic.'U', fixed = true);
  protected enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS1.Nor2.auxiliary[2](start = Modelica.Electrical.Digital.Interfaces.Logic.'U', fixed = true);
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS1.s;
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS1.r;
  output enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS1.q;
  output enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS1.qn;
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS1.TD1.x(start = Modelica.Electrical.Digital.Interfaces.Logic.'U', fixed = true) ""Connector of Digital input signal"";
  output enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS1.TD1.y ""Connector of Digital output signal"";
  parameter Real jKFF.RS1.TD1.delayTime(quantity = ""Time"", unit = ""s"", start = 0.0) = jKFF.RS1.delayTime ""delay time"";
  parameter enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS1.TD1.y0 = jKFF.RS1.q0 ""initial value of output"";
  protected enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS1.TD1.x_delayed;
  parameter Real jKFF.RS2.delayTime(quantity = ""Time"", unit = ""s"") = jKFF.delayTime ""delay time"";
  parameter enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS2.q0 = jKFF.q0 ""initial value of output"";
  parameter Integer jKFF.RS2.Nor1.n(min = 2) = 2 ""Number of inputs"";
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS2.Nor1.x[1] ""Connector of Digital input signal vector"";
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS2.Nor1.x[2] ""Connector of Digital input signal vector"";
  output enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS2.Nor1.y ""Connector of Digital output signal"";
  protected enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS2.Nor1.auxiliary[1](start = Modelica.Electrical.Digital.Interfaces.Logic.'U', fixed = true);
  protected enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS2.Nor1.auxiliary[2](start = Modelica.Electrical.Digital.Interfaces.Logic.'U', fixed = true);
  parameter Integer jKFF.RS2.Nor2.n(min = 2) = 2 ""Number of inputs"";
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS2.Nor2.x[1] ""Connector of Digital input signal vector"";
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS2.Nor2.x[2] ""Connector of Digital input signal vector"";
  output enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS2.Nor2.y ""Connector of Digital output signal"";
  protected enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS2.Nor2.auxiliary[1](start = Modelica.Electrical.Digital.Interfaces.Logic.'U', fixed = true);
  protected enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS2.Nor2.auxiliary[2](start = Modelica.Electrical.Digital.Interfaces.Logic.'U', fixed = true);
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS2.s;
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS2.r;
  output enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS2.q;
  output enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS2.qn;
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS2.TD1.x(start = Modelica.Electrical.Digital.Interfaces.Logic.'U', fixed = true) ""Connector of Digital input signal"";
  output enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS2.TD1.y ""Connector of Digital output signal"";
  parameter Real jKFF.RS2.TD1.delayTime(quantity = ""Time"", unit = ""s"", start = 0.0) = jKFF.RS2.delayTime ""delay time"";
  parameter enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS2.TD1.y0 = jKFF.RS2.q0 ""initial value of output"";
  protected enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.RS2.TD1.x_delayed;
  parameter Integer jKFF.And1.n(min = 2) = 3 ""Number of inputs"";
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And1.x[1] ""Connector of Digital input signal vector"";
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And1.x[2] ""Connector of Digital input signal vector"";
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And1.x[3] ""Connector of Digital input signal vector"";
  output enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And1.y ""Connector of Digital output signal"";
  protected enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And1.auxiliary[1](start = Modelica.Electrical.Digital.Interfaces.Logic.'U', fixed = true);
  protected enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And1.auxiliary[2](start = Modelica.Electrical.Digital.Interfaces.Logic.'U', fixed = true);
  protected enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And1.auxiliary[3](start = Modelica.Electrical.Digital.Interfaces.Logic.'U', fixed = true);
  parameter Integer jKFF.And2.n(min = 2) = 3 ""Number of inputs"";
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And2.x[1] ""Connector of Digital input signal vector"";
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And2.x[2] ""Connector of Digital input signal vector"";
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And2.x[3] ""Connector of Digital input signal vector"";
  output enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And2.y ""Connector of Digital output signal"";
  protected enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And2.auxiliary[1](start = Modelica.Electrical.Digital.Interfaces.Logic.'U', fixed = true);
  protected enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And2.auxiliary[2](start = Modelica.Electrical.Digital.Interfaces.Logic.'U', fixed = true);
  protected enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And2.auxiliary[3](start = Modelica.Electrical.Digital.Interfaces.Logic.'U', fixed = true);
  parameter Integer jKFF.And3.n(min = 2) = 2 ""Number of inputs"";
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And3.x[1] ""Connector of Digital input signal vector"";
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And3.x[2] ""Connector of Digital input signal vector"";
  output enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And3.y ""Connector of Digital output signal"";
  protected enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And3.auxiliary[1](start = Modelica.Electrical.Digital.Interfaces.Logic.'U', fixed = true);
  protected enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And3.auxiliary[2](start = Modelica.Electrical.Digital.Interfaces.Logic.'U', fixed = true);
  parameter Integer jKFF.And4.n(min = 2) = 2 ""Number of inputs"";
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And4.x[1] ""Connector of Digital input signal vector"";
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And4.x[2] ""Connector of Digital input signal vector"";
  output enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And4.y ""Connector of Digital output signal"";
  protected enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And4.auxiliary[1](start = Modelica.Electrical.Digital.Interfaces.Logic.'U', fixed = true);
  protected enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.And4.auxiliary[2](start = Modelica.Electrical.Digital.Interfaces.Logic.'U', fixed = true);
  input enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.Not1.x ""Connector of Digital input signal"";
  output enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.Not1.y ""Connector of Digital output signal"";
  protected enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') jKFF.Not1.auxiliary(start = Modelica.Electrical.Digital.Interfaces.Logic.'0', fixed = true);
  parameter enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') set.x(start = Modelica.Electrical.Digital.Interfaces.Logic.'1') = Modelica.Electrical.Digital.Interfaces.Logic.'1' ""Logic value to be set"";
  output enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') set.y;
  parameter Real clock.startTime(quantity = ""Time"", unit = ""s"", start = 0.0) ""Output = offset for time < startTime"";
  parameter Real clock.period(quantity = ""Time"", unit = ""s"", min = 1e-60, start = 1.0) = 0.4 ""Time for one period"";
  parameter Real clock.width(min = 1e-60, max = 100.0, start = 50.0) ""Width of pulses in % of period"";
  output enumeration('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') clock.y ""Connector of Digital output signal"";
  protected Real clock.t_i(quantity = ""Time"", unit = ""s"", start = clock.startTime) ""Start time of current period"";
  protected Real clock.t_width(quantity = ""Time"", unit = ""s"") = clock.period * clock.width / 100.0;
equation
  jKFF.RS1.Nor1.auxiliary[1] = jKFF.RS1.Nor1.x[1];
  jKFF.RS1.Nor1.auxiliary[2] = D.Tables.OrTable[auxiliary[1],x[2]];
  jKFF.RS1.Nor1.y = pre(D.Tables.NotTable[auxiliary[2]]);
  jKFF.RS1.Nor2.auxiliary[1] = jKFF.RS1.Nor2.x[1];
  jKFF.RS1.Nor2.auxiliary[2] = D.Tables.OrTable[auxiliary[1],x[2]];
  jKFF.RS1.Nor2.y = pre(D.Tables.NotTable[auxiliary[2]]);
  jKFF.RS1.TD1.x_delayed = DAE.CAST(ENUM TYPE, integer(delay(Real(jKFF.RS1.TD1.x),jKFF.RS1.TD1.delayTime,jKFF.RS1.TD1.delayTime)));
  jKFF.RS1.TD1.y = if jKFF.RS1.TD1.delayTime > 0.0 then if time >= jKFF.RS1.TD1.delayTime then jKFF.RS1.TD1.x_delayed else jKFF.RS1.TD1.y0 else pre(jKFF.RS1.TD1.x);
  jKFF.RS2.Nor1.auxiliary[1] = jKFF.RS2.Nor1.x[1];
  jKFF.RS2.Nor1.auxiliary[2] = D.Tables.OrTable[auxiliary[1],x[2]];
  jKFF.RS2.Nor1.y = pre(D.Tables.NotTable[auxiliary[2]]);
  jKFF.RS2.Nor2.auxiliary[1] = jKFF.RS2.Nor2.x[1];
  jKFF.RS2.Nor2.auxiliary[2] = D.Tables.OrTable[auxiliary[1],x[2]];
  jKFF.RS2.Nor2.y = pre(D.Tables.NotTable[auxiliary[2]]);
  jKFF.RS2.TD1.x_delayed = DAE.CAST(ENUM TYPE, integer(delay(Real(jKFF.RS2.TD1.x),jKFF.RS2.TD1.delayTime,jKFF.RS2.TD1.delayTime)));
  jKFF.RS2.TD1.y = if jKFF.RS2.TD1.delayTime > 0.0 then if time >= jKFF.RS2.TD1.delayTime then jKFF.RS2.TD1.x_delayed else jKFF.RS2.TD1.y0 else pre(jKFF.RS2.TD1.x);
  jKFF.And1.auxiliary[1] = jKFF.And1.x[1];
  jKFF.And1.auxiliary[2] = D.Tables.AndTable[auxiliary[1],x[2]];
  jKFF.And1.auxiliary[3] = D.Tables.AndTable[auxiliary[2],x[3]];
  jKFF.And1.y = pre(jKFF.And1.auxiliary[3]);
  jKFF.And2.auxiliary[1] = jKFF.And2.x[1];
  jKFF.And2.auxiliary[2] = D.Tables.AndTable[auxiliary[1],x[2]];
  jKFF.And2.auxiliary[3] = D.Tables.AndTable[auxiliary[2],x[3]];
  jKFF.And2.y = pre(jKFF.And2.auxiliary[3]);
  jKFF.And3.auxiliary[1] = jKFF.And3.x[1];
  jKFF.And3.auxiliary[2] = D.Tables.AndTable[auxiliary[1],x[2]];
  jKFF.And3.y = pre(jKFF.And3.auxiliary[2]);
  jKFF.And4.auxiliary[1] = jKFF.And4.x[1];
  jKFF.And4.auxiliary[2] = D.Tables.AndTable[auxiliary[1],x[2]];
  jKFF.And4.y = pre(jKFF.And4.auxiliary[2]);
  jKFF.Not1.auxiliary = D.Tables.NotTable[x];
  jKFF.Not1.y = pre(jKFF.Not1.auxiliary);
  clock.y = jKFF.And1.x[1];
  clock.y = jKFF.And2.x[3];
  clock.y = jKFF.Not1.x;
  clock.y = jKFF.clk;
  jKFF.And1.x[2] = jKFF.And2.x[2];
  jKFF.And1.x[2] = jKFF.j;
  jKFF.And1.x[2] = jKFF.k;
  jKFF.And1.x[2] = set.y;
  jKFF.And2.x[1] = jKFF.RS1.Nor1.x[1];
  jKFF.And2.x[1] = jKFF.RS1.Nor2.y;
  jKFF.And2.x[1] = jKFF.RS1.q;
  jKFF.And2.x[1] = jKFF.qn;
  jKFF.And1.x[3] = jKFF.RS1.Nor1.y;
  jKFF.And1.x[3] = jKFF.RS1.TD1.x;
  jKFF.And1.x[3] = jKFF.RS1.qn;
  jKFF.And1.x[3] = jKFF.q;
  jKFF.And3.x[1] = jKFF.And4.x[1];
  jKFF.And3.x[1] = jKFF.Not1.y;
  jKFF.And3.x[2] = jKFF.RS2.Nor1.x[1];
  jKFF.And3.x[2] = jKFF.RS2.Nor2.y;
  jKFF.And3.x[2] = jKFF.RS2.q;
  jKFF.And4.x[2] = jKFF.RS2.Nor1.y;
  jKFF.And4.x[2] = jKFF.RS2.TD1.x;
  jKFF.And4.x[2] = jKFF.RS2.qn;
  jKFF.And3.y = jKFF.RS1.Nor1.x[2];
  jKFF.And3.y = jKFF.RS1.s;
  jKFF.And4.y = jKFF.RS1.Nor2.x[1];
  jKFF.And4.y = jKFF.RS1.r;
  jKFF.And1.y = jKFF.RS2.Nor1.x[2];
  jKFF.And1.y = jKFF.RS2.s;
  jKFF.And2.y = jKFF.RS2.Nor2.x[1];
  jKFF.And2.y = jKFF.RS2.r;
  jKFF.RS2.Nor2.x[2] = jKFF.RS2.TD1.y;
  jKFF.RS1.Nor2.x[2] = jKFF.RS1.TD1.y;
algorithm
  set.y := set.x;
  when sample(clock.startTime,clock.period) then
    clock.t_i := time;
  end when;
  clock.y := if  NOT time >= clock.startTime OR time >= clock.t_i + clock.t_width then Modelica.Electrical.Digital.Interfaces.Logic.'0' else Modelica.Electrical.Digital.Interfaces.Logic.'1';
end jktest;
}}}"	defect	closed	critical	Red October	Instantiation	1.6.0	fixed		Adrian Pop Frenkel TUD Per Östlund
