.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\00-basic\12-get_material_properties.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_00-basic_12-get_material_properties.py: .. _ref_get_material_properties: 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. .. GENERATED FROM PYTHON SOURCE LINES 12-17 .. code-block:: Python # Import necessary modules from ansys.dpf import core as dpf from ansys.dpf.core import examples .. GENERATED FROM PYTHON SOURCE LINES 18-19 Create a model object to establish a connection with an example result file. .. GENERATED FROM PYTHON SOURCE LINES 19-21 .. code-block:: Python model = dpf.Model(examples.find_simple_bar()) .. GENERATED FROM PYTHON SOURCE LINES 22-24 Get the :class:`meshed_region ` from model's metadata. .. GENERATED FROM PYTHON SOURCE LINES 24-27 .. code-block:: Python mesh = model.metadata.meshed_region print(mesh) .. rst-class:: sphx-glr-script-out .. code-block:: none DPF Meshed Region: 3751 nodes 3000 elements Unit: m With solid (3D) elements .. GENERATED FROM PYTHON SOURCE LINES 28-30 See available properties in the :class:`meshed_region `. .. GENERATED FROM PYTHON SOURCE LINES 30-32 .. code-block:: Python print(mesh.available_property_fields) .. rst-class:: sphx-glr-script-out .. code-block:: none ['connectivity', 'elprops', 'eltype', 'apdl_element_type', 'section', 'mat'] .. GENERATED FROM PYTHON SOURCE LINES 33-34 Get all material properties. .. GENERATED FROM PYTHON SOURCE LINES 34-36 .. code-block:: Python mats = mesh.property_field("mat") .. GENERATED FROM PYTHON SOURCE LINES 37-42 Use the DPF operator :class:`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. .. GENERATED FROM PYTHON SOURCE LINES 42-45 .. code-block:: Python mat_prop = model.operator("mapdl_material_properties") mat_prop.inputs.materials.connect(mats) .. GENERATED FROM PYTHON SOURCE LINES 46-49 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. .. GENERATED FROM PYTHON SOURCE LINES 49-51 .. code-block:: Python print(mat_prop) .. rst-class:: sphx-glr-script-out .. code-block:: none 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] 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] .. GENERATED FROM PYTHON SOURCE LINES 52-54 To extract the Young's modulus for element ID ``1``, first we need to get the mat_id for EID ``1``. .. GENERATED FROM PYTHON SOURCE LINES 54-56 .. code-block:: Python mat_id = mats.get_entity_data_by_id(1) .. GENERATED FROM PYTHON SOURCE LINES 57-58 And then use the mat_id get the material property. .. GENERATED FROM PYTHON SOURCE LINES 58-62 .. code-block:: Python 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])) .. rst-class:: sphx-glr-script-out .. code-block:: none [2.e+11] .. GENERATED FROM PYTHON SOURCE LINES 63-64 Extract Poisson's ratio for element ID ``1``. .. GENERATED FROM PYTHON SOURCE LINES 64-67 .. code-block:: Python 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])) .. rst-class:: sphx-glr-script-out .. code-block:: none [0.3] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.016 seconds) .. _sphx_glr_download_examples_00-basic_12-get_material_properties.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 12-get_material_properties.ipynb <12-get_material_properties.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 12-get_material_properties.py <12-get_material_properties.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_