Porosity analysis#

This example shows how you can use PyAdditive to determine porosity for a given material and machine parameter combinations.

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, PorosityInput, SimulationError

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

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: ['316L', 'Ti64', '17-4PH', 'CoCr', 'IN718', 'IN625', 'AlSi10Mg', 'Al357']

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

material = additive.material("316L")

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.2  # m/s
machine.laser_power = 250  # W

Specify inputs for porosity simulation#

Create a PorosityInput object containing the desired simulation parameters.

input = PorosityInput(
    machine=machine,
    material=material,
    id="porosity-example",
    size_x=0.001,  # meters
    size_y=0.001,
    size_z=0.001,
)

Run simulation#

Use the simulate() method of the additive object to run the simulation. The returned object is either a PorositySummary object containing the input and the relative density of the simulated sample or a SimulationError object.

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