Single bead analysis#

This example shows how to use PyAdditive to determine melt pool characteristics for a given material and machine parameter combinations.

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

Perform required imports and connect#

Perform the required imports and connect to the Additive service.

import os

import matplotlib.pyplot as plt
import pyvista as pv

from ansys.additive.core import (
    Additive,
    AdditiveMachine,
    MeltPoolColumnNames,
    SimulationError,
    SingleBeadInput,
)

additive = Additive()

Get server connection information#

Get server connection information using the about() method.

print(additive.about())
ansys.additive.core version 0.20.dev5
Client side API version: 2.2.2
Server localhost:50052 is connected.
  API version: 2.2.2
  Version: 25.2.0-alpha6

Select material#

Select a material. You can use the materials_list() method to obtain a list of available materials.

print("Available material names: {}".format(additive.materials_list()))
Available material names: ['17-4PH', 'IN625', 'AlSi10Mg', '316L', 'IN718', 'CoCr', 'Al357', 'Ti64']

You can obtain the parameters for a single material by passing a name from the materials list to the material() method.

material = additive.material("IN718")

Specify machine parameters#

Specify machine parameters by first creating an AdditiveMachine object and then assigning the desired values. All values are in SI units (m, kg, s, K) unless otherwise noted.

machine = AdditiveMachine()

# Show available parameters
print(machine)
AdditiveMachine
laser_power: 195 W
scan_speed: 1.0 m/s
heater_temperature: 80 °C
layer_thickness: 5e-05 m
beam_diameter: 0.0001 m
starting_layer_angle: 57 °
layer_rotation_angle: 67 °
hatch_spacing: 0.0001 m
slicing_stripe_width: 0.01 m

Set laser power and scan speed#

Set the laser power and scan speed.

machine.scan_speed = 1  # m/s
machine.laser_power = 300  # W

Specify inputs for single bead simulation#

Create a SingleBeadInput object containing the desired simulation parameters.

input = SingleBeadInput(
    machine=machine,
    material=material,
    bead_length=0.0012,  # meters
    output_thermal_history=True,
    thermal_history_interval=1,
)

Run simulation#

Use the simulate() method of the additive object to run the simulation. The returned object is either a SingleBeadSummary object containing the input and a MeltPool or a SimulationError object.

summary = additive.simulate(input)
if isinstance(summary, SimulationError):
    raise Exception(summary.message)

Plot melt pool statistics#

Obtain a Pandas DataFrame instance containing the melt pool statistics by using the data_frame() method of the melt_pool attribute of the summary object. The column names for the DataFrame instance are described in the documentation for data_frame(). Use the plot() method to plot the melt pool dimensions as a function of bead length.

df = summary.melt_pool.data_frame().multiply(1e6)  # convert from meters to microns
df.index *= 1e3  # convert bead length from meters to millimeters

df.plot(
    y=[
        MeltPoolColumnNames.LENGTH,
        MeltPoolColumnNames.WIDTH,
        MeltPoolColumnNames.DEPTH,
        MeltPoolColumnNames.REFERENCE_WIDTH,
        MeltPoolColumnNames.REFERENCE_DEPTH,
    ],
    ylabel="Melt Pool Dimensions (µm)",
    xlabel="Bead Length (mm)",
    title="Melt Pool Dimensions vs Bead Length",
)
plt.show()
Melt Pool Dimensions vs Bead Length

List melt pool statistics#

You can show a table of the melt pool statistics by typing the name of the data frame object and pressing enter. For brevity, the following code uses the head() method so that only the first few rows are shown. Note, if running this example as a Python script, no output is shown.

length width depth reference_width reference_depth
bead_length
0.00 91.414399 93.027800 27.820900 0.000000 0.000000
0.02 125.782996 120.333999 55.808499 26.588401 5.808540
0.04 148.120999 130.749002 75.404100 64.150102 25.404099
0.06 168.338999 139.558002 89.802198 81.839800 39.802201
0.08 187.985003 145.352006 97.820804 91.859899 47.820799


Save melt pool statistics#

Save the melt pool statistics to a CSV file using the to_csv() method.

df.to_csv("melt_pool.csv")

Plot thermal history#

Plot the thermal history of the single bead simulation using the class pyvista.Plotter. The plot shows the temperature distribution in the melt pool at each time step.

plotter_xy = pv.Plotter(notebook=False, off_screen=True)
plotter_xy.open_gif("thermal_history_xy.gif")

path = summary.melt_pool.thermal_history_output
files = [f for f in os.listdir(path) if f.endswith(".vtk")]

for i in range(len(files)):
    i = f"{i:07}"
    mesh = pv.read(os.path.join(path, f"GridFullThermal_L0000000_T{i}.vtk"))
    plotter_xy.add_mesh(mesh, scalars="Temperature_(C)", cmap="coolwarm")
    plotter_xy.view_xy()
    plotter_xy.write_frame()

plotter_xy.close()
00 additive single bead

Total running time of the script: (2 minutes 52.528 seconds)

Gallery generated by Sphinx-Gallery