.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/gallery_examples/009_short_fiber_orientation_tensor.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_009_short_fiber_orientation_tensor.py: .. _short_fiber_orientation_tensor: Plot of the orientation tensor for short fiber composites --------------------------------------------------------- This example shows how to reconstruct and plot the components of the fiber orientation tensor in the global coordinate system. For more details about the fiber orientation tensor, refer to the Short Fiber Composites help. .. note:: To run this example you first need to install the SciPy package. .. GENERATED FROM PYTHON SOURCE LINES 41-47 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 47-56 .. code-block:: default import ansys.dpf.core as dpf import numpy as np from scipy.spatial.transform import Rotation from ansys.dpf.composites.data_sources import get_short_fiber_composites_data_sources from ansys.dpf.composites.example_helper import get_short_fiber_example_files from ansys.dpf.composites.server_helpers import connect_to_or_start_server .. GENERATED FROM PYTHON SOURCE LINES 57-62 Start a DPF server and copy the example files into the current working directory. These files are needed: * Mechanical APDL result (RST) file containing the simulation results * Mechanical APDL input file (DS.DAT) containing the fiber orientation tensor data .. GENERATED FROM PYTHON SOURCE LINES 62-65 .. code-block:: default server = connect_to_or_start_server() composite_files_on_server = get_short_fiber_example_files(server, "short_fiber") .. GENERATED FROM PYTHON SOURCE LINES 66-69 Set up data sources ~~~~~~~~~~~~~~~~~~~ Set up the data sources. .. GENERATED FROM PYTHON SOURCE LINES 69-71 .. code-block:: default data_sources = get_short_fiber_composites_data_sources(composite_files_on_server) .. GENERATED FROM PYTHON SOURCE LINES 72-75 Initialize DPF model ~~~~~~~~~~~~~~~~~~~~ Initialize the DPF model. .. GENERATED FROM PYTHON SOURCE LINES 75-78 .. code-block:: default model = dpf.Model(data_sources=data_sources) mesh = model.metadata.meshed_region .. GENERATED FROM PYTHON SOURCE LINES 79-81 Should your mesh contain both solid and shell elements, for visualization purposes it can be useful to scope the mesh to the solid ones. .. GENERATED FROM PYTHON SOURCE LINES 81-91 .. code-block:: default # solid_scoping_op = dpf.operators.scoping.on_mesh_property( # property_name='solid_elements', # mesh=mesh, # ) # solid_mesh = dpf.operators.mesh.from_scoping( # scoping=solid_scoping_op.outputs.mesh_scoping(), # mesh=model.metadata.mesh_provider, # ).outputs.mesh() .. GENERATED FROM PYTHON SOURCE LINES 92-96 Plot input data ~~~~~~~~~~~~~~~ Plot the two largest eigenvalues (a11 and a22) of the fiber orientation tensor. Note that the plots reveal the presence of a weld line in the middle of the specimen. .. GENERATED FROM PYTHON SOURCE LINES 96-110 .. code-block:: default field_variable_provider = dpf.Operator("composite::inistate_field_variables_provider") field_variable_provider.inputs.data_sources(data_sources) field_variable_provider.inputs.mesh(mesh) field_variable_dict = { fv.name: fv for fv in field_variable_provider.outputs.fields_container.get_data() } A11_NAME = "Orientation Tensor A11" A22_NAME = "Orientation Tensor A22" a11 = field_variable_dict[A11_NAME] a11.plot() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/gallery_examples/images/sphx_glr_009_short_fiber_orientation_tensor_001.png :alt: 009 short fiber orientation tensor :srcset: /examples/gallery_examples/images/sphx_glr_009_short_fiber_orientation_tensor_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_009_short_fiber_orientation_tensor_001.vtksz .. GENERATED FROM PYTHON SOURCE LINES 111-115 .. code-block:: default a22 = field_variable_dict[A22_NAME] a22.plot() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/gallery_examples/images/sphx_glr_009_short_fiber_orientation_tensor_002.png :alt: 009 short fiber orientation tensor :srcset: /examples/gallery_examples/images/sphx_glr_009_short_fiber_orientation_tensor_002.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_009_short_fiber_orientation_tensor_002.vtksz .. GENERATED FROM PYTHON SOURCE LINES 116-119 Compute results ~~~~~~~~~~~~~~~~~~~~~~~~ Reconstruct the fiber orientation tensor in the global coordinate system. .. GENERATED FROM PYTHON SOURCE LINES 119-151 .. code-block:: default element_ids = a11.scoping.ids # Alternatively, you could for instance scope to a named selection with # >>> element_ids = model.metadata.meshed_region.named_selection('CENTER').ids # Define the fiber orientation tensor in the global coordinate system # as a symmetrical 3x3 tensor with components XX,YY,ZZ,XY,YZ,XZ. fiber_orientation_tensor = dpf.fields_factory.create_tensor_field( num_entities=len(element_ids), location=dpf.locations.elemental ) ele_orientation_op = dpf.operators.result.element_orientations( data_sources=data_sources, requested_location="Elemental", bool_rotate_to_global=False ) euler_angles_field = ele_orientation_op.outputs.fields_container()[0] for eid in element_ids: V = Rotation.from_euler( seq="ZXY", angles=euler_angles_field.get_entity_data_by_id(eid)[0], degrees=True ).as_matrix() d1 = a11.get_entity_data_by_id(eid)[0] d2 = a22.get_entity_data_by_id(eid)[0] D = np.diag([d1, d2, max(1.0 - d1 - d2, 0.0)]) aRot = np.matmul(np.matmul(V, D), V.transpose()) fiber_orientation_tensor.append( [aRot[0, 0], aRot[1, 1], aRot[2, 2], aRot[0, 1], aRot[1, 2], aRot[0, 2]], eid ) fiber_orientation_tensor_fc = dpf.operators.utility.field_to_fc( field=fiber_orientation_tensor ).outputs.fields_container() .. GENERATED FROM PYTHON SOURCE LINES 152-155 Plot results ~~~~~~~~~~~~~~~~~~~~~~~~ Plot some components of the fiber orientation tensor. .. GENERATED FROM PYTHON SOURCE LINES 155-162 .. code-block:: default aXX = fiber_orientation_tensor_fc.select_component(0)[0] aYY = fiber_orientation_tensor_fc.select_component(1)[0] aXZ = fiber_orientation_tensor_fc.select_component(5)[0] mesh.plot(aXX, title="Axx", text="Axx plot") .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/gallery_examples/images/sphx_glr_009_short_fiber_orientation_tensor_003.png :alt: 009 short fiber orientation tensor :srcset: /examples/gallery_examples/images/sphx_glr_009_short_fiber_orientation_tensor_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_009_short_fiber_orientation_tensor_003.vtksz .. GENERATED FROM PYTHON SOURCE LINES 163-165 .. code-block:: default mesh.plot(aYY, title="Ayy", text="Ayy plot") .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/gallery_examples/images/sphx_glr_009_short_fiber_orientation_tensor_004.png :alt: 009 short fiber orientation tensor :srcset: /examples/gallery_examples/images/sphx_glr_009_short_fiber_orientation_tensor_004.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_009_short_fiber_orientation_tensor_004.vtksz .. GENERATED FROM PYTHON SOURCE LINES 166-167 .. code-block:: default mesh.plot(aXZ, title="Axz", text="Axz plot") .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/gallery_examples/images/sphx_glr_009_short_fiber_orientation_tensor_005.png :alt: 009 short fiber orientation tensor :srcset: /examples/gallery_examples/images/sphx_glr_009_short_fiber_orientation_tensor_005.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_009_short_fiber_orientation_tensor_005.vtksz .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 5.979 seconds) .. _sphx_glr_download_examples_gallery_examples_009_short_fiber_orientation_tensor.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 009_short_fiber_orientation_tensor.py <009_short_fiber_orientation_tensor.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 009_short_fiber_orientation_tensor.ipynb <009_short_fiber_orientation_tensor.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_