在JModelica中未正确调用c函数

在JModelica中未正确调用c函数,modelica,fmi,jmodelica,Modelica,Fmi,Jmodelica,我有一个Modelica模型: 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 acc

我有一个Modelica模型:

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;
上面的代码在Dymola中运行良好,但当我在JModelica中运行它时,我遇到了一个问题:

在[0200]期间模拟此模型时,我预计c函数将被调用4次:t=10,30,90150。但是我在Jmodelica中发现,c函数实际上被调用了24次


对于解释上述问题的任何帮助,我们将不胜感激。

只是一些小的修正和改进,例如,使其成为无效函数

model Test
  Real x;
  discrete Real y(start=10, fixed=true);

function try
    input Real x;
    output Real y; 
    external "C" testC(x,y)
    annotation(Include="
void testC(double x, double* y)
{
   *y=x+30;
}");
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;
annotation(experiment(StopTime=200));
end Test;

顺便说一句,与FMI无关。

谢谢,我对模型进行了修改,但问题似乎仍然存在。顺便问一下,你能解释一下为什么修改可以解决问题吗?
model Test
  Real x;
  discrete Real y(start=10, fixed=true);

function try
    input Real x;
    output Real y; 
    external "C" testC(x,y)
    annotation(Include="
void testC(double x, double* y)
{
   *y=x+30;
}");
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;
annotation(experiment(StopTime=200));
end Test;