-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmagnet_segmentation.py
118 lines (94 loc) · 3.59 KB
/
magnet_segmentation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# # Magnet segmentation
# This example shows how to use PyAEDT to segment magnets of an electric motor.
# The method is valid and usable for any object you would like to segment.
#
# Keywords: **Maxwell 3D**, **Magnet segmentation**.
# ## Perform imports and define constants
#
# Perform required imports.
import tempfile
import time
import ansys.aedt.core
# Define constants.
AEDT_VERSION = "2025.1"
NG_MODE = False # Open AEDT UI when it is launched.
# ## Create temporary directory
#
# Create a temporary directory where downloaded data or
# dumped data can be stored.
# If you'd like to retrieve the project data for subsequent use,
# the temporary folder name is given by ``temp_folder.name``.
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
# ## Download AEDT file example
#
# Set the local temporary folder to export the AEDT file to.
aedt_file = ansys.aedt.core.downloads.download_file(
source="object_segmentation",
name="Motor3D_obj_segments.aedt",
destination=temp_folder.name,
)
# ## Launch Maxwell 3D
#
# Launch Maxwell 3D, providing the version, rgw path to the project, and the graphical mode.
m3d = ansys.aedt.core.Maxwell3d(
project=aedt_file,
version=AEDT_VERSION,
new_desktop=True,
non_graphical=NG_MODE,
)
# ## Segment first magnet by specifying number of segments
#
# Select the first magnet to segment by specifying the number of segments.
# The method accepts as input the list of magnets names to segment,
# magnet IDs, or the magnet :class:`ansys.aedt.core.modeler.cad.object3d.Object3d` object.
# When ``apply_mesh_sheets`` is enabled, the mesh sheets are also
# applied in the geometry.
# In the following code, the name of the magnet is also given as an input.
segments_number = 2
object_name = "PM_I1"
sheets_1 = m3d.modeler.objects_segmentation(
object_name,
segments=segments_number,
apply_mesh_sheets=True,
mesh_sheets=3,
)
# ## Segment second magnet by specifying number of segments
#
# Select the second magnet to segment by specifying the number of segments.
# The following code gives the ID of the magnet as an input.
segments_number = 2
object_name = "PM_I1_1"
magnet_id = [obj.id for obj in m3d.modeler.object_list if obj.name == object_name][0]
sheets_2 = m3d.modeler.objects_segmentation(
magnet_id, segments=segments_number, apply_mesh_sheets=True
)
# ## Segment third magnet by specifying segmentation thickness
#
# Select the third magnet to segment by specifying the segmentation thickness.
# The following code gives the magnet object type `ansys.aedt.core.modeler.cad.object3d.Object3d`
# as an input.
segmentation_thickness = 1
object_name = "PM_O1"
magnet = [obj for obj in m3d.modeler.object_list if obj.name == object_name][0]
sheets_3 = m3d.modeler.objects_segmentation(
magnet, segmentation_thickness=segmentation_thickness, apply_mesh_sheets=True
)
# ## Segment fourth magnet by specifying number of segments
#
# Select the fourth magnet to segment by specifying the number of segments.
# The following code gives the name of the magnet as input and disables the mesh sheets.
object_name = "PM_O1_1"
segments_number = 2
sheets_4 = m3d.modeler.objects_segmentation(object_name, segments=segments_number)
# ## Release AEDT
m3d.save_project()
m3d.release_desktop()
# Wait 3 seconds to allow AEDT to shut down before cleaning the temporary directory.
time.sleep(3)
# ## Clean up
#
# All project files are saved in the folder ``temp_folder.name``.
# If you've run this example as a Jupyter notebook, you
# can retrieve those project files. The following cell
# removes all temporary files, including the project folder.
temp_folder.cleanup()