System Modeling in the Wolfram Language

Patrik Ekenberg, Malte Lenz, Wolfram MathCore AB

Join the Conversation #WolframTechConf

Outline

Motivation, What and Why

What are we changing

How does system modeling in the Wolfram Language work?

What can we do with them?

How can we create system models from the Wolfram Language?

What is System Modeling?

Understand, design and analyze systems

Mechanical

Electrical

Information

Industrial

Life sciences

Social sciences

…

Real world examples of system modeling

Analyze different configurations of a spacecraft and how they would perform during a planned mission

Help with vibration analysis of proposed engine test bench design, guiding it in the right direction

Analyze metabolism of drug treatment to replace or add to clinical trials

Teaching and understanding electric circuits in communication equipment

…

What’s New?

Previous situation

System Modeling functionality was available as a package for Wolfram SystemModeler users

What are we changing?

System Modeling functionality included with Wolfram Language (starting with desktop Mathematica)

Enables collaborating and sharing with colleagues that don’t have the SystemModeler product

Tighter integration into Wolfram Language workflows

The design is not yet finalized, and details are likely to change before release

So how does it work?

The central object is a SystemModel:

m=SystemModel["Systems.InvertedPendulum"]

The model can be queried for a lot of information:

["Summary"]

Show the diagram of the model:

m["Diagram"]

There are a lot of other properties available to explore the model:

m["Properties"]

Simulation of SystemModels

The SystemModel is used in other functions:

SystemModelPlot[]

Use an electrical filter model to filter a TimeSeries signal:

SystemModel["ElectricCircuit.LowpassFilter"]

ts=TimeSeries[];

sim=SystemModelSimulate[,ts["LastTime"],<|"Inputs"->{"Vi"->ts},"ParameterValues"->{"C1"->0.03,"C2"->0.115}|>]

SystemModelPlot[sim,{"Vi","Vo"}]

More uses of SystemModels

Parametric simulations

Set up a parametric function that simulates with a given “a”:

sol=SystemModelParametricSimulate[,"z",{"a"}]

Evaluate for a range of values of “a”:

Plot[Evaluate[Table[sol[a][t],{a,0,1,.1}]],{t,0,10}]

Linearization

Easily create a linearized state-space representation of a model:

statespace=SystemModelLinearize[]

Or go the other way, get a SystemModel representation of a StateSpaceModel:

CreateSystemModel[(StateSpaceModelFull[-13.`, 0.`, -1.6000000000000003`, 0.9999999999999998`, 0.`, 0.`, 1.`, 0.`, 1.6`, 0.`, 0.`, 0.`, 0.`, 0.`, 1.`, 0.`, , "V", "w", "inductor.i", "inertia.phi", "inertia.w", Vwinductor.iinertia.phiinertia.wVwinductor.iinertia.phiinertia.w, ])]

Programmatic Model Creation

From equations

Create a model of a bouncing ball:

eqs={
velocity[t]==height'[t],
velocity'[t]==-9.81,
WhenEvent[height[t]≤0,velocity[t]->-restitution*velocity[t]],
height[0]==1
};

model=CreateSystemModel[eqs,t,<|"ParameterValues"->{"restitution"->0.95}|>]

Simulate the model and plot the height of the ball over time:

sim=SystemModelSimulate[model,10];

SystemModelPlot[sim,{"height"}]

Create a signal generator by building on existing building blocks:

myFunModel=CreateSystemModel[{y[t]==Sin[t+Cos[2t]]},t,<|"Extends"->"Modelica.Blocks.Interfaces.SO"|>]

SystemModelPlot[{myFunModel,10},"y"]

Connecting multiple components

Connect the created signal generator to a discrete sampler component:

comp={"myFun"∈myFunModel,"sample"∈SystemModel["Discrete.Sampler"]};

conn={"myFun.y"\[UndirectedEdge]"sample.u"};

samplerModel=ConnectSystemModelComponents[comp,conn]

SystemModelPlot[{samplerModel,10},{"sample.y"}]

Integration with SystemModeler GUI

Tighter integration between SystemModeler graphical interface and Wolfram Language.

Automatic selection of action:

SystemModeler[]

SystemModeler[]

Explicit actions:

SystemModeler[,"Animation"]

SystemModeler[,"Text"]

SystemModeler[,"Documentation"]

Neat Examples

Easily accessible computable data for a model:

["Dataset"]

New “immutable” workflow:

newmodel=SystemModel["IntroductoryExamples.HelloWorld",<|"InitialValues"->{"x"->5}|>]

Unnamed models are forgotten when quitting, unless saved:

newmodel["ModelName"]

savedNewmodel=SaveSystemModel[newmodel,FileNameJoin[{$TemporaryDirectory,"MyModel.mo"}]]

savedNewmodel["ModelName"]

Change more things in your model:

SystemModel[,<|"Description"->"My new description with a 🐺"|>]

%["Description"]

Thanks!

SystemModeler in Education

Badger

Wednesday, October 18, 2:00 pm

What’s New in SystemModeler

Badger

Thursday, October 19, 2:00 pm

SystemModeler in the Wolfram Language

Little Chief

Thursday, October 19, 4:00 pm

SystemModeler in Industry

Little Chief

Friday, October 20, 9:00 am

Reinforcement Learning with SystemModeler

Little Chief

Friday, October 20, 9:30 am

SystemModeler Hardware Lab

Basement

All other time

Questions?

What Happens to Previous Code and Functions?

The WSMLink` package with all the previous functionality will still be available.

New features will primarily be added to the fully integrated system, so switching to the new functions is encouraged.

When Can I Use It?

We hope to release it with an upcoming version of Wolfram Language.