# WSM Part 1

0 (0 Likes / 0 Dislikes)

And we will start right off with the first part
which is the introduction to system modeling
Here we will go through the most basic parts of system modeling,
talk a bit about Wolfram SystemModeler
and how it fits into all of this
We will also talk a bit about what you need
to get up and running with all this new functionality
but most importantly in this part,
we'll cover the most important thing,
which is the system models, the actual models
that we will be interacting with today
We will be finding out how you can browse
the built-in model repository in order to find models
that you can simulate, that you can modify and analyze
And also how you can import new models
into your Wolfram Language session.
So let's start with Wolfram SystemModeler,
what is Wolfram SystemModeler?
It is a stand-alone product from Wolfram Mathematica
and other Wolfram Language Products, and it's a graphical user interface
that allows you to create arbitrarily complex models
from any number of different domains,
including electrical, mechanical, thermal,
biological models and so on.
And I think I'll jump into SystemModeler a bit
to show you how it looks
so you can get a feeling for what a system model is.
Now actually this first new command
that I'm running from my Wolfram Mathematica notebook here,
will actually not be available
to Wolfram Language users
those that don't have a copy of SystemModeler installed.
And that is because it opens up SystemModeler itself,
so that's pretty logical.
So once I run this command,
you'll notice that for you existing SystemModeler users,
you'll notice that I didn't need to call the WSMLink package
that you might be used to calling now.
All of these functions are built into
the Wolfram Language, they will just be there from the start.
You can just type them into the session
and the Wolfram Language will recognize it.
No need to load any additional package
or anything like that.
So we call this SystemModeler function,
it will open without any arguments,
it will just open up a blank session of SystemModeler.
And this is what it looks like,
and what SystemModeler is,
it's a tool that is flexible enough to build anything
from a simple circuit, for example
let's see if I can find a DC motor,
there's some of them here.
A simple electrical circuit like this one,
this DC motor and you build models
of different things in SystemModeler
by dragging and dropping different components onto the canvas
and then connecting them up together with the ports,
in the case of an electrical circuit,
you're connecting it kind of like…
Yeah you're creating an electrical connection
between the different components,
and in the case of a mechanical system, like this inertia here,
it's a mechanical system that's attached to the DC motor,
then you're connecting things, like a solid mechanical connection.
Now this is a very simple example of a model.
We can scale this up to something
which has for example thousands of different components
we could look at the model of a car driveline instead
and on the surface, this model
built in SystemModeler might not look so complicated
but in SystemModeler, in order to be able to build these
highly detailed models without actually
risking cluttering things up, you build things heirachily.
You build them using like a normal whole,
how things would look normally,
where you, for example, could collect everything
needed to model a transmission,
you could collect that in one component,
and then have smaller components
that describe how this car transmission works.
So you have a component that is the automatic control unit
and you have one for the gear box
and these can have even smaller components.
So this is how the graphical user interface
of SystemModeler allows you to create these
arbitrarily complex models ranging from simple
to very very advanced using just
simple drag-and-drop methodology.
And I forgot to mention but the components
that you use here, they are all provided
built-in to SystemModeler from many different domains,
such as electrical, mechanical, thermal, biological and so on.
However, today in this session
we won't be as concerned with how these models are built,
we will instead assume that you have a model
that you want to analyze in some way,
you might want to optimize this car driveline
you might want to test how reliable this DC motor is
to different types of scenarios.
Then, we can use the Wolfram Language
to try these different models in different scenarios.
And that is what we will learn about today.
So I'll switch back to my Wolfram Language session here
and as I mentioned in the introduction,
while it has previously been possible
to connect SystemModeler with the Wolfram Language
using a package previously called WSMLink,
now we are fully integrating the simulation engine
from SystemModeler, that is what allows you to
actually take these models, analyze them,
simulate them, visualize them and so on.
And we are fully integrating it into Mathematica 11.3
And this means that we have a completely new
system modeling interface, so this function here,
it's completely new, and all the functions
I will be showing today are brand new for 11.3
and they have expanded and streamlined capabilities
compared to the old functions that were present
in the WSMLink package.
And as I also mentioned, this allows you to do
a lot of these simulations and analysis
of models without having a copy of SystemModeler,
with just having a copy of the Wolfram Language,
it allows you to send, if you are a model developer
working in SystemModeler that would also allow you
to send these models for any other Wolfram Language user
to pick up, explore, analyze, visualize, and so on.
But first I need to start with
a bit of system requirements.
Now in terms of systems that isn't a problem.
Wolfram SystemModeler and Wolfram Mathematica,
they both run on the same types of system.
They include the simulation engine.
It works for Windows, Mac OS, Linux,
all the major platforms.
So if you are able to run Mathematica,
or any other Wolfram Language desktop product today,
then you should be able to use this functionality,
however one small caveat is that you need to install a compiler.
And you might wonder why this is needed.
And in order to take all these advanced system models,
for example, take a model of a car
which might have thousands of different components
and then making it so that you can run these models
very efficiently and simulate them very quickly
then we translate those models, those equations,
that form up those models.
We translate that into highly optimized C++ code
and then compile it into a standalone executable.
And with this we want to ensure that
even for very large systems,
they can be simulated very quickly.
So there's some built-in
steps in order to configure a compiler
for when those, there's even a built-in workflow
where you can just click install
and it should install the compiler.
And once you've done that
you can verify that you have a compiler
hat SystemModeler recognizes up and running,
and as we'll send out these notebooks
I want to go through what each of these does,
but there's a full list of instructions
for installing these compilers are available
in this presentation notebook that we sent out.
Right, now if we want to simulate these models
and we want to visualize them,
how exactly do we find them?
Now, SystemModeler comes with a wide range
of pre-built models. I've shown you two right now,
DC motor and a model of a car driveline.
But I think there's hundreds,
maybe thousands of other built-in simulation models
that you can run just straight from your Wolfram Language session.
And you can browse all of these
with the new SystemModelExamples command.
And this one provides, once it's loaded,
provides you with an interactive interface
where you can explore different packages in SystemModeler,
or rather the SystemModeler engine
that is included in the Wolfram Language.
So even if you don't have SystemModeler,
you can still call this SystemModelExamples function
and find all the currently loaded run-able simulation models.
And they are organized into different packages
so we have some packages for different educational domains for example.
So in electrical engineering
we can find different run-able models,
for example, a BoostConverter.
And this will only look at the models
that you can take and start to simulate directly.
So that's one way of finding a model.
Now if you already know what you're looking for,
you can use the new SystemModel command
and call a...
with a string, ask for a model.
And this might look a bit unconventional.
It uses dots to separate these packages
that I showed previously in the explorers.
So if you have education examples,
that's your top package,
then “.ElectricalEngineering” so that's down one step
in the package, and then another “.”
and you'll find the model.
So we can call this one
and what we'll get back then
is a SystemModel object.
Now these are completely new in 11.3
and they provide you with different ways
to interact with this model.
You can think of it as a representation
of a model that is loaded into SystemModeler.
And we'll make use of these model representations pretty soon.
Now if the name is unique, such as this BuckBoostConverter,
you can just ask for “BuckBoostConverter”
and then you'll get back exactly the same model.
Now this also has autocomplete,
so if for example, say you're looking for an engine,
you can start typing in “Engine”
and it would find different types of engine models
that are currently loaded into SystemModeler.
So here we'll get a V6 engine model
that we can simulate and run.
Now you might have more
than one model that's called a certain thing,
and if they exist in different packages
this is perfectly allowed.
But if you then try to use a short name
to call the model, you'll get an error.
But it will list all the available models
that is called Rectifier.
So we have some different types of rectifiers
that we can get a model representation of.
So say we want a multiphase rectifier,
then we could call if by the complete name instead.
And we'll get the model representation of that.
So the models here that I've been showing,
while you use drag-and-drop to create them,
what is actually happening is that the graphical user interface
is creating something that's called Modelica code
or code that's written in the Modelica language.
And this is a non-proprietary language
that is used to describe different systems of equations.
And it's pretty simple when you look at
the most fundamental component for example.
This is just a model of a simple differential equation.
You just type down the equations
and you can do this for yourself
using the built-in text tool in SystemModeler,
or you can create models using drag-and-drop
and these equations and everything you need
to accurately model your system will be created for you.
But it's pretty nice actually, it's human-readable,
so you can find out exactly what is happening inside the model
And since it's completely text based
you can get out a string from your model,
which is pretty nice if you're doing revision control and so on.
So, I only showed you now the models
that are built into the SystemModeler engine,
those that you will have access to,
just as soon as you load up your Wolfram Language session,
you will have access to those models.
Now, since there's a lot of other sources for models that you can find.
We publish a lot of downloadable examples
on the SystemModeler webpage,
the Wolfram Library Store provides you with different ways
to extend the modeling capabilities of SystemModeler
and also contains a lot of different run-able models.
The Wolfram Community is a great source of models
that you can import into your engine.
And now, of course models that you create yourself
either using the graphical user interface of Wolfram SystemModeler,
or if you are creating models from the Wolfram Language,
now that is also possible.
And I will cover that later in this session.
However, since the language is non-proprietary,
there are also non-Wolfram sources that you can get models from,
and the Modelica Association maintains a list of different model libraries
that you can download and import into SystemModeler.
And if you don't have SystemModeler,
you can still import these models that you download from the web or so on.
You just use the normal Import command in Wolfram Language
and say that it's a model file, and Wolfram Language
will recognize that and then load that model into your SystemModeler session.
Now there's a new function in 11.3 which is pretty nice,
which is called Iconize, and since these are SystemModels,
they are just text based.
You can pretty easily embed that text
inside of a Wolfram Language notebook.
And you can use the Iconize command to do this.
So if I ask for the string of this SystemModel,
I will get back that string in Wolfram Language representation,
and I'll call Iconize to get back an iconized representation of that string.
Now I can completely embed this in the model
and for example have a function,
at the beginning of my notebook that takes this string
and imports it into the SystemModel engine session.
So now I've imported this differential equation
and I can find it in the browser I showed previously,
or I can see if I switch to SystemModeler,
I can see that it has been loaded.
Now one thing I might not have made clear
is that SystemModeler and the Wolfram Language
these two sessions here, they are working on,
they are using a shared state.
Everything that happens in the Wolfram Language
when I say to Import this,
it will immediately be available in SystemModeler.