c function is not correctly called in JModelica
up vote
1
down vote
favorite
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.
modelica fmi jmodelica
add a comment |
up vote
1
down vote
favorite
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.
modelica fmi jmodelica
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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.
modelica fmi jmodelica
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.
modelica fmi jmodelica
modelica fmi jmodelica
asked Nov 9 at 17:02
Sen
111
111
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
Just some small corrections and improvements, e.g., make it a void function.
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;
Btw, unrelated to FMI.
Thanks, I applied the modifications to the model but it seems the issue still occur.
– Sen
Nov 13 at 22:35
by the way, can you please explain why this modification can resolve the issue?
– Sen
Nov 13 at 22:36
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Just some small corrections and improvements, e.g., make it a void function.
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;
Btw, unrelated to FMI.
Thanks, I applied the modifications to the model but it seems the issue still occur.
– Sen
Nov 13 at 22:35
by the way, can you please explain why this modification can resolve the issue?
– Sen
Nov 13 at 22:36
add a comment |
up vote
1
down vote
Just some small corrections and improvements, e.g., make it a void function.
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;
Btw, unrelated to FMI.
Thanks, I applied the modifications to the model but it seems the issue still occur.
– Sen
Nov 13 at 22:35
by the way, can you please explain why this modification can resolve the issue?
– Sen
Nov 13 at 22:36
add a comment |
up vote
1
down vote
up vote
1
down vote
Just some small corrections and improvements, e.g., make it a void function.
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;
Btw, unrelated to FMI.
Just some small corrections and improvements, e.g., make it a void function.
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;
Btw, unrelated to FMI.
answered Nov 12 at 21:48
tbeu
29525
29525
Thanks, I applied the modifications to the model but it seems the issue still occur.
– Sen
Nov 13 at 22:35
by the way, can you please explain why this modification can resolve the issue?
– Sen
Nov 13 at 22:36
add a comment |
Thanks, I applied the modifications to the model but it seems the issue still occur.
– Sen
Nov 13 at 22:35
by the way, can you please explain why this modification can resolve the issue?
– Sen
Nov 13 at 22:36
Thanks, I applied the modifications to the model but it seems the issue still occur.
– Sen
Nov 13 at 22:35
Thanks, I applied the modifications to the model but it seems the issue still occur.
– Sen
Nov 13 at 22:35
by the way, can you please explain why this modification can resolve the issue?
– Sen
Nov 13 at 22:36
by the way, can you please explain why this modification can resolve the issue?
– Sen
Nov 13 at 22:36
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230262%2fc-function-is-not-correctly-called-in-jmodelica%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown