Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Unexpected results with pre-operator used on array-elements

Unexpected results with pre-operator used on array-elements

Dear all,

I'm working on in-cooperating a matlab/simulink dependent package into modelica using external objects and external c-function calls. The program makes use of state-events and time-events and my first idea was to write it has an FMU and import it into OpenModelica. I noticed that a lot of errors occurred when OM tried to wrap the FMU's. I can provide a list of errors if that is of interest for the OM community. However, for other reasons as well, the approach of directly using external objects/functions suites better for this case.

The problem I have is in the following code;

Code:


model testForAndPre
  Real x[2];
  Modelica.Blocks.Sources.Sine sine1(freqHz = 1 / 4, phase = 1 / 8) annotation(Placement(visible = true, transformation(origin = {-56.4972,58.3804}, extent = {{-12,-12},{12,12}}, rotation = 0)));
  Modelica.Blocks.Sources.Sine sine2(freqHz = 1 / 2) annotation(Placement(visible = true, transformation(origin = {-53.8606,-2.63653}, extent = {{-12,-12},{12,12}}, rotation = 0)));
  Boolean z[2];
  annotation(experiment(StartTime = 0.0, StopTime = 5, Tolerance = 1e-006));
initial equation
  x[1] = 0;
  x[2] = 0;
equation
  z[1] = sine1.y > 0;
  z[2] = sine2.y > 0;
algorithm
  when z[1] <> pre(z[1]) or z[2] <> pre(z[2]) then
      for i in 1:2 loop
          if z[i] <> pre(z[i]) then
            x[i]:=10;
      else 
      end if;
    end for;
  end when;
end testForAndPre;

What you'll notice when you simulate the model is that the if clause within the when statement are never activated.
Since the when clause is activated at the right time, (compare with the sin1.y and sin2.y), my suspection is that
the error occurs from the varying index, i, used together with the pre() operator. 

Any comments would be highly appreciated.  Hopefully it's an easy fix.


cheers!,


Patrik


PS. this is just a simplified model to show the error. For the finnished implemation I cannot "hard-code" the array-element
accessing, since I need the model to be paramterizable.

Re: Unexpected results with pre-operator used on array-elements

In this model one cannot actually see that the when-clause is activated. I've tried it for other model before and the when clause is activated.

There are 0 guests and 0 other users also viewing this topic
You are here: