.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/gallery_examples/01_porosity_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_01_porosity_study.py: Porosity evaluation plot ======================== This example shows how to use PyAdditive-Widgets to visualize the results of a parametric study containing porosity 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("porosity-study") .. rst-class:: sphx-glr-script-out .. code-block:: none Saving parametric study to /home/runner/work/pyadditive-widgets/pyadditive-widgets/examples/porosity-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/porosity-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 porosity evaluation -------------------------- Generate a set of porosity simulations using the :meth:`~ParametricStudy.generate_porosity_permutations` method. This method's parameters allow you to specify the material and machine parameters for the simulations. Not all parameters are required. Optional parameters that are not specified use the default values defined in the :class:`MachineConstants` class. .. GENERATED FROM PYTHON SOURCE LINES 73-107 .. code-block:: Python # Specify a range of laser powers. Valid values are 50 to 700 W. laser_powers = [50, 150, 250, 350] # Specify a range of laser scan speeds. Valid values are 0.35 to 2.5 m/s. scan_speeds = [0.35, 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] stripe_widths = [0.05] study.generate_porosity_permutations( material_name=material, laser_powers=laser_powers, scan_speeds=scan_speeds, size_x=1e-3, size_y=1e-3, size_z=1e-3, layer_thicknesses=layer_thicknesses, heater_temperatures=heater_temperatures, beam_diameters=beam_diameters, start_angles=start_angles, rotation_angles=rotation_angles, hatch_spacings=hatch_spacings, stripe_widths=stripe_widths, iteration=1, ) .. GENERATED FROM PYTHON SOURCE LINES 108-112 Show simulations as a table --------------------------- Use the :obj:`display ` package to list the simulations as a table. .. GENERATED FROM PYTHON SOURCE LINES 112-115 .. code-block:: Python display.show_table(study) .. image-sg:: /examples/gallery_examples/images/sphx_glr_01_porosity_study_001.png :alt: 01 porosity study :srcset: /examples/gallery_examples/images/sphx_glr_01_porosity_study_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none show_table .. GENERATED FROM PYTHON SOURCE LINES 116-119 Run porosity simulations ------------------------ Run the simulations using the :meth:`~ParametricStudy.run_simulations` method. .. GENERATED FROM PYTHON SOURCE LINES 119-122 .. code-block:: Python study.run_simulations(additive) .. rst-class:: sphx-glr-script-out .. code-block:: none 2024-06-14 17:49:37 Completed 0 of 12 simulations 2024-06-14 17:52:29 Completed 1 of 12 simulations 2024-06-14 17:54:28 Completed 2 of 12 simulations 2024-06-14 17:55:57 Completed 3 of 12 simulations 2024-06-14 18:01:42 Completed 4 of 12 simulations 2024-06-14 18:04:33 Completed 5 of 12 simulations 2024-06-14 18:06:15 Completed 6 of 12 simulations 2024-06-14 18:31:08 Completed 7 of 12 simulations 2024-06-14 18:39:35 Completed 8 of 12 simulations 2024-06-14 18:42:46 Completed 9 of 12 simulations 2024-06-14 19:17:25 Completed 10 of 12 simulations 2024-06-14 19:37:36 Completed 11 of 12 simulations 2024-06-14 19:45:03 Completed 12 of 12 simulations .. GENERATED FROM PYTHON SOURCE LINES 123-128 Plot porosity results --------------------- Visualize porosity simulation results for relative density and build rate as a contour plot using the :func:`~ansys.additive.widgets.display.porosity_contour_plot` function. .. GENERATED FROM PYTHON SOURCE LINES 128-131 .. code-block:: Python display.porosity_contour_plot(study) .. image-sg:: /examples/gallery_examples/images/sphx_glr_01_porosity_study_002.png :alt: 01 porosity study :srcset: /examples/gallery_examples/images/sphx_glr_01_porosity_study_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none porosity_contour_plot .. GENERATED FROM PYTHON SOURCE LINES 132-135 Visualize a heat map plot of porosity results to determine parametric regions with desirable relative density statistics using the :func:`~ansys.additive.widgets.display.porosity_eval_plot` function. .. GENERATED FROM PYTHON SOURCE LINES 135-137 .. code-block:: Python display.porosity_eval_plot(study) .. image-sg:: /examples/gallery_examples/images/sphx_glr_01_porosity_study_003.png :alt: 01 porosity study :srcset: /examples/gallery_examples/images/sphx_glr_01_porosity_study_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none porosity_eval_plot .. rst-class:: sphx-glr-timing **Total running time of the script:** (115 minutes 32.139 seconds) .. _sphx_glr_download_examples_gallery_examples_01_porosity_study.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01_porosity_study.ipynb <01_porosity_study.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01_porosity_study.py <01_porosity_study.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_