Using a custom material#

This example shows how to use a custom material in PyAdditive simulations. For background information and file formats, see Material Tuning Tool (Beta) to Create User Defined Materials in the Additive Manufacturing Beta Features documentation. To prevent wasted time, before executing this example, carefully review the steps described in this PyAdditive documentation.

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

Perform required import and connect#

Perform the required import and connect to the Additive service.

from ansys.additive.core import Additive, AdditiveMachine, SingleBeadInput

additive = Additive()

Download custom material#

Download an example of a custom material. Typically, you would have the files defining your custom material stored locally.

import ansys.additive.core.examples as examples

material_files = examples.download_custom_material()

Load custom material files#

Use the load_material() method on the additive object to load custom material defnition files. The method returns an AdditiveMaterial object that you can use in simulations. The AdditiveMaterial object exists only in the current Python session and is not saved.

custom_material = additive.load_material(
    parameters_file=material_files.material_configuration_file,
    thermal_lookup_file=material_files.thermal_properties_lookup_file,
    characteristic_width_lookup_file=material_files.characteristic_width_lookup_file,
)

Use the custom material in a simulation#

Once the custom material has been loaded, you can assign it to a simulation input object.

input = SingleBeadInput(
    machine=AdditiveMachine(),
    material=custom_material,
    bead_length=0.001,  # meters
)

# Remove '#' to run the simulation
# additive.simulate(input)

Add a custom material to the material library#

You can add a custom material to the material library for use in future Python sessions. The add_material() method is similar to the load_material() method, except that it saves the material to the server.

# show current available materials
print(additive.materials_list())

custom_material = additive.add_material(
    parameters_file=material_files.material_configuration_file,
    thermal_lookup_file=material_files.thermal_properties_lookup_file,
    characteristic_width_lookup_file=material_files.characteristic_width_lookup_file,
)

# show updated available materials
print(additive.materials_list())
['17-4PH', 'IN625', 'AlSi10Mg', '316L', 'IN718', 'CoCr', 'Al357', 'Ti64']
['17-4PH', 'IN625', 'AlSi10Mg', '316L', 'IN718', 'CoCr', 'Al357', 'Ti64', 'Vibranium']

Remove the custom material from the material library#

You can remove a custom material from the material library using the remove_material() method. Ansys-supplied materials cannot be removed and will raise an error if you try to remove them.

# show current available materials
print(additive.materials_list())

additive.remove_material(custom_material.name)

# show updated available materials
print(additive.materials_list())
['17-4PH', 'IN625', 'AlSi10Mg', '316L', 'IN718', 'CoCr', 'Al357', 'Ti64', 'Vibranium']
['17-4PH', 'IN625', 'AlSi10Mg', '316L', 'IN718', 'CoCr', 'Al357', 'Ti64']

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

Gallery generated by Sphinx-Gallery