.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/gallery_examples/011_dpf_composite_failure_workflow.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_011_dpf_composite_failure_workflow.py: .. _basic_example: DPF composite failure workflow ------------------------------ This example shows how to use the native DPF Python interface to configure and run the composite failure evaluator. It connects the different DPF operators that are needed to evaluate composite failure criteria. .. note:: For simple use cases, using the composite failure operator or composite sampling point operator is preferable. For examples, see :ref:`sphx_glr_examples_gallery_examples_001_failure_operator_example.py` and :ref:`sphx_glr_examples_gallery_examples_002_sampling_point_example.py`. Additionally, :ref:`sphx_glr_examples_gallery_examples_006_filter_composite_data_example.py` shows how helper functions can be used to obtain composite result data. .. GENERATED FROM PYTHON SOURCE LINES 24-31 Set up analysis ~~~~~~~~~~~~~~~ Setting up the analysis consists of loading Ansys libraries, configuring the combined failure criterion, connecting to the DPF server, and preparing files. Load Ansys libraries. .. GENERATED FROM PYTHON SOURCE LINES 31-49 .. code-block:: default import ansys.dpf.core as dpf from ansys.dpf.composites.data_sources import get_composites_data_sources from ansys.dpf.composites.example_helper import get_continuous_fiber_example_files from ansys.dpf.composites.failure_criteria import ( CombinedFailureCriterion, CoreFailureCriterion, CuntzeCriterion, HashinCriterion, HoffmanCriterion, MaxStrainCriterion, MaxStressCriterion, TsaiHillCriterion, TsaiWuCriterion, VonMisesCriterion, ) from ansys.dpf.composites.server_helpers import connect_to_or_start_server, version_older_than .. GENERATED FROM PYTHON SOURCE LINES 50-51 Configure the combined failure criterion. .. GENERATED FROM PYTHON SOURCE LINES 51-67 .. code-block:: default combined_fc = CombinedFailureCriterion( name="My Failure Criteria", failure_criteria=[ MaxStrainCriterion(), MaxStressCriterion(), TsaiHillCriterion(), TsaiWuCriterion(), HoffmanCriterion(), HashinCriterion(), CuntzeCriterion(), CoreFailureCriterion(), VonMisesCriterion(vme=True, vms=False), ], ) .. GENERATED FROM PYTHON SOURCE LINES 68-69 Start a DPF server and prepare files .. GENERATED FROM PYTHON SOURCE LINES 69-74 .. code-block:: default server = connect_to_or_start_server() composite_files_on_server = get_continuous_fiber_example_files(server, "shell") composite_data_sources = get_composites_data_sources(composite_files_on_server) .. GENERATED FROM PYTHON SOURCE LINES 75-78 Initialize DPF model and data sources ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Initialize the DPF model and the data sources. .. GENERATED FROM PYTHON SOURCE LINES 78-91 .. code-block:: default rst_data_source = composite_data_sources.rst material_support_data_source = composite_data_sources.material_support eng_data_source = composite_data_sources.engineering_data if version_older_than(server, "7.0"): # Get datasources of composite definition files for the backend 2023 R2 or before composite_definitions_source = composite_data_sources.old_composite_sources["shell"] else: # Get datasources of composite definition files for the backend 2024 R1 or later composite_definitions_source = composite_data_sources.composite model = dpf.Model(rst_data_source) .. GENERATED FROM PYTHON SOURCE LINES 92-95 Set up providers ~~~~~~~~~~~~~~~~ Set up the mesh provider. .. GENERATED FROM PYTHON SOURCE LINES 95-97 .. code-block:: default mesh_provider = model.metadata.mesh_provider .. GENERATED FROM PYTHON SOURCE LINES 98-102 Set up the material support provider. The material support provider takes care of mapping the materials in the RST file to the materials in the composite definitions. The material support contains all materials from the RST file. .. GENERATED FROM PYTHON SOURCE LINES 102-108 .. code-block:: default material_support_provider = dpf.Operator("support_provider") material_support_provider.inputs.property("mat") material_support_provider.inputs.data_sources(material_support_data_source) material_support_provider.run() .. GENERATED FROM PYTHON SOURCE LINES 109-111 Set up the result information provider, which gets the unit system from the RST file. .. GENERATED FROM PYTHON SOURCE LINES 111-114 .. code-block:: default result_info_provider = dpf.Operator("ResultInfoProvider") result_info_provider.inputs.data_sources(rst_data_source) .. GENERATED FROM PYTHON SOURCE LINES 115-119 Set up the material provider The material provider combines the material support in the engineering data XML file and the unit system. Its output can be used to evaluate material properties. .. GENERATED FROM PYTHON SOURCE LINES 119-126 .. code-block:: default material_provider = dpf.Operator("eng_data::ans_mat_material_provider") material_provider.inputs.data_sources = eng_data_source material_provider.inputs.unit_system_or_result_info(result_info_provider.outputs.result_info) material_provider.inputs.abstract_field_support( material_support_provider.outputs.abstract_field_support ) material_provider.inputs.Engineering_data_file(eng_data_source) .. GENERATED FROM PYTHON SOURCE LINES 127-129 Set up the lay-up provider, which reads the composite definition file and enriches the mesh with the composite lay-up information. .. GENERATED FROM PYTHON SOURCE LINES 129-138 .. code-block:: default layup_provider = dpf.Operator("composite::layup_provider_operator") layup_provider.inputs.mesh(mesh_provider.outputs.mesh) layup_provider.inputs.data_sources(composite_definitions_source) layup_provider.inputs.abstract_field_support( material_support_provider.outputs.abstract_field_support ) layup_provider.inputs.unit_system(result_info_provider.outputs.result_info) layup_provider.run() .. GENERATED FROM PYTHON SOURCE LINES 139-144 Set up result operators ~~~~~~~~~~~~~~~~~~~~~~~ Set up result operators for strains and stresses. ``rotate_to_global`` is ``False`` because the postprocessing engine expects the results to be in the element coordinate system (material coordinate system). .. GENERATED FROM PYTHON SOURCE LINES 144-152 .. code-block:: default strain_operator = dpf.operators.result.elastic_strain() strain_operator.inputs.data_sources(rst_data_source) strain_operator.inputs.bool_rotate_to_global(False) stress_operator = dpf.operators.result.stress() stress_operator.inputs.data_sources(rst_data_source) stress_operator.inputs.bool_rotate_to_global(False) .. GENERATED FROM PYTHON SOURCE LINES 153-158 Set up failure evaluator ~~~~~~~~~~~~~~~~~~~~~~~~ Set up the failure evaluator, which combines the results and evaluates all failure criteria. The output contains the maximum failure criteria for each integration point. .. GENERATED FROM PYTHON SOURCE LINES 158-165 .. code-block:: default failure_evaluator = dpf.Operator("composite::multiple_failure_criteria_operator") failure_evaluator.inputs.configuration(combined_fc.to_json()) failure_evaluator.inputs.materials_container(material_provider.outputs) failure_evaluator.inputs.strains_container(strain_operator.outputs.fields_container) failure_evaluator.inputs.stresses_container(stress_operator.outputs.fields_container) failure_evaluator.inputs.mesh(mesh_provider.outputs.mesh) .. GENERATED FROM PYTHON SOURCE LINES 166-170 Compute and plot failure criteria ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Use the output of the multiple failure criteria operator to compute the minimum and maximum failure criteria for each element. .. GENERATED FROM PYTHON SOURCE LINES 170-177 .. code-block:: default minmax_per_element = dpf.Operator("composite::minmax_per_element_operator") minmax_per_element.inputs.fields_container(failure_evaluator.outputs.fields_container) minmax_per_element.inputs.mesh(mesh_provider.outputs.mesh) minmax_per_element.inputs.material_support(material_support_provider.outputs.abstract_field_support) output = minmax_per_element.outputs.field_max() .. GENERATED FROM PYTHON SOURCE LINES 178-180 Plot the maximum and minimum values. .. GENERATED FROM PYTHON SOURCE LINES 180-182 .. code-block:: default value_index = 1 model.metadata.meshed_region.plot(output[value_index]) .. image-sg:: /examples/gallery_examples/images/sphx_glr_011_dpf_composite_failure_workflow_001.png :alt: 011 dpf composite failure workflow :srcset: /examples/gallery_examples/images/sphx_glr_011_dpf_composite_failure_workflow_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 13.473 seconds) .. _sphx_glr_download_examples_gallery_examples_011_dpf_composite_failure_workflow.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 011_dpf_composite_failure_workflow.py <011_dpf_composite_failure_workflow.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 011_dpf_composite_failure_workflow.ipynb <011_dpf_composite_failure_workflow.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_