You are on page 1of 34

SPEEDTM to HEEDS® Tutorial 13.

04

Simple Cogging Torque Optimization Example

SPEEDTM with HEEDS®

HEEDS® MDO is a Multidisciplinary Design space exploration and Optimization software


package that automates the search for better and more robust solutions within a given design
space, and can dramatically reduce design time.

SPEEDTM can be linked to HEEDS® via SPEEDTM ’s Python API and the general analysis portal
within HEEDS® MDO. A full discussion of HEEDS® capabilities is beyond this tutorial (please
refer to the HEEDS® documentation). However, this tutorial presents an example that shows
the basic operation and can be easily extended to cover more complex cases such as multi-
parameter and drive cycle optimization. The example described in this tutorial is a simple
cogging torque optimization of a surface mounted permanent magnet synchronous machine
using PC-BDC with PC-FEA.
SPEED™ to HEEDS® Tutorial

Introduction
This tutorial demonstrates how to link SPEEDTM with HEEDS® through a python script interface
which is automatically created with the new GUI available from SPEEDTM v11.04 onwards and
used in the background. In the older v11.02 release the user needed to write this script
manually (and still can do for enhanced cases, see user script option or Appendix A).
The tutorial has been restructured and consists now of the following 6 main sections:
1. SPEED GUI using the HEEDS Add-On or the full HEEDS installation.
2. HEEDS Post.
3. SPEED GUI with user script option.
4. Notes and Troubleshooting.
5. Appendix A: The Python script (as used in the initial SPEED to HEEDS tutorial) and
6. Appendix B: Working in the full HEEDS environment.
The general procedure has still the following three main steps (see also the figure from
above):
i. The starting point is the SPEEDTM motor design model. You prepare the model in the
usual manner (geometry, winding, materials, initial sizing, and analysis settings). It is
highly recommended to check that the SPEEDTM model works for multiple parameter
variations that may come up during the optimization process.
ii. The next step is creating a Python analysis script to automate the optimization
process. With the new GUI in SPEED v11.04 onwards this script is created
automatically. Nevertheless this script can be still modified and with that be as flexible
as your coding skills in leveraging the python API functionality available within
SPEEDTM. Also, you can make use of PC-FEA to e.g.
a. set-up sub-optimizations to match FEA outputs or
b. find the current / phase advance angle tuple that gives the highest output
torque or shaft power.
Python is a free programming language with an interactive development tool and
many numerical libraries. Python functions in a similar way to Matlab.
To ease the process, a sample SPEEDTM interface, the “SPEED Wrapper”, is available
for all SPEEDTM users that ties into SPEEDTM through the API. The SPEED Wrapper is a
collection of helpful SPEEDTM dedicated functions and subroutines, so that the Python
script that is used to drive the interaction between SPEEDTM and HEEDS® can be clearly
laid out, as only a few code lines are needed.
iii. A new HEEDS® MDO analysis model is created automatically (from SPEED v11.04
onwards) and also
a. SPEEDTM automatically connects the Python script to HEEDS® at a press of a
button.
b. The automated procedure
i. sets variable boundaries and relationships for input search parameters
and
ii. defines the goals of the design space exploration study and the number
of allowed SPEEDTM model evaluations
depending on the data entered into the new HEEDS GUI in SPEEDTM.

SPEED™ 13.04 2
SPEED™ to HEEDS® Tutorial

This tutorial explores the important concepts and workflow for:


• setting up the SPEEDTM model,
• preparing the input variables, constraints and objectives in the new HEEDS GUI in
SPEEDTM which then will be used in the HEEDS Add-on1 or the full HEEDS® MDO
installation,
• specifying HEEDS® specifics,
• running the simulation and
• post-processing the results in HEEDS® Post.

Installation of the Required Components


Before you begin the tutorial, ensure that you have installed all of the required components:
• SPEEDTM, see the SPEED Installation Guide.
• Python, see the SPEED Installation Guide.
• The SPEED Wrapper, see the SPEED Installation Guide.
• The full HEEDS® or the HEEDS® Add-on tool for SPEEDTM, see the Installation Notes for
HEEDS® and/or the SPEED Installation Guide
• FLEXlm and the license file, see the notes in the SPEED Installation Guide.

Setting the Correct Paths


A final step needs to be conducted to allow SPEED to work with HEEDS:
Providing the correct paths for Python and the full HEEDS installation:
• Open SPUD and select the Directories Pull Down Menu
• Select Python… and chose the correct path for the python.exe file.
• Select HEEDS/MDO… in the case you have a full HEEDS installation
and provide the correct path for the HEEDSMDO.exe file.
Note: In the
case of the
HEEDS Add-On
installation you
do not need to
provide the
path as you
have copied
the files into
the HEEDS sub
folder.

1
Since SPEEDTM v11.06 we provide additional to a full HEEDS® installation the use of a HEEDS® Add-on tool
directly linked to SPEED similar to the OPTIMATE+ solution in STAR-CCM+.

SPEED™ 13.04 3
SPEED™ to HEEDS® Tutorial

1 Simple Cogging Torque example


The example used in this tutorial takes a sample machine and adjusts various parameters in
order to minimize the cogging torque as calculated by PC-BDC using PC-FEA but keeping the
shaft power above a certain limit. Obviously, if there are no constraints, an optimization
process might reduce cogging torque by removing the magnets entirely. Therefore, some
discussion is required to choose the parameters, define their limits, and decide the criteria on
which a successful design is judged. It is in designing these constraints that you can introduce
your own unique expertise to the optimization.

The first decision that you make is what parameters to vary. An experienced designer will
generally know the parameters that strongly affect the cogging torque. These are amongst
others the slot opening SO, air-gap length Gap, magnet arc BetaM, and the stator tooth tip
geometry controlled by TGD and SOAng. Parameters that affect the cogging torque to a lesser
extent are the tooth width TWS and the magnet length LM.

Creating the Geometry in SPEEDTM


Launch SPEEDTM and prepare the model.
1. Start SPEEDTM PC-BDC and
open the 1st example from
the EMDS2 book: Click File
> New and on the EMDS
tab, select Squarewave
surface magnet, and then
click OK.

The cross section of the


example machine is
displayed in the Outline
Editor:

2
Electric Machine Design using SPEED and Motor-CAD by T.J.E. Miller and D.A. Staton

SPEED™ 13.04 4
SPEED™ to HEEDS® Tutorial

2. Open the Materials selection


dialog (Ctrl+M) and select the
materials that you want to use.

3. Run a Static Design


(Ctrl+2) and check the
results. For example, view
a graph (Ctrl+G) and the
Design Sheet (Ctrl+4) or
the Tabbed Design Sheet
(Shift+Ctrl+F4).

You can also check that the


output is behaving as you
expect, by varying the
parameters that you
intend to use for the
optimization.
For example, try varying
the following parameters:
• Gap
• SO
• TGD,
• SOAng
• BetaM
• LM
• TWS

4. Save the file as testcog.bd4 in the folder in which you want to run the optimization (for
example C:\SPEED\Work).

Now we are going to make use of the HEEDS/MDO GUI in SPEEDTM first provided in the release
v11.04 for preparing the data for the HEEDS® optimization solving process.

SPEED™ 13.04 5
SPEED™ to HEEDS® Tutorial

5. Select from the Tools > HEEDS/MDO


and the HEEDS optimisation setup window pops up:

6. Provide a Project name

7. Either
i. Check the Use full HEEDS installation under the
HEEDS pull down menu for using a full HEEDS
installation or
ii. Uncheck the Use full HEEDS installation in the case
of the HEEDS® Add-on solution.

8. On the Input parameters tab select the Parameter and provide its Minimum,
Maximum and Resolution value. The parameter can be easily selected by typing quickly
and continuously the first characters. By pressing on the Add button the parameter and
its values are stored and presented in the parameter list. Once the parameter occurs in
the list it now can be edited (by pressing on the Replace button as you have been
providing a new data set
for the parameter) or
removed (by pressing on
the Remove button). In
our example it should
finally look like:

SPEED™ 13.04 6
SPEED™ to HEEDS® Tutorial

9. At this point it would be good to save the project the first time
(so not to lose the information already provided): HEEDS >
Save project file. The file is saved under the provided Project
name in the folder where the SPEEDTM file has been saved as
well.

10. As one objective is to minimize the cogging torque we have to


select the according pre-defined procedure which adds a call
to run the PC-FEA cogging torque GoFER and add the
associated CogPk parameter in the Objective parameter list
for optimization.

11. Changing over to the Constraints and Objectives tab and adding Pshaft to the
Objectives as we are willing to get the max output power and providing a constraint to
Pshaft as well as we want to keep the shaft power at a certain output power limit. In
this case the output shaft power should be greater than 750 W:

12. In this example we are going to make use of


a. Create thumbnail – this creates a small image of the
machine being designed and adds it to the HEEDS® study
for automatic display in the post-processor and
b. Validate geometry – this adds a call to check the
geometry before running an analysis. The design is
marked as unfeasible if the geometry is not valid.
We are sticking to Static Design analysis (Run Dynamic design is left unchecked) as the
cogging torque analysis is going to make use of the Cogging Torque GoFER using PC-
FEA.
Finally we are providing the number of Max. iterations which then will be forwarded to
HEEDS® for the Max. number of evaluations used in the exploration.

13. Finally select the Multiple objective tradeoff


study (Pareto front) in the Hybrid Adaptive
Method/SHERPA window.

14. Again save the project: HEEDS > Save project file as well as the SPEEDTM file itself: File
> Save.

SPEED™ 13.04 7
SPEED™ to HEEDS® Tutorial

15. Under HEEDS you can select between


• Create .HEEDS file which is the recommended choice for
the full HEEDS® installation (and Use full HEEDS
installation needs to be checked in this case): It starts
HEEDS®/MDO with the files created by pressing F9 or
selecting Run HEEDS®/MDO. Changes can then be made
inside the HEEDS® interface and the study run in the usual
way. Within the normal HEEDS® interface the HEEDS
Postprocessor can be started after the study has
completed.

• The second option, Run study, is the


recommended choice for the HEEDS®
Add-On feature as it creates the HEEDS®
files and then automatically runs the
study with the HEEDS Add-On tool. A
progress bar has been added to indicate
the progress of the study until the study
completes:

After completion the HEEDS Post button can then be used to start the HEEDS® post-
processor for analyzing the results in the full HEEDS Post environment.

SPEED™ 13.04 8
SPEED™ to HEEDS® Tutorial

2 HEEDS® MDO Results


Open HEEDS® MDO (for the full installation of HEEDS® if you
might have closed it after starting the solving process) or
click on the HEEDS Post button in the HEEDS optimization
setup window to review the results.

The table to the left of center on the bottom row (Study Details highlighted) summarizes the
results. It can be seen that the best design has an output power of Pshaft = 811 W and a
minimum of cogging torque CogPk of 0.01947 Nm can be achieved. But note that those values
have come from different designs.
The solving process of the 180 cases including the cogging torque analysis using PC-FEA with
30 rotor steps per case will take
about 50 minutes on the
hardware as shown above.

SPEED™ 13.04 9
SPEED™ to HEEDS® Tutorial

HEEDS® MDO Post-processing


Several standard plots are created automatically after a
successful run and can be found under the Plots section in the
project tree window. More advanced plots and information is
available in the HEEDS® Post-processor, which you can access
from the Open HEEDS|Post toolbar button.

As we have saved with each design the cross section of


the machine we are able to visualize all those
designs by clicking on the Model View icon. In
the Model View window we just have to press Finish
to see the different cross sections in the
graphic area. With a selector under the Design Set we
may want to select only the Feasible Designs to be
shown.

A Parallel plot allows the visualization of the influence of the different


variables and response data for all designs evaluated during the study.
Again a selector allows you to filter the result between all, feasible and
infeasible designs. In the graph below you can use the mouse to draw
a small window and catch for example all the lines with a low peak cogging torque value which
are then highlighted in black colour. In the graph also the infeasible design results have been
switched off.

SPEED™ 13.04 10
SPEED™ to HEEDS® Tutorial

We can see that all of the selected designs with a low cogging torque value have the smallest
slot openings, and vary with the air gap, tooth tip depth, pole arc and magnet width. The tooth
width seems to have little influence.

A relation (bubble) plot is a particularly useful way of displaying multiple factors


on a single chart. To create a relation chart, select Create plot from the tool bar
or choose the 2D Relation icon from the General Plots icons.

In the Create New Plot Wizard dialog, select 2D Relation, click , assign the
parameters and click on to close the New Plot Wizard dialog.

SPEED™ 13.04 11
SPEED™ to HEEDS® Tutorial

As there are two output parameters, it makes


sense to use these as the main X- and Y-axis
parameters. The actual “bubble” in the chart
can have two additional characteristics: its
size and its color.

You can select SO in the Series Data dialog to


control the size – the bigger the bubble, the
bigger SO and finalize the plot by selecting
Gap in the Color drop down selection box in
the tool bar.

As expected, there is a clear correlation between low cogging torque and small slot-opening
as the size of the bubbles is generally smaller towards the X-axis (as we already could see
from the parallel plot as well). The correlation between PShaft and Gap is also clear as most
of the bubbles to the right of the plot are darker blue indicating a smaller air gap. At Pshaft =
750 W we have the constraint line. Only the designs to the right are giving at least the
requested shaft power output. All to the left hand does not fulfil this criterion.

You can view the corresponding design


parameters and cross section (as we have saved
the cross section in a .png file) by hovering over a
bubble.

SPEED™ 13.04 12
SPEED™ to HEEDS® Tutorial

Looking at the Correlation plot


confirms some of our original
ideas. For example, as expected
SO has the strongest effect on
cogging torque, along with SOAng
and LM. BetaM and Gap have
strong effects on Pshaft, with one
being positive and one being
negative (that is, the bigger the
Gap the lower the performance).

More surprisingly, TWS and LM have the second strongest effect on cogging torque and also
have a relatively strong effect on Pshaft. However, this may be because in the range in which
it is being varied, saturation comes in to play more often than it would in a manual design
process, as 2 mm is unrealistically narrow.

From the Optimization Plots we can create a 2D Pareto Front Plot (this is only
available if the multiple objective tradeoff study has been chosen) providing the
family of possible designs to pick and choose from. There are actually multiple
Rank 1 designs in a trade-off study.

In the Create New Plot Wizard dialog, select for the


• Design Set only the Feasible Designs,
• X-Axis: CogPk and
• Y-Axis: Pshaft.
Finally click on .
With the selectors for the X-, Y- (and Z-) axis you can
switch the parameters easily (as shown having
Pshaft now on the X-Axis and CogPk on the Y-Axis)
or even select another parameter instead.

SPEED™ 13.04 13
SPEED™ to HEEDS® Tutorial

About Cycle and Rank: HEEDS® selects designs to be launched in a cycle. One cycle contains
number of designs. The size of the cycle is decided by the search algorithm. It is a part of the
learning process that HEEDS® uses to better search the design space in each cycle. Our focus
is to look at the best designs found by HEEDS®, which is why it makes sense to view designs
evaluated in the last cycle and particularly the Rank 1 design in that cycle. In our case the last
cycle was 18. Therefore, in the graph (Plot tab is active) select:
• Cycle: 18 and
• Rank: 1.

Finally we can have a Customized Plot View by pressing on the Create Custom
View icon. This allows us to specify first the basic orientation and then the number
of rows and columns we would like to have by pressing on .

With the selectors in the different graph zone we now can select what we would like to see:

SPEED™ 13.04 14
SPEED™ to HEEDS® Tutorial

With the Sync button (the Model View plot has to be active, just left-
clicking with the mouse in that graphic area) or in the top line, right hand
corner of the Model window the cross section plots can be synchronized
with the bubbles (by left-clicking on them) or the entries in the table (by left-clicking on a cell
in the table).

SPEED™ 13.04 15
SPEED™ to HEEDS® Tutorial

3 User Script Option


The easiest way of creating a User Script is to start with a standard (Simple or Cogging torque)
case and then modify the *_analysis.py script.
1. Starting with the Minimise cogging torque optimization case by selecting Tools >
HEEDS/MDO and then HEEDS > New project (assuming we
are using the same SPEED model as above in 1):
2. Now specify first the Project name (e.g. MinCog3) and then select the radio button
Minimise cogging torque. Under the Input parameter tab select and specify the Input
parameters SO and BetaM (simplified example to the one under 1, page 4) as shown
below (with having Create thumbnail and Validate geometry activated as well):

3. The Constraints and Objectives will be:

As you can see, we have been introducing an additional parameter as being used as a
placeholder ABar. We are going to assign to ABar a cost function.

SPEED™ 13.04 16
SPEED™ to HEEDS® Tutorial

4. Now save the HEEDS project file: HEEDS > Save project file.

5. Now select HEEDS > Create the script files


With that the python script files have been created (a
message window acknowledge the creation of the files)
and in the next step we can make use of it.

The HEEDS file needs to be create as well: Select HEEDS >


Create .HEEDS file.

6. In the working folder you should now be able to open with a


standard text editor your *_analysis.py file:

SPEED™ 13.04 17
SPEED™ to HEEDS® Tutorial

7. We are now making our users changes:


Move the lines #39 - #41 (static desgin) above the cogging torque calculation, line #34
- Add the cost function costfct after the cogging torque calculation, line #42. The
magnet cost is very high (unrealistic for a ferrite magnet) but this is to force HEEDS
to lower the magnet volume for the cost minimization.
- Assign costfct to the placeholder parameter ABar, line #47

8. Save your changes to the py-script!

Note: It may be the case that the order of parameters in line #46 to #48 may differ in your
script. If so, leave them as they are otherwise the tagging gets mixed up in HEEDS!
If you are working with the full HEEDS version, you are able to provide more precise names
for the placeholder ABar in the parameters section of HEEDS– but for the HEEDS AddOn solver
we have to stick to this kludge approach.

SPEED™ 13.04 18
SPEED™ to HEEDS® Tutorial

9. Now select in the HEEDS optimization setup window the radio button User script and
provide the full path and the name of your python script (which we just created) in the
according path field under User script file name:

10. We keep the Max. iterations number at 100.


11. Select HEEDS > Save project file.
12. Finally press the Run study button in the HEEDS optimization setup
window (on top of the text window with the entry “Log file”).

HEEDS is now running on the basis of the user python script including the (simple) cost
function. Again after the completing the solving process in HEEDSPC-BDC will reply with a
HEEDS run complete message. To access the results, press the HEEDS Post button and load
in the results of the study. You are then able to present the results in any preferred graph.

SPEED™ 13.04 19
SPEED™ to HEEDS® Tutorial

4 Notes and Troubleshooting

Notes

In some cases, the results that you achieve in your run may be different to the results that are
presented in this tutorial. The differences can be due to the following:
• Different versions of HEEDS® used for the comparison. CD-adapco is continually
improving SHERPA and modifying its techniques to solve over a large range of problems.
These changes can cause differences in the results for different versions of HEEDS®.
• A different number of evaluations having been used. In this scenario, a higher number of
evaluations should reduce the differences that you see, as is it likely that you haven’t
reached a converged solution.

Troubleshooting
This section contains workarounds to common problems.
An error message indicates that the PYTHONHOME environment variable is not set.
If PYTHONHOME is not set, the HEEDS® install of python is used by default. This install does
not include the modules that the post-install script added, so the simulation fails.
To resolve this problem, set the PYTHONHOME environment variable to the folder that
python.exe is in. When PYTHONHOME is set, HEEDS® does not write out a local
PYTHONHOME variable at runtime, and uses the variable that is set globally. This should only
be an issue if you are using a HEEDS® version prior to 2015.04.4.

SPEED™ 13.04 20
SPEED™ to HEEDS® Tutorial

5 Appendix-A

Create and Edit the Python Script


In the former releases of SPEED (before v11.04) the user had to write the python script on his
own. With the new HEEDS/MDO GUI in SPEED v11.04 it has been created automatically from
SPEEDTM. Nevertheless you as a user have the flexibility of editing the python script to match
what you are looking for. For that purpose or if you would like to follow the old manual
procedure of writing an individual python script and to perform the analysis from batch mode
(outside the SPEEDTM user interface) we have been moving those pages from the v11.02
SPEED to HEEDS tutorial in the Appendix A.

You have to perform the following steps:


• Initialize Python
• Load the testcog.bd4 file
• Set the input parameters
• Check for validity
• Create an image file to show the geometry
• Run a cogging torque GoFER
• Calculate the peak cogging torque
• Run a static design
• Write the output file for HEEDS®
• Save the updated file.

SPEED™ 13.04 21
SPEED™ to HEEDS® Tutorial

About the Python Script


A sample Python script associated with this example is shown on the next page. A brief
description of what the script does follows:
1. Keep the first 11 lines without changing anything as these imports the necessary Python
modules for interfacing with SPEEDTM through the API.
2. Lines #14 through #20 specify the baseline values of the parameters that HEEDS® is
allowed to vary during the optimization process and correspond with those in the
baseline cogging torque SPEEDTM file. The range for each parameter that HEEDS® is
allowed to vary will be specified in HEEDS®. HEEDS® will then replace the values on
these for a given design to correspond with the selected combination it makes for that
design.
3. Line #23 is the path to the prepared SPEEDTM file and should be modified to match the
location you saved the file.
4. Lines #25 through #27 create a new file for each new HEEDS® case.
5. Line #30 applies the new parameter values that come from HEEDS® from the Python
file into the actual SPEEDTM file.
6. Line #33 saves the SPEEDTM model.
7. Line #36 checks that the geometry is valid. If the geometry is not valid, the cogging
torque calculation is not executed. This check is to speed up the process by performing
calculations only where it makes sense.
8. Line #39 saves the cross section from the outline editor as a .png image that can then
be accessed for every design in the HEEDS® post-processor.
9. Line #42 is the active calculation of the cogging torque using the cogging torque GoFER
for the given set of parameters. The script example shows a setting for 30 rotor steps.
If you want to increase the number of rotor steps, you need to change this value in the
script.
10. Line #44 uses the Co-energy method to extract the peak cogging torque value from the
results of the cogging torque calculations.
11. Line #47 runs a Static Design to get basic performance data. This data is then used in
lines #51 and #54 to provide values as an output to HEEDS®.
For example (line #51), you can check the change in the shaft output power. If you
want to keep that value constant, you can apply an appropriate rule in HEEDS®. For
example (line #54), you can check the peak value of the cogging torque at each
variation step as you attempt to minimize it. You can store these values (in an Excel
file, for example) along with the corresponding images.

SPEED™ 13.04 22
SPEED™ to HEEDS® Tutorial

Python script example

1 # Example for running HEEDS with SPEED on cogging torque analysis


2
3 import os
4 import numpy as np
5
6 from speed import speedWrapper # load speed.py from the python lib folder, make sure
7 # you have copied it. It may take a few seconds if run
8 # the first time
9
10 #Empty dictionary
11 HEEDS_Input = {}
12
13 # Parameters which are used by HEEDS needs to be specified
14 HEEDS_Input['Gap'] = 0.7 # 0.5 to 2
15 HEEDS_Input['SO'] = 2.8 # 1 to 4
16 HEEDS_Input['TGD'] = 1.4 # 0.5 to 3
17 HEEDS_Input['SOang'] = 20 # 10 to 55
18 HEEDS_Input['BetaM'] = 170 # 130 to 180
19 HEEDS_Input['LM'] = 7.7 # 2 to 12
20 HEEDS_Input['TWS'] = 7 # 2 to 10
21
22 # Analysis Section; reading the prepared SPEED PC-BDC file
23 infile= r"C:\SPEED\Work\testcog.bd4"
24
25 dID = "_"+(os.getcwd().split("\\")[-1]).replace("Design","D")
26 print("dID=",dID)
27 sp = speedWrapper(infile, dID)
28
29 # Set the new design inputs from HEEDS into the SPEED model
30 sp.setParams(HEEDS_Input)
31
32 # Save the file in the current folder
33 sp.SaveCWD()
34
35 # Check if geometry is valid
36 geomValid = sp.ValidateGeometry()
37
38 # Create png instead of bmp images
39 sp.WriteLamBMP (fileName=sp.GetCWD()+"\\testcog_updatedLamDesign.png")
40
41 # Run the cogging torque GoFER
42 cog = sp.DoCoggingTorqueGoFER(30, savefig=True, appendTitle=dID)
43 # Calculate the peak value of cogging torque from Co-energy method
44 cogpk = np.amax(np.abs(cog['Coenergy']))
45
46 # Run a static design to get basic performance data
47 sp.Static()
48
49 # Output some parameters to HEEDS output file
50 # Simple form of HEEDSOutput takes just a SPEED parameter name and writes its name and value
51 sp.HEEDSOutput("Pshaft")
52
53 # Second form of HEEDSOutput takes a name and value
54 sp.HEEDSOutput("CogPk", cogpk)
55

SPEED™ 13.04 23
SPEED™ to HEEDS® Tutorial
Editing the Python Script
Save the provided script file as mincog.py (or another suitable name) under your working
directory (e.g. C:\SPEED\Work).

It is best to test the script by running it, as it is easier to debug a script outside of HEEDS®. You
are more in control and can see all of Python’s output. It is also beneficial to do this as having
the script-generated output file simplifies linking the output parameters to HEEDS®.

To run the Python script manually:


1. Start Python (use the program icon or double-click python.exe from the Windows
Explorer in C:\WinPython-32bit-3.4.3.4\python-3.4.3).

2. Type in the commands from the script line by line.

To copy the Python script from the example:


1. Start WinPython Command Prompt (use the program icon or double-click WinPython
Command Prompt.exe from the Windows Explorer in C:\WinPython-
32bit-3.4.3.4).
2. Change the directory to your working directory.
3. Type > python, to change from the Standard CMD window to the WinPython-32bit-
3.4 command window.
4. Highlight the commands from the example script, press Ctrl+C and then move over to
the WinPython command window. Right-click and select Paste.

SPEED™ 13.04 24
SPEED™ to HEEDS® Tutorial
5. Running through all the steps of the script creates all of the files for a single run case:

Alternatively, for step 3, you can also call the script directly in python, i.e.
Your local working directory>python mincog.py
The same call HEEDS® will make the same call upon execution so this method is more like the
way that the script is going to behave when being called directly. Nevertheless the step by
step process will give a more detailed response.

SPEED™ 13.04 25
SPEED™ to HEEDS® Tutorial
The following examples show the working directory before and after executing the
commands of the script.

When you have a working script, you can set up HEEDS® to run your design optimization. You
use the created file from your Python script execution heeds.output to define the output
responses within HEEDS®.

SPEED™ 13.04 26
SPEED™ to HEEDS® Tutorial

6 Appendix-B

Launch HEEDS® to Set Up the Optimization Task


You can also setup HEEDS® from the HEEDS® MDO program as shown in this Appendix. When
you start HEEDS® (use the program icon or double-click HEEDSMDO.exe from the Windows
Explorer in C:\HEEDS\MDO\Ver2014.11\Win64) the entry window visualizes the steps that
are needed to set up a HEEDS® Design Study:

Building the HEEDS® Design Study


The main steps in building the HEEDS® Design Study are:
• Start the design process by creating a HEEDS® file.
• Specify the execution command and adding the input and output file.
• Specify the variables to be changed in SPEEDTM as well as the responses that are to be
used for measuring the performance of the design – the output of SPEEDTM.
• Define the search process; that is setting the objectives and constraints (study goals).
• Execute the study.
• Visualize the results of the design exploration study.

To start in HEEDS® with a new Design Study, click


File > New.

SPEED™ 13.04 27
SPEED™ to HEEDS® Tutorial
In the HEEDS® environment the general workflow is working:
 from left to right,
 top to bottom.

Use this general rule and perform


the steps in the following order:
• process definition,
• parameter specification,
• tagging (connecting the
process definition with the
parameter specification),
• running the study and
• post-processing.

In this simple cogging torque example, the process consists only of the “Analysis_1” which is
displayed in the middle of the graphical area – the Process pane. You can keep this as it is.

Click the Analysis_1 icon and enter the following information in the analysis property pane
underneath the Process pane:
• Analysis name: Change this name to
Minimizing cogging torque in PC-BDC
• Run in: Design folder
(You will create the corresponding *.heeds file in
your working folder, C:\SPEED\Work)

• Execution command:
C:/WinPython-32bit-3.4.3.4/python-3.4.3/python.exe mincog.py

Note: You may have a different path to the python executable and a different python
script file name! Please check carefully!
We are going to save the HEEDS® file under the same path as the mincog.py file and
therefore we do not have to provide a path for the .py file at this time.

Below these entries is a tabbed page Files, which defines the files that HEEDS® uses to set
inputs and get outputs from the analysis program. The input file that you specify here is the
name of your python script, as HEEDS® is able to alter the code automatically once you tell it
what to change – this will be done on the Tagging tab. The output file is the file that the

SPEED™ 13.04 28
SPEED™ to HEEDS® Tutorial
Python script produces: heeds.output. This file also has to be parsed to extract output
information.
To specify the input file:
• Click the Input File button on the
lower right corner of the left Input
File window to add a new input file.
• Navigate to working folder and
select the mincog.py file.
To specify the output file:
• Click the Output File button on
the lower right corner of the right
Output File window to add a new
output file.
• Navigate to your working folder and
select the heeds.output file. This file
was created during the manual testing of your script mincog.py in the python command
window (either line by line or due to the python command).

HEEDS® offers the visualization of the


different geometries created in each
optimization step as SPEEDTM is capable
in saving the cross section of the machine
in a png file (see line #39 in the mincog.py
script file). For that we have to click on
the Add item and type in the file name
which is going to be created as part of the
process. Again we can make use of taking the name directly from the “dry run” of the python
script which created a file called “testcog_updatedLamDesign.png” in the working folder.
With that it will then be available in the post-processor for visualization for every design.

You now have to tell HEEDS® how to parse these files, identify what HEEDS® should change
at each analysis step, and specify how it should be changed. This process is called Tagging.
However, before you can tag the files, you have to define the parameters that you want to
have available in the input and output files.

The first step is to select the Parameters


tabbed page at the top left of the HEEDS®
interface.

SPEED™ 13.04 29
SPEED™ to HEEDS® Tutorial
This opens a new window with pages called Variables and Responses which list the inputs
and outputs respectively once you have defined them.

In your script you defined several input parameters. To ease data entry, create them in
HEEDS® in the same order as they appear in the python file. For the input these are (shown
in the excerpt from the py-script):
# Parameters which are used by HEEDS needs to be specified
HEEDS_Input['Gap'] = 0.7 # 0.5 to 2
HEEDS_Input['SO'] = 2.8 # 1 to 4
HEEDS_Input['TGD'] = 1.4 # 0.5 to 3
HEEDS_Input['SOang'] = 20 # 10 to 55
HEEDS_Input['BetaM'] = 170 # 130 to 180
HEEDS_Input['LM'] = 7.7 # 2 to 12
HEEDS_Input['TWS'] = 7 # 2 to 10

Create 7 new variables by clicking the Create Variable button at the upper left corner
7 times or use the arrow to the right and select:

and then fill in the required information:

SPEED™ 13.04 30
SPEED™ to HEEDS® Tutorial
Note that you call these variables anything you would like as long as they have meaning to
you. The variable Type is Continuous as they do not need to take discrete, stepped values as,
for example, TC (the number of turns) would be restricted to. Continuous variables require
input as to the minimum (min) allowed value, baseline (starting) value, and maximum (max)
allowed value. HEEDS® will search within the min-to-max range for the ideal combination of
variable values. The Resolution determines the number of steps by which each parameter
can be varied. In this example, the length variations are limited to 0.1 mm and the angle
variations are limited to 1 degree. For example, for a Gap varying between 0.5 mm and 2 mm
with a step size of 0.1 mm, you need 16 steps (to include both end points) so that is what you
use for Resolution. A similar calculation is applied to the other parameters. The Distribution
column is not relevant in this tutorial; this setting is used to apply statistical distributions to
the parameters, such as for sensitivity analysis.
With the Variables defined, you now tell HEEDS® about the output parameters that the script
writes to the heeds.output file. These parameters are Pshaft and CogPk. They are created in
a very similar manner to the input variables.
Switch from the input variables to the output responses by clicking on the Responses
tab. Then click the Create Response button twice and enter the parameter names
Pshaft and CogPk. Note that you can again call these responses anything you would
like as long as they have meaning to you.

With the parameters (Variables and Responses) known to HEEDS®, you can now perform the
tagging: Select the Tagging tabbed page.

In the Select a file to start tagging box in the center of the window,
select the mincog.py file. The screen displays a parsed version of the
python script, as shown below:

SPEED™ 13.04 31
SPEED™ to HEEDS® Tutorial
The section of script that deals with the input parameters is in lines 14-20 (this may differ in
your case) and the actual values that are being set are in column D.

You can do either of the following:


 Select each cell D14-D20 in turn and assign it to a
Variable by right-clicking and selecting the appropriate
variable in the Tag Variable pop-up menu.

 Select all the D14-D20 cells


(containing default values)
and then click the Multi-
Tag toolbar button.
Choose the parameters that
you want and follow the dialog
prompts automatically assign
the Variables in a single
operation. You can do this
only if the order of the
parameters in the script is the same as the
order in which you defined the Variables.

When Variable tagging is complete the screen


should look as shown on the right.

Repeat the previous process for the


Responses. Select heeds.ouput in the File:
edit box and then use the same steps as
before (select the B1 and B2 cells with the
numbers, click Multi-Tag…, and select all the
variables shown) to tag the parsed sections
of the file.

SPEED™ 13.04 32
SPEED™ to HEEDS® Tutorial
You can now move on to setting up the
Study.

Select the appropriate Study tabbed page and fill in the relevant information. For this example
we are going to use the Multiple objective tradeoff study (Pareto front) as there is a likely
chance for a trade-off between our 2 objectives of maximizing (at least keeping) the shaft
power and minimizing the cogging torque. We leave the rest of the parameters at their
default values. However, note that this page lets us adjusting the Max. number of evaluations
used in the exploration and also to select which designs to save. Here we are running 180
design evaluations which is a reasonable amount for the 7 variables we have here. The
number of evaluations is typically a function of the project timeframe and the number of
variables. The Archive size is set to 12.

You need to set the objectives and constraints for the


Responses. Select the Responses tabbed page, then
right click Pshaft and CogPk and select Add
Objective. For Pshaft, the objective should be to
Maximize and for CogPk to Minimize.

You also need to select Pshaft. Right-click and select Add Constraint. Set the Lower limit for
this to 750 W and leave the Upper limit blank to indicate that you need at least 750 W output.

Save the HEEDS® file by selecting File > Save As… “MinCog.heeds”. It is simplest to save it in
the same folder as the python file, for example, C:\SPEED\Work.

SPEED™ 13.04 33
SPEED™ to HEEDS® Tutorial
Running HEEDS®

You are now ready to run the study.


Select the Run tabbed page and click Run.

Upon completion of running HEEDS® Open HEEDS|post.

© Copyright 2017 Siemens Product Lifecycle Management Software Inc.

SPEED™ 13.04 34

You might also like