.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/gallery_examples/02_microstructure_study.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_02_microstructure_study.py: Microstructure average grain size plot ====================================== This example shows how to use PyAdditive-Widgets to visualize the results of a parametric study containing microstructure simulations. It uses the :obj:`display ` package to visualize the results of the study. Units are SI (m, kg, s, K) unless otherwise noted. .. GENERATED FROM PYTHON SOURCE LINES 34-37 Perform required imports and create study ----------------------------------------- Perform the required imports and create a :class:`ParametricStudy` instance. .. GENERATED FROM PYTHON SOURCE LINES 37-44 .. code-block:: Python from ansys.additive.core import Additive from ansys.additive.core.parametric_study import ParametricStudy from ansys.additive.widgets import display study = ParametricStudy("microstructure-study") .. rst-class:: sphx-glr-script-out .. code-block:: none Saving parametric study to /home/runner/work/pyadditive-widgets/pyadditive-widgets/examples/microstructure-study.ps .. GENERATED FROM PYTHON SOURCE LINES 45-50 Get name of study file ---------------------- The current state of the parametric study is saved to a file on each update. This code retrieves the name of the file. This file uses a binary format and is not human readable. .. GENERATED FROM PYTHON SOURCE LINES 50-53 .. code-block:: Python print(study.file_name) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/work/pyadditive-widgets/pyadditive-widgets/examples/microstructure-study.ps .. GENERATED FROM PYTHON SOURCE LINES 54-59 Select material for study ------------------------- Select a material to use in the study. The material name must be known by the Additive service. You can connect to the Additive service and print a list of available materials prior to selecting one. .. GENERATED FROM PYTHON SOURCE LINES 59-64 .. code-block:: Python additive = Additive() additive.materials_list() material = "IN718" .. rst-class:: sphx-glr-script-out .. code-block:: none user data path: /home/runner/.local/share/pyadditive .. GENERATED FROM PYTHON SOURCE LINES 65-73 Create microstructure evaluation -------------------------------- The following code generates a set of microstructure simulations using many of the same parameters used for the porosity simulations in the previous example. Because the ``cooling_rate``, ``thermal_gradient``, ``melt_pool_width``, and ``melt_pool_depth`` parameters are not specified, they are calculated. The code then uses the :meth:`~ParametricStudy.generate_microstructure_permutations` method to add microstructure simulations to the study. .. GENERATED FROM PYTHON SOURCE LINES 73-106 .. code-block:: Python # Specify a range of laser powers. Valid values are 50 to 700 W. laser_powers = [150, 250, 350] # Specify a range of laser scan speeds. Valid values are 0.35 to 2.5 m/s. scan_speeds = [0.5, 0.7] # Specify a range of layer thicknesses. Valid values are 10-6 to 100e-6 m. layer_thicknesses = [40e-6] # Specify a range of heater temperatures. Valid values 20 - 500 C. heater_temperatures = [80] # Specify laser beam diameters. Valid values are 20e-6 to 140e-6 m. beam_diameters = [80e-6] # Specify the machine parameters for the simulations. start_angles = [45] rotation_angles = [67.5] hatch_spacings = [100e-6] study.generate_microstructure_permutations( material_name=material, laser_powers=laser_powers, scan_speeds=scan_speeds, size_x=1e-3, size_y=1e-3, size_z=1.1e-3, sensor_dimension=1e-4, layer_thicknesses=layer_thicknesses, heater_temperatures=heater_temperatures, beam_diameters=beam_diameters, start_angles=start_angles, rotation_angles=rotation_angles, hatch_spacings=hatch_spacings, iteration=2, ) .. GENERATED FROM PYTHON SOURCE LINES 107-111 Show simulations as a table --------------------------- Use the :obj:`display ` package to list the simulations as a table. .. GENERATED FROM PYTHON SOURCE LINES 111-114 .. code-block:: Python display.show_table(study) .. image-sg:: /examples/gallery_examples/images/sphx_glr_02_microstructure_study_001.png :alt: 02 microstructure study :srcset: /examples/gallery_examples/images/sphx_glr_02_microstructure_study_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none show_table .. GENERATED FROM PYTHON SOURCE LINES 115-118 Run microstructure simulations ------------------------------ Run the simulations using the :meth:`~ParametricStudy.run_simulations` method. .. GENERATED FROM PYTHON SOURCE LINES 118-121 .. code-block:: Python study.run_simulations(additive) .. rst-class:: sphx-glr-script-out .. code-block:: none 2024-06-14 19:45:09 Completed 0 of 6 simulations 2024-06-14 19:47:11 Completed 1 of 6 simulations 2024-06-14 19:48:39 Completed 2 of 6 simulations 2024-06-14 19:52:16 Completed 3 of 6 simulations 2024-06-14 19:53:59 Completed 4 of 6 simulations 2024-06-14 20:06:31 Completed 5 of 6 simulations 2024-06-14 20:10:18 Completed 6 of 6 simulations .. GENERATED FROM PYTHON SOURCE LINES 122-127 Plot microstructure results --------------------------- Plot and compare the average grain sizes from the microstructure simulations using the :func:`~ansys.additive.widgets.display.ave_grain_size_plot` function. .. GENERATED FROM PYTHON SOURCE LINES 127-129 .. code-block:: Python display.ave_grain_size_plot(study) .. image-sg:: /examples/gallery_examples/images/sphx_glr_02_microstructure_study_002.png :alt: 02 microstructure study :srcset: /examples/gallery_examples/images/sphx_glr_02_microstructure_study_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none ave_grain_size_plot .. rst-class:: sphx-glr-timing **Total running time of the script:** (25 minutes 13.331 seconds) .. _sphx_glr_download_examples_gallery_examples_02_microstructure_study.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 02_microstructure_study.ipynb <02_microstructure_study.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 02_microstructure_study.py <02_microstructure_study.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_