Message Boards Message Boards

2
|
9012 Views
|
3 Replies
|
7 Total Likes
View groups...
Share
Share this post:

Creating custom SystemModeler components in Mathematica?

Posted 6 years ago

Is there any way to create a SystemModeler component in Mathematica?

I have a set of Mathematica functions that I would like to call from SystemModeler blocks. Is this possible?

It looks like Mathematica can run SystemModeler simulations. Can I create a custom component in SystemModeler that calls a Mathematica function.

POSTED BY: mdkimzey Kimzey
3 Replies

Malte hints in 2018 that it will eventually be possible to call MMA functions from SystemModeler, does anyone know how this is progressing. To date the focus has been on adding SystemModeler's capabilities into Wolfram Language.

While Malte is correct that there is no general way to do this directly, with a little extra effort you can do this.

You can call Mathematica from C using WSTP. See the documentation here. Also the tutorials referenced from that page will describe how to create a C wrapper function that will send any data, run any function, and return results from MMA using C.

The C wrapper function can be called from SystemModeler using an external C block in WSM. The documentation for calling C from WSM can be found in the WSM help system and also in Modelica By Example at this link within the WSM documentation center:

wsm:///ref/ModelicaByExample/behavior/functions/controller/

The overall process would be to write a small (few lines of code) C function based on the examples in the WSTP documentation that executes whatever MMA function you want using data sent in from C. Call the function from SystemModeler using the examples above. I hope this helps.

Regards,

Neil

POSTED BY: Neil Singer

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

I 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.

POSTED BY: Malte Lenz
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract