Mr.Stier98
Mr.Stier98

Reputation: 21

Event triggered definition of array elements gives wrong values

The purpose of this model is to provide the indexed elements of the "vector" array the values of the array "tester", which are increasing numbers from 1 to 12.
This shall happen every time the BooleanPulse is true. The arrays are indexed by the Integer counter, which increases by 1 every boolean pulse.

The model simulates but gives every "vector" element the value 0. Also the warning message is "Failed to solve linear system of equations (no. 21) at time 0.000000. Residual norm is 0.5."

model Array_Test_simple
  Real vector[12];
  Integer counter;
  Real tester[12]=1:1:12;
  Modelica.Blocks.Sources.BooleanPulse booleanPulse(period = 0.1);

initial algorithm
  counter:=1;
algorithm
  when booleanPulse.y then
    vector[counter]:=tester[counter];
    counter:=pre(counter)+1;
  end when;

equation

annotation(
    uses(Modelica(version = "4.0.0")));
end Array_Test_simple;

Upvotes: 2

Views: 59

Answers (1)

AnHeuermann
AnHeuermann

Reputation: 848

This is a known bug in OpenModelica and was recently fixed in PR #8541. Try out the latest nightly-build of OpenModelica and check if that solves your issue.

enter image description here

But four your example it should also work to use equations and not algorithm equations. In general they are supported much better and the compiler can try to optimize them. Algorithms stay basically untouched.

Upvotes: 2

Related Questions