Get material properties from the result file#

Material properties are assigned to each element in APDL and by default they are written out in the APDL result file. This example shows how you can extract material properties of each element using PyDPF-Core.

# Import necessary modules
from ansys.dpf import core as dpf
from ansys.dpf.core import examples

Create a model object to establish a connection with an example result file.

model = dpf.Model(examples.find_simple_bar())

Get the meshed_region from model’s metadata.

mesh = model.metadata.meshed_region
print(mesh)
DPF  Meshed Region:
  3751 nodes
  3000 elements
  Unit: m
  With solid (3D) elements

See available properties in the meshed_region.

print(mesh.available_property_fields)
['connectivity', 'elprops', 'eltype', 'apdl_element_type', 'section', 'mat']

Get all material properties.

mats = mesh.property_field("mat")

Use the DPF operator mapdl_material_properties to extract data for the # materials - mats. For the input properties_name, you need the correct material property string. To see which strings are supported, you can print the operator help.

mat_prop = model.operator("mapdl_material_properties")
mat_prop.inputs.materials.connect(mats)

For the input pin properties_name, you need the correct material property string. To see which strings are supported, you can print the operator help.

print(mat_prop)
DPF mapdl_material_properties Operator:
  Read the values of the properties of a material for a given materials property field (property field that contains materials information for each element of a mesh).It returns a fields container containing a field for each material property, with only one value per material. The following keys can be used: Young's modulus (keys: EX, EY, EZ), Poisson's ratio (keys: NUXY, NUYZ, NUXZ), Shear Modulus (keys: GXY, GYZ, GXZ), Coefficient of Thermal Expansion (keys: ALPX, ALPY, ALPZ), Volumic Mass (key: DENS), second Lame's coefficient (key: MU), Damping coefficient (key: DAMP), thermal Conductivity (keys: KXX, KYY, KZZ), Resistivity (keys: RSVX, RSVY, RSVZ), Specific heat in constant volume (key: C), Film coefficient (key: HF), Viscosity (key: VISC), Emissivity (key: EMIS).
  Inputs:
         properties_name [string, vector<string>]
         materials [property_field]: Property field that contains a material id per element.
         streams_container [streams_container]
         data_sources [data_sources]
  Outputs:
         properties_value [fields_container]

To extract the Young’s modulus for element ID 1, first we need to get the mat_id for EID 1.

mat_id = mats.get_entity_data_by_id(1)

And then use the mat_id get the material property.

mat_prop.inputs.properties_name.connect("EX")
mat_field = mat_prop.outputs.properties_value.get_data()[0]
print(mat_field.get_entity_data_by_id(mat_id[0]))
[2.e+11]

Extract Poisson’s ratio for element ID 1.

mat_prop.inputs.properties_name.connect("NUXY")
mat_field = mat_prop.outputs.properties_value.get_data()[0]
print(mat_field.get_entity_data_by_id(mat_id[0]))
[0.3]

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

Gallery generated by Sphinx-Gallery