.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/gallery_examples/4_get_material_properties_example.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_gallery_examples_4_get_material_properties_example.py: .. _material_properties: Material properties and custom failure criterion ------------------------------------------------ This example shows how to access constant material properties and how to implement a custom failure criterion. The failure criterion is computed for all layers and integration points. Finally, the elemental maximum is computed and shown. Note: Only constant material properties are currently supported. .. GENERATED FROM PYTHON SOURCE LINES 15-19 Script ~~~~~~ Import dependencies .. GENERATED FROM PYTHON SOURCE LINES 19-29 .. code-block:: default import ansys.dpf.core as dpf import numpy as np from ansys.dpf.composites.composite_model import CompositeModel from ansys.dpf.composites.constants import Sym3x3TensorComponent from ansys.dpf.composites.example_helper import get_continuous_fiber_example_files from ansys.dpf.composites.layup_info.material_properties import MaterialProperty from ansys.dpf.composites.select_indices import get_selected_indices from ansys.dpf.composites.server_helpers import connect_to_or_start_server .. GENERATED FROM PYTHON SOURCE LINES 30-32 Start a server and get the examples files. This will copy the example files into the current working directory. .. GENERATED FROM PYTHON SOURCE LINES 32-35 .. code-block:: default server = connect_to_or_start_server() composite_files_on_server = get_continuous_fiber_example_files(server, "shell") .. GENERATED FROM PYTHON SOURCE LINES 36-37 Set up the composite model .. GENERATED FROM PYTHON SOURCE LINES 37-39 .. code-block:: default composite_model = CompositeModel(composite_files_on_server, server) .. GENERATED FROM PYTHON SOURCE LINES 40-45 Get dictionary that maps dpf_material_id to properties The creation of the dictionary is currently quite slow and should be done before using the properties in a loop. Currently only constant properties are supported. For variable material properties, the default value is returned. .. GENERATED FROM PYTHON SOURCE LINES 45-50 .. code-block:: default material_property = MaterialProperty.Strain_Limits_eXt property_dict = composite_model.get_constant_property_dict([material_property]) .. GENERATED FROM PYTHON SOURCE LINES 51-52 Get strain field .. GENERATED FROM PYTHON SOURCE LINES 52-57 .. code-block:: default strain_operator = composite_model.core_model.results.elastic_strain() strain_operator.inputs.bool_rotate_to_global(False) strain_field = strain_operator.get_output(pin=0, output_type=dpf.types.fields_container)[0] .. GENERATED FROM PYTHON SOURCE LINES 58-59 Implement a custom failure criterion: basic max strain .. GENERATED FROM PYTHON SOURCE LINES 59-82 .. code-block:: default result_field = dpf.field.Field(location=dpf.locations.elemental, nature=dpf.natures.scalar) with result_field.as_local_field() as local_result_field: component = Sym3x3TensorComponent.TENSOR11 for element_id in strain_field.scoping.ids: strain_data = strain_field.get_entity_data_by_id(element_id) element_info = composite_model.get_element_info(element_id) element_max = 0 for layer_index, dpf_material_id in enumerate(element_info.dpf_material_ids): tensile_strain_limit_1 = property_dict[dpf_material_id][material_property] selected_indices = get_selected_indices(element_info, layers=[layer_index]) # Tensile max strain criteria in 1 direction layer_strain_values = strain_data[selected_indices][:, component] if tensile_strain_limit_1 > 0: layer_max = np.max(layer_strain_values) element_max = max(element_max, layer_max / tensile_strain_limit_1) # add to output field local_result_field.append([element_max], element_id) composite_model.get_mesh().plot(result_field) .. image-sg:: /examples/gallery_examples/images/sphx_glr_4_get_material_properties_example_001.png :alt: 4 get material properties example :srcset: /examples/gallery_examples/images/sphx_glr_4_get_material_properties_example_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 5.550 seconds) .. _sphx_glr_download_examples_gallery_examples_4_get_material_properties_example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 4_get_material_properties_example.py <4_get_material_properties_example.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 4_get_material_properties_example.ipynb <4_get_material_properties_example.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_