【问题标题】:How can I generate complex events in modelica for when statement?如何在 modelica 中为 when 语句生成复杂事件?
【发布时间】:2017-05-16 09:41:28
【问题描述】:

我尝试使用此代码:

Real x,y;
Boolean trigger(start = true) 
when x < y and trigger then
   trigger = false;
end when;

我只想为“何时”生成一次事件。但是我的代码不起作用。 如何在 modelica 中为 when 语句生成复杂事件?

【问题讨论】:

  • “但我的代码不起作用”不是很有帮助——您期望会发生什么,会发生什么?另外,请发布一个完整的、有效的示例。
  • 我收到翻译错误,我认为这是无效代码。我使用时的代码工作:when x &lt; y then ...。但后来我得到了很多事件(x
  • 那么,发布确切的错误,以及用于获取错误的确切代码。
  • 另外,如果您找到相关示例,请查看文档,例如build.openmodelica.org/Documentation/…book.xogeny.com/behavior/discrete/when
  • 我只是想知道是否可以在“when”语句中使用逻辑运算符“and”的多个条件。我如何理解这是不可能的,但文档并没有说明这一点。可以使用多个条件,如when {condition1, condition2, etc} then,但它与运算符“或”的作用类似(条件不相互排斥)。

标签: modelica openmodelica


【解决方案1】:

在 Dymola 中,您会收到以下错误消息:

计算因果分析需要变量触发 由方程求解:当 x

您可以通过在这些周围加上“pre”来切断循环 when 条件中的引用。

因此解决方案是:

Real x,y;
Boolean trigger(start = true) ;
equation
when x < y and pre(trigger) then
   trigger = false;
end when;

如您所见,这非常简单(并且在 Dymola 中进行了模拟),但我还没有在 OpenModelica 中检查过。

【讨论】:

  • 非常感谢,OM也是模拟的。它可能是没有'pre()'的模拟,有'算法':Boolean trigger(start = true, fixed = true); algorithm when time &gt; 5 and trigger then trigger := false; end when;
【解决方案2】:

您似乎遇到的问题是第一条错误消息Internal error BackendDAETransform.analyseStrongComponentBlock failed (Sorry - Support for Discrete Equation Systems is not yet implemented)。这似乎是https://trac.openmodelica.org/OpenModelica/ticket/1232,我认为这是由于在 when 语句中重新定义了部分条件变量造成的。

您可以使用reinit 解决此问题。另见Bouncing ball examplethe reference。它需要作用于状态变量,这就是我将der(trigger) 放在那里的原因。

model test_when
  Real trigger(start = 1.0, fixed = true);
equation
  der(trigger) = 0;
  when trigger > 0.5 and time > 5 then
    reinit(trigger, 0);
  end when;
  annotation(
    experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-06, Interval = 0.02));
end test_when;

可能有更好的方法来实现这一点。其他人对此有意见吗?

您可以检查编译日志(统计 - 事件)以确认仅触发了一个事件。

【讨论】:

  • 感谢您的回答。我看到它的工作原理,我会发现我的实现有问题。
猜你喜欢
  • 2017-08-06
  • 2020-04-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-11
  • 1970-01-01
  • 1970-01-01
  • 2019-05-17
相关资源
最近更新 更多