This repository contains various small models to show different concepts that can be used to build up a fast-running electrical model in Simulink and Simscape Electrical
All demos are based on MATLAB Live-Scripts that use a programmatic approach to change settings in the models. This should help users to reproduce the exact steps, even if most of those steps can be also done interactively.
All the demos are organized in the following way:
Project: Fast Electrical Simulation
- Analysis Tools
- Overview Example
- Simulation Modes and Fast Restart
- Parallel Computing
- Model Fidelity
5.2. Phasor Mode Simulation
5.4. Converter
5.5. Battery - Modeling Techniques
6.1. Fast PWM Simulation
6.2. Variable Frequency Pulse Generator - Solver Overview
- ...
- Simscape To HDL
The Model Advisor is used to perform several performance checks for your specific model concerning non optimal model settings or blocks. It also suggests counter measures.
The Simulink Profiler is used to figure out how much simulation time is needed for the whole model, per subsystem or per block. It works for normal and accelerator mode.
The Solver Profiler helps to figure out performance bottlenecks for models using a variable step solver. It shows the step sizes used during simulation and shows what blocks are causing small step sizes. It shows solver exceptions, solver resets, zero crossings and Jacobian updates.
The Statistics Viewer will aggregate Simscape model statistics for a given model with its solver configurations. Use it to evaluate model statistics to analyse models containing blocks and investigate the model complexity.
Scaling Simscape variables by their expected magnitude increases simulation robustness and performance. The techniques allows to provide a fine-tune scaling of variables in a Simscape model.
The Variable Viewer can be used to check the results of the initialization for the model. It allows to check, if individual initial value targets for variables have been satisfied. Use the Variable Viewer to check the models’ initial conditions with their priorities, explore issues when model initialization fails or throws warnings.
The Overview Example shows some typical performance bottlenecks in electrical system models like
- global fixed step solver
- no local solver for Simscape (only for fixed step)
- continuous PI controller
- many Scopes
- Slow PWM Implementation
- Normal Simulation Mode
- No Fast Restart
- Dedicated delays
- Detailed Power Electronics (IGBTs)
- No Parallel computing Please watch the corresponding YouTube video, if you want to learn, how to analyze a model step-by-step.
This section shows what impact the various simulation modes have on electrical system model. These modes are Normal, Accelerator and Rapid Accelerator Mode.
Additionally, the Fast Restart option is shown here. Fast Restart will prevent the check for model updates and will prevent recompilation as long as only parameters and no structures are changed in the model.
Run the MATLAB Live Script "SimulationModes_FastRestart.mlx" to learn more about these features.
This section shows how you can speed up electrical Simulation with Parallel Computing in normal or accelerator mode. Parallel Simulation can be used everywhere, where iterations are order independent. This is the case for
- Parameter sweeps
- Monte-carlo analysis
- Gradient calculation within local optimization problem
- Parallel calculations during global optimiuzation problem
- Model testing (Simulink Test)
Run the MATLAB Live Script “ParallelSimulationSetup_NormalOrAccelerator.mlx” to learn more about these features.
This section describes how different model fidelity variants influence the execution speed of a model.
This section compares a full electromagnetic transient (EMT) simulation of an AC power system to a phasor simulation. The requirements for a successful phasor mode simulation are shown, as well as how to switch the solver to phasor (called frequency and time).
Run the MATLAB Live Script “PhasorModeSimulationExample.mlx” to learn more about these features.
This section compares different model fidelity variants for power converters, like averaged, ideal switching and detailed converters. It shows when you have to use which converter variant and how fast they run in comparison.
Run the MATLAB Live Script “Converter_Avrg_Ideal_Detailed_Subcycle.mlx” to learn more about these features.
This section compares two battery packs with different model fidelity. Subsequently, the results are compared in terms of calculation time.
Run the MATLAB Live Script “SimscapeBattery.mlx” to learn more about these features.
This section describes how pulse generators for Pulse Width Modulation (PWM) and for variable frequency converters can be modeled efficiently.
This chapter shows what you must consider when you build up a model with fast PWM switching. It will show the dependency of execution speed from the solver selection, the converter fidelity variants and from different PWM block implementations.
Run the MATLAB Live Script “FastPWMsimulation.mlx” to learn more about these features.
This chapter shows techniques to model a fast implementation of variable frequency pulse generator for variable frequency converters.
Run the MATLAB Live Script “VariableFrequencyConverter.mlx” to learn more about these features.
This chapter gives an overview on solver and model considerations when simulating physical networks.
To run this chapter, please first start “PMSM_FPGA_HIL_Demo.prj” inside the corresponding folder “_9_SimscapeToHDL”.
Please see this in-product example for an introduction to this method. This demo project extends the previous example comparing different approaches, and adding further steps for code generation and deployment to complete a full workflow for FPGA-based HIL.
Pejovic's method replaces the Simscape switches and diodes with a combination of linear Simscape blocks and Simulink switches that will enable a conversion to a LTI (linear time-invariant) model. This method works with any solver, it has been tested with backward Euler and partitioning solver. This sample project features the latter but Pejovic and its implementation library is not restricted to that application and can be used with other converters and network topologies, please see the model TwoLevelConverterIdealExample_Pejovic
for another simple example.
This project shows the different manual steps for the transformation of a Simscape model to an HDL-optimized Simulink model. In a later MATLAB Release, the Pejovic replacement of switches in a Simscape network may become automated.
See the original Pejovic's paper for further technical reference.
To enable further optimization of timing and resources on FPGA, the model TwoLevelConverterIdealExample_HDL implements a variant using the Fixed-Point State-Space block with the input data obtained from the Simscape to HDL Workflow Advisor. Using the built-in block simplifies the eventual conversion of the HDL model to fixed-point w.r.t. the HDL subystem automatically built by the advisor.
As a proof of concept, the Simscape Pejovic Switch library has been extended with a linear averaged switch subsystem that interpolates linearly between the extreme values feeding the switch block in the standard built-in implementation. The subcycle averaging logic used is optimized for HDL code generation and is therefore suitable for very high frequency switching applications.
Please open the live scripts from the shortcut toolstrip or the liveScripts folder for more detailed and step-by-step instructions.
Pablo Romero, promero@mathworks.com
All, electrification, power electronics.
- Simulink Real-Time
- HDL Coder
- Simscape Electrical
- Speedgoat IO334 HDL Coder Integration Package
The model was developed using MATLAB release R2023b and requires the following products:
- MATLAB®
- Simulink®
- Simscape™
- Simscape Battery™
- Simscape Electrical™
- Parallel Computing Toolbox™
For any questions regarding the model place a comment in the repository.
- Gernot Schraberger: Chapters 2,3,4 & 6
- Eva Pelster: Chapters 1 & 7
- Nils Hornik: Chapter 5.2
- Lorenzo Nicoletti Chapter 5.5
- Pablo Romero Cumbreras Chapter 9
- Hugo De Kock Chapter 5.4
See license file attached to this repository
In development.
Copyright 2023-2024 The MathWorks, Inc.