.. 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 32-40 .. 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 47-52 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 52-57 .. 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 62-66 Start a PRIME session --------------------- Start a PRIME session and get the model from the client. .. GENERATED FROM PYTHON SOURCE LINES 66-72 .. 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 .. GENERATED FROM PYTHON SOURCE LINES 73-78 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 78-98 .. 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=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) 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_tet_cells : 0 n_pyra_cells : 0 n_prism_cells : 0 n_poly_cells : 0 n_hex_cells : 0 n_unmeshed_topo_faces : 0 /opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/site-packages/pyvista/core/pointset.py:1365: PyVistaDeprecationWarning: The current behavior of `pv.PolyData.n_faces` has been deprecated. Use `pv.PolyData.n_cells` or `pv.PolyData.n_faces_strict` instead. See the documentation in '`pv.PolyData.n_faces` for more information. warnings.warn( .. GENERATED FROM PYTHON SOURCE LINES 99-109 Mesh generation --------------- The mesh is generated using the Ansys PRIME API. The mesh is generated using the following steps: 1. Initialize the connection tolerance and other parameters. 2. Scaffold the part. 3. Mesh the surfaces. 4. Write the mesh to a file. .. GENERATED FROM PYTHON SOURCE LINES 109-132 .. code-block:: Python # Initialize the connection tolerance and other parameters -- # # Target element size element_size = 0.5 # Initialize the parameters params = prime.ScaffolderParams( model, absolute_dist_tol=0.1 * element_size, intersection_control_mask=prime.IntersectionMask.FACEFACEANDEDGEEDGE, constant_mesh_size=element_size, ) # Get existing topoface or topoedge IDs faces = part.get_topo_faces() beams = [] scaffold_res = prime.Scaffolder(model, part.id).scaffold_topo_faces_and_beams( topo_faces=faces, topo_beams=beams, params=params ) print(scaffold_res) .. rst-class:: sphx-glr-script-out .. code-block:: none n_incomplete_topo_faces : 0 error_code : 0 .. GENERATED FROM PYTHON SOURCE LINES 133-138 Surface meshing --------------- The surface mesh is generated using the previous element size and the topological faces of the part. .. GENERATED FROM PYTHON SOURCE LINES 138-153 .. code-block:: Python surfer_params = prime.SurferParams( model=model, size_field_type=prime.SizeFieldType.CONSTANT, constant_size=element_size, generate_quads=True, ) surfer_result = prime.Surfer(model).mesh_topo_faces(part.id, topo_faces=faces, params=surfer_params) # Display the mesh 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_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 .. GENERATED FROM PYTHON SOURCE LINES 154-159 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 159-164 .. code-block:: Python mapdl_cdb = Path(OUTPUT_DIR, "modeling_demo.cdb") file_io.export_mapdl_cdb(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 165-169 Close the PRIME session ----------------------- Close the PRIME session to release the resources. This is important to prevent memory leaks. .. GENERATED FROM PYTHON SOURCE LINES 169-170 .. code-block:: Python prime_client.exit() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 30.345 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 `