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?

  • $\begingroup$ 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. $\endgroup$
    – gwr
    Commented Sep 27, 2018 at 8:05

1 Answer 1


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.

  • $\begingroup$ 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? $\endgroup$
    – gwr
    Commented Sep 27, 2018 at 8:10
  • 1
    $\begingroup$ 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. $\endgroup$
    – Malte Lenz
    Commented Sep 27, 2018 at 9:05
  • 1
    $\begingroup$ Thanks for the explanation, that would definitely be a (better: the) "killer application" ! :) $\endgroup$
    – gwr
    Commented Sep 27, 2018 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.