0% found this document useful (0 votes)
24 views15 pages

JMAG Topology Optimization with Python

This document describes how to perform topology optimization in JMAG using Python scripts to define response values. It explains how to load a model, set the optimization conditions and NGnet, create a response value from a Python script, set the optimization and run the calculation. It then confirms the results.

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)
24 views15 pages

JMAG Topology Optimization with Python

This document describes how to perform topology optimization in JMAG using Python scripts to define response values. It explains how to load a model, set the optimization conditions and NGnet, create a response value from a Python script, set the optimization and run the calculation. It then confirms the results.

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

Defining Response Values with Scripts in Topology


Optimization Using NGnet

Contents

Overview........................................................................................................................................ 2
1 Function Description ................................................................................................................... 2
2 Performing the Procedure .......................................................................................................... 3
2.1 Starting JMAG-Designer ...................................................................................................... 5
2.2 Loading the Model ............................................................................................................... 5
2.3 Confirming the Topology Optimization Condition Settings .................................................. 5
2.4 Setting the Response Values from the Script ...................................................................... 7
2.5 Optimization Settings ........................................................................................................... 9
2.6 Running the Topology Optimization Calculation ................................................................ 11
2.7 Confirming the Analysis Results ........................................................................................ 12

This document was created using the following software versions.


■ Version JMAG-Designer 19.1, Python3.8
This document uses the following data.
■ JMAG Project File A JFT112TopologyOpt_PostScript-[Link]
■ Python Script File B JFT112TopologyOpt_PostScript-[Link]
JMAG Function Tutorial
- Defining Response Values with Scripts in Topology Optimization Using NGnet -

Overview
Optimized designs are validated within the electrical appliance design space through various
processes of trial and error. Attempts have been made to optimize topology capable of making
significant changes to geometry itself, with innovative design proposals not yet considered until
now gradually being produced.
In JMAG, there exists topology optimization functions that use NGnet (the on / off method). To
that end, various objective functions can be handled by using the response values that are
defined with Python scripts.
In this document, response values are calculated using a Python script, and a method for
performing topology optimization used as an objective function is described.

Keywords: Python, Script, Topology Optimization, on / off method, NGnet, Objective function,
Response value

1 Function Description
[Creating Response Value from Script] is a function that uses response values calculated with
scripts in topology optimization calculations that utilize NGnet.

2
JFT112-03e
JMAG Function Tutorial
- Defining Response Values with Scripts in Topology Optimization Using NGnet -

2 Performing the Procedure


This document describes the process of setting topology optimization conditions to the below
reactor model followed by running the topology optimization. Response value L is created by
reading Python scripts prepared in advance as optimization conditions, and the objective
functions of optimization calculations are used.
Operation flow is shown in Fig. 2-1, and analysis model information is shown in Fig. 2-2.
The scripting used in this document is Python3.8.

<Optimization conditions>
 Objective function
 The volume of the design area known as "Area" is minimized while maintaining
inductance L.
In this document, the variable expression Area is defined with user components.
 The criterion of L is Lbase, and abs(Lbase-L) is minimized.
In this document, the value of Lbase calculated in advance has been registered as
an equation.

 Response values defined with a script


 The inductance expressed by the following expression (2.1) is defined as a response
value

𝛥𝛥𝛥𝛥
𝐿𝐿 = (2.1)
𝛥𝛥𝛥𝛥

3
JFT112-03e
JMAG Function Tutorial
- Defining Response Values with Scripts in Topology Optimization Using NGnet -

Load model

Set topology optimization conditions (NGnet)

Set response values with scripts


Optimization settings

Run topology optimization

Confirm results after running optimization

Fig. 2-1 Operation flow

Fig. 2-2 Analysis model (Left: Whole model, Right: 2D 1/4 model)

4
JFT112-03e
JMAG Function Tutorial
- Defining Response Values with Scripts in Topology Optimization Using NGnet -

2.1 Starting JMAG-Designer


Start JMAG-Designer.

1. Start JMAG-Designer.

2.2 Loading the Model


Open JMAG Project File A in JMAG-Designer.

1. Select [File] > [Open] from the JMAG-Designer menu bar.


The [Open File] dialog box appears.
2. Select JMAG Project File A (*.jproj).
3. Click [Open].
JMAG Project File A opens.

2.3 Confirming the Topology Optimization Condition Settings


Confirm the set NGnet from the topology optimization conditions that are set in advance.

1. Right-click [Topology Optimization] from [Study] > [Conditions] in the [Project Manager]
tree.
2. Select [Edit] from the context menu.
The [Topology Optimization] setting panel is displayed.
3. Confirm the parameters (Table 2-3-1, Table 2-3-2).
A preview of NGnet is displayed in the graphics window. Confirm that settings are as per
Fig. 2-3-1.
4. Click [Cancel].
The [Topology Optimization] setting panel closes.

5
JFT112-03e
JMAG Function Tutorial
- Defining Response Values with Scripts in Topology Optimization Using NGnet -

Fig. 2-3-1 NGnet positions

Table 2-3-1 [Topology Optimization] settings


Parameter Setting

Parts Core

X 4.0 mm
Radius
Y 4.0 mm

Set from Coordinate System


Center Positions
(see Table 2-3-2)

Specify Mirror Symmetry Cleared

Model Material Properties with


Cleared
Continuous Variables

Table 2-3-2 [Create Center of Gaussian] settings


Parameter Setting

Coordinate System Global Rectangular

X 5.0 mm
Grid
Y 5.0 mm

Region All Specified Regions Selected

6
JFT112-03e
JMAG Function Tutorial
- Defining Response Values with Scripts in Topology Optimization Using NGnet -

2.4 Setting the Response Values from the Script


Read Python Script File B with the script editor, and set the response values.

1. Right-click [Response Data] under [Study] > [Result Items] > [Response Graph] in the
[Project Manager] tree.
2. Select [Create Response Value from Script] from the context value (Fig. 2-4-1).
The [Creating Response Value from Script] dialog box appears (Fig. 2-4-2).
3. Set the parameters (Table 2-4-1).
4. Click the [Set Python Code] button.
The [Script Editor] opens.
5. Select [File] > [Open] from the [Script Editor] menu bar.
The [Open File] dialog box appears.
6. Select Python Script File B.
7. Click [Open].
The [Open File] dialog box closes.
The contents of Python Script File B are expanded in the [Script Editor] (Fig. 2-4-3).
8. Refer to Fig. 2-4-3, and confirm that there are no discrepancies in the content of each
item listed in the script editor.
9. Click [OK] in the [Script Editor].
The [Script Editor] closes.
10. Click [OK] in the [Creating Response Value from Script] dialog box.
The [Creating Response Value from Script] dialog box closes.
L<L> is added beneath [Response Data] under [Study] > [Result Items] > [Response
Graph] in the [Project Manager] tree (Fig. 2-4-4).

Fig. 2-4-1 [Create Response Value from Script] context menu

7
JFT112-03e
JMAG Function Tutorial
- Defining Response Values with Scripts in Topology Optimization Using NGnet -

Fig. 2-4-2 [Creating Response Value from Script] dialog box

Fig. 2-4-3 The script editor

Fig. 2-4-4 Added response value

Table 2-4-1 [Creating Response Value from Script] settings


Parameter Setting

Title L

Variable L

8
JFT112-03e
JMAG Function Tutorial
- Defining Response Values with Scripts in Topology Optimization Using NGnet -

2.5 Optimization Settings


Configure settings for optimization calculations.

1. Right-click [Case Control] under [Study] in the [Project Manager] tree.


2. Select [Optimization] from the context menu (Fig. 2-5-1).
The [Optimization] dialog box appears.
3. Confirm that the [Objective Functions] tab is displayed.
4. Confirm that the response values <Area> and the response value <L> set in 2.4 are
added to the [Response Data Variables] panel.
The settings of the response values created in 2.4 can also be set or added here.
5. Click [Add] below the [Objective Functions] panel.
The [Edit Expression] dialog box appears.
6. Set the parameters (Table 2-5-1).
7. Click [OK] in the [Edit Expression] dialog box.
The [Edit Expression] dialog box closes.
8. Repeat the same operations from Step 6 to Step 7 to enter the parameters (Table 2-5-2).
9. Select the [Options] tab, and set the parameters (Table 2-5-3).
10. Select the [Output] tab, and set an arbitrary CSV file path in [Output File] in the [CSV
Output] panel.
Ensure that the CSV file extension (*.csv) is entered in the file name.
When running optimization calculations, the progress of optimization calculations can be
confirmed from the result values output to this CSV file.

9
JFT112-03e
JMAG Function Tutorial
- Defining Response Values with Scripts in Topology Optimization Using NGnet -

Fig. 2-5-1 [Optimization] context menu

Table 2-5-1 [Objective Functions](Lbase) settings


Name Expression Type

Lbase abs(Lbase-L) Minimize

Table 2-5-2 [Objective Functions](Area_min) settings


Name Expression Type

Area_min Area Minimize

Table 2-5-3 [Options] tab settings


Parameter Setting

Optimization Engine Genetic Algorithm (Topology)

Number of
1 (*Note)
Generations

Population Size 25

Number of Children 25

Continuous Shape Do not use the continuity of the shape as an

Evaluation evaluation criterion

Results Evaluation Save the results of all cases


(*Note) This document takes into consideration the time required for calculations,
so only the 1st generation is calculated.
As a result, the geometry obtained is not the most optimum solution.

10
JFT112-03e
JMAG Function Tutorial
- Defining Response Values with Scripts in Topology Optimization Using NGnet -

2.6 Running the Topology Optimization Calculation


Run the optimization calculation.

1. Click [Run] in the lower portion of the [Optimization] dialog box.


The [Optimization] dialog box appears, and the calculation starts.
After analysis ends, the [Load Topology Optimization Results] dialog box appears (Fig. 2-
6-1).
2. Set the parameters (Table 2-6-1).
3. Click [OK].
The [Load Topology Optimization Results] dialog box closes.
A total of 51 cases is displayed as the number of cases.

図 2-6-1 [Load Topology Optimization Results] dialog box

Table 2-6-1 [Load Topology Optimization Results] settings


Parameter Setting

Read Only the Specified Number of Best


Selected
Objective Cases

11
JFT112-03e
JMAG Function Tutorial
- Defining Response Values with Scripts in Topology Optimization Using NGnet -

2.7 Confirming the Analysis Results


Along with the results obtained from the optimization, also confirm that response value L is
functioning normally.

1. Right-click Studies in the Project Manager tree.


2. Select Properties from the context menu.
The Study Properties dialog box appears.
3. Access the file path of [Calculation Folder].
4. Open the CSV file specified in Step 9 of Section 2.5 with a text editor.
The value of the objective functions obtained from the optimization can be confirmed
(Fig. 2-7-1).
Because this describes a state where Case 1 is yet to be calculated in JMAG-Designer,
the number of cases displayed in the CSV file is one case less.
5. Click [Cancel] in the [Study Properties] dialog box.
The [Study Properties] dialog box closes.
6. Change the case with [Case Control] in the toolbar to Case 2.
7. Right-click [Graphs] under [Study] > [Results].
8. Select [Show Table] from the context menu.
The [Table Results] dialog box appears.
9. Click the [Circuit Current] tab.
The value of "current" set in the Python script is obtained for two steps (Fig. 2-7-2).
10. Click the [Coil Flux-Linkage] tab.
The value of "flux" set in the Python script is obtained for two steps (Fig. 2-7-3).
11. Similar to Fig. 2-7-4, copy the values calculated from Step 9 to Step 10 with a text editor
and apply them the below calculation formula, and confirm that the values are equal to
the response value L of Case 2 confirmed in Step 4.
The calculation formula is "L = (b2-b1) / (i2-i1)".
Circuit current Step 1 corresponds to "i1", circuit current Step 2 corresponds to "i2", coil
flux linkage Step 1 corresponds to "b1", and coil flux linkage Step 2 corresponds to "b2".

12
JFT112-03e
JMAG Function Tutorial
- Defining Response Values with Scripts in Topology Optimization Using NGnet -

Fig. 2-7-1 CSV file results display


Because random numbers are used when multi-objective generic algorithms are chosen for optimization

engines, created cases and obtained response values do not match exactly.

Fig. 2-7-2 [Circuit Current] table display


Because random numbers are used when multi-objective generic algorithms are chosen for optimization

engines, created cases and obtained response values do not match exactly.

Fig. 2-7-3 [Coil Flux-Linkage] table display


Because random numbers are used when multi-objective generic algorithms are chosen for optimization

engines, created cases and obtained response values do not match exactly.

13
JFT112-03e
JMAG Function Tutorial
- Defining Response Values with Scripts in Topology Optimization Using NGnet -

Fig. 2-7-4 Calculation example to confirm response value L


Because random numbers are used when multi-objective generic algorithms are chosen for optimization

engines, created cases and obtained response values do not match exactly.

END

14
JFT112-03e
JMAG Function Tutorial
- Defining Response Values with Scripts in Topology Optimization Using NGnet -

URL [Link]

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

JMAG Function Tutorial


Copyright(C) 2020-2022 JSOL Corporation All Rights Reserved.

15
JFT112-03e

You might also like