如何防止在每个时间步调用assert()?

问题描述 投票:0回答:1

我对

assert()
函数相当熟悉,但我刚刚注意到它在函数内调用时的行为有所不同。这是 MRE:

model toto

  Real y;
  Real z;

equation 

  y = sin(time);

  assert(
    noEvent(y > 0),
    "y smaller than 0",
    AssertionLevel.warning);

  z = function_titi(y);

  annotation (experiment(
      StopTime=10,
      Interval=0.01,
      __Dymola_Algorithm="Dassl"));

end toto;

和功能:

function function_titi

  input Real y;
  output Real z=1 "Dummy output";

algorithm 

  assert(
    noEvent(y < 0),
    "y greater than 0",
    AssertionLevel.warning);

end function_titi;

在这种情况下,当

assert()
y处变为负数时,方程部分中的
t≡pi mod 2*pi
只会被触发
一次
。然而,当
assert()
为正值时,
function_titi()
中的
y
在每个时间步都会被触发。尽管我理解其背后的逻辑(该函数没有“记忆”),但我正在寻找一种方法来获得相同的行为以避免不合时宜的警告。也许使用标志?有什么想法吗?

modelica dymola
1个回答
0
投票

我建议您提出一个 Modelica 扩展:

AssertionLevel.once
,具有您想要的语义。

© www.soinside.com 2019 - 2024. All rights reserved.