How to Add an Output Variable into a Motor-CAD optiSLang Optimization Workflow

Create a custom output variable in Motor-CAD, create optiSLang project, and modify the OPF file.

  1. Find the Automation Names of the Required Output Parameters
  2. Find the Automation Names of the Required Output Parameters

There are two ways to locate them: 

From the Motor-CAD Interface
Hover over the output parameter with your mouse. The automation name will appear in the bottom-left corner of the interface.
Example: For system efficiency, it displays {SystemEfficiency}. 

A screenshot of a computer

AI-generated content may be incorrect.

From the Automation Parameter Names Tab
Go to Help > Automation Parameter Names.

A screenshot of a computer

AI-generated content may be incorrect.

A pop-up window will appear. You can search for any parameter and note its Automation Name to include in the optimization. 

A screenshot of a computer

AI-generated content may be incorrect.

Create an optiSLang Optimization
Navigate to Tools > Ansys optiSLang

A screenshot of a computer

AI-generated content may be incorrect.
Assign Geometry Ranges and Objective Constraints

A screenshot of a data

AI-generated content may be incorrect.

 

You can initially define only torque ripple as an objective and leave the others for later. 
If you intend to run only the E-Mag module in the optimization, this helps avoid loading scripts for the thermal and mechanical modules. 

A screenshot of a computer

AI-generated content may be incorrect.

Run a test to ensure the model is functioning properly. Even if the Lab module isn't selected, optiSLang runs it by default — we’ll remove it in later steps. 

Keep the optiSLang settings as shown below: 

A screenshot of a computer

AI-generated content may be incorrect.

 

Create the optiSLang Project
You may adjust the number of sensitivity analyses and parameter types here. We’ll add the additional objectives later. 

A screenshot of a computer

AI-generated content may be incorrect.


Go to the Exported optiSLang Folder Directory

A screenshot of a computer

AI-generated content may be incorrect.

Find the optimisationSetup File
Right-click the file and select Edit with Notepad (or your preferred editor). 

A screenshot of a computer

AI-generated content may be incorrect.

Disable the Lab Model

Scroll down to where the script builds the Lab model (in some cases around line 338). Remove or comment out the three rows that activate the Lab module: 

 

if mcApp.set_variable("LabMagneticCoupling", 0)  # If value is 1, change it to 0 

A screenshot of a computer program

AI-generated content may be incorrect.

Add Output Parameter Code

Now remove the portion where Motor-CAD runs the Operating Point in the Lab module — this will speed up the process. 

Then, use the following template to insert your desired output parameters (from Step 1). 
You can copy the existing torque ripple row and paste a new line underneath: 

GetOutputValue('ParameterName', 'ParameterName_AnySpecificName', mcApp) 

You can use this template to include any of your parameter name. 

So for SystemEfficiency it should be as follow 

GetOutputValue('SystemEfficiency', 'SystemEfficiency_1050rpm', mcApp) 

A screenshot of a computer program

AI-generated content may be incorrect.

Your final section should look like this: 

A screenshot of a computer

AI-generated content may be incorrect.

Define Output Variables for optiSLang

Still in the same file, scroll to the section where outputs are declared. 
Copy the torque ripple output row and add your new parameter using the following templates: 

The template for output parameter assignments 

o_ParameterName _SameSpecificNameUsedAbove = float('nan') 

For the efficiency, 

o_SystemEfficiency_1050rpm = float('nan') 

The template for outputs 

outputs['ParameterName_ SameSpecificNameUsedAbove '] = o_ParameterName _SameSpecificNameUsed 

For the efficiency parameter, 

outputs['SystemEfficiency_1050rpm'] = o_SystemEfficiency_1050rpm 

A screenshot of a computer program

AI-generated content may be incorrect.

‘ 

 

 

 

Final version of this section should look like below 

A screenshot of a computer program

AI-generated content may be incorrect.

Edit the MotorCAD_Outputs File

Open MotorCAD_Outputs in Notepad. 

A screenshot of a computer

AI-generated content may be incorrect.

Add the same output parameters using the following format: 

The template is 

ParameterName_SpecificName=0.0 

For efficiency, 

SystemEfficiency_1050rpm=0.0 

A screenshot of a computer

AI-generated content may be incorrect.

Save and close the file. 

 

 

  1. Load the Modified optiSLang Project

Open the optiSLang project, then double-click on the Motor-CAD system block (usually labeled exportedProj). 

A screenshot of a computer

AI-generated content may be incorrect.

Click Load to reload the modified code. 

A screenshot of a computer

AI-generated content may be incorrect.

 

 

 

Add the Output Parameter to the Optimization

The new parameter (e.g., SystemEfficiency_1050rpm) will appear in the Outputs box in white, indicating it’s recognized but not yet used in the optimization. 

Drag it to the Responses section on the right to include it in the optimization. 

It should look like this: 

A screenshot of a computer

AI-generated content may be incorrect.

A screenshot of a computer

AI-generated content may be incorrect.

Now you can close this window. 

 

 

 

 

 

Finalize the Optimization Settings

Double-click the outer workflow box to enter the optimization settings. 

A screenshot of a computer

AI-generated content may be incorrect.

 

 

Go to the Criteria tab and assign your new parameters as needed. 

Click OK to close the window. 

A screenshot of a computer

AI-generated content may be incorrect.

Now your simulation is ready to run — and the new output variable is included in the optimization 

 

As seen below, efficiency is part of the optimization now! 

A screenshot of a computer

AI-generated content may be incorrect.