.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\03-Maxwell\Maxwell3D_Segmentation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_03-Maxwell_Maxwell3D_Segmentation.py: Maxwell 3D: magnet segmentation ------------------------------- This example shows how you can use PyAEDT to segment magnets of an electric motor. The method is valid and usable for any object the user would like to segment. .. GENERATED FROM PYTHON SOURCE LINES 8-11 Perform required imports ~~~~~~~~~~~~~~~~~~~~~~~~ Perform required imports. .. GENERATED FROM PYTHON SOURCE LINES 11-17 .. code-block:: Python from pyaedt import downloads from pyaedt import Maxwell3d import tempfile .. GENERATED FROM PYTHON SOURCE LINES 18-21 Set AEDT version ~~~~~~~~~~~~~~~~ Set AEDT version. .. GENERATED FROM PYTHON SOURCE LINES 21-24 .. code-block:: Python aedt_version = "2024.1" .. GENERATED FROM PYTHON SOURCE LINES 25-28 Create temporary directory ~~~~~~~~~~~~~~~~~~~~~~~~~~ Create temporary directory. .. GENERATED FROM PYTHON SOURCE LINES 28-31 .. code-block:: Python temp_dir = tempfile.TemporaryDirectory(suffix=".ansys") .. GENERATED FROM PYTHON SOURCE LINES 32-36 Set non-graphical mode ~~~~~~~~~~~~~~~~~~~~~~ Set non-graphical mode. You can set ``non_graphical`` either to ``True`` or ``False``. .. GENERATED FROM PYTHON SOURCE LINES 36-39 .. code-block:: Python non_graphical = False .. GENERATED FROM PYTHON SOURCE LINES 40-43 Download .aedt file example ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Set local temporary folder to export the .aedt file to. .. GENERATED FROM PYTHON SOURCE LINES 43-46 .. code-block:: Python aedt_file = downloads.download_file("object_segmentation", "Motor3D_obj_segments.aedt", temp_dir.name) .. GENERATED FROM PYTHON SOURCE LINES 47-50 Launch Maxwell 3D ~~~~~~~~~~~~~~~~~ Launch Maxwell 3D. .. GENERATED FROM PYTHON SOURCE LINES 50-56 .. code-block:: Python m3d = Maxwell3d(projectname=aedt_file, specified_version=aedt_version, new_desktop_session=True, non_graphical=non_graphical) .. rst-class:: sphx-glr-script-out .. code-block:: none C:\actions-runner\_work\_tool\Python\3.10.9\x64\lib\subprocess.py:1072: ResourceWarning: subprocess 2208 is still running _warn("subprocess %s is still running" % self.pid, C:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\pyaedt\generic\settings.py:368: ResourceWarning: unclosed file <_io.TextIOWrapper name='D:\\Temp\\pyaedt_ansys.log' mode='a' encoding='cp1252'> self._logger = val .. GENERATED FROM PYTHON SOURCE LINES 57-60 Create object to access 3D modeler ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create the object ``mod3D`` to access the 3D modeler easily. .. GENERATED FROM PYTHON SOURCE LINES 60-63 .. code-block:: Python modeler = m3d.modeler .. GENERATED FROM PYTHON SOURCE LINES 64-72 Segment first magnet by specifying the number of segments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Select first magnet to segment by specifying the number of segments. The method accepts in input either the list of magnets names to segment or magnets ids or the magnet object :class:`pyaedt.modeler.cad.object3d.Object3d`. ``apply_mesh_sheets`` is enabled which means that the mesh sheets will be applied in the geometry too. In this specific case we give as input the name of the magnet. .. GENERATED FROM PYTHON SOURCE LINES 72-77 .. code-block:: Python segments_number = 5 object_name = "PM_I1" sheets_1 = modeler.objects_segmentation(object_name, segments_number=segments_number, apply_mesh_sheets=True) .. GENERATED FROM PYTHON SOURCE LINES 78-82 Segment second magnet by specifying the number of segments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Select second magnet to segment by specifying the number of segments. In this specific case we give as input the id of the magnet. .. GENERATED FROM PYTHON SOURCE LINES 82-88 .. code-block:: Python segments_number = 4 object_name = "PM_I1_1" magnet_id = [obj.id for obj in modeler.object_list if obj.name == object_name][0] sheets_2 = modeler.objects_segmentation(magnet_id, segments_number=segments_number, apply_mesh_sheets=True) .. GENERATED FROM PYTHON SOURCE LINES 89-93 Segment third magnet by specifying the segmentation thickness ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Select third magnet to segment by specifying the segmentation thickness. In this specific case we give as input the magnet object of type :class:`pyaedt.modeler.cad.object3d.Object3d`. .. GENERATED FROM PYTHON SOURCE LINES 93-99 .. code-block:: Python segmentation_thickness = 1 object_name = "PM_O1" magnet = [obj for obj in modeler.object_list if obj.name == object_name][0] sheets_3 = modeler.objects_segmentation(magnet, segmentation_thickness=segmentation_thickness, apply_mesh_sheets=True) .. GENERATED FROM PYTHON SOURCE LINES 100-104 Segment fourth magnet by specifying the number of segments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Select fourth magnet to segment by specifying the number of segments. In this specific case we give as input the name of the magnet and we disable the mesh sheets. .. GENERATED FROM PYTHON SOURCE LINES 104-109 .. code-block:: Python object_name = "PM_O1_1" segments_number = 10 sheets_4 = modeler.objects_segmentation(object_name, segments_number=segments_number) .. GENERATED FROM PYTHON SOURCE LINES 110-113 Save project and close AEDT ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Save the project and close AEDT. .. GENERATED FROM PYTHON SOURCE LINES 113-117 .. code-block:: Python m3d.save_project() m3d.release_desktop() temp_dir.cleanup() .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 24.839 seconds) .. _sphx_glr_download_examples_03-Maxwell_Maxwell3D_Segmentation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: Maxwell3D_Segmentation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: Maxwell3D_Segmentation.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_