.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/gallery_examples/gallery/01_bracket_scaffold.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_gallery_examples_gallery_01_bracket_scaffold.py: .. _ref_bracket_mid_surface_mesh: ===================================================== Mesh a mid-surfaced bracket for a structural analysis ===================================================== **Summary**: This example demonstrates how to use topology-based connection to generate conformal surface mesh. Objective ~~~~~~~~~ To create conformal surface mesh, you can scaffold topofaces, topoedges, or both to connect all the surface bodies and mesh the bracket with quad elements. .. image:: ../../../images/bracket_mid_surface_scaffold_w.png :align: center :width: 400 :alt: Scaffolding result in a wireframe representation. Procedure ~~~~~~~~~ #. Launch Ansys Prime Server. #. Import the CAD geometry and create the part per the CAD model. #. Scaffold topofaces and topoedges with a tolerance parameter. #. Surface mesh topofaces with a constant size and generate quad elements. #. Write a CDB file for use in the APDL solver. #. Exit the PyPrimeMesh session. .. GENERATED FROM PYTHON SOURCE LINES 56-61 Launch Ansys Prime Server ~~~~~~~~~~~~~~~~~~~~~~~~~ Import all necessary modules. Launch an instance of Ansys Prime Server. Connect the PyPrimeMesh client and get the model. .. GENERATED FROM PYTHON SOURCE LINES 61-71 .. code-block:: Python import os import tempfile from ansys.meshing import prime from ansys.meshing.prime.graphics import PrimePlotter prime_client = prime.launch_prime() model = prime_client.model .. GENERATED FROM PYTHON SOURCE LINES 72-77 Import CAD geometry ~~~~~~~~~~~~~~~~~~~ Download the bracket geometry (FMD) file exported by SpaceClaim. Import the CAD geometry. Create the part per the CAD model for the topology-based connection. .. GENERATED FROM PYTHON SOURCE LINES 77-93 .. code-block:: Python # For Windows OS users, scdoc is also available: # bracket_file = prime.examples.download_bracket_scdoc() bracket_file = prime.examples.download_bracket_fmd() file_io = prime.FileIO(model) file_io.import_cad( file_name=bracket_file, params=prime.ImportCadParams( model=model, length_unit=prime.LengthUnit.MM, part_creation_type=prime.PartCreationType.MODEL, ), ) .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 94-105 Review the part ~~~~~~~~~~~~~~~ Get the part summary. Display the model to show edges by connection. Use keyboard shortcuts to switch between the surface (``s``) and wireframe (``w``) representations. Color code for edge connectivity: - Red: free - Black: double - Purple: triple .. GENERATED FROM PYTHON SOURCE LINES 105-114 .. code-block:: Python part = model.get_part_by_name('bracket_mid_surface-3') part_summary_res = part.get_summary(prime.PartSummaryParams(model, print_mesh=False)) print(part_summary_res) display = PrimePlotter() display.add_model(model) display.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/gallery_examples/gallery/images/sphx_glr_01_bracket_scaffold_001.png :alt: 01 bracket scaffold :srcset: /examples/gallery_examples/gallery/images/sphx_glr_01_bracket_scaffold_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/pyprimemesh/pyprimemesh/doc/source/examples/gallery_examples/gallery/images/sphx_glr_01_bracket_scaffold_001.vtksz .. rst-class:: sphx-glr-script-out .. code-block:: none message : Part Name: bracket_mid_surface-3 Part ID: 2 67 Topo Edges 9 Topo Faces 0 Topo Volumes 0 Edge Zones Edge Zone Name(s) : [] 5 Face Zones Face Zone Name(s) : [midsurface1.1, midsurface2, midsurface3, midsurface4, midsurface1.2] 0 Volume Zones Volume Zone Name(s) : [] 3 Label(s) Names: [back, hole_d14, hole_d20] Bounding box (1 1 0) (20 30 30) n_topo_edges : 67 n_topo_faces : 9 n_topo_volumes : 0 n_edge_zonelets : 0 n_face_zonelets : 0 n_cell_zonelets : 0 n_edge_zones : 0 n_face_zones : 5 n_volume_zones : 0 n_labels : 3 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 .. GENERATED FROM PYTHON SOURCE LINES 115-120 Connection ~~~~~~~~~~ Initialize the connection tolerance and other parameters. (The connection tolerance is smaller than the target element size.) Scaffold the topofaces, topoedges, or both with connection parameters. .. GENERATED FROM PYTHON SOURCE LINES 120-140 .. code-block:: Python # Target element size element_size = 0.5 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 : ErrorCode.NOERROR .. GENERATED FROM PYTHON SOURCE LINES 141-145 Surface mesh ~~~~~~~~~~~~ Initialize surface meshing parameters. Mesh topofaces with the constant size and generate quad elements. .. GENERATED FROM PYTHON SOURCE LINES 145-160 .. 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 pl = PrimePlotter() pl.plot(model, update=True) pl.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/gallery_examples/gallery/images/sphx_glr_01_bracket_scaffold_002.png :alt: 01 bracket scaffold :srcset: /examples/gallery_examples/gallery/images/sphx_glr_01_bracket_scaffold_002.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/pyprimemesh/pyprimemesh/doc/source/examples/gallery_examples/gallery/images/sphx_glr_01_bracket_scaffold_002.vtksz .. GENERATED FROM PYTHON SOURCE LINES 161-164 Write mesh ~~~~~~~~~~ Write a CDB file for use in the APDL solver. .. GENERATED FROM PYTHON SOURCE LINES 164-171 .. code-block:: Python with tempfile.TemporaryDirectory() as temp_folder: mapdl_cdb = os.path.join(temp_folder, 'bracket_scaffold.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 MAPDL case exported at /tmp/tmph02krf_z/bracket_scaffold.cdb .. GENERATED FROM PYTHON SOURCE LINES 172-174 Exit the PyPrimeMesh session ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 174-176 .. code-block:: Python prime_client.exit() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 16.782 seconds) .. _sphx_glr_download_examples_gallery_examples_gallery_01_bracket_scaffold.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01_bracket_scaffold.ipynb <01_bracket_scaffold.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01_bracket_scaffold.py <01_bracket_scaffold.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_