.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/gallery_examples/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_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_1_failure_operator_example.py` and :ref:`sphx_glr_examples_gallery_examples_2_sampling_point_example.py`. Additionally, :ref:`sphx_glr_examples_gallery_examples_6_filter_composite_data_example.py` shows how helper functions can be used to obtain composite result data. .. GENERATED FROM PYTHON SOURCE LINES 23-30 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 30-47 .. code-block:: default import ansys.dpf.core as dpf 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 .. GENERATED FROM PYTHON SOURCE LINES 48-49 Configure the combined failure criterion. .. GENERATED FROM PYTHON SOURCE LINES 49-65 .. 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 66-67 Start a DPF server and prepare files .. GENERATED FROM PYTHON SOURCE LINES 67-70 .. 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 71-74 Initialize DPF model and data sources ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Initialize the DPF model and the data sources. .. GENERATED FROM PYTHON SOURCE LINES 74-85 .. code-block:: default model = dpf.Model(composite_files_on_server.rst) rst_data_source = dpf.DataSources(composite_files_on_server.rst) eng_data_source = dpf.DataSources() eng_data_source.add_file_path(composite_files_on_server.engineering_data, "EngineeringData") composite_definitions_source = dpf.DataSources() composite_definitions_source.add_file_path( composite_files_on_server.composite["shell"].definition, "CompositeDefinitions" ) .. GENERATED FROM PYTHON SOURCE LINES 86-89 Set up providers ~~~~~~~~~~~~~~~~ Set up the mesh provider. .. GENERATED FROM PYTHON SOURCE LINES 89-91 .. code-block:: default mesh_provider = model.metadata.mesh_provider .. GENERATED FROM PYTHON SOURCE LINES 92-96 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 96-100 .. code-block:: default material_support_provider = dpf.Operator("support_provider") material_support_provider.inputs.property("mat") material_support_provider.inputs.data_sources(rst_data_source) .. GENERATED FROM PYTHON SOURCE LINES 101-103 Set up the result information provider, which gets the unit system from the RST file. .. GENERATED FROM PYTHON SOURCE LINES 103-106 .. code-block:: default result_info_provider = dpf.Operator("ResultInfoProvider") result_info_provider.inputs.data_sources(rst_data_source) .. GENERATED FROM PYTHON SOURCE LINES 107-111 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 111-118 .. 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 119-121 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 121-130 .. 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 131-136 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 136-144 .. 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 145-150 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 150-157 .. 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 158-162 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 162-169 .. 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 170-172 Plot the maximum and minimum values. .. GENERATED FROM PYTHON SOURCE LINES 172-174 .. code-block:: default value_index = 1 model.metadata.meshed_region.plot(output[value_index]) .. image-sg:: /examples/gallery_examples/images/sphx_glr_dpf_composite_failure_workflow_001.png :alt: dpf composite failure workflow :srcset: /examples/gallery_examples/images/sphx_glr_dpf_composite_failure_workflow_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 9.451 seconds) .. _sphx_glr_download_examples_gallery_examples_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: dpf_composite_failure_workflow.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: dpf_composite_failure_workflow.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_