.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/gallery_examples/gallery/07_saddle_bracket.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_07_saddle_bracket.py: .. _ref_saddle_thin_hex: =============================================== Mesh a saddle bracket for a structural analysis =============================================== **Summary**: This example demonstrates how to mesh a thin solid with hexahedral and prism cells. Objective ~~~~~~~~~ This example creates a mainly hexahedral mesh on a thin solid volume. .. image:: ../../../images/saddle_bracket.png :align: center :width: 400 :alt: Thin volume hexahedral mesh. Procedure ~~~~~~~~~ * Launch Ansys Prime Server. * Import the CAD geometry. * Quad surface mesh the source face. * Surface mesh the remaining unmeshed TopoFaces with tri surface mesh. * Delete the topology. * Define volume meshing controls to use thin volume meshing. * Volume mesh with hexahedral and prism cells. * Write a CDB file for use in the APDL solver. * Exit the PyPrimeMesh session. .. GENERATED FROM PYTHON SOURCE LINES 58-63 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 63-76 .. code-block:: Python import os import tempfile import ansys.meshing.prime as prime from ansys.meshing.prime.graphics import Graphics prime_client = prime.launch_prime() model = prime_client.model display = Graphics(model=model) mesh_util = prime.lucid.Mesh(model) .. GENERATED FROM PYTHON SOURCE LINES 77-81 Import geometry ~~~~~~~~~~~~~~~ Download the saddle bracket geometry (FMD) file exported by SpaceClaim. Import the geometry and display all. .. GENERATED FROM PYTHON SOURCE LINES 81-94 .. code-block:: Python # For Windows OS users, scdoc is also available: # saddle_bracket = prime.examples.download_saddle_bracket_scdoc() saddle_bracket = prime.examples.download_saddle_bracket_fmd() mesh_util.read(file_name=saddle_bracket) print(model) display = Graphics(model) display() .. image-sg:: /examples/gallery_examples/gallery/images/sphx_glr_07_saddle_bracket_001.png :alt: 07 saddle bracket :srcset: /examples/gallery_examples/gallery/images/sphx_glr_07_saddle_bracket_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Part Summary: Part Name: saddle_bracket Part ID: 2 42 Topo Edges 17 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) : [solid] 12 Label(s) Names: [hole1, hole2, hole3, round_group1, round_group2, round_group4, round_group5, round_group6, round_group7, round_group8, source_thin, target_thin] Bounding box (-27.3636 -0.62 -21.923) (46.7236 27.82 7.62845) .. GENERATED FROM PYTHON SOURCE LINES 95-98 Quad mesh source faces ~~~~~~~~~~~~~~~~~~~~~~ Mesh the source faces for the thin volume control with quads. .. GENERATED FROM PYTHON SOURCE LINES 98-113 .. code-block:: Python scope = prime.lucid.SurfaceScope( part_expression="*", entity_expression="source_thin", scope_evaluation_type=prime.ScopeEvaluationType.LABELS, ) mesh_util.surface_mesh( scope=scope, min_size=2.0, generate_quads=True, ) display() .. image-sg:: /examples/gallery_examples/gallery/images/sphx_glr_07_saddle_bracket_002.png :alt: 07 saddle bracket :srcset: /examples/gallery_examples/gallery/images/sphx_glr_07_saddle_bracket_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 114-120 Surface mesh unmeshed faces ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Mesh unmeshed faces with tri surface mesh. Tri surface mesh on the target and side faces is used to show more clearly that the result of the thin volume control is a hex mesh that is imprinted up to the side faces. All quads could be used for the surface mesh to simplify the process. .. GENERATED FROM PYTHON SOURCE LINES 120-149 .. code-block:: Python part = model.parts[0] all_faces = part.get_topo_faces() meshed_faces = part.get_topo_faces_of_label_name_pattern( label_name_pattern="source_thin", name_pattern_params=prime.NamePatternParams(model), ) unmeshed_faces = [face for face in all_faces if face not in meshed_faces] part.add_labels_on_topo_entities( labels=["unmeshed_faces"], topo_entities=unmeshed_faces, ) scope = prime.lucid.SurfaceScope( part_expression="*", entity_expression="unmeshed_faces", scope_evaluation_type=prime.ScopeEvaluationType.LABELS, ) mesh_util.surface_mesh( scope=scope, min_size=2.0, ) display() .. image-sg:: /examples/gallery_examples/gallery/images/sphx_glr_07_saddle_bracket_003.png :alt: 07 saddle bracket :srcset: /examples/gallery_examples/gallery/images/sphx_glr_07_saddle_bracket_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 150-154 Delete topology ~~~~~~~~~~~~~~~ Delete topology to leave only the surface mesh. This is necessary for the thin volume control to be used. .. GENERATED FROM PYTHON SOURCE LINES 154-163 .. code-block:: Python part.delete_topo_entities( prime.DeleteTopoEntitiesParams( model=model, delete_geom_zonelets=True, delete_mesh_zonelets=False, ) ) .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 164-176 Define volume meshing controls ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Define volume meshing controls to use thin volume meshing. Specify source and target faces for the thin volume using imported labels. Set the number of layers of cells through the thickness of the thin solid to be 4. To create a fully hexahedral and prism mesh the side faces must be imprinted on the side faces. If needed, a buffer region at the sides of the volume can be defined where the volume fill type used for the volume mesh parameters is used to infill. This is useful on more complex geometries, where it provides more robustness of the method. To create a buffer region set ``imprint_sides`` to ``False`` and specify how many rings of cells to ignore at the sides using ``n_ignore_rings``. .. GENERATED FROM PYTHON SOURCE LINES 176-206 .. code-block:: Python auto_mesh_params = prime.AutoMeshParams(model=model) thin_vol_ctrls_ids = [] thin_vol_ctrl = model.control_data.create_thin_volume_control() thin_vol_ctrl.set_source_scope( prime.ScopeDefinition( model=model, label_expression="source_thin", ) ) thin_vol_ctrl.set_target_scope( prime.ScopeDefinition( model=model, label_expression="target_thin", ) ) thin_params = prime.ThinVolumeMeshParams( model=model, n_layers=4, imprint_sides=True, ) thin_vol_ctrl.set_thin_volume_mesh_params(thin_volume_mesh_params=thin_params) thin_vol_ctrls_ids.append(thin_vol_ctrl.id) auto_mesh_params.thin_volume_control_ids = thin_vol_ctrls_ids auto_mesh_params.volume_fill_type = prime.VolumeFillType.TET .. GENERATED FROM PYTHON SOURCE LINES 207-212 Generate volume mesh ~~~~~~~~~~~~~~~~~~~~ Volume mesh to obtain hexahedral and prism mesh. Print mesh summary. Display volume mesh. .. GENERATED FROM PYTHON SOURCE LINES 212-219 .. code-block:: Python volume_mesh = prime.AutoMesh(model=model) result_vol = volume_mesh.mesh(part_id=part.id, automesh_params=auto_mesh_params) print(part.get_summary(prime.PartSummaryParams(model))) display() .. image-sg:: /examples/gallery_examples/gallery/images/sphx_glr_07_saddle_bracket_004.png :alt: 07 saddle bracket :srcset: /examples/gallery_examples/gallery/images/sphx_glr_07_saddle_bracket_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none message : Part Name: saddle_bracket Part ID: 2 42 Edge Zonelets 17 Face Zonelets 1 Cell Zonelets 0 Edge Zones Edge Zone Name(s) : [] 0 Face Zones Face Zone Name(s) : [] 1 Volume Zones Volume Zone Name(s) : [solid] 13 Label(s) Names: [hole1, hole2, hole3, round_group1, round_group2, round_group4, round_group5, round_group6, round_group7, round_group8, source_thin, target_thin, unmeshed_faces] Bounding box (-27.3636 -0.62 -21.923) (46.7236 27.82 7.62845) Mesh Summary: 4640 Nodes 0 Poly Faces 2266 Quad Faces 26 Tri Faces 2292 Faces 0 Poly Cells 3180 Hex Cells 52 Prism Cells 0 Pyramid Cells 0 Tet Cells 3232 Cells n_topo_edges : 0 n_topo_faces : 0 n_topo_volumes : 0 n_edge_zonelets : 42 n_face_zonelets : 17 n_cell_zonelets : 1 n_edge_zones : 0 n_face_zones : 0 n_volume_zones : 1 n_labels : 13 n_nodes : 4640 n_faces : 2292 n_cells : 3232 n_tri_faces : 26 n_poly_faces : 0 n_quad_faces : 2266 n_tet_cells : 0 n_pyra_cells : 0 n_prism_cells : 52 n_poly_cells : 0 n_hex_cells : 3180 n_unmeshed_topo_faces : 0 .. GENERATED FROM PYTHON SOURCE LINES 220-223 Write mesh ~~~~~~~~~~ Write a CDB file for use in the MAPDL solver. .. GENERATED FROM PYTHON SOURCE LINES 223-230 .. code-block:: Python with tempfile.TemporaryDirectory() as temp_folder: mesh_file = os.path.join(temp_folder, "saddle_bracket.cdb") mesh_util.write(mesh_file) assert os.path.exists(mesh_file) print("\nExported file:\n", mesh_file) .. rst-class:: sphx-glr-script-out .. code-block:: none Exported file: /tmp/tmpuvw8u_tx/saddle_bracket.cdb .. GENERATED FROM PYTHON SOURCE LINES 231-233 Exit PyPrimeMesh ~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 233-235 .. code-block:: Python prime_client.exit() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 19.401 seconds) .. _sphx_glr_download_examples_gallery_examples_gallery_07_saddle_bracket.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 07_saddle_bracket.ipynb <07_saddle_bracket.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 07_saddle_bracket.py <07_saddle_bracket.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_