I am rather familiar with the assert()
function, but I have just noticed that it behaves differently when called within a function. Here’s an 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;
and the function:
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;
In this case, the assert()
in the equation section will only be triggered once, when y
becomes negative at t≡pi mod 2*pi
. However, the assert()
in the function_titi()
is triggered at every time step while y
is positive. Though I understand the logic behind it (i.e. the function has no “memory”), I am looking for a way to get the same behaviour to avoid untimely warnings. Perhaps using flags? Any idea?