.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/geometry-mesh/wf_gm_02_mesh.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_geometry-mesh_wf_gm_02_mesh.py: .. _ref_geometry-mesh_02-mesh: Mesh generation ############### This example shows how to generate a mesh from a CAD model. The CAD model is imported from a file, and the mesh is generated using the Ansys PRIME API. .. GENERATED FROM PYTHON SOURCE LINES 33-42 .. code-block:: Python import os from pathlib import Path from ansys.meshing import prime from ansys.meshing.prime.graphics import Graphics .. GENERATED FROM PYTHON SOURCE LINES 50-55 Parameters for the script ------------------------- The following parameters are used to control the script execution. You can modify these parameters to suit your needs. .. GENERATED FROM PYTHON SOURCE LINES 55-60 .. code-block:: Python GRAPHICS_BOOL = False # Set to True to display the graphics OUTPUT_DIR = Path(Path(__file__).parent, "outputs") # Output directory .. GENERATED FROM PYTHON SOURCE LINES 65-69 Start a PRIME session --------------------- Start a PRIME session and get the model from the client. .. GENERATED FROM PYTHON SOURCE LINES 69-75 .. code-block:: Python prime_client = prime.launch_prime(timeout=120) print(prime_client) # Get the model from the client model = prime_client.model .. rst-class:: sphx-glr-script-out .. code-block:: none Using Ansys Prime Server from container ansys-prime-server-1 .. GENERATED FROM PYTHON SOURCE LINES 76-81 Load the CAD file ----------------- Load the CAD file from the previous example. The file is loaded into the model, and the part is extracted. The part is then summarized to get the details of the part. .. GENERATED FROM PYTHON SOURCE LINES 81-102 .. code-block:: Python # Load the FMD file modeling_file = Path(OUTPUT_DIR, "modeling_demo.fmd") file_io = prime.FileIO(model) file_io.import_cad( file_name=str(modeling_file), params=prime.ImportCadParams( model=model, ), ) # Review the part part = model.get_part_by_name("modelingdemo") part_summary_res = part.get_summary(prime.PartSummaryParams(model, print_mesh=False)) print(part_summary_res) # Display the imported geometry if GRAPHICS_BOOL: display = Graphics(model=model) display() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/geometry-mesh/images/sphx_glr_wf_gm_02_mesh_001.png :alt: wf gm 02 mesh :srcset: /examples/geometry-mesh/images/sphx_glr_wf_gm_02_mesh_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/pyansys-workflows/pyansys-workflows/doc/source/examples/geometry-mesh/images/sphx_glr_wf_gm_02_mesh_001.vtksz .. rst-class:: sphx-glr-script-out .. code-block:: none message : Part Name: modelingdemo Part ID: 2 32 Topo Edges 14 Topo Faces 1 Topo Volumes 0 Edge Zones Edge Zone Name(s) : [] 0 Face Zones Face Zone Name(s) : [] 1 Volume Zones Volume Zone Name(s) : [design_body] 0 Label(s) Names: [] Bounding box (-40 -50 0) (40 50 10) n_topo_edges : 32 n_topo_faces : 14 n_topo_volumes : 1 n_edge_zonelets : 0 n_face_zonelets : 0 n_cell_zonelets : 0 n_edge_zones : 0 n_face_zones : 0 n_volume_zones : 1 n_labels : 0 n_nodes : 0 n_faces : 0 n_cells : 0 n_tri_faces : 0 n_poly_faces : 0 n_quad_faces : 0 n_second_order_tri_faces : 0 n_second_order_quad_faces : 0 n_tet_cells : 0 n_pyra_cells : 0 n_prism_cells : 0 n_poly_cells : 0 n_hex_cells : 0 n_second_order_tet_cells : 0 n_second_order_pyra_cells : 0 n_second_order_prism_cells : 0 n_second_order_hex_cells : 0 n_unmeshed_topo_faces : 0 /opt/hostedtoolcache/Python/3.12.14/x64/lib/python3.12/site-packages/ansys/meshing/prime/graphics/plotter.py:362: UserWarning: DeprecationWarning: The `Graphics` class is deprecated. Use the `PrimePlotter` class instead. warnings.warn( .. GENERATED FROM PYTHON SOURCE LINES 103-112 Mesh generation --------------- The mesh is generated using the Ansys PRIME API. The mesh is generated using the following steps: 1. Mesh the surfaces of the part. 2. Mesh the volume of the part. 3. Write the mesh to a file. .. GENERATED FROM PYTHON SOURCE LINES 112-119 .. code-block:: Python # Element size element_size = 4.0 # Get topoface IDs faces = part.get_topo_faces() .. GENERATED FROM PYTHON SOURCE LINES 120-125 Surface meshing --------------- The surface mesh is generated using the previous element size and the topological faces of the part. .. GENERATED FROM PYTHON SOURCE LINES 125-134 .. code-block:: Python surfer_params = prime.SurferParams( model=model, size_field_type=prime.SizeFieldType.CONSTANT, constant_size=element_size, ) surfer_result = prime.Surfer(model).mesh_topo_faces(part.id, topo_faces=faces, params=surfer_params) .. GENERATED FROM PYTHON SOURCE LINES 135-138 Volume meshing --------------- .. GENERATED FROM PYTHON SOURCE LINES 138-158 .. code-block:: Python volume_mesh = prime.AutoMesh(model) auto_mesh_param = prime.AutoMeshParams( model, size_field_type=prime.SizeFieldType.GEOMETRIC, volume_fill_type=prime.VolumeFillType.TET, ) volume_mesh.mesh(part.id, auto_mesh_param) # Display the mesh if GRAPHICS_BOOL: model._model_pv_mesh = None display = Graphics(model=model) display() # Review the mesh part = model.get_part_by_name("modelingdemo") part_summary_res = part.get_summary(prime.PartSummaryParams(model, print_mesh=True)) print(part_summary_res) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/geometry-mesh/images/sphx_glr_wf_gm_02_mesh_002.png :alt: wf gm 02 mesh :srcset: /examples/geometry-mesh/images/sphx_glr_wf_gm_02_mesh_002.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/pyansys-workflows/pyansys-workflows/doc/source/examples/geometry-mesh/images/sphx_glr_wf_gm_02_mesh_002.vtksz .. rst-class:: sphx-glr-script-out .. code-block:: none /opt/hostedtoolcache/Python/3.12.14/x64/lib/python3.12/site-packages/ansys/meshing/prime/graphics/plotter.py:362: UserWarning: DeprecationWarning: The `Graphics` class is deprecated. Use the `PrimePlotter` class instead. warnings.warn( message : Part Name: modelingdemo Part ID: 2 32 Topo Edges 14 Topo Faces 1 Topo Volumes 0 Edge Zones Edge Zone Name(s) : [] 0 Face Zones Face Zone Name(s) : [] 1 Volume Zones Volume Zone Name(s) : [design_body] 0 Label(s) Names: [] Bounding box (-40 -50 0) (40 50 10) Mesh Summary: 2044 Nodes 0 Poly Faces 0 Quad Faces 2994 Tri Faces 2994 Faces 0 Poly Cells 0 Hex Cells 0 Prism Cells 0 Pyramid Cells 7356 Tet Cells 7356 Cells 0 out of 14 TopoFaces are unmeshed n_topo_edges : 32 n_topo_faces : 14 n_topo_volumes : 1 n_edge_zonelets : 0 n_face_zonelets : 0 n_cell_zonelets : 0 n_edge_zones : 0 n_face_zones : 0 n_volume_zones : 1 n_labels : 0 n_nodes : 2044 n_faces : 2994 n_cells : 7356 n_tri_faces : 2994 n_poly_faces : 0 n_quad_faces : 0 n_second_order_tri_faces : 0 n_second_order_quad_faces : 0 n_tet_cells : 7356 n_pyra_cells : 0 n_prism_cells : 0 n_poly_cells : 0 n_hex_cells : 0 n_second_order_tet_cells : 0 n_second_order_pyra_cells : 0 n_second_order_prism_cells : 0 n_second_order_hex_cells : 0 n_unmeshed_topo_faces : 0 .. GENERATED FROM PYTHON SOURCE LINES 159-164 Export the mesh --------------- The mesh is exported to a CDB file. The CDB file can be used to create a MAPDL case. .. GENERATED FROM PYTHON SOURCE LINES 164-169 .. code-block:: Python mapdl_cdb = Path(OUTPUT_DIR, "modeling_demo.cdb") file_io.export_mapdl_cdb(str(mapdl_cdb), params=prime.ExportMapdlCdbParams(model)) assert os.path.exists(mapdl_cdb) print(f"MAPDL case exported at {mapdl_cdb}") .. rst-class:: sphx-glr-script-out .. code-block:: none This get_abaqus_simulation_data is a beta API. The behavior and implementation may change in future. MAPDL case exported at /home/runner/work/pyansys-workflows/pyansys-workflows/geometry-mesh/outputs/modeling_demo.cdb .. GENERATED FROM PYTHON SOURCE LINES 170-174 Close the PRIME session ----------------------- Close the PRIME session to release the resources. This is important to prevent memory leaks. .. GENERATED FROM PYTHON SOURCE LINES 174-175 .. code-block:: Python prime_client.exit() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 31.761 seconds) .. _sphx_glr_download_examples_geometry-mesh_wf_gm_02_mesh.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: wf_gm_02_mesh.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: wf_gm_02_mesh.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: wf_gm_02_mesh.zip `