πŸ“œ ⬆️ ⬇️

Managing CST MWS with Matlab

Introduction


Many engineers in the field of electromagnetic modeling often face issues of further processing and using the results of modeling a task in other environments or, conversely, transferring parameters from one medium to another. It would seem that there is no problem to export the results in a form that is understandable to another program and use them, or enter data manually. However, there are often tasks that require performing this sequence of actions N times and the performance of these actions rushes to zero. If you are interested in the topic indicated in the title, then I ask for cat.

Modern trends in data processing have led radio engineers to become widely used to achieve their goals with the powerful tool Mathworks Matlab . This package allows you to solve problems of digital signal processing, simulation of FPGAs and communication systems in general, the design of radar models and much more. All this makes Matlab an indispensable assistant of almost any radio engineer.

Specialists in high-precision electrodynamic modeling often operate with other specific software packages, one of which is CST Microwave Studio . There are a lot of articles about this product on the website of Eurointech . Therefore, to challenge its leading aspects is not necessary.

The author recently faced the challenge of simultaneously using the above packages. In this article I would like to reflect a possible way to solve this problem, as well as a range of similar tasks.
')

Strategy


In the general case, it was necessary to carry out a simulation of the project in Microwave Studio in the frequency range specified by some function running in Matlab and the subsequent use of the results of modeling the transmission coefficient S ij in other calculations.

The method of manual data input and output fell immediately, since the described sequence of actions had to be performed from 1 to several thousand times.

It was decided to try to adjust the control of the Microwave Studio simulation parameters directly from the Matlab functions. Analysis of the available help CST and Matlab, as well as Internet resources showed that both programs support the use of the ActiveX framework.
ActiveX is a framework for defining software components suitable for use from programs written in different programming languages. Software may be assembled from one or more of these components in order to use their functionality.

This technology was first introduced in 1996 by Microsoft as the development of the Component Object Model (COM) and Object Linking and Embedding (OLE) technologies and is now widely used in the Microsoft Windows operating systems, although the technology itself is not tied to the operating system.

From the description of CST Studio it follows that any of its components can act as a managed OLE server. OLE is a technology for linking and embedding objects in other documents and objects developed by Microsoft. Thus, here it is a solution of Microsoft Windows, Matlab, CST Microwave Studio + OLE technology.

Now you need to figure out how to implement all this in Matlab.

Basic functions for managing CST from Matlab


From [1] we can distinguish several basic functions required for working with the ActiveX interface:

actxserver 
- create a local or remote server;

 invoke 
- call a method for an ActiveX object.

Simply put, the essence of the actxserver command comes down to initializing (opening) a program that acts as a managed invoke - to refer to certain sections of the managed program.

Example:

 st = actxserver('CSTStudio.Application') 
- the command binds to the variable β€œcst” the OST -controlled object β€œ CSTStudio.Application ”. In this case, the name β€œ CSTStudio.Application ” is a unique name in the ActiveX environment, which allows us to understand which program we want to access.

 mws = invoke(cst , 'NewMWS') 
- allows you to move between the main menu of the program, in this case, sends a command to the variable β€œ cst ” associated with the CST Studio application to create a new empty project file;

 invoke(mws, 'OpenFile', '<  >') 
- sends a command to open a specific file located at <File path> in the newly created empty tab, with which the variable β€œmws” is associated;

 solver = invoke(mws, 'Solver') 
–This command assigns the solver variable a call to the solver's tab in the project tab associated with the Microwave Studio β€œ mws ” variable;

 invoke(solver, 'start') 
- this command, referring to CST Studio to the open project, will enter the solver's tab and start the model calculation.

If you refer to the Workspace tab in Matlab and see the values ​​(Value) of the variables: cst , mws , solver , you will notice the following:


Hierarchy of Managed Objects


Based on the above, a certain hierarchy of managed items can be distinguished, which will have to be followed to access CST Studio from Matlab.

image

Figure 1 - The hierarchy of managed elements CST Studio

As can be seen from Figure 1, to change any parameter in the project it is necessary: ​​first, to initialize the main window of CST Studio, secondly to access the specific tab of the project, thirdly to access the window for changing properties of a specific interface object (calculator, geometry, units measurements, etc.).

Algorithm for finding commands to control


If everything is simple with the initialization of the main window and the project tab, then the set of windows for entering and changing parameters is very large, and all ways of accessing them in one article seems impossible. In full, they are available in reference materials supplied with the CST Studio Suite. But the following algorithm of finding the format of all commands for referring to any place of CST Studio seems to be simpler.

Consider the previous example of creating a cube with dimensions of 20x20x20. Create the same cube, but using the graphical interface in CST Studio and find the History List button in the Modeling tab.

image alt

Figure 2 - Window Call List History List

Open the item Define brick and refer to its contents and code in Matlab, allowing you to repeat this sequence of actions.

image alt

Figure 3 - Define brick window and Matlab code

From Figure 3 it can be seen that the code in Matlab is practically a copy of the item from the History List . Thus, you can understand which target object should be accessed after selecting the project tab (after the second line of Matlab code) by forming a connection between the CST interface object, in this case the Brick , and sequentially sending commands to this object directly from the History List .

However, not all commands in the History List have this syntax. For example, setting the frequency range for the calculation is performed using the following line:

image alt

Figure 4 - Setting the frequency range in the History List

Here again, in the obvious way, the name of the object to which commands should be sent is Solver . Then the command to change the frequency range from Matlab will look like this:

 solver = invoke(mws,'Solver'); invoke(solver,'FrequencyRange','150','225'); 

We formulate an algorithm for finding the names of objects and the format of commands for managing CST Studio from Matlab:

  1. You must perform all the actions that you want to automate in Matlab, from the graphical interface of CST Studio;
  2. Open the text of the required operation in the Modeling \ History List (β€œ define brick ”, β€œ define frequency range ”, etc.);
  3. Using the commands below, contact CST Studio from Matlab and open the required file:

     st = actxserver('CSTStudio.Application') mws = invoke(cst , 'NewMWS') invoke(mws, 'OpenFile', '<  >') 

  4. Initialize the connection with the CST Studio object, whose parameters are to be changed, by the title from the History List using the command:

     <> = invoke(mws, '< >') 
  5. Line by line enter the commands described in the History List for the object:

     invoke(<>, '<>', '<1>', '<2>') 

This algorithm of actions by trial and error leads to the solution of the problem of managing CST Studio through Matlab code.

Conclusion of analysis results


After what was written above, you can already send the reader to understand further yourself, but at the very beginning of the article the task was posed as entering frequency range parameters from Matlab to CST and importing simulation results in the form of S-transmission parameters back to Matlab. In addition, operations to export results in the History List are not displayed.

Using the graphical interface, this is done as follows:

  1. After calculation, select the file in the "tree" of folders to display it;
  2. 2 Export it to an ASCII file via the Post Processing \ Import / Export \ Plot Data (ASCII) tab.

Now with the help of the Matlab commands you need to do the same.

Above the command has already been mentioned

 invoke(mws,'SelectTreeItem','1D Results/S-Parameters/S1,1') 

allows you to select the desired file in the "tree" of the working field. To display the results in ASCII, we use the built-in CST function " ASCIIExport ".
From the help to the CST to perform this function, you must send the following commands to the CST:
 export = invoke(mws,'ASCIIExport') 
- initialization of the export function with the export variable;

 invoke(export,'reset') 
- reset all internal parameters to default values;

 invoke(export,'FileName','C:/Result.txt') 
- set the save path and file name;

 invoke(export,'Mode','FixedNumber') 
- select the method of points saving. FixedNumber β€” displays a strictly specified number of points; FixedWidth β€” displays points through a specified step;

 invoke(export,'step','1001') 
- number of points for output / step width;

 invoke(export,'execute') 
- command to output.

This set of commands allows you to display the values ​​of the reflection coefficient S 11 in the amount of 1001 points to a file located on the C drive with the name Results.txt
Thus, the task set initially was completely solved.

Used Books


[1] Potemkin, Valery Georgievich Introduction to MATLAB / VG Potemkin. - Moscow: Dialog-MEPI, 2000. - 247 pp.: Table. - ISBN 5-86404-140-8
[2] Reference materials supplied with CST Studio Suite

Source: https://habr.com/ru/post/325012/


All Articles