Professional Documents
Culture Documents
04
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
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
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.
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
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
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.
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:
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
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
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
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.
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 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.
SPEED™ 13.04 12
SPEED™ to HEEDS® Tutorial
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.
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
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.
SPEED™ 13.04 17
SPEED™ to HEEDS® Tutorial
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:
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
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
SPEED™ 13.04 21
SPEED™ to HEEDS® Tutorial
SPEED™ 13.04 22
SPEED™ to HEEDS® Tutorial
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®.
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
SPEED™ 13.04 27
SPEED™ to HEEDS® Tutorial
In the HEEDS® environment the general workflow is working:
from left to right,
top to bottom.
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).
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.
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:
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.
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 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®
SPEED™ 13.04 34