连续时间内的Modelica布尔变量

编程入门 行业动态 更新时间:2024-10-21 19:52:40
本文介绍了连续时间内的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布尔变量

本文发布于:2023-11-27 07:22:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637115.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间内   布尔   变量   Modelica

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!