0% found this document useful (0 votes)
11 views20 pages

Surrogate Models for Response Evaluation

This document explains how to use surrogate models in JMAG to evaluate design parameters and obtain response values using Excel macros. It describes creating a case by randomly assigning design parameters, obtaining response values from the surrogate model, and creating graphs of the results. Procedures to run the macros in Excel are also provided.

Uploaded by

Huynh Thanh Anh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views20 pages

Surrogate Models for Response Evaluation

This document explains how to use surrogate models in JMAG to evaluate design parameters and obtain response values using Excel macros. It describes creating a case by randomly assigning design parameters, obtaining response values from the surrogate model, and creating graphs of the results. Procedures to run the macros in Excel are also provided.

Uploaded by

Huynh Thanh Anh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JMAG Function Tutorial

Output of Response Values Using Surrogate Models

Contents

Overview........................................................................................................................................ 2
1 Function Description ................................................................................................................... 2
1.1 Creating the Surrogate Model.............................................................................................. 2
1.2 Creating the Case ................................................................................................................ 3
1.3 Obtaining the Response Value ............................................................................................ 4
1.4 Creating the Graph .............................................................................................................. 5
2 Procedures ................................................................................................................................. 6
2.1 Replacing the Script File ...................................................................................................... 9
2.2 Placing the File .................................................................................................................... 9
2.3 Starting Microsoft Excel ....................................................................................................... 9
2.4 Loading the File ................................................................................................................. 10
2.5 Setting the File Path .......................................................................................................... 11
2.6 Creating the Case .............................................................................................................. 12
2.7 Obtaining the Response Value .......................................................................................... 14
2.8 Creating the Graph ............................................................................................................ 16
2.9 Checking the Results ......................................................................................................... 18

This document was created using the following software version.


■ Version JMAG-Designer 21.0, Microsoft Excel 2016
This document uses the following data.
■ JMAG Project File A [Link]
■ Excel File B [Link]
■ Surrogate Model Folder C JFT152UsingSurrogateModel_SurrogateModel_C-01
■ Python Script File D Make_Surrogate_Model.py
■ Python Script File Folder E JFT152UsingSurrogateModel_scripts_E-01
JMAG Function Tutorial - Output of Response Values Using Surrogate Models -

Overview
JMAG allows for optimization calculation using surrogate models. Not only for optimization
calculation, but the surrogate models can also be used for obtaining response values by setting
the parameter values in advance. This enables running evaluations, combined with multiple
design parameters, in a short time.
In this document, a macro is provided for quickly evaluating the results obtained by design
parameter combinations using surrogate models. This document, as a workflow for parametric
calculation using surrogate models, explains how to create a case that combines design
parameters randomly, obtain response values and create graphs from the response values.

Keywords: Surrogate model, Python, AI, Machine learning, Response value, Parametric, Excel,
VBA, Macro

1 Function Description
1.1 Creating the Surrogate Model
The [Create a surrogate model (beta version)] is a function to create a surrogate model using
training data prepared in advance. When a surrogate model is created, the same number of
CSV files as response values are output.

Notes
 This document does not explain how to create the surrogate model. To apply the contents
of this document to your model, create a surrogate model referencing the following
function tutorial after replacing the [Create a surrogate model (beta version)] script file.
The procedure of script file replacement is described in step 2.1 of this document.

JMAG Function Tutorial


[JFT146] Optimization Calculation Using Surrogate Models
[Link]

2
JFT152-01e
JMAG Function Tutorial - Output of Response Values Using Surrogate Models -

1.2 Creating the Case


Clicking [Generate sampling case] in an Excel file, a case is created by randomly assigning
parameters within the range of each variable [Minimum] to [Maximum] up to the number of
setting values in [Generate cases] in cell C8 of the sheet. The created case is added in the
sheet. Column B is the number of cases, and column C and subsequent columns are randomly
assigned parameters.
Match the setting of [Number of parameters] in cell C6 with the number of variable names to
be entered in a cell under [Parameter] in range [B22:D22]. For example, if [Number of
parameters] is 4, enter four variable names in the cells under [Parameter]. Specify minimum
values and maximum values of the parameter for each variable.

Input the number of cases to be generated.

Match the setting of [Number of parameters] with the number of

design parameters to be input under [Parameter].

Fig. 1-1 Parameter setting

3
JFT152-01e
JMAG Function Tutorial - Output of Response Values Using Surrogate Models -

1.3 Obtaining the Response Value


When clicking [Get response using surrogate model] in the Excel file, a response value is
output for the case created in “1.2 Creating the Case”. The response value is output in the
sheet.
Match the setting of [Number of response data] in cell C7 with the number of response values
to be entered in the cells under [Response data] in range [F22:F23]. For example, if [Number of
response data] is 6, enter six variable names in the cells under [Response data]. In addition, for
[Response data], specify the response value title set to the project file (*.jproj) used for creating
the surrogate model. The csv file name of the surrogate model is output with the same name as
the response value.

Match the setting of [Number of response data] with the number

of response value to be input under [Response data].

Fig. 1-2 Response value setting

4
JFT152-01e
JMAG Function Tutorial - Output of Response Values Using Surrogate Models -

1.4 Creating the Graph


Clicking [Draw Plot] in the Excel file creates a graph of the number of setting values for
[Number of graphs] in cell C9. The graph is added to column M and subsequent columns in the
sheet.
The graph axes are determined by the [X] and [Y] settings under [Axis] in range [H22:I22]. The
response value name entered under [Response data] in range [F22:F23] and variable name
entered under [Parameter] in range [B22:D22] can be used for setting values of [X] and [Y].

Match the setting of [Number of graphs] with


numbers of X and Y to be input under [Axis].

Can be used for X and Y axes of the graph.

Fig. 1-3 Graph axis setting

5
JFT152-01e
JMAG Function Tutorial - Output of Response Values Using Surrogate Models -

2 Procedures
Three macros are added to Excel file B. These macros create each case, obtain response
values, and create graphs. In this document, the macros are sequentially run using the created
surrogate model. Excel file B and script file folder E must be placed in the same folder. The
parameter of Excel file B is shown in table 2-1.
A model used for creating the surrogate model is shown in Fig. 2-1. For design variables,
assume that the maximum current of inverter rating is Imax, the thickness of model is
StackLength, the position of magnet radial direction is MagPos, and the width of magnet is
WMag. The design variable of magnet is shown in Fig. 2-2.
For response values, the maximum torque is MaxTorque, maximum speed is MaxSpeed,
efficiency is Eff, maximum torque output point is MaxPout, magnet area is MagArea, and N-T
curve knee point is BasisSpeed.

<Preconditions>
The following environment is required in order to follow this tutorial.
 Assume that the surrogate model is created.
 In Microsoft Excel, macro execution must be enabled.
 Versions of Python 3 are required to run the scripts (Python 2.7 is not supported).
 Either the Python library already installed in the machine you are using or the Python
library that is installed with JMAG-Designer can be used.
 However, it is necessary for you to place “tensorflow” and redistributable packages
on the machines currently used. “Tensorflow” and the redistributable packages can
be downloaded from the JMAG website in a compressed file (*.zip ).
 For the remaining steps, see “[Link]” in the compressed file.

JMAG website:
[Link]

6
JFT152-01e
JMAG Function Tutorial - Output of Response Values Using Surrogate Models -

Coil Stator core

Magnet

Rotor core

Fig. 2-1 2D motor model to be used

WMag

MagPos

Origin X

Fig. 2-2 Definition of magnet design variable

7
JFT152-01e
JMAG Function Tutorial - Output of Response Values Using Surrogate Models -

Table 2-1 Parameter Setting


Parameter Description

PythonExe path Specify the full path of Python library

Surrogate model folder path Specify the full path of the surrogate model folder

Number of parameters Specify the number of parameters

Number of response data Specify the number of response values

Generate cases Specify the number of cases to be generated

Number of graphs Specify the number of graphs

Parameter Specify the parameter names

Minimum Specify the minimum value of parameters

Maximum Specify the maximum value of parameters

Response data Specify the response value names

Axis Set axes to be used for creating graphs

X Specify X-axis of graph

Y Specify Y-axis of graph

8
JFT152-01e
JMAG Function Tutorial - Output of Response Values Using Surrogate Models -

2.1 Replacing the Script File


Replace the [Create a surrogate model (beta version)] script file. In this document, replace the
existing script file in the JMAG-Designer installation folder with the script file D. File replacement
is run with an administrator privilege account.
This is the procedure when creating a surrogate model for your model. When the included
surrogate model is used, this procedure is not necessary.

Open the JMAG-Designer installation folder.


Installed in “C:¥Program Files¥JMAG-Designer21.0” by default.
Open the scripts folder.
Back up Make_Surrogate_Model.py.
Rename the file or move it to another folder. In this document,
Make_Surrogate_Model.py is renamed as Make_Surrogate_Model.py_old.
Place the script file D (*.py) in the folder (Fig. 2-1-1).

Fig. 2-1-1 After replacing the script file

2.2 Placing the File


Place Excel file B and the script file folder E in the same folder. The files can be placed in any
folder.

Place Excel file B (*.xlsm) and the script file folder E in any folder (Fig. 2-2-1).
The script file folder E contains two script files.

Fig. 2-2-1 Placing files

2.3 Starting Microsoft Excel


Start Microsoft Excel.

Start Microsoft Excel.

9
JFT152-01e
JMAG Function Tutorial - Output of Response Values Using Surrogate Models -

2.4 Loading the File


Open Excel file B in Microsoft Excel.

Select the [File] tab from the Microsoft Excel menu bar.
Select [Open] > [This PC].
Specify Excel file B (*.xlsm).
Click [Open].
Excel file B opens. Three buttons are set to run the macros in advance (Fig. 2-4-1). When
a security warning appears, click [Enable Content] (Fig. 2-4-2).

Fig. 2-4-1 Excel file

Fig. 2-4-2 Security warning

10
JFT152-01e
JMAG Function Tutorial - Output of Response Values Using Surrogate Models -

2.5 Setting the File Path


Specify the Python library path and folder of the surrogate model.

Enter the full path for Python library in the cell on the right side of [PythonExe PATH] in
cell B4.
Specify [Link] in the python3.8 folder of the JMAG-Designer installation folder. In
this document, “C:¥Program Files¥JMAG-Designer21.0¥python3.8¥[Link]” is specified.
The Python3 libraries already installed in the machine you are using can also be used.
Enter the full path for surrogate model folder C in the cell to the right of [Surrogate model
folder path] in cell B5.
The surrogate model folder C contains the same number of csv and zip files as the
number of response values. In this document, the surrogate model folder C is placed
directly under D drive.

Table 2-5-1 File path setting


Parameter Setting

Enter the path where the Python library to use is located

PythonExe PATH Input example:

C:¥Program Files¥JMAG-Designer21.0¥python3.8¥[Link]

Enter the path to the folder where the surrogate model to use is

located
Surrogate model folder path
Input example:

D:¥JFT152UsingSurrogateModel_SurrogateModel_C-01

11
JFT152-01e
JMAG Function Tutorial - Output of Response Values Using Surrogate Models -

2.6 Creating the Case


Set the parameters and create a case.

Specify “4” in the cell to the right of [Number of parameters] in cell B6.
Specify “6” in the cell to the right of [Number of response data] in cell B7.
Specify “10000” in the cell to the right of [Generate cases] in cell B8.
Specify “1” in the cell to the right of [Number of graphs] in cell B9.
Check that “Imax”, “StackLength”, “MagPos”, and “WMag” are entered in each cell from
B24 to B27 under [Variable] in cell B23 under [Parameter] in range [B22:D22].
Match the number of variables with the number of parameters in step 1. Also, the variable
name to be entered should match the variable name of design variables when the
surrogate model is created.
Set the parameters shown in Fig. 2-6-1 in the cells under [Minimum] and [Maximum] in
range [C23:D23].
Click the [Generate sampling case] button (Fig. 2-6-2).
A case assigned with random parameters is added to the cell in row 32 and subsequent
rows (Fig. 2-6-3).

Fig. 2-6-1 Parameter setting for creating a case

Fig. 2-6-2 The [Generate sampling case] button

12
JFT152-01e
JMAG Function Tutorial - Output of Response Values Using Surrogate Models -



Fig. 2-6-3 Created case
The resulting parameters do not match because a case is created by using random numbers.

13
JFT152-01e
JMAG Function Tutorial - Output of Response Values Using Surrogate Models -

2.7 Obtaining the Response Value


Obtain a response value using the surrogate model for the created case.

Check that “MaxTorque”, “MaxSpeed”, “Eff”, “MaxPout”, “MagArea”, and “BasisSpeed”


are entered in each cell from F24 to F29 under [Response data] in range [F22:F23] (Fig.
2-7-1).
Match the number of response values with the number in [Number of response data].
Also, the name of the response value to be entered should match the variable name
when the surrogate model was created.
Click the [Get response using surrogate model] button (Fig. 2-7-2).
The progress bar is displayed (Fig. 2-7-3).
The response value results are output in the cell of row 32 and subsequent rows after the
processing is finished.

Fig. 2-7-1 Response value name setting

Fig. 2-7-2 The [Get response using surrogate model] button

14
JFT152-01e
JMAG Function Tutorial - Output of Response Values Using Surrogate Models -

Fig. 2-7-3 Progress bar






Fig. 2-7-4 Response value results
The resulting response values do not match because a case is created by using random numbers.

15
JFT152-01e
JMAG Function Tutorial - Output of Response Values Using Surrogate Models -

2.8 Creating the Graph


Create a graph.

Check that “MagArea” is entered in cell H24 under [X] in cell H23 under [Axis] in range
[H22:I22].
For the graph axes, the variable names in [Variable] of [Parameter] and the response
names in [Response data] can be used. The combination number to be specified should
match the number in [Number of graphs].
Check that “MaxTorque” is entered in cell I24 under [Y] in cell I23 (Fig. 2-8-1).
Click the [Draw Plot] button (Fig. 2-8-2).
A graph is displayed (Fig. 2-8-3). In this document, a graph of the magnet area and
maximum torque is created.

Fig. 2-8-1 Graph combination setting

Fig. 2-8-2 The [Draw Plot] button

16
JFT152-01e
JMAG Function Tutorial - Output of Response Values Using Surrogate Models -

300

250

200

150
MaxTorque

100

50

0
25 50 75 100 125 150

-50
MagArea

Fig. 2-8-3 Magnet area – Maximum torque


The resulting response values do not match because a case is created by using random numbers.

17
JFT152-01e
JMAG Function Tutorial - Output of Response Values Using Surrogate Models -

2.9 Checking the Results


Use the Microsoft Excel filter function to extract a design plan with a maximum torque greater
than 200 (Nm).

Select a range B32:L32 (Fig. 2-9-1).


Select the [Home] tab from the menu bar.
Select [Sort & Filter] > [Filter] in the ribbon tab.
The ▼button is displayed in the header in 32 row (Fig. 2-9-2).
Click the ▼button displayed above [MaxTorque] in cell G32.
Select [Number Filters] > [Greater Than].
The [Custom AutoFilter] dialog box appears.
Specify “200”.
Click [OK].
The [Custom AutoFilter] dialog box closes and only the case with a maximum torque
greater than 200(Nm) appears (Fig. 2-9-3).

18
JFT152-01e
JMAG Function Tutorial - Output of Response Values Using Surrogate Models -

Fig. 2-9-1 Selecting header range

Fig. 2-9-2 Setting filter

Fig. 2-9-3 Filtering results


The resulting parameters and response values do not match because a case is created by using random

numbers.

END

19
JFT152-01e
JMAG Function Tutorial - Output of Response Values Using Surrogate Models -

URL [Link]

JSOL Corporation
jmag-support@[Link]
Technical Support
or
A distributor in your country

JMAG Function Tutorial


Copyright(C) 2022 JSOL Corporation All Rights Reserved.

20
JFT152-01e

You might also like