Getting Started with Wolfram SystemModeler Link

Wolfram SystemModeler consists of three parts: Model Center, Simulation Center, and SystemModeler Link. Modelica models are constructed in the Model Center and can be simulated both in Simulation Center and in the Wolfram Language using SystemModeler Link. The simulation results and model properties, such as system equations, can be analyzed in the Wolfram Language using SystemModeler Link.

This tutorial gives an introduction to the functionality of SystemModeler Link. To learn more about Model Center and Simulation Center, see the Help menu in those programs.

To use the SystemModeler Link package, we need to load it with Needs:

In[0]:=
Click for copyable input

Create a Model

System models can be created in the Model Center with an intuitive drag-and-drop interface with components and connections. Documentation and help on the modeling aspect can be found in the Model Center Help menu. In this tutorial, you will use models from the MathematicaExamples library, which is included in SystemModeler. The following screen shot shows the Model Center with a model from the library opened.

Simulation

WSMSimulate runs a simulation of a model created in the Model Center and returns a WSMSimulationData object. WSMPlot is used to visualize results from that simulation.

WSMSimulate["mmodel",{tmin,tmax}]simulate the model from to
WSMSimulationData[]object containing simulation results
WSMPlot[sd,{"v1",}]plot variable from the WSMSimulationData sd

SystemModeler simulation functions.

Basic Simulation

Once a model has been created in the Model Center of SystemModeler (screen shot above), it can be simulated from the Wolfram Language. To simulate a model, use the command WSMSimulate with the model name and the simulation time as arguments.

In[2]:=
Click for copyable input
Out[2]=

The output from WSMSimulate is a WSMSimulationData object. This object can be used in WSMPlot to plot variables from the simulation.

In[3]:=
Click for copyable input
Out[3]=

Simulation Data

The simulation result object also has a number of properties.

In[4]:=
Click for copyable input
Out[4]=

Take a look at the variable names in the simulation.

In[5]:=
Click for copyable input
Out[5]=

Retrieve the value of the variables and at time .

In[6]:=
Click for copyable input
Out[6]=

Parameter Changes

Simulate again, changing two parameters using the option WSMParameterValues and compare a result variable between the simulations.

In[7]:=
Click for copyable input
In[8]:=
Click for copyable input
In[9]:=
Click for copyable input
Out[9]=

Parameter Sweeps

Multiple simulations for a number of values of a parameter are automatically done in parallel. Simulate a bouncing ball with different amounts of bounciness, .

In[10]:=
Click for copyable input
Out[10]=

Plot the height of the balls over time.

In[11]:=
Click for copyable input
Out[11]=

Custom Plots

By retrieving the simulation results as data, results can be visualized and analyzed in many ways. For example, plotting the results from a Chua circuit on a ParametricPlot.

In[12]:=
Click for copyable input
In[13]:=
Click for copyable input

Pick out the variables and .

In[14]:=
Click for copyable input
In[15]:=
Click for copyable input
Out[15]=

A Lorenz attractor makes for a beautiful simulation result with ParamatricPlot3D.

In[16]:=
Click for copyable input
In[17]:=
Click for copyable input
In[18]:=
Click for copyable input
Out[18]=

Model Data

In addition to driving simulations of models from the Wolfram Language, it is also possible to work with the model more directly. WSMModelData is used to retrieve information about models, and WSMFindEquilibrium and WSMLinearize are used to obtain equilibrium points and linear state-space representations.

WSMModelData["mmodel",]retrieve information about
WSMFindEquilibrium["mmodel"]find equilibrium points for
WSMLinearize["mmodel"]get a linear state-space representation of

SystemModeler model functions.

Equations from Model

Retrieve information about a model with WSMModelData. First, get an overview of the model information.

In[19]:=
Click for copyable input
Out[19]=

Get the system equations depending on the time variable t.

In[6]:=
Click for copyable input
Out[6]=

Find a point where all derivatives are zero, also called an equilibrium point.

In[7]:=
Click for copyable input
Out[7]=

There are a large number of properties of WSMModelData that can be used to get information about the model.

In[8]:=
Click for copyable input
Out[8]=

The default format for all Modelica variables contains symbols like and . Use to convert variables to strings.

In[9]:=
Click for copyable input
Out[9]=
In[10]:=
Click for copyable input
Out[10]=

Equilibrium Points and Linear Representation

Use WSMFindEquilibrium to find an equilibrium point for a model of a mixing tank.

In[25]:=
Click for copyable input
Out[25]=

The function WSMLinearize gives a linear state-space representation of a model at an equilibrium point. The result is a Wolfram Language StateSpaceModel.

In[1]:=
Click for copyable input
Out[1]=

The control functionality in the Wolfram Language can be used to further work with this representation. Design a controller using pole placement and show the output response to a unit step.

In[2]:=
Click for copyable input
In[5]:=
Click for copyable input
Out[5]=