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 display package to visualize the results of the study.

Units are SI (m, kg, s, K) unless otherwise noted.

Perform required imports and create study#

Perform the required imports and create a ParametricStudy instance.

from ansys.additive.core import Additive
from ansys.additive.core.parametric_study import ParametricStudy

from ansys.additive.widgets import display

study = ParametricStudy("microstructure-study")
Saving parametric study to /home/runner/work/pyadditive-widgets/pyadditive-widgets/examples/microstructure-study.ps

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.

print(study.file_name)
/home/runner/work/pyadditive-widgets/pyadditive-widgets/examples/microstructure-study.ps

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.

additive = Additive()
additive.materials_list()
material = "IN718"
user data path: /home/runner/.local/share/pyadditive

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 generate_microstructure_permutations() method to add microstructure simulations to the study.

# 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,
)

Show simulations as a table#

Use the display package to list the simulations as a table.

display.show_table(study)
02 microstructure study
show_table

Run microstructure simulations#

Run the simulations using the run_simulations() method.

study.run_simulations(additive)
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

Plot microstructure results#

Plot and compare the average grain sizes from the microstructure simulations using the ave_grain_size_plot() function.

display.ave_grain_size_plot(study)
02 microstructure study
ave_grain_size_plot

Total running time of the script: (25 minutes 13.331 seconds)

Gallery generated by Sphinx-Gallery