Compose – PSIM Integration Starter’s Guide 2: PsimASimulate


Altair PSIM is a simulation and design software for power electronics, motor drives, and power conversion systems. Altair Compose is an environment for doing math calculations, handling data, automating workflows and much more.

 

A new, powerful, library has been released on Compose from v2022.3 onwards, the PSIM Integration library. This library allows to seamlessly build workflows integrating both tools for running simulations in batch mode, extracting, handling, and writing results for further usage and, in general, for saving time and effort in design and simulation tasks on PSIM.

 

This is the second posts in a series in which I explore the newly added capabilities briefly, so you can get a head start on how to leverage Compose if you are a PSIM user or vice versa. To follow along, you just need Compose and PSIM, both v2022.3, installed on your machine.

 

PSIM Schematic

 

The PSIM Schematic file (.psimsch) that we will be using is a simple buck converter: A DC – DC converter that is very common in power electronics. It lowers voltage applied to a load with respect to its input, while increasing current.

 

 

The simulation runs for 2 milliseconds and the results produced are I(L): Current passing through the inductor, I(R): Current passing through the resistor and Vout: Voltage at the voltage probe. The parameters that can be defined in the circuit are Vin: Input voltage, C: Capacitance, L: Inductance, R: Load resistance and Fsw: Switching frequency for the MOSFET. We will be working with this model throughout this guide.

 

PsimASimulate

 

This script is very similar to the one used in the first post of this series. Therefore, I will focus on their differences rather than going over the specifics again. Please check the previous post if you haven’t already.

 

We begin by setting up an internal clock, setting the path to the schematic, declaring both fixed and varying parameters and, in this case, creating a cell that will contain the setup for all the simulations we’ll be running.

 

close all, clear, clc

 

% Start measuring time elapsed running script

tic;

 

% Define input .psimsch file

filePath = '..\buck.psimsch';

 

% Fixed parameters

C = 50e-6;

Fsw = 200e3;

R = 2.5;

Vin = 120;

 

% Design parameter

Lspace = linspace(50e-6, 200e-6, 10);

 

% Cell array for containing specifics for each simulation

nL = numel(Lspace);

input_var = cell(nL,1);

 

Now, let’s go into a for loop just to set up input_var which is a cell array that contains structures with the specifics for each simulation: The schematic to run, the desired output file and the parameters to use.

 

% Set up simulation array for each value of L

for i = 1:nL

     

      L = Lspace(i);

     

      % Define output .smv graph file & parameters

      graphFilePath = sprintf('.\\Results\\buck_L_%1.2g.smv', L);

      parametersTxt = sprintf('L = %e\nC = %e\nFsw = %e\nR = %e\nVin = %e', L, C, Fsw, R, Vin);

     

      % Fill simulations array

      input_var{i} = struct('FilePath', filePath, 'GraphFilePath', graphFilePath, 'Parameters', parametersTxt);

     

end

 

With input_var ready, a single call to PsimASimulate will run all the simulations concurrently, i.e., at the same time, so we may save lots of time. We can also initialize the figure which will contain all results here.

 

% Run PSIM simulations in multiple threads

simResults = PsimASimulate(input_var);

 

% Create figure & format

figure; hold on, grid on, legend on

xlabel('Time [ms]');

ylabel('Output Voltage [V]');

 

Last, let’s plot results from every simulation using another loop and output the time elapsed for this whole process with toc.

 

% Extract results from each simulation & plot

for i = 1:nL

     

      L = Lspace(i);

     

      % Extract graph results

      t = simResults{i}.Graph.Values{1};

      IL = simResults{i}.Graph.Values{2};

      IR = simResults{i}.Graph.Values{3};

      Vout = simResults{i}.Graph.Values{4};

     

      % Plot & set legend with L value

      lineHandle = plot(t,Vout);

      leg = sprintf('L = %1.2e', L);

      set(lineHandle, 'displayname', leg);

     

end

 

toc

 

This is the resulting plot, identical to last time;

 

 

For me, running this only took 0.678 seconds. Compared to 0.966 seconds when running with PsimSimulate, the advantage becomes clear. Right now, we are running the simulation only 10 times, but this 30%-time reduction would become much more valuable when running a simulation thousands of times!

 

Go ahead and try it on your own, explore, and continue to the next post, in which we will have a look at how to read existing PSIM result files into Compose, how to process their data and write new files, and use Simview straight from Compose for signal visualization.

 

Contents

Compose – PSIM Integration Starter’s Guide 1: PsimSimulate

Compose – PSIM Integration Starter’s Guide 2: PsimASimulate

Compose – PSIM Integration Starter’s Guide 3: PsimSimview, PsimWriteGraphFile, PsimReadGraphFile

Automate PSIM using Python in Altair Compose