2

I'm trying to use the integerChange block from the Modelica Standard library It doesn't seem to work however. What am i doing wrong? I would have expected a spike at each change,but i get a constant "false". I'm using OpenModelica 1.17

Here is the simple model

model integerChangeTest
  Modelica.Blocks.Math.IntegerChange integerChange annotation(
    Placement(visible = true, transformation(origin = {26, 24}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Math.RealToInteger realToInteger annotation(
    Placement(visible = true, transformation(origin = {-6, 24}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Sources.Sine sine(amplitude = 5, freqHz = 5) annotation(
    Placement(visible = true, transformation(origin = {-48, 26}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
  connect(realToInteger.y, integerChange.u) annotation(
    Line(points = {{5, 24}, {13, 24}}, color = {255, 127, 0}));
  connect(sine.y, realToInteger.u) annotation(
    Line(points = {{-37, 26}, {-19, 26}, {-19, 24}}, color = {0, 0, 127}));
  annotation(
    uses(Modelica(version = "3.2.3")));
end integerChangeTest;

enter image description here

1 Answer 1

2

The block works, but plotting change(x) is complicated in many Modelica tools.

The reason is that at an event there are a number of intermediate values, and to avoid plotting too many values one common solution is to just store the first and last; that also simplifies the implementation since it avoids a callback for storing values during the event iteration. Unfortunately change is only true in intermediate values during event iterations - and thus plotting it becomes meaningless.

I don't know if OpenModelica has some special mode for including them as well.

If you want to see that it changes you can use the code in the comment or graphically add not+OnDelay

model integerChangeTest
  Modelica.Blocks.Math.IntegerChange integerChange annotation (
    Placement(visible = true, transformation(origin = {26, 24}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Math.RealToInteger realToInteger annotation (
    Placement(visible = true, transformation(origin = {-6, 24}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Sources.Sine sine(amplitude = 5, freqHz = 5) annotation (
    Placement(visible = true, transformation(origin = {-48, 26}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Logical.Not not1
    annotation (Placement(transformation(extent={{46,14},{66,34}})));
  Modelica.Blocks.MathBoolean.OnDelay onDelay(delayTime=1e-3)
    annotation (Placement(transformation(extent={{82,20},{90,28}})));
equation 
  connect(realToInteger.y, integerChange.u) annotation (
    Line(points={{5,24},{14,24}},      color = {255, 127, 0}));
  connect(sine.y, realToInteger.u) annotation (
    Line(points={{-37,26},{-18,26},{-18,24}},        color = {0, 0, 127}));
  connect(integerChange.y, not1.u)
    annotation (Line(points={{37,24},{44,24}}, color={255,0,255}));
  connect(onDelay.u, not1.y)
    annotation (Line(points={{80.4,24},{67,24}}, color={255,0,255}));
  annotation (
    uses(Modelica(version="3.2.2")));
end integerChangeTest;
Sign up to request clarification or add additional context in comments.

3 Comments

No there is no such flag for OpenModelica. But you could make change(x) visible by counting every time it become true: when integerChange.u then count = pre(count)+1; end when;
Ah, yes, good idea to suggest such a work-around
Ok thank you, good to know that its just the plotting. Yes, i intended to visualize the events. The triggeredTrapezoid block with a falling value >0 also seems to do the job.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.