Which converter model has the right fidelity for your simulation goal? | Simscape Electrical Modeling Practices for Fast Simulation - MATLAB & Simulink
Video length is 14:57

Which converter model has the right fidelity for your simulation goal? | Simscape Electrical Modeling Practices for Fast Simulation

From the series: Simscape Electrical Modeling Practices for Fast Simulation

This video compares different model fidelity variants for power converters, like averaged, ideal switching and detailed converters.

Published: 7 May 2024

Hello, my name is Hugo de Kock. I'm an application engineer at the MathWorks. Today I would like to talk about model fidelity of converters, so using average or detailed or ideal switching. And let's start by having a look at a few examples.

In this example, a power converter model with different levels of fidelity is shown. Here you can see one model with-- using ideal switches and here one with average switches and also average pulses. It's in there in that subsystem. And then also here a model that's using average switching with the modulation waveform.

So in this example, if you run it-- you can see that for the case that you are using the modulation waveform, then you have these ideal currents, so you have the sinusoidal voltages. And in the phase currents, you don't have any harmonic content, you only see the sinusoidal shapes. And the DC values are also looking like DC values. But in the other cases, the ideal switch and also the averaged pulses that you can see that we have an actual switch voltage and then the effect that has on the harmonics.

So you can have a look at this example. And in this other example, it's basically the same content, but it's using variant subsystems, so, in this case, only one variant is active at each time and this is the one that I would like to showcase today and focus about the simulation execution time and the differences and maybe looking at some ways how to improve the simulation execution time.

So before we get into that, we have the three cases that is shown-- a low, a medium, and a high fidelity model. For the low fidelity model, we are using the modulation wave only with average switching. So in that case there is no harmonics contained and you would typically use this for example when you are only busy with the control system design and you don't need to have a closer look at the harmonics.

For the second case, the medium fidelity-- there you will start by averaging the pulses that are coming in and then apply that to an average switch model. This could be useful when you have a-- when you want to deploy a model to a hardware-in-the-loop system and when the input to the hardware-in-the-loop system are the actual pulses but you want to average out those pulses and apply it to an average switch model when this is, for example, running on the CPU on the hardware-in-the-loop system and you are not deploying the models to FPGA, for example.

In the third case, we are looking at a high fidelity model that we are using the actual pulses and we are using an ideal switch. In this case, you can really use this model if you are interested in the harmonics and want to do a harmonic analysis. Yes. So let's start by opening that model.

So I'm using the example as it is given on that web page. I only change the simulation stop time here and I'm also setting one parameter, it's called return workspace output, as you can find over here in the settings.

A single simulation output-- I like that because it contains metadata that has the simulation execution time in there so that would be very useful if we are comparing different modes and different models. So let's start off with the low fidelity model. I'm just doing this here by script, but on the model itself you can also see here some hyperlinks with callbacks. You can just click that, it will also set the model to low fidelity. And it's basically just changing some parameters in the base workspace that again is changing some of the settings here in the variant subsystem. So let us have a look at what it is doing. I will compile the model using the sample time colors.

So for the low fidelity model we are only using the modulation wave. You can see here in this variant source that this part is deactivated since we are only using the-- changing the mod waveform into a duty cycle and then we are applying that to an average switch. On this converter model we have the switching device as an average switch. And we can see that the whole model is running at a rate of 1 e minus 4. That's 100 microseconds. Also, just to show you this, if we look at the solver-- in this case, it's running at a fixed step. So that's the Simulink part. The Simscape part here also has a local solver and it's also running at the same rate.

So what I want to do next is to look at the different simulation modes. I will set it into normal mode at first and also activate the fast restart. And I will update the model. So I'm doing that there by script but basically-- if I would do this here in the user interface, I would basically just set it to normal and activate fast restart and compile the model.

The next step is that I want to run the simulation multiple times so that I get a good understanding of the variations in the different execution times. Let's start by doing that. Since we-- since I'm running this now on my PC, it's not a real time hardware and it means that depending on the other processes that's running on my PC, like this video that I'm recording now or other things that-- the times can vary quite a lot.

It was compiling first and then it was running 10 times and this is the result. So this is a histogram that I have of all the different execution times. Just to show you the execution times here, I got out of that simulation results object. So this is the object that I saved here to the base workspace. Going to have a look here, you get all the log signals and, additionally, the simulation metadata. We can also get you the timing information. And I'm looking at the execution elapsed all time.

So I documented that and you can see quite a range of times, but let's say we're more or less running at 1.25 seconds per simulation. So if I'm using this model-- this low fidelity model-- what can I do to accelerate it. I can try to use the accelerator mode. So I set the model to accelerator, again, activating fast restart. And now I will run it again 10 times.

So it will generate some code and compile that code and then run that code. Between the runs it doesn't have to recompile the code again, it can just run it directly. So that's done and we can see here that the times-- most of the time here it was around 0.9 seconds or also equally often it was around 1.1. So I'm just going to go for an average year of about 1 second.

So we can see a slight improvement. This really depends on what other processes are running on the PC. That's why I also wanted to show multiple runs that you can get a feeling of the variance.

So the next thing I want to do is to look at the other use case, let's say medium fidelity. In that case, I will also just activate the normal mode again and fast restart. And we can have a look at the model.

So in this case, we have the gate signals coming in. In the use case that I explained before, this would be like the input to the HIL model. So we start here by averaging the gate signals and then taking those averaged pulses in here to this average switch. The rest is the same-- well, not entirely. You can see here that we did decrease the sample time here to 5 e minus 5. So let's run that 10 times and-- so we can see that most of the time you're sitting here around 2.5, 2.75 seconds, around there. That's in the normal mode. Now I can switch it over to the accelerator mode and just run the 10 simulations again.

So it's ready. Finished. We can see that quite often it's around 2 seconds, between 2 and 2.2 seconds. So I will set it to 2.1 seconds. You can see an improvement there from normal to accelerator mode.

In the first use case, we will look at a high fidelity model. Here we will reduce the time stepped with another factor five. And let's have a look at the model.

Now we are using these pulses directly and we are applying it here to an ideal switch. So it's not using the average switch anymore, but it's using an ideal switch. Let's run that 10 times. So we can see most of the time it's took about 6.8 seconds. I'll just set it here to 7. These are just quite relative numbers anyway.

Now, let's see if we keep it to the high fidelity model, what is the improvement we can get by setting this to accelerator mode? I will run this again 10 times. So we can say-- see that quite often it took about 6.25 seconds and something between 6.25 and 6.7, so I'll set it to 6.5 here. So let's review the results.

We can see that for the low fidelity model, it took the fastest-- the accelerator mode brought an improvement maybe around 20% here with the medium fidelity model where we where we were using averaged pulses it took about three times as long in the normal mode and also here we can get quite a significant factor improvement when we switch it to accelerator and for the high fidelity model it takes a lot longer than the two other modes.

And also here we can get a slight improvement when we use the accelerator. So depending on the length of your simulation-- if you are simulating, for example, a very long drive cycle-- using the accelerator mode can make quite a big difference and is-- and depending on your use case just choosing the right fidelity of model will of course here make the biggest impact.

So I hope that this will help you also with your examples so that you can choose the right level of fidelity and then also consider using accelerator mode to increase the speed of your simulations. Thank you.