.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "examples/gallery_examples/gallery/02_lucid_mixing_elbow.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_examples_gallery_examples_gallery_02_lucid_mixing_elbow.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_examples_gallery_examples_gallery_02_lucid_mixing_elbow.py:


.. _ref_mixing_elbow_mesh:

=======================================
Mesh a mixing elbow for a flow analysis
=======================================

**Summary**: This example demonstrates how to mesh a mixing elbow for a flow analysis.

Objective
~~~~~~~~~

This example meshes a mixing elbow with polyhedral elements and wall boundary
layer refinement. It uses several meshing utilities available in the ``lucid`` class for
convenience and ease.

.. image:: ../../../images/elbow.png
   :align: center
   :width: 400
   :alt: Mixing elbow mesh.

Procedure
~~~~~~~~~
#. Launch Ansys Prime Server and instantiate meshing utilities from the ``lucid`` class.
#. Import the geometry and create face zones from labels imported from the geometry.
#. Surface mesh geometry with curvature sizing.
#. Volume mesh with polyhedral elements and boundary layer refinement.
#. Print statistics on the generated mesh.
#. Write a CAS file for use in the Fluent solver.
#. Exit the PyPrimeMesh session.

.. GENERATED FROM PYTHON SOURCE LINES 57-63

Launch Ansys Prime Server
~~~~~~~~~~~~~~~~~~~~~~~~~
Import all necessary modules.
Launch an instance of Ansys Prime Server.
Connect the PyPrimeMesh client and get the model.
Instantiate meshing utilities from the ``lucid`` class.

.. GENERATED FROM PYTHON SOURCE LINES 63-74

.. 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
    mesh_util = prime.lucid.Mesh(model=model)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    Using Ansys Prime Server from container ansys-prime-server-3




.. GENERATED FROM PYTHON SOURCE LINES 75-80

Import geometry
~~~~~~~~~~~~~~~
Download the elbow geometry (FMD) file exported by SpaceClaim.
Import the geometry.
Create face zones from labels imported from the geometry for use in Fluent solver.

.. GENERATED FROM PYTHON SOURCE LINES 80-90

.. code-block:: Python



    # For Windows OS users, scdoc is also available:
    # mixing_elbow = prime.examples.download_elbow_scdoc()

    mixing_elbow = prime.examples.download_elbow_fmd()

    mesh_util.read(file_name=mixing_elbow)
    mesh_util.create_zones_from_labels("inlet,outlet")








.. GENERATED FROM PYTHON SOURCE LINES 91-95

Surface mesh
~~~~~~~~~~~~
Surface mesh the geometry setting minimum and maximum sizing
to use for curvature refinement.

.. GENERATED FROM PYTHON SOURCE LINES 95-98

.. code-block:: Python


    mesh_util.surface_mesh(min_size=5, max_size=20)








.. GENERATED FROM PYTHON SOURCE LINES 99-106

Volume mesh
~~~~~~~~~~~
Volume mesh with polyhedral elements and boundary layer refinement.
Fill the volume with polyhedral and prism mesh
specifying the location and number of layers for prisms.
Use expressions to define the surfaces to have prisms grown
where ``* !inlet !outlet`` states ``all not inlet or outlet``.

.. GENERATED FROM PYTHON SOURCE LINES 106-118

.. code-block:: Python


    mesh_util.volume_mesh(
        volume_fill_type=prime.VolumeFillType.POLY,
        prism_surface_expression="* !inlet !outlet",
        prism_layers=3,
    )

    # Display the mesh
    pl = PrimePlotter(allow_picking=True)
    pl.plot(model)
    pl.show()








.. tab-set::



   .. tab-item:: Static Scene



            
     .. image-sg:: /examples/gallery_examples/gallery/images/sphx_glr_02_lucid_mixing_elbow_001.png
        :alt: 02 lucid mixing elbow
        :srcset: /examples/gallery_examples/gallery/images/sphx_glr_02_lucid_mixing_elbow_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_02_lucid_mixing_elbow_001.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 119-121

Print mesh statistics
~~~~~~~~~~~~~~~~~~~~~

.. GENERATED FROM PYTHON SOURCE LINES 121-142

.. code-block:: Python


    # Get meshed part
    part = model.get_part_by_name("flow_volume")

    # Get statistics on the mesh
    part_summary_res = part.get_summary(prime.PartSummaryParams(model=model))

    # Get element quality on all parts in the model
    search = prime.VolumeSearch(model=model)
    params = prime.VolumeQualitySummaryParams(
        model=model,
        scope=prime.ScopeDefinition(model=model, part_expression="*"),
        cell_quality_measures=[prime.CellQualityMeasure.SKEWNESS],
        quality_limit=[0.95],
    )
    results = search.get_volume_quality_summary(params=params)

    # Print statistics on meshed part
    print(part_summary_res)
    print("\nMaximum skewness: ", results.quality_results_part[0].max_quality)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    message :  
    Part Name: flow_volume
    Part ID: 2
        13 Topo Edges
        9 Topo Faces
        1 Topo Volumes

        0 Edge Zones
            Edge Zone Name(s) : []
        2 Face Zones
            Face Zone Name(s) : [inlet, outlet]
        1 Volume Zones
            Volume Zone Name(s) : [volume]

        2 Label(s)
            Names: [inlet, outlet]

        Bounding box (-203.2 -228.6 -50.8)
                     (203.169 203.2 50.8)

        Mesh Summary: 
            38522 Nodes 
            3249 Poly Faces 
            0 Quad Faces 
            0 Tri Faces 
            3249 Faces 
            12090 Poly Cells 
            0 Hex Cells 
            0 Prism Cells 
            0 Pyramid Cells 
            0 Tet Cells 
            12090 Cells 
        0 out of 9 TopoFaces are unmeshed

    n_topo_edges :  13
    n_topo_faces :  9
    n_topo_volumes :  1
    n_edge_zonelets :  0
    n_face_zonelets :  0
    n_cell_zonelets :  0
    n_edge_zones :  0
    n_face_zones :  2
    n_volume_zones :  1
    n_labels :  2
    n_nodes :  38522
    n_faces :  3249
    n_cells :  12090
    n_tri_faces :  0
    n_poly_faces :  3249
    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 :  12090
    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

    Maximum skewness:  0.680207




.. GENERATED FROM PYTHON SOURCE LINES 143-146

Write mesh
~~~~~~~~~~
Write a CAS file for use in the Fluent solver.

.. GENERATED FROM PYTHON SOURCE LINES 146-153

.. code-block:: Python


    with tempfile.TemporaryDirectory() as temp_folder:
        mesh_file = os.path.join(temp_folder, "mixing_elbow.cas")
        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/tmpytmy42vv/mixing_elbow.cas




.. GENERATED FROM PYTHON SOURCE LINES 154-156

Exit PyPrimeMesh
~~~~~~~~~~~~~~~~

.. GENERATED FROM PYTHON SOURCE LINES 156-158

.. code-block:: Python


    prime_client.exit()








.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 15.447 seconds)


.. _sphx_glr_download_examples_gallery_examples_gallery_02_lucid_mixing_elbow.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: 02_lucid_mixing_elbow.ipynb <02_lucid_mixing_elbow.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: 02_lucid_mixing_elbow.py <02_lucid_mixing_elbow.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: 02_lucid_mixing_elbow.zip <02_lucid_mixing_elbow.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_