Watch videos with subtitles in your language, upload your videos, create your own subtitles! Click here to learn more on "how to Dotsub"

WSM Part 2

0 (0 Likes / 0 Dislikes)
Now we found a few models but we haven't really done anything interesting with them yet, besides seeing how they look. And now we'll learn what we can actually do with these models, how we can put them to use, so to say. But before we get started we need to understand a bit more about the SystemModel objects, and then we'll use some built-in functions to get out a simulation result form the model. And lastly, rather than just simulating the model, we will also be looking at some more advanced usage of the simulation results. So first off, we'll be again using these SystemModel objects, and we will first be looking at this model of a driveline. So we explored this previously in SystemModeler, but we can just as well explore this model of a driveline in the Wolfram Language, we can get the diagram, we can learn about different parts and so on. Now using these model representations, there are a lot of ways you can interact with it. One of the first things you might care about when you get this SystemModel driveline model. You might wonder, can I simulate it? So then you can call the SystemModel, with the name of the SystemModel and ask, is it a simulation model with the SimulationModel property and it will tell you, yes this is a model that you can simulate. And what that means is that is has all the information needed to just run a simulation from it. Now if we're looking at something like a component from this model, for example, the brake here. You can ask it here is the component... I'll ask is the brake component the simulation model? No, it isn't, because it doesn't have enough information to just run it. There are a lot of other properties you can extract, all computational of course. But a more digestible way to explore the model would be to ask for the summary, which just tells you the most important parts of this driveline model. And it will tell you if it's a simulation model, how many system equations there are, how many variables there are. Which would, in the case of a simulation model these two values should be the same because then there is one equation to describe each and every variable. It will also tell you a bit about what the model is composed of. Is it from translational mechanics, rotational mechanics, electrical, and so on. But enough blabbering about learning about the model. Now let's put the model to use. The absolutely easiest way that you can take a model and simulate it is to use the SystemModelPlot command. So I'll run this function. So what happened there in the beginning was that it took this complete model of the car driveline and it translated it into highly efficient C code and that's where it was using the compiler. Then it took that executable that was compiled from the C code and it ran a simulation using that. And from that simulation it was able to get some variables. And if you just call SystemModelPlot without anything else, anything other than the model name, then you'll get back what's called the default plot. And this is something that a model developer can add to the model and what it is, is kind saying like, okay, this is the most important thing that you can look at in the model. And in this case the model of the driveline has been constructed in order to assess the instantaneous fuel consumption during a normal drive cycle. So the default plot here it looks at the the fuel consumption given a certain speed. And the x-axis here is time then so it has a certain drive cycle that it's supposed to follow, and then from the model we can get out the instantaneous fuel consumption. And but of course you can store an infinite amount of these plots in your model. And we can get out all the plots that have been stored all the names of the plots that have been stored in this particular model. So we can pick out another one of them, we could ask for the selected gear plot, which as the name suggest, is the current gear that the car is in and it's an automatic transmission so this will be automatically determined based on the vehicle speed. So then we get back a plot from that. So you might notice that these plots they can be one, they can be two or any number. They can be parametric or they can have multiple variables plotted in the same plot. But something you might have also noticed is that when I ran this command the second time it re-simulated the model, and does it have to be like that? I mean in this case it wasn't really a problem because we're just simulating it for 15 minutes or so of drive time and it goes pretty fast, but for larger simulations of course you might not want that. But you don't have to do that, you can call this SystemModelSimulate command. And this is the last time we'll simulate this model, I promise. And store the result in a Wolfram Language symbol, we'll call it “res” here, and you get back a SystemModelSimulationData. This simulation data contains all the information necessary in order to recreate what happened during the simulation. It contains the stored plots that we explored previously. It contains all the model variables, in fact there are 739 of them. And this number is smaller than the one that we looked at previously in the model properties because some of them are reduced down when the code is optimized. But now since we have the result, we can get a lot of plots really quickly. So for example, we can ask for all the stored plots from the model. So we'll just create a simple table and call SystemModelPlot with all the different plot names and get back a table. Now, it didn't have to re-simulate anything because all of that information was stored in the SystemModelSimulationData object. Okay, what more can we do with this? Well, I've only shown now the stored plots that the model developer might have put in the model, but if you wanted to go beyond what the developer thought you would do with the model, you might want to look at something else entirely and the good news is that every single variable from the simulation, all these 739 of them are available in the simulation result. So we can just pick out a specific variable from the simulation, and use the same command SystemModelPlot to plot that variable. So now, what we're looking at here, and this is just the same notation that I talked about previously, we're looking at the variable <i>v</i>, which usually stands for the angular velocity of an inertia inside of the right wheel, and it uses this dot notation I talked about previously. So you might recognize this graph, it's very similar to the car speed plot that we were looking at previously, which makes kind of sense because if your car is going in with one velocity, the angular velocity of the wheels will probably be very proportional to that. And we pick out just a random variable from the simulation using random choice. Sometimes you get something interesting to plot, this looks pretty good I think. It's whether the synchro gear is active or not at a particular time. So you know you can get anything from your model if it's the temperature of the brakes, or if it's the current acceleration, or the air drag acting on the car, anything you can get out from the model if it is a part of the model, of course. But so far we've only looked at things like the original plot setup. Now there's a lot of different things that you are able to change inside of these SystemModels, we call them parameters. So these are things you might provide a default value for, for example the the mass of the car we were looking at, or the mileage or anything like that, so these might be parameters in your model and right now we were just using the default ones that were in the model but of course we can change these parameters during a simulation from the Wolfram Language, and to illustrate this, I'll import a completely deployed model, “InvertedPendulum”. And we will first just look at how it looks with default parameter settings, so this is a controlled inverted pendulum where you get back the position of the pendulum tip and the angle of the pendulum. You feed that into a linear controller which acts on a motor which tries to keep the pendulum upright, or actually tries to keep it in a certain reference position so we can compare with the default plot, we can compare what the actual position is and what the reference position is. So we can see how well the controller behaves. Now we might want to simulate this for a different setting for a parameter. And how do we find these parameters using the SystemModeler graphical interface is one way, but we can of course get all available model parameters right in the Wolfram Language here I'll ask the SystemModel and I'll ask for one the properties which is the parameter names in the model. And then you'll get all the parameters from every subcomponent in the model as well but here I'll ask for everything that doesn't contain a dot, which will return only the top-most parameters in the model which is usually where a model developer would put the most important parameters, the most important parameters would be available in this scope of the model. Now you can have parameters for this DC motor which might only be accessible if you go inside that level in the hierarchy and so on. But the most important will be available at the top level, now depending on the model setup, you might get some warnings, because not all translations between the Wolfram language and Modelica code is currently supported but in this case there's nothing to worry about. So we'll find some different parameters, and we'll try and change the first one, the reference type, and it takes some different scenarios. As integers, we can ask for descriptions if you want to know more about what the actual parameter is. But we can call SystemModelSimulate with the model name, and an association which modifies the model in different ways. So we'll try this model with some different referenceTypes and they are just enumerated “{1, 2, 3}” in this case. And then we can take this result and plot the pendulum position. And we'll see how the model behaves. Now this doesn't actually entail what the reference was, with reference I mean this type of scenarios, so we can ask for this variable “controller.switch1.y” there's probably a stored plot for that which I can't remember but we can ask for “controller.switch1.y” and we can see how all the different reference types look. So I think I'll jump right ahead and see what more power we can get out of these models, and jump right into the visualizing part, but first we have a question from the audience, and it is: Do the compiled model files get deleted after quitting Mathematica, or are they saved somewhere? So by default they are not saved. But just as you can use the Import command from the Wolfram Language, you can also use the Export command. So we can take this model that we imported here, the inverted pendulum, and we can call the Export command and we export it to the disk, we'll just call this file name here “” And this will save the model file and then you can load it again into your next session. Does the new system integration take complete advantage of GPUs? Right now, there's no possibility of distributing a simulation on different… using a GPU it's using the CPU however, and I'm not sure if this works with a GPU especially but I'll check that out. When you run a simulation like the one we run here where we tried three different scenarios. This will run these three in parallel.

Video Details

Duration: 18 minutes and 10 seconds
Language: English
License: Dotsub - Standard License
Genre: None
Views: 15
Posted by: wolfram on Jul 10, 2018

WSM Part 2

Caption and Translate

    Sign In/Register for Dotsub to translate this video.