.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/gallery_examples/099_dpf_composite_failure_workflow.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_gallery_examples_099_dpf_composite_failure_workflow.py: .. _basic_example_composite_failure_workflow: 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 46-53 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 53-71 .. code-block:: Python 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 72-73 Configure the combined failure criterion. .. GENERATED FROM PYTHON SOURCE LINES 73-89 .. code-block:: Python 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 90-91 Start a DPF server and prepare files .. GENERATED FROM PYTHON SOURCE LINES 91-96 .. code-block:: Python 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 97-100 Initialize DPF model and data sources ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Initialize the DPF model and the data sources. .. GENERATED FROM PYTHON SOURCE LINES 100-113 .. code-block:: Python 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 114-117 Set up providers ~~~~~~~~~~~~~~~~ Set up the mesh provider. .. GENERATED FROM PYTHON SOURCE LINES 117-119 .. code-block:: Python mesh_provider = model.metadata.mesh_provider .. GENERATED FROM PYTHON SOURCE LINES 120-124 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 124-130 .. code-block:: Python 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 131-133 Set up the result information provider, which gets the unit system from the RST file. .. GENERATED FROM PYTHON SOURCE LINES 133-136 .. code-block:: Python result_info_provider = dpf.Operator("ResultInfoProvider") result_info_provider.inputs.data_sources(rst_data_source) .. GENERATED FROM PYTHON SOURCE LINES 137-141 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 141-148 .. code-block:: Python 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 149-151 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 151-160 .. code-block:: Python 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 161-166 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 166-174 .. code-block:: Python 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 175-180 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 180-187 .. code-block:: Python 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 188-192 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 192-199 .. code-block:: Python 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 200-202 Plot the maximum and minimum values. .. GENERATED FROM PYTHON SOURCE LINES 202-204 .. code-block:: Python value_index = 1 model.metadata.meshed_region.plot(output[value_index]) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/gallery_examples/images/sphx_glr_099_dpf_composite_failure_workflow_001.png :alt: 099 dpf composite failure workflow :srcset: /examples/gallery_examples/images/sphx_glr_099_dpf_composite_failure_workflow_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/pydpf-composites/pydpf-composites/doc/source/examples/gallery_examples/images/sphx_glr_099_dpf_composite_failure_workflow_001.vtksz .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 13.828 seconds) .. _sphx_glr_download_examples_gallery_examples_099_dpf_composite_failure_workflow.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 099_dpf_composite_failure_workflow.ipynb <099_dpf_composite_failure_workflow.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 099_dpf_composite_failure_workflow.py <099_dpf_composite_failure_workflow.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 099_dpf_composite_failure_workflow.zip <099_dpf_composite_failure_workflow.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_