Export/interface Julia code to FMI/FMU standard .fmu

Thank for your answer and your links.

First of all, I have also a look here, where FMI import and export tools are listed. However according to the webpage, SimulatorToFMU is able to export pyhton script.

Second, I can convert the Modelica models to Modia, however I have also some models which are based on Simscape toolbox from Simulink. My constraint is to export julia script to .fmu, where the .fmu can be reutilised.

Third, I tried a different way. According to Dymola User Manuel page 407, external functions in orther languages is possible (C, C++, fortran and Java), and also link to DLL in this web page and of course Dymola user manuel page 412.

I tried to build a share library from my julia function with PackageCompiler.jl which it can be a external library in modelica/Dymola and, finaly export this modelica model with the external function in .fmu. It can be summarise as:

  1. Julia function : MyFunction.jl
  2. Build a share library from the julia function with build_shared_lib(“.jl”): Myfunction.dll
  3. External functions linking with DLL inside one Modelica model: ModelicaModelWithExternalFunction.mo
  4. Export the modelica model with the linking DLL to .FMU: MyFMU.fmu

I have implemented the 4 steps. My trial julia function return the cab number:

Base.@ccallable function julia_main()::Cint
return 1729
end

Then, with REPL : build_shared_lib(“TaxiCabNumber.jl”). REPL wrote “All done”. The builddir is created, with the TaxiCabNumber.dll, however a large amount of other .dll are also there.

Then, I did my modelica.mo with external function. The modelica function is called add2bis (please note the julia_main) (I did like here case B):

function add2bis
output Real sum;
external “C” sum=julia_main() annotation (
LibraryDirectory=“modelica://TestFunctionExt2/Ressources/Library”,
Library=“TaxiCabNumber”);
end add2bis;

Then, I exported my modelica model (with add2bis call) to .fmu. My fmu is called TestfunctionsExt2.fmu. Dymola built the .fmu and I imported with simulink:
simulinkFMU

Then, I have run the simulation, and there was an error and simulation failed. I logged the FMU debug and I’ve got the following log:

Log From FMU: [category:, status:fmierror] Problem with loading TaxiCabNumber.dll

The .fmu is equiavalent to .zip, I have modified .fmu to .zip in order to have a look inside, and the two dll files are presents: TaxeCabNumber.dll and TestFunctionsExt2.dll.

I have the following questions:

  • Did I do some mistakes with the julia function according to PackageCompiler usage?
  • According to build_shared_lib, the generated library is called : buildir/libhello.{so,dylib,dll}. I do not understand the others files.dll from the buildir, what are their purpose? Also, what is the TaxiCabNumber.a?
  • Are there some limitations with the TaxiCabNumber.dll generated from build_shared_lib(“TaxiCabNumber.jl”)?

Thanks for all your answers. Warmest regards.