Maxwell 3D segmentation#
This example shows how to use the Magnet Segmentation Toolkit to segment your AEDT motor model.
Perform required imports#
Perform required imports.
[1]:
import os
import shutil
import tempfile
from ansys.aedt.toolkits.common.utils import download_file
from ansys.aedt.toolkits.magnet_segmentation.backend.api import ToolkitBackend
Initialize temporary folder and project settings#
Initialize a temporary folder to copy the input file into and specify project settings.
[2]:
URL_BASE = "https://raw.githubusercontent.com/ansys/example-data/master/toolkits/magnet_segmentation/"
AEDT_PROJECT = "e9_eMobility_IPM_3D"
URL = os.path.join(URL_BASE, AEDT_PROJECT + ".aedt")
temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
active_project = os.path.join(temp_dir.name, AEDT_PROJECT + ".aedt")
download_file(URL, active_project)
active_design = "e9_eMobility_IPM_3D_test"
Initialize toolkit#
Initialize the toolkit.
[3]:
toolkit = ToolkitBackend()
Get toolkit properties#
Get the toolkit properties.
[4]:
properties = toolkit.get_properties()
Initialize properties#
Initialize a dictionary of properties.
[5]:
properties["active_project"] = AEDT_PROJECT
properties["active_design"] = active_design
properties["design_list"] = {AEDT_PROJECT: [active_design]}
properties["is_skewed"] = False
properties["rotor_material"] = "M250-35A_20C"
properties["stator_material"] = "M250-35A_20C"
properties["magnets_material"] = "N30UH_65C"
properties["magnet_segments_per_slice"] = 2
properties["rotor_slices"] = 2
properties["apply_mesh_sheets"] = False
# properties["mesh_sheets_number"] = 3
properties["skew_angle"] = "2deg"
Set non-graphical mode#
Set non-graphical mode. The default value is False
.
[6]:
properties["non_graphical"] = False
Set properties#
Set properties.
[7]:
toolkit.set_properties(properties)
INFO - Updating internal properties.
DEBUG - Updating 'is_skewed' with value False
DEBUG - Updating 'apply_mesh_sheets' with value False
DEBUG - Updating 'magnets_material' with value N30UH_65C
DEBUG - Updating 'rotor_material' with value M250-35A_20C
DEBUG - Updating 'stator_material' with value M250-35A_20C
DEBUG - Updating 'rotor_slices' with value 2
DEBUG - Updating 'magnet_segments_per_slice' with value 2
DEBUG - Updating 'mesh_sheets_number' with value 0
DEBUG - Updating 'skew_angle' with value 2deg
DEBUG - Updating 'setup_to_analyze' with value Setup1
DEBUG - Updating 'objects' with value []
DEBUG - Updating 'aedt_version' with value 2024.2
DEBUG - Updating 'non_graphical' with value False
DEBUG - Updating 'active_project' with value e9_eMobility_IPM_3D
DEBUG - Updating 'active_design' with value e9_eMobility_IPM_3D_test
DEBUG - Updating 'project_list' with value []
DEBUG - Updating 'design_list' with value {'e9_eMobility_IPM_3D': ['e9_eMobility_IPM_3D_test']}
DEBUG - Updating 'selected_process' with value 0
DEBUG - Updating 'use_grpc' with value True
DEBUG - Updating 'is_toolkit_busy' with value False
DEBUG - Updating 'url' with value 127.0.0.1
DEBUG - Updating 'port' with value 5001
DEBUG - Updating 'debug' with value True
DEBUG - Updating 'toolkit_name' with value common
DEBUG - Updating 'log_file' with value common_backend.log
DEBUG - Properties were updated successfully.
[7]:
(True, 'Properties were updated successfully.')
Initialize AEDT#
Launch a new AEDT session.
[8]:
toolkit.launch_aedt()
DEBUG - Toolkit is not connected to AEDT.
DEBUG - Launching AEDT.
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.10.0.
PyAEDT INFO: Initializing new Desktop session.
PyAEDT WARNING: Argument `specified_version` is deprecated for method `__init__`; use `version` instead.
PyAEDT WARNING: Argument `new_desktop_session` is deprecated for method `__init__`; use `new_desktop` instead.
PyAEDT INFO: Log on console is enabled.
PyAEDT INFO: Log on file C:\Users\ansys\AppData\Local\Temp\pyaedt_ansys_39d488c3-5f2f-424b-9f1a-02ea723f5944.log is enabled.
PyAEDT INFO: Log on AEDT is enabled.
PyAEDT INFO: Debug logger is disabled. PyAEDT methods will not be logged.
PyAEDT INFO: Launching PyAEDT with gRPC plugin.
PyAEDT INFO: New AEDT session is starting on gRPC port 52475
PyAEDT INFO: AEDT installation Path C:\Program Files\AnsysEM\v242\Win64
PyAEDT INFO: Ansoft.ElectronicsDesktop.2024.2 version started with process ID 4964.
DEBUG - AEDT launched.
DEBUG - Grpc port 52475.
PyAEDT INFO: Desktop has been released.
INFO - AEDT is released.
DEBUG - AEDT is released and project properties are loaded.
[8]:
True
Open project#
Open the project.
[9]:
toolkit.open_project(active_project)
DEBUG - Toolkit is not connected to AEDT.
DEBUG - Connecting AEDT.
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.10.0.
PyAEDT INFO: Initializing new Desktop session.
PyAEDT WARNING: Argument `specified_version` is deprecated for method `__init__`; use `version` instead.
PyAEDT WARNING: Argument `new_desktop_session` is deprecated for method `__init__`; use `new_desktop` instead.
PyAEDT INFO: Log on console is enabled.
PyAEDT INFO: Log on file C:\Users\ansys\AppData\Local\Temp\pyaedt_ansys_39d488c3-5f2f-424b-9f1a-02ea723f5944.log is enabled.
PyAEDT INFO: Log on AEDT is disabled.
PyAEDT INFO: Debug logger is disabled. PyAEDT methods will not be logged.
PyAEDT INFO: Launching PyAEDT with gRPC plugin.
PyAEDT INFO: Connecting to AEDT session on gRPC port 52475
PyAEDT INFO: AEDT installation Path C:\Program Files\AnsysEM\v242\Win64
DEBUG - Toolkit is connected to AEDT.
DEBUG - Project C:\Users\ansys\AppData\Local\Temp\tmpc1ub_xi5.ansys\e9_eMobility_IPM_3D.aedt is opened
DEBUG - Project name: e9_eMobility_IPM_3D
INFO - Updating internal properties.
DEBUG - Updating 'project_list' with value ['C:/Users/ansys/AppData/Local/Temp/tmpc1ub_xi5.ansys/e9_eMobility_IPM_3D.aedt']
DEBUG - Updating 'active_design' with value e9
DEBUG - Updating 'active_project' with value C:/Users/ansys/AppData/Local/Temp/tmpc1ub_xi5.ansys/e9_eMobility_IPM_3D.aedt
DEBUG - Updating 'design_list' with value {'e9_eMobility_IPM_3D': ['e9']}
DEBUG - Properties were updated successfully.
PyAEDT INFO: Desktop has been released.
INFO - AEDT is released.
[9]:
True
Connect design#
Connect or create a new design.
[10]:
toolkit.connect_design()
DEBUG - Toolkit is not connected to AEDT.
DEBUG - Connecting AEDT.
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.10.0.
PyAEDT INFO: Initializing new Desktop session.
PyAEDT WARNING: Argument `specified_version` is deprecated for method `__init__`; use `version` instead.
PyAEDT WARNING: Argument `new_desktop_session` is deprecated for method `__init__`; use `new_desktop` instead.
PyAEDT INFO: Log on console is enabled.
PyAEDT INFO: Log on file C:\Users\ansys\AppData\Local\Temp\pyaedt_ansys_39d488c3-5f2f-424b-9f1a-02ea723f5944.log is enabled.
PyAEDT INFO: Log on AEDT is disabled.
PyAEDT INFO: Debug logger is disabled. PyAEDT methods will not be logged.
PyAEDT INFO: Launching PyAEDT with gRPC plugin.
PyAEDT INFO: Connecting to AEDT session on gRPC port 52475
PyAEDT INFO: AEDT installation Path C:\Program Files\AnsysEM\v242\Win64
DEBUG - Toolkit is connected to AEDT.
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.10.0.
PyAEDT INFO: Returning found Desktop session with PID 4964!
PyAEDT INFO: Project e9_eMobility_IPM_3D set to active.
PyAEDT INFO: Aedt Objects correctly read
INFO - Toolkit is connected to AEDT design.
[10]:
True
Apply segmentation#
Apply segmentation and assign the relative coordinate system.
[11]:
toolkit.segmentation()
PyAEDT INFO: Desktop has been released.
INFO - AEDT is released.
DEBUG - Toolkit is not connected to AEDT.
DEBUG - Connecting AEDT.
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.10.0.
PyAEDT INFO: Initializing new Desktop session.
PyAEDT WARNING: Argument `specified_version` is deprecated for method `__init__`; use `version` instead.
PyAEDT WARNING: Argument `new_desktop_session` is deprecated for method `__init__`; use `new_desktop` instead.
PyAEDT INFO: Log on console is enabled.
PyAEDT INFO: Log on file C:\Users\ansys\AppData\Local\Temp\pyaedt_ansys_39d488c3-5f2f-424b-9f1a-02ea723f5944.log is enabled.
PyAEDT INFO: Log on AEDT is disabled.
PyAEDT INFO: Debug logger is disabled. PyAEDT methods will not be logged.
PyAEDT INFO: Launching PyAEDT with gRPC plugin.
PyAEDT INFO: Connecting to AEDT session on gRPC port 52475
PyAEDT INFO: AEDT installation Path C:\Program Files\AnsysEM\v242\Win64
DEBUG - Toolkit is connected to AEDT.
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.10.0.
PyAEDT INFO: Returning found Desktop session with PID 4964!
PyAEDT INFO: Project e9_eMobility_IPM_3D set to active.
PyAEDT INFO: Aedt Objects correctly read
INFO - Toolkit is connected to AEDT design.
PyAEDT INFO: Modeler class has been initialized! Elapsed time: 0m 6sec
PyAEDT INFO: Parsing design objects. This operation can take time
PyAEDT INFO: Parsing C:/Users/ansys/AppData/Local/Temp/tmpc1ub_xi5.ansys/e9_eMobility_IPM_3D.aedt.
PyAEDT INFO: File C:/Users/ansys/AppData/Local/Temp/tmpc1ub_xi5.ansys/e9_eMobility_IPM_3D.aedt correctly loaded. Elapsed time: 0m 1sec
PyAEDT INFO: aedt file load time 0.6792018413543701
PyAEDT INFO: 3D Modeler objects parsed. Elapsed time: 0m 1sec
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.10.0.
PyAEDT INFO: Returning found Desktop session with PID 4964!
PyAEDT INFO: Project e9_eMobility_IPM_3D set to active.
PyAEDT INFO: Aedt Objects correctly read
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.10.0.
PyAEDT INFO: Returning found Desktop session with PID 4964!
PyAEDT INFO: Project e9_eMobility_IPM_3D set to active.
PyAEDT INFO: Aedt Objects correctly read
INFO - Updating internal properties.
DEBUG - Updating 'is_skewed' with value False
DEBUG - Updating 'apply_mesh_sheets' with value False
DEBUG - Updating 'magnets_material' with value N30UH_65C
DEBUG - Updating 'rotor_material' with value M250-35A_20C
DEBUG - Updating 'stator_material' with value M250-35A_20C
DEBUG - Updating 'rotor_slices' with value 2
DEBUG - Updating 'magnet_segments_per_slice' with value 2
DEBUG - Updating 'mesh_sheets_number' with value 0
DEBUG - Updating 'skew_angle' with value 2deg
DEBUG - Updating 'setup_to_analyze' with value Setup1
DEBUG - Updating 'objects' with value []
DEBUG - Updating 'aedt_version' with value 2024.2
DEBUG - Updating 'non_graphical' with value False
DEBUG - Updating 'active_project' with value C:/Users/ansys/AppData/Local/Temp/tmpc1ub_xi5.ansys/e9_eMobility_IPM_3D.aedt
DEBUG - Updating 'active_design' with value e9_1
DEBUG - Updating 'project_list' with value ['C:/Users/ansys/AppData/Local/Temp/tmpc1ub_xi5.ansys/e9_eMobility_IPM_3D.aedt']
DEBUG - Updating 'design_list' with value {'e9_eMobility_IPM_3D': ['e9', 'e9_1']}
DEBUG - Updating 'selected_process' with value 52475
DEBUG - Updating 'use_grpc' with value True
DEBUG - Updating 'is_toolkit_busy' with value False
DEBUG - Updating 'url' with value 127.0.0.1
DEBUG - Updating 'port' with value 5001
DEBUG - Updating 'debug' with value True
DEBUG - Updating 'toolkit_name' with value common
DEBUG - Updating 'log_file' with value common_backend.log
DEBUG - Properties were updated successfully.
PyAEDT INFO: Modeler class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Parsing design objects. This operation can take time
PyAEDT INFO: Parsing C:/Users/ansys/AppData/Local/Temp/tmpc1ub_xi5.ansys/e9_eMobility_IPM_3D.aedt.
PyAEDT INFO: File C:/Users/ansys/AppData/Local/Temp/tmpc1ub_xi5.ansys/e9_eMobility_IPM_3D.aedt correctly loaded. Elapsed time: 0m 2sec
PyAEDT INFO: aedt file load time 1.5324978828430176
PyAEDT INFO: 3D Modeler objects parsed. Elapsed time: 0m 2sec
PyAEDT INFO: Deleted 1 Objects: Rotor_1_ObjectFromFace1_1.
PyAEDT INFO: Deleted 1 objects
PyAEDT INFO: Boundary Insulating L1_1Magnet1N1_1_1_segments has been correctly created.
PyAEDT INFO: Boundary Insulating L1_1Magnet2N1_1_1_segments has been correctly created.
PyAEDT INFO: Boundary Insulating L1_1Magnet1N1_1_1_Split1_segments has been correctly created.
PyAEDT INFO: Boundary Insulating L1_1Magnet2N1_1_1_Split1_segments has been correctly created.
INFO - Updating internal properties.
DEBUG - Updating 'is_skewed' with value False
DEBUG - Updating 'apply_mesh_sheets' with value False
DEBUG - Updating 'magnets_material' with value N30UH_65C
DEBUG - Updating 'rotor_material' with value M250-35A_20C
DEBUG - Updating 'stator_material' with value M250-35A_20C
DEBUG - Updating 'rotor_slices' with value 2
DEBUG - Updating 'magnet_segments_per_slice' with value 2
DEBUG - Updating 'mesh_sheets_number' with value 0
DEBUG - Updating 'skew_angle' with value 2deg
DEBUG - Updating 'setup_to_analyze' with value Setup1
DEBUG - Updating 'objects' with value ['L1_1Magnet1N1_1_1', 'L1_1Magnet2N1_1_1', 'L1_1Magnet1N1_1_1_Split1', 'L1_1Magnet2N1_1_1_Split1', 'L1_1Magnet1N1_1_1_ObjectFromFace1_1_ObjectFromFace1', 'L1_1Magnet2N1_1_1_ObjectFromFace1_1_ObjectFromFace1', 'L1_1Magnet1N1_1_1_Split1_ObjectFromFace1_1_ObjectFromFace1', 'L1_1Magnet2N1_1_1_Split1_ObjectFromFace1_1_ObjectFromFace1']
DEBUG - Updating 'aedt_version' with value 2024.2
DEBUG - Updating 'non_graphical' with value False
DEBUG - Updating 'active_project' with value C:/Users/ansys/AppData/Local/Temp/tmpc1ub_xi5.ansys/e9_eMobility_IPM_3D.aedt
DEBUG - Updating 'active_design' with value e9_1
DEBUG - Updating 'project_list' with value ['C:/Users/ansys/AppData/Local/Temp/tmpc1ub_xi5.ansys/e9_eMobility_IPM_3D.aedt']
DEBUG - Updating 'design_list' with value {'e9_eMobility_IPM_3D': ['e9', 'e9_1']}
DEBUG - Updating 'selected_process' with value 52475
DEBUG - Updating 'use_grpc' with value True
DEBUG - Updating 'is_toolkit_busy' with value False
DEBUG - Updating 'url' with value 127.0.0.1
DEBUG - Updating 'port' with value 5001
DEBUG - Updating 'debug' with value True
DEBUG - Updating 'toolkit_name' with value common
DEBUG - Updating 'log_file' with value common_backend.log
DEBUG - Properties were updated successfully.
PyAEDT INFO: Project e9_eMobility_IPM_3D Saved correctly
PyAEDT INFO: Desktop has been released.
INFO - AEDT is released.
[11]:
True
Apply skew angle#
Apply the skew angle to rotor slices.
[12]:
toolkit.apply_skew()
DEBUG - Toolkit is not connected to AEDT.
DEBUG - Connecting AEDT.
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.10.0.
PyAEDT INFO: Initializing new Desktop session.
PyAEDT WARNING: Argument `specified_version` is deprecated for method `__init__`; use `version` instead.
PyAEDT WARNING: Argument `new_desktop_session` is deprecated for method `__init__`; use `new_desktop` instead.
PyAEDT INFO: Log on console is enabled.
PyAEDT INFO: Log on file C:\Users\ansys\AppData\Local\Temp\pyaedt_ansys_39d488c3-5f2f-424b-9f1a-02ea723f5944.log is enabled.
PyAEDT INFO: Log on AEDT is disabled.
PyAEDT INFO: Debug logger is disabled. PyAEDT methods will not be logged.
PyAEDT INFO: Launching PyAEDT with gRPC plugin.
PyAEDT INFO: Connecting to AEDT session on gRPC port 52475
PyAEDT INFO: AEDT installation Path C:\Program Files\AnsysEM\v242\Win64
DEBUG - Toolkit is connected to AEDT.
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.10.0.
PyAEDT INFO: Returning found Desktop session with PID 4964!
PyAEDT INFO: Project e9_eMobility_IPM_3D set to active.
PyAEDT INFO: Aedt Objects correctly read
INFO - Toolkit is connected to AEDT design.
PyAEDT INFO: Modeler class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Parsing design objects. This operation can take time
PyAEDT INFO: Parsing C:/Users/ansys/AppData/Local/Temp/tmpc1ub_xi5.ansys/e9_eMobility_IPM_3D.aedt.
PyAEDT INFO: File C:/Users/ansys/AppData/Local/Temp/tmpc1ub_xi5.ansys/e9_eMobility_IPM_3D.aedt correctly loaded. Elapsed time: 0m 1sec
PyAEDT INFO: aedt file load time 1.4381940364837646
PyAEDT INFO: 3D Modeler objects parsed. Elapsed time: 0m 2sec
PyAEDT INFO: Union of 2 objects has been executed.
PyAEDT INFO: Desktop has been released.
INFO - AEDT is released.
[12]:
True
Validate and analyze design#
Uncomment the line to validate and analyze the design.
toolkit.validate_and_analyze()
Create magnet loss report#
Uncomment the lines to create magnet loss report and compute average value.
magnet_loss = toolkit.get_magnet_loss() print(f”Average magnet loss: {magnet_loss[‘SolidLoss’][‘Value’]}{magnet_loss[‘SolidLoss’][‘Unit’]}”)
Save and release AEDT#
Save and release AEDT.
toolkit.save_project()
[13]:
toolkit.release_aedt(True, True)
DEBUG - Toolkit is not connected to AEDT.
DEBUG - Connecting AEDT.
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.10.0.
PyAEDT INFO: Initializing new Desktop session.
PyAEDT WARNING: Argument `specified_version` is deprecated for method `__init__`; use `version` instead.
PyAEDT WARNING: Argument `new_desktop_session` is deprecated for method `__init__`; use `new_desktop` instead.
PyAEDT INFO: Log on console is enabled.
PyAEDT INFO: Log on file C:\Users\ansys\AppData\Local\Temp\pyaedt_ansys_39d488c3-5f2f-424b-9f1a-02ea723f5944.log is enabled.
PyAEDT INFO: Log on AEDT is disabled.
PyAEDT INFO: Debug logger is disabled. PyAEDT methods will not be logged.
PyAEDT INFO: Launching PyAEDT with gRPC plugin.
PyAEDT INFO: Connecting to AEDT session on gRPC port 52475
PyAEDT INFO: AEDT installation Path C:\Program Files\AnsysEM\v242\Win64
DEBUG - Toolkit is connected to AEDT.
PyAEDT INFO: Desktop has been released and closed.
INFO - AEDT is released.
[13]:
True
Remove temporary folder#
Remove the temporary folder.
[14]:
shutil.rmtree(temp_dir.name, ignore_errors=True)