首页 > 解决方案 > Modelica integerChange 块没有按预期工作?

问题描述

我正在尝试使用 Modelica 标准库中的 integerChange 块,但它似乎不起作用。我究竟做错了什么?我本来预计每次更改都会出现峰值,但我得到一个恒定的“错误”。我正在使用 OpenModelica 1.17

这是简单的模型

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;

在此处输入图像描述

标签: modelicaopenmodelica

解决方案


该块可以工作,但在许多 Modelica 工具中绘图change(x)很复杂。

原因是在一个事件中有许多中间值,为了避免绘制太多值,一个常见的解决方案是只存储第一个和最后一个;这也简化了实现,因为它避免了在事件迭代期间存储值的回调。不幸change的是,只有在事件迭代期间的中间值才是正确的——因此绘制它变得毫无意义。

我不知道 OpenModelica 是否也有一些特殊的模式来包含它们。

如果您想看到它的变化,您可以使用注释中的代码或以图形方式添加 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;

推荐阅读