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;
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?
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.