# Is it possible to call a Mathematica function from a SystemModeler component?

Is it possible to call Mathematica 11.3 functions from a SystemModeler 5.1 component?

I see that Mathematica can run a SystemModeler simulation. Are there any examples of this?

It would be very useful to be able to create custom SystemModeler blocks that call Mathematica functions.

It appears that the Mathematica may make calls the SystemModeler. Can SystemModeler call Mathematica?

• You can at least write numerical functions in Mathematica and compile them down to C. Thus you can use Mathematica to write exogenous functions for Modelica models. – gwr Sep 27 '18 at 8:05

It is not in general possible (at this point) to call WL functions from SystemModeler components.

I (as a member of the SystemModeler development team) agree that it would be a great feature to have.

What you can currently do is use functions that are simple enough to be converted to Modelica (the language used by SystemModeler models) in CreateSystemModel:

model = CreateSystemModel[{Unevaluated[Function[#1 + Sin[#2]]][1,
u[t]] == u'[t]}, t]


The Scope section of the CreateSystemModel reference page has an overview of what is currently supported.

• We are talking calls to Mma functions before compilation of a model though, aren‘t we? Wouldn‘t these functions have to be embedded (thus in C) in the compiled model? – gwr Sep 27 '18 at 8:10
• The example I gave actually translates the Function given to Modelica, which in turn (by SystemModeler) is eventually compiled into C. One can imagine (and I have actually done experiments with) a compiled simulation actually starting up a WolframKernel process and calling it during simulation runtime. All the technical parts for that are actually in place for it, but it takes a bit of coding to glue it all together. With such a framework, you'd be able to run any piece of WL code you want during your simulation. – Malte Lenz Sep 27 '18 at 9:05
• Thanks for the explanation, that would definitely be a (better: the) "killer application" ! :) – gwr Sep 27 '18 at 9:38