I have one Modelica model :
model test
Real x;
Real y (start=10);
function try
input Real x;
output Real y;
external "C" testC(x,y)
annotation(Include="#include <test.c>");
end try;
function round
input Real u;
input Real accuracy;
output Real y;
algorithm
y :=if (u > 0) then floor(u/accuracy + 0.5)*accuracy else ceil(u/accuracy - 0.5)*accuracy;
end round;
algorithm
x:=round(time, 60);
when time>=pre(y) then
y:=try(x);
end when;
end test;
And the c code is also shown as below:
int testC(double x, double* y)
{
puts("run ex");
*y=x+30;
}
The above code works well in Dymola, but when I run it in JModelica, I got one issue:
When simulate this model in period [0,200], I expect the c function will be called by 4 times: t=10,30,90,150. But I found in Jmodelica, the c function is actually called by 24 times!
Any help to explain the above issue will be highly appreciated.
Just some small corrections and improvements, e.g., make it a void function.
Btw, unrelated to FMI.