.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/gallery_examples/012_fatigue_example.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_012_fatigue_example.py: .. _fatigue_plate_example: Evaluate fatigue for a composite plate -------------------------------------- This example shows how to evaluate fatigue for a flat plate. It shows how you can use PyPDF Composites to select specific layers and define a custom combination method. For this example, the custom combination method is stress in fibre direction. A random load time series is created. Taking into account that the load is assumed proportional, rainflow counting is applied to the load time series. Load ranges are then applied on the stress combination method, and damage is evaluated by using a dummy S-N curve. Be aware that the fatpack package is not developed by Ansys, so it is the responsibility of the user to verify that it works as expected. For more information, see the `fatpack package `_, .. note:: When using a Workbench project, use the :func:`.composite_files_from_workbench_harmonic_analysis` method to obtain the input files. .. GENERATED FROM PYTHON SOURCE LINES 54-60 Set up analysis ~~~~~~~~~~~~~~~ Setting up the analysis consists of loading the required modules, connecting to the DPF server, and retrieving the example files. Load Ansys libraries and numpy, matplotlib and fatpack .. GENERATED FROM PYTHON SOURCE LINES 60-72 .. code-block:: Python import ansys.dpf.core as dpf import fatpack import matplotlib.pyplot as plt 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 import AnalysisPlyInfoProvider from ansys.dpf.composites.select_indices import get_selected_indices_by_analysis_ply from ansys.dpf.composites.server_helpers import connect_to_or_start_server .. GENERATED FROM PYTHON SOURCE LINES 73-74 Start a DPF server and copy the example files into the current working directory. .. GENERATED FROM PYTHON SOURCE LINES 74-77 .. code-block:: Python server = connect_to_or_start_server() composite_files_on_server = get_continuous_fiber_example_files(server, "fatigue") .. GENERATED FROM PYTHON SOURCE LINES 78-79 Create a composite model .. GENERATED FROM PYTHON SOURCE LINES 79-81 .. code-block:: Python composite_model = CompositeModel(composite_files_on_server, server) .. GENERATED FROM PYTHON SOURCE LINES 82-85 Read stresses and define a specific layer and a component of stress tensor ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 87-88 Read stresses .. GENERATED FROM PYTHON SOURCE LINES 88-93 .. code-block:: Python stress_operator = composite_model.core_model.results.stress() stress_operator.inputs.bool_rotate_to_global(False) stress_fc = stress_operator.get_output(pin=0, output_type=dpf.types.fields_container) stress_field = stress_fc.get_field_by_time_id(1) .. GENERATED FROM PYTHON SOURCE LINES 94-95 Select layer P1L1__ModelingPly.2 .. GENERATED FROM PYTHON SOURCE LINES 95-99 .. code-block:: Python analysis_ply_info_provider = AnalysisPlyInfoProvider( mesh=composite_model.get_mesh(), name="P1L1__ModelingPly.2" ) .. GENERATED FROM PYTHON SOURCE LINES 100-101 Select Sigma11 as the combination method .. GENERATED FROM PYTHON SOURCE LINES 101-104 .. code-block:: Python component = Sym3x3TensorComponent.TENSOR11 .. GENERATED FROM PYTHON SOURCE LINES 105-111 Load time series and apply rainflow counting ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A random time series is created. Load is assumed proportional, so rainflow counting can be directly done on the load time series to get the load ranges. No mean stress correction is applied. .. GENERATED FROM PYTHON SOURCE LINES 111-119 .. code-block:: Python number_of_times = 100 load_factor_time_series = np.random.normal(-1, 2.5, size=number_of_times) x = np.linspace(1, number_of_times, number_of_times) plt.xlabel("Load Index") plt.ylabel("Load Factor") plt.plot(x, load_factor_time_series, color="red") .. image-sg:: /examples/gallery_examples/images/sphx_glr_012_fatigue_example_001.png :alt: 012 fatigue example :srcset: /examples/gallery_examples/images/sphx_glr_012_fatigue_example_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [] .. GENERATED FROM PYTHON SOURCE LINES 120-121 Fatpack package is used for doing the rainflow counting .. GENERATED FROM PYTHON SOURCE LINES 121-124 .. code-block:: Python load_range_factors = fatpack.find_rainflow_ranges(load_factor_time_series) .. GENERATED FROM PYTHON SOURCE LINES 125-131 S-N curve ~~~~~~~~~ A dummy S-N curve is created. Note that this curve is not based on any experimental data. Sc is chosen to be twice the orthotropic stress limit in the fiber direction. and Nc is set to 1. .. GENERATED FROM PYTHON SOURCE LINES 131-147 .. code-block:: Python Sc = 2 * 1979 Nc = 1 s_n_curve = fatpack.LinearEnduranceCurve(Sc) # Value for UD materials s_n_curve.m = 14 s_n_curve.Nc = Nc N = np.logspace(0, 9, 1000) S = s_n_curve.get_stress(N) line = plt.loglog(N, S) plt.grid(which="both") plt.title("Dummy Linear S-N curve") plt.xlabel("Cycles to failure") plt.ylabel("Stress range (MPa)") .. image-sg:: /examples/gallery_examples/images/sphx_glr_012_fatigue_example_002.png :alt: Dummy Linear S-N curve :srcset: /examples/gallery_examples/images/sphx_glr_012_fatigue_example_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(15.914246690538194, 0.5, 'Stress range (MPa)') .. GENERATED FROM PYTHON SOURCE LINES 148-153 Damage evaluation ~~~~~~~~~~~~~~~~~ Stress S11 at time 1 and layer P1L1__ModelingPly.2 are read for each load range. Its damage is evaluated using the dummy S-N curve. .. GENERATED FROM PYTHON SOURCE LINES 153-173 .. code-block:: Python damage_result_field = dpf.field.Field(location=dpf.locations.elemental, nature=dpf.natures.scalar) with damage_result_field.as_local_field() as local_result_field: element_ids = analysis_ply_info_provider.property_field.scoping.ids for element_id in element_ids: stress_data = stress_field.get_entity_data_by_id(element_id) element_info = composite_model.get_element_info(element_id) assert element_info is not None selected_indices = get_selected_indices_by_analysis_ply( analysis_ply_info_provider, element_info ) # Load Range scaled by S11 s_11 = max(stress_data[selected_indices][:, component]) stress_ranges = load_range_factors * s_11 fatigue_damage = s_n_curve.find_miner_sum(stress_ranges) local_result_field.append([fatigue_damage], element_id) .. GENERATED FROM PYTHON SOURCE LINES 174-175 Plot damage .. GENERATED FROM PYTHON SOURCE LINES 175-178 .. code-block:: Python composite_model.get_mesh().plot(damage_result_field, text="Fatigue Damage") .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/gallery_examples/images/sphx_glr_012_fatigue_example_003.png :alt: 012 fatigue example :srcset: /examples/gallery_examples/images/sphx_glr_012_fatigue_example_003.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_012_fatigue_example_003.vtksz .. GENERATED FROM PYTHON SOURCE LINES 179-182 Identify the element with the maximum damage ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 182-186 .. code-block:: Python maximum_element_scoping = damage_result_field.max().scoping max_element_id = maximum_element_scoping[0] print(f"The element with highest damage is {max_element_id}.") print(f"The highest damage value is {damage_result_field.max().data[0]}.") .. rst-class:: sphx-glr-script-out .. code-block:: none The element with highest damage is 27. The highest damage value is 8.379742808101406e-06. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 6.934 seconds) .. _sphx_glr_download_examples_gallery_examples_012_fatigue_example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 012_fatigue_example.ipynb <012_fatigue_example.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 012_fatigue_example.py <012_fatigue_example.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 012_fatigue_example.zip <012_fatigue_example.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_