.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/gallery_examples/gallery/05_pcb_stacker.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_05_pcb_stacker.py: .. _ref_pcb: ========================================== Mesh a PCB for structural thermal analysis ========================================== **Summary**: This example demonstrates how to mesh a printed circuit board with mainly hexahedral elements for structural thermal simulation using the volume sweeper. Objective ~~~~~~~~~~ This example uses the volume sweeper to mesh the solids of a printed circuit board for a structural thermal analysis using predominantly hexahedral elements. .. image:: ../../../images/pcb_stacker.png :align: center :width: 800 :alt: Thermal structural mesh. Procedure ~~~~~~~~~~ #. Launch an Ansys Prime Server instance and connect the PyPrimeMesh client. #. Read the CAD geometry. #. Create a base face, projecting edge loops and imprinting to capture the geometry. #. Surface mesh the base face with quad elements. #. Stack the base face mesh through the volumes to create a mainly hexahedral volume mesh. #. Write the mesh for the structural thermal analysis. .. GENERATED FROM PYTHON SOURCE LINES 54-59 Launch Ansys Prime Server ~~~~~~~~~~~~~~~~~~~~~~~~~ Import all necessary modules. Launch the Ansys Prime Server instance and connect the client. Get the client model and instantiate meshing utilities from the ``lucid`` class. .. GENERATED FROM PYTHON SOURCE LINES 59-70 .. code-block:: Python import os import tempfile import ansys.meshing.prime as prime from ansys.meshing.prime.graphics import PrimePlotter prime_client = prime.launch_prime() model = prime_client.model mesh_util = prime.lucid.Mesh(model=model) .. GENERATED FROM PYTHON SOURCE LINES 71-78 Import geometry ~~~~~~~~~~~~~~~ Download the PCB geometry (PMDAT) file. Import the geometry. Display the imported geometry. Purple edges indicate that the geometry is connected and the topology is shared between the different volumes. This means that the mesh is also to be connected between volumes. .. GENERATED FROM PYTHON SOURCE LINES 78-97 .. code-block:: Python # For Windows OS users, SCDOC files are also available. # To read the geometry as connected with shared topology, you must use # the Workbench ``CadReaderRoute``: # mesh_util.read( # file_name=prime.examples.download_pcb_scdoc(), # cad_reader_route=prime.CadReaderRoute.WORKBENCH, # ) mesh_util.read(file_name=prime.examples.download_pcb_pmdat()) display = PrimePlotter() display.plot(model) display.show() sizing_params = prime.GlobalSizingParams(model=model, min=0.5, max=1.0) model.set_global_sizing_params(params=sizing_params) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/gallery_examples/gallery/images/sphx_glr_05_pcb_stacker_001.png :alt: 05 pcb stacker :srcset: /examples/gallery_examples/gallery/images/sphx_glr_05_pcb_stacker_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_05_pcb_stacker_001.vtksz .. GENERATED FROM PYTHON SOURCE LINES 98-110 Create base face ~~~~~~~~~~~~~~~~ Define stacker parameters: - Set the direction vector for defining stacking. - Set the maximum offset size for mesh layers created by the stacker method. - Set the base faces to delete after stacking. Create the base face from the part and volumes. Define a label for the generated base faces and display. When coloured by zonelet, the display shows the imprints on the base face. .. GENERATED FROM PYTHON SOURCE LINES 110-138 .. code-block:: Python part = model.parts[0] sweeper = prime.VolumeSweeper(model) stacker_params = prime.MeshStackerParams( model=model, direction=[0, 1, 0], max_offset_size=1.0, delete_base=True, ) createbase_results = sweeper.create_base_face( part_id=part.id, topo_volume_ids=part.get_topo_volumes(), params=stacker_params, ) base_faces = createbase_results.base_face_ids part.add_labels_on_topo_entities(["base_faces"], base_faces) scope = prime.ScopeDefinition(model=model, label_expression="base_faces") display = PrimePlotter() display.plot(model, scope=scope) display.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/gallery_examples/gallery/images/sphx_glr_05_pcb_stacker_002.png :alt: 05 pcb stacker :srcset: /examples/gallery_examples/gallery/images/sphx_glr_05_pcb_stacker_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_05_pcb_stacker_002.vtksz .. GENERATED FROM PYTHON SOURCE LINES 139-142 Surface mesh base face ~~~~~~~~~~~~~~~~~~~~~~ Quad surface mesh the generated base faces for stacking. .. GENERATED FROM PYTHON SOURCE LINES 142-155 .. code-block:: Python base_scope = prime.lucid.SurfaceScope( entity_expression="base_faces", part_expression=part.name, scope_evaluation_type=prime.ScopeEvaluationType.LABELS, ) mesh_util.surface_mesh(min_size=0.5, scope=base_scope, generate_quads=True) display = PrimePlotter() display.plot(model, scope=scope, update=True) display.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/gallery_examples/gallery/images/sphx_glr_05_pcb_stacker_003.png :alt: 05 pcb stacker :srcset: /examples/gallery_examples/gallery/images/sphx_glr_05_pcb_stacker_003.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_05_pcb_stacker_003.vtksz .. GENERATED FROM PYTHON SOURCE LINES 156-160 Stack base face ~~~~~~~~~~~~~~~~~~~~~~ Create a mainly hexahedral volume mesh using the stacker method. Display the volume mesh. .. GENERATED FROM PYTHON SOURCE LINES 160-172 .. code-block:: Python stackbase_results = sweeper.stack_base_face( part_id=part.id, base_face_ids=base_faces, topo_volume_ids=part.get_topo_volumes(), params=stacker_params, ) display = PrimePlotter() display.plot(model, update=True) display.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/gallery_examples/gallery/images/sphx_glr_05_pcb_stacker_004.png :alt: 05 pcb stacker :srcset: /examples/gallery_examples/gallery/images/sphx_glr_05_pcb_stacker_004.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_05_pcb_stacker_004.vtksz .. GENERATED FROM PYTHON SOURCE LINES 173-176 Write mesh ~~~~~~~~~~ Write a CDB file. .. GENERATED FROM PYTHON SOURCE LINES 176-183 .. code-block:: Python with tempfile.TemporaryDirectory() as temp_folder: mesh_file = os.path.join(temp_folder, "pcb.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/tmpqzcjzmxc/pcb.cdb .. GENERATED FROM PYTHON SOURCE LINES 184-186 Exit PyPrimeMesh ~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 186-188 .. code-block:: Python prime_client.exit() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 33.839 seconds) .. _sphx_glr_download_examples_gallery_examples_gallery_05_pcb_stacker.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 05_pcb_stacker.ipynb <05_pcb_stacker.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 05_pcb_stacker.py <05_pcb_stacker.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_