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


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.

 

PsimSimview, PsimWriteGraphFile & PsimReadGraphFile

 

In this script, apart from leveraging the aforementioned PSIM Integration functions, I will share some tips on how to handle interactive file selection (always useful!).

 

Let’s start by asking the user where the .smv files of interest are located, uigetdir takes care of that through a popup menu. With the path provided, we can now get a list of all the files matching the query …\GraphFilePath\*.smv, note how we can use wildcard characters in ls for retrieving all .smv files present. Command listdlg lets the user choose a specific file through a popup window as well, making the process intuitive and requiring no change in the script.

 

close all, clear, clc

 

% Ask user for results directory & get all .smv files present

GraphFilePath = uigetdir(pwd, 'Select Results Directory');

smvFiles = strsplit(ls([GraphFilePath, '\*.smv']), '\n');

 

% Interactively ask user for .smv file to show in Simview

R = listdlg('ListString', smvFiles, 'SelectionMode', 'single', 'Name', 'Select File to Visualize');

smvFileName = smvFiles{R};

smvFile = [GraphFilePath, '\', smvFileName];

 

 

 

Simview is PSIM’s waveform display and post-processing tool. Launching it from Compose for visualizing, measuring, and handling signals just as it would be done directly from PSIM just requires a .smv file, the signals we want to visualize, and a call to PsimSimview. Simview will launch automatically in another window.

 

% Launch Simview with .smv file

PsimSimview(smvFile, 'I(L1)', 'Vout');

 

 

If you’re not a seasoned PSIM user, this may look a bit irrelevant, given there’s already plotting capabilities from within Compose, but Simview has tools that let you interactively measure handle and compare signals. So go ahead and give it a try if you haven’t before!

 

Next, let’s read the data contained in the .smv file into Compose and do some very simple post-processing. Let’s calculate the power absorbed by the load. As the results include both the voltage and current we need to get the power from P = VI, a simple matrix multiplication in Compose will do the job. We can plot the result as well.

 

% Read results from .smv file into Compose

results = PsimReadGraphFile(smvFile);

 

t = results.Graph.Values{1};

IL = results.Graph.Values{2};

IR = results.Graph.Values{3};

Vout = results.Graph.Values{4};

 

% Get power & plot in Compose

P = Vout.*IR;

plot(t*1000,P);

grid on

xlabel('Time [ms]');

ylabel('Power [W]');

 

Let’s now write a new .smv file with the newly obtained result as well as the already existing data. Any signal must be saved in a cell, so we’ll use the function mat2cell to convert the matrices to the required format.

 

% Convert results to cells for writing .smv file

v2 = ones(1, length(t));

t = mat2cell(t, 1, v2);

IL = mat2cell(IL, 1, v2);

IR = mat2cell(IR, 1, v2);

Vout = mat2cell(Vout, 1, v2);

P = mat2cell(P, 1, v2);

 

Before going further, let me clarify how to use mat2cell. Let’s say we have matrix a = [1, 2, 3, 4] and we want to create a cell with its contents. If we just use b = mat2cell(a), b will be a cell containing matrix a in a single element, i.e., b = {[1, 2, 3, 4]}.

 

If we want to assign each element of matrix a to a single element of cell b, i.e., b = {1, 2, 3, 4}, we need to explicitly declare it with b = mat2cell(a, 1, [1 1 1 1]). In this way, we are telling the command to take the contents of a, arrange them in a single row in which the contents of a are arranged according to the mapping [1 1 1 1], i.e., one element on the first slot of b, another element in its second slot, and so on.

 

If we wanted two slots, the first one containing one element and the second containing three elements, we would use [1 3] as the mapping, and it would result in b = {1, [2, 3, 4]}. This can get a bit confusing, so I wanted to clarify. Let’s move on.

 

Calling PsimWriteGraphFile requires a specific format the data to write. Each input must be a cell containing the signal along with the name we want for it as {‘signal name’, datacell}.

 

% Write new entry in another .smv

outputGraphFile = '.\newResults.smv';

PsimWriteGraphFile(outputGraphFile, {'t', t}, {'I(L)', IL}, {'I(R)', IR}, {'Vout', Vout}, {'P', P});

 

Finally, the only thing we have yet to do is to visualize the new contents of our file in Simview.

 

% Visualize new data in Simview

PsimSimview(outputGraphFile, 'I(L)', 'Vout', 'P');

 

The existing instance of Simview receives the new file and displays it on a separate internal window. Here you can see the how our post-processed signal is now present in the file.

 

 

I hope this series of posts help you get started integrating both Compose and PSIM to build better workflows and automate more of them. Let’s leverage all the tools we have at our disposal to save the most time on these steps. That way, we’ll more time for more important parts of our workflow!

 

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