0

I am trying to call an external C function in modelica with a function as an argument. So the C function needs to take a modelica "function" as input. Is it possible to do that in modelica ?

For example :

function foo

  input Function fun;
  output Real bar ;

  external "C" bar = myCFunction(fun) annotations(...);

end foo;

function Function
  input Real u;
  output Real y;
algorithm
   y := u*2;
end Function;

When I use the "check" option, I get some error stating fun is undeclared which I don't if I do not use a function as input. I looked online and in the use manual of dymola but I haven't found an example stating it was possible, nor impossible.

MrBellamy
  • 29
  • 5

1 Answers1

1

No, I don't think that's possible. You can check the Modelica Specification about allowed input types to external functions.

Manuel
  • 313
  • 1
  • 6
  • I checked this page before posting and indeed I did not find anything about functions. I hoped that maybe it was still possible somehow. – MrBellamy Jan 23 '23 at 08:38
  • Note that function inputs in Modelica are a bit generalized compared to C, and is actually a closure - https://en.wikipedia.org/wiki/Closure_(computer_programming) - That means it is slightly more complicated - but Dymola already handles it internally when generating C-code for the internal functions. However, that handling isn't standarized (yet). – Hans Olsson Jan 23 '23 at 11:02