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
Mathematica using
SystemModeler Link. The simulation results and model properties, such as system equations, can be analyzed in
Mathematica 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 menu in those programs.
To use the
SystemModeler Link package, we need to load it with
Needs:
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 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.
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
Mathematica. To simulate a model, use the command
WSMSimulate with the model name and the simulation time as arguments.
Out[2]= | |
The output from
WSMSimulate is a
WSMSimulationData object. This object can be used in
WSMPlot to plot variables from the simulation.
Out[3]= | |
Simulation Data
The simulation result object also has a number of properties.
Out[4]= | |
Take a look at the variable names in the simulation.
Out[5]= | |
Retrieve the value of the variables
and
at time
.
Out[6]= | |
Parameter Changes
Simulate again, changing two parameters using the option
WSMParameterValues and compare a result variable between the simulations.
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,
.
Out[10]= | |
Plot the height of the balls over time.
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.
Pick out the variables
and
.
Out[15]= | |
A Lorenz attractor makes for a beautiful simulation result with
ParamatricPlot3D.
Out[18]= | |
Model Data
In addition to driving simulations of models from
Mathematica, 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.
SystemModeler model functions.
Equations from Model
Retrieve information about a model with
WSMModelData. First, get an overview of the model information.
Out[19]= | |
Get the system equations depending on the time variable
t.
Out[6]= | |
Find a point where all derivatives are zero, also called an equilibrium point.
Out[7]= | |
There are a large number of properties of
WSMModelData that can be used to get information about the model.
Out[8]= | |
The default format for all Modelica variables contains symbols like
and
. Use
to convert variables to strings.
Out[9]= | |
Out[10]= | |
Equilibrium Points and Linear Representation
Use
WSMFindEquilibrium to find an equilibrium point for a model of a mixing tank.
Out[25]= | |
The function
WSMLinearize gives a linear state-space representation of a model at an equilibrium point. The result is a
Mathematica StateSpaceModel.
Out[1]= | |
The control functionality in
Mathematica can be used to further work with this representation. Design a controller using pole placement and show the output response to a unit step.
Out[5]= | |