连续时间内的Modelica布尔变量 [英] Modelica Boolean variable in continuous time

查看:88
本文介绍了连续时间内的Modelica布尔变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下Modelica模型进行检查和模拟.

The following Modelica model checks and simulates.

model boolCheck_OK1
  Real a = sin(time);
  Real b = cos(time);
  Real c;
//protected 
//  Boolean isInReg = inRegionCheck(a, b);
equation 
  c = if inRegionCheck(a, b) then 1.3*a^b else 0.7*b^a;
end boolCheck_OK1;

inRegionCheck()函数返回一个布尔值,这是一个简化版本:

The function inRegionCheck() returns a Boolean, here is a simplified version:

function inRegionCheck
  input Real a;
  input Real b;
  output Boolean c;
algorithm 
   c := a>b;
end inRegionCheck;

在实际的代码中,该函数具有更多的输入和更长的名称,并且多行,并且多次使用同一检查,因此为了可读性,我想引入一个中间变量,如带注释的保护部分所示,但这会导致错误连续时间内的非真实方程式不合法".

In the actual code, the function has more inputs and a longer name and is several lines long and the same check is used several times, so for readability I would like to introduce an intermediate variable as shown in the commented protected section, but that results in an error "Non-real equation in continuous time are not legal".

有什么优雅的解决方法建议吗?

Any suggestions for an elegant workaround?

推荐答案

如果inRegionCheck函数由 annotation(GenerateEvents = true); 注释,则可以在SimulationX中工作(具有受保护的布尔变量isInReg).在Dymola中,您需要设置 annotation(Inline = true,GenerateEvents = true); 使其起作用.

Works in SimulationX (with protected Boolean variable isInReg) if the function inRegionCheck is annotated by annotation(GenerateEvents=true);. In Dymola, you need to set annotation(Inline=true,GenerateEvents=true); to make it working.

这篇关于连续时间内的Modelica布尔变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆