In Modelica, one could define a protected final constant Boolean debug
and then use that in an assert statement to print out some values while debugging, similar to the code shown below (or as seen on github).
In the final version, debug would then be set to false. Would that slow down the simulation or does the assert get eliminated, because debug is a constant?
model debugexample
parameter Real a;
parameter Real b;
Real sum;
protected
final constant Boolean debug = false "set to true while debugging";
equation
assert(not debug, "a=" + String(a), level=AssertionLevel.warning);
sum = a+b;
end debugexample;
The assert would be eliminated because debug
is constant. If debug
is a parameter however the assert might (depending on the tool) still only be called once rather than every timestep, because the Boolean
input to assert is not changing.