.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/gallery_examples/2_sampling_point_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_2_sampling_point_example.py: .. _sampling_point_example: Sampling point -------------- This example extracts ply-wise laminate properties and results. The :class:`Sampling Point <.SamplingPoint>` class is used to extract through-the-thickness data of the laminate, such as ply-wise properties, strains and stresses. It then implements basic visualization to plot the laminate. This example uses the :class:`Composite Model <.CompositeModel>` to scope a Sampling Point to a certain element and to visualize the laminate. .. GENERATED FROM PYTHON SOURCE LINES 20-26 Set up analysis ~~~~~~~~~~~~~~~ Setting up the analysis consists of loading Ansys libraries, connecting to the DPF server, and retrieving the example files. Load Ansys libraries. .. GENERATED FROM PYTHON SOURCE LINES 26-39 .. code-block:: default from ansys.dpf.composites.composite_model import CompositeModel from ansys.dpf.composites.constants import Spot from ansys.dpf.composites.example_helper import get_continuous_fiber_example_files from ansys.dpf.composites.failure_criteria import ( CombinedFailureCriterion, CoreFailureCriterion, MaxStrainCriterion, MaxStressCriterion, VonMisesCriterion, ) from ansys.dpf.composites.server_helpers import connect_to_or_start_server .. GENERATED FROM PYTHON SOURCE LINES 40-41 Start a DPF server and copy the example files into the current working directory. .. GENERATED FROM PYTHON SOURCE LINES 41-44 .. 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 45-46 Configure the combined failure criterion .. GENERATED FROM PYTHON SOURCE LINES 46-56 .. code-block:: default combined_fc = CombinedFailureCriterion( name="failure of all materials", failure_criteria=[ MaxStrainCriterion(), MaxStressCriterion(), CoreFailureCriterion(), VonMisesCriterion(vme=True, vms=False), ], ) .. GENERATED FROM PYTHON SOURCE LINES 57-60 Set up model and create sampling point ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Set up the composite model. .. GENERATED FROM PYTHON SOURCE LINES 60-62 .. code-block:: default composite_model = CompositeModel(composite_files_on_server, server) .. GENERATED FROM PYTHON SOURCE LINES 63-64 Create a sampling point .. GENERATED FROM PYTHON SOURCE LINES 64-66 .. code-block:: default sampling_point = composite_model.get_sampling_point(combined_criterion=combined_fc, element_id=3) .. GENERATED FROM PYTHON SOURCE LINES 67-72 Plot results ~~~~~~~~~~~~ Plot results uing preconfigured plots. For more information, see the :meth:`.SamplingPoint.get_result_plots` method. .. GENERATED FROM PYTHON SOURCE LINES 72-81 .. code-block:: default sampling_point_plot = sampling_point.get_result_plots( strain_components=[], # do not plot strains core_scale_factor=0.1, spots=[Spot.BOTTOM, Spot.TOP], show_failure_modes=True, ) sampling_point_plot.figure.set_figheight(8) sampling_point_plot.figure.set_figwidth(12) .. image-sg:: /examples/gallery_examples/images/sphx_glr_2_sampling_point_example_001.png :alt: Stresses, Failures :srcset: /examples/gallery_examples/images/sphx_glr_2_sampling_point_example_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 82-83 Plot polar properties. .. GENERATED FROM PYTHON SOURCE LINES 83-85 .. code-block:: default sampling_point_plot = sampling_point.get_polar_plot(["E1", "G12"]) .. image-sg:: /examples/gallery_examples/images/sphx_glr_2_sampling_point_example_002.png :alt: Polar Properties :srcset: /examples/gallery_examples/images/sphx_glr_2_sampling_point_example_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 86-90 Generate custom plots. You can customize existing plots or build them from scratch using a package like Matplot or Plotly. This code uses Matplotlib to generate a custom plot of results ``s13`` and ``s23``. .. GENERATED FROM PYTHON SOURCE LINES 90-109 .. code-block:: default import matplotlib.pyplot as plt fig, ax1 = plt.subplots() core_scale_factor = 0.5 sampling_point.add_results_to_plot( ax1, ["s13", "s23"], [Spot.BOTTOM, Spot.TOP], core_scale_factor, "Out-of-plane shear stresses", "MPA", ) ax1.legend() plt.rcParams["hatch.linewidth"] = 0.2 plt.rcParams["hatch.color"] = "silver" sampling_point.add_ply_sequence_to_plot(ax1, core_scale_factor) .. image-sg:: /examples/gallery_examples/images/sphx_glr_2_sampling_point_example_003.png :alt: Out-of-plane shear stresses :srcset: /examples/gallery_examples/images/sphx_glr_2_sampling_point_example_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 110-111 This code uses Matplotlib to generate a custom plot of results ``e12`` and ``e2``. .. GENERATED FROM PYTHON SOURCE LINES 111-128 .. code-block:: default interfaces = [Spot.BOTTOM, Spot.TOP] core_scale_factor = 1.0 indices = sampling_point.get_indices(interfaces) offsets = sampling_point.get_offsets_by_spots(interfaces, core_scale_factor) e12 = sampling_point.e12[indices] e2 = sampling_point.e2[indices] fig, ax1 = plt.subplots() plt.rcParams["hatch.linewidth"] = 0.2 plt.rcParams["hatch.color"] = "silver" line = ax1.plot(e12, offsets, label="e12") line = ax1.plot(e2, offsets, label="e2") ax1.set_yticks([]) ax1.legend() ax1.set_title("e12 and e2") .. image-sg:: /examples/gallery_examples/images/sphx_glr_2_sampling_point_example_004.png :alt: e12 and e2 :srcset: /examples/gallery_examples/images/sphx_glr_2_sampling_point_example_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(0.5, 1.0, 'e12 and e2') .. GENERATED FROM PYTHON SOURCE LINES 129-130 This code plots the lay-up only. .. GENERATED FROM PYTHON SOURCE LINES 130-133 .. code-block:: default fig2, layup_axes = plt.subplots() sampling_point.add_ply_sequence_to_plot(layup_axes) .. image-sg:: /examples/gallery_examples/images/sphx_glr_2_sampling_point_example_005.png :alt: 2 sampling point example :srcset: /examples/gallery_examples/images/sphx_glr_2_sampling_point_example_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 134-138 Sample another element ~~~~~~~~~~~~~~~~~~~~~~ You can change the element ID of the sampling point to generate another plot. .. GENERATED FROM PYTHON SOURCE LINES 138-147 .. code-block:: default sampling_point.element_id = 4 sampling_point_plot = sampling_point.get_result_plots( strain_components=[], # do not plot strains core_scale_factor=0.1, spots=[Spot.BOTTOM, Spot.TOP], show_failure_modes=True, ) sampling_point_plot.figure.set_figheight(8) sampling_point_plot.figure.set_figwidth(12) .. image-sg:: /examples/gallery_examples/images/sphx_glr_2_sampling_point_example_006.png :alt: Stresses, Failures :srcset: /examples/gallery_examples/images/sphx_glr_2_sampling_point_example_006.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 4.355 seconds) .. _sphx_glr_download_examples_gallery_examples_2_sampling_point_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: 2_sampling_point_example.py <2_sampling_point_example.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 2_sampling_point_example.ipynb <2_sampling_point_example.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_