.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\04-advanced\04-extrapolation_stress_3d.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_04-advanced_04-extrapolation_stress_3d.py: .. _extrapolation_test_stress_3Delement: Extrapolation method for stress result of a 3D element ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This example shows how to compute the stress nodal components from Gaussian points (integration points) for a 3D element using extrapolation. Extrapolate results available at Gaussian or quadrature points to nodal points for a field or fields container. The available elements are: * Linear quadrangle * Parabolic quadrangle * Linear hexagonal * Quadratic hexagonal * Linear tetrahedral * Quadratic tetrahedral Here are the steps for extrapolation: #. Get the data source's solution from the integration points. (This result file was generated with the Ansys Mechanical APDL (MAPDL) option ``ERESX, NO``). #. Use the extrapolation operator to compute the nodal stress. #. Get the result for nodal stress from the data source. The analysis was computed by MAPDL. #. Compare the result for nodal stress from the data source and the nodal stress computed by the extrapolation method. .. GENERATED FROM PYTHON SOURCE LINES 34-39 .. code-block:: Python from ansys.dpf import core as dpf from ansys.dpf.core import examples .. GENERATED FROM PYTHON SOURCE LINES 40-41 Get the data source's analysis of integration points and analysis reference .. GENERATED FROM PYTHON SOURCE LINES 41-61 .. code-block:: Python datafile = examples.download_extrapolation_3d_result() # Get integration points (Gaussian points) data_integration_points = datafile["file_integrated"] data_sources_integration_points = dpf.DataSources(data_integration_points) # Get the reference dataSourceref = datafile["file_ref"] data_sources_ref = dpf.DataSources(dataSourceref) # Get the mesh model = dpf.Model(data_integration_points) mesh = model.metadata.meshed_region # Operator instantiation scoping op_scoping = dpf.operators.scoping.split_on_property_type() # operator instantiation op_scoping.inputs.mesh.connect(mesh) op_scoping.inputs.requested_location.connect("Elemental") mesh_scoping = op_scoping.outputs.mesh_scoping() .. GENERATED FROM PYTHON SOURCE LINES 62-66 Extrapolate from integration points for stress result ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This example uses the ``gauss_to_node_fc`` operator to compute the nodal component stress result from the stress result of integration points. .. GENERATED FROM PYTHON SOURCE LINES 66-72 .. code-block:: Python # Create stress operator to get stress result of integration points stressop = dpf.operators.result.stress() stressop.inputs.data_sources.connect(data_sources_integration_points) stress = stressop.outputs.fields_container() .. GENERATED FROM PYTHON SOURCE LINES 73-82 Nodal stress result of integration points ############################################################################## The MAPLD command ``ERESX,NO`` is used to copy directly the Gaussian (integration) points results to the nodes, instead of the results at nodes or elements (which are interpolation of results at a few gauss points). The following plot shows the nodal values, which are the averaged values of stresses at each node. The value shown at the node is the average of the stresses from the Gaussian points of each element that it belongs to. .. GENERATED FROM PYTHON SOURCE LINES 82-88 .. code-block:: Python # Plot stress_nodal_op = dpf.operators.averaging.elemental_nodal_to_nodal_fc() stress_nodal_op.inputs.fields_container.connect(stress) mesh.plot(stress_nodal_op.outputs.fields_container()) .. image-sg:: /examples/04-advanced/images/sphx_glr_04-extrapolation_stress_3d_001.png :alt: 04 extrapolation stress 3d :srcset: /examples/04-advanced/images/sphx_glr_04-extrapolation_stress_3d_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 89-91 Create operator ``gauss_to_node_fc`` and compute nodal component stress by applying the extrapolation method. .. GENERATED FROM PYTHON SOURCE LINES 91-100 .. code-block:: Python ex_stress = dpf.operators.averaging.gauss_to_node_fc() # connect mesh ex_stress.inputs.mesh.connect(mesh) # connect fields container stress ex_stress.inputs.fields_container.connect(stress) # get output fex = ex_stress.outputs.fields_container() .. GENERATED FROM PYTHON SOURCE LINES 101-103 Stress result of reference Ansys Workbench ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 103-110 .. code-block:: Python # Stress from file dataSourceref stressop_ref = dpf.operators.result.stress() stressop_ref.inputs.data_sources.connect(data_sources_ref) stressop_ref.inputs.mesh_scoping.connect(mesh_scoping) stress_ref = stressop_ref.outputs.fields_container() .. GENERATED FROM PYTHON SOURCE LINES 111-114 Plot ~~~~~~~~~~ Show plots of the extrapolation's stress result and the reference's stress result .. GENERATED FROM PYTHON SOURCE LINES 114-127 .. code-block:: Python # extrapolation fex_nodal_op = dpf.operators.averaging.elemental_nodal_to_nodal_fc() fex_nodal_op.inputs.fields_container.connect(fex) fex_nodal_fc = fex_nodal_op.eval() mesh.plot(fex_nodal_fc) # reference stress_ref_nodal_op = dpf.operators.averaging.elemental_nodal_to_nodal_fc() stress_ref_nodal_op.inputs.fields_container.connect(stress_ref) stress_ref_nodal_fc = stress_ref_nodal_op.eval() mesh.plot(stress_ref_nodal_fc) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/04-advanced/images/sphx_glr_04-extrapolation_stress_3d_002.png :alt: 04 extrapolation stress 3d :srcset: /examples/04-advanced/images/sphx_glr_04-extrapolation_stress_3d_002.png :class: sphx-glr-multi-img * .. image-sg:: /examples/04-advanced/images/sphx_glr_04-extrapolation_stress_3d_003.png :alt: 04 extrapolation stress 3d :srcset: /examples/04-advanced/images/sphx_glr_04-extrapolation_stress_3d_003.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 128-136 Compare stress results ~~~~~~~~~~~~~~~~~~~~~~ Compare the stress result computed by extrapolation and the reference's result. Check if the two fields container are identical using the :class:`identical_fc ` operator. The relative tolerance is set to 1.1e-6. The smallest value that is considered during the comparison step: all the ``abs(values)`` in field less than 1e-2 is considered as null. .. GENERATED FROM PYTHON SOURCE LINES 136-145 .. code-block:: Python # operator AreFieldsIdentical_fc op = dpf.operators.logic.identical_fc() op.inputs.fields_containerA.connect(fex_nodal_op) op.inputs.fields_containerB.connect(stress_ref_nodal_op) op.inputs.tolerance.connect(1.1e-6) op.inputs.small_value.connect(0.01) op.outputs.boolean() .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 146-147 Compute absolute and relative errors .. GENERATED FROM PYTHON SOURCE LINES 147-161 .. code-block:: Python abs_error_sqr = dpf.operators.math.sqr_fc() abs_error = dpf.operators.math.sqrt_fc() error = stress_ref_nodal_op - fex_nodal_op abs_error_sqr.inputs.fields_container.connect(error) abs_error.inputs.fields_container.connect(abs_error_sqr) divide = dpf.operators.math.component_wise_divide() divide.inputs.fieldA.connect(stress_ref_nodal_op - fex_nodal_op) divide.inputs.fieldB.connect(stress_ref_nodal_op) rel_error = dpf.operators.math.scale() rel_error.inputs.field.connect(divide) rel_error.inputs.ponderation.connect(1.0) .. GENERATED FROM PYTHON SOURCE LINES 162-168 Plot absolute and relative errors. The absolute value is the order of 10, which is very small when compared to the magnitude of 1e8 of the displacements. This is reflected in the relative error plot, where the errors are found to be below 1.02e-6%. The result of these plots can be used to set the tolerances for the :class:`identical_fc ` operator. .. GENERATED FROM PYTHON SOURCE LINES 168-170 .. code-block:: Python mesh.plot(abs_error.eval(), scalar_bar_args={"title": "Absolute error [mm]"}) mesh.plot(rel_error.eval(), scalar_bar_args={"title": "Relative error [%]"}) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/04-advanced/images/sphx_glr_04-extrapolation_stress_3d_004.png :alt: 04 extrapolation stress 3d :srcset: /examples/04-advanced/images/sphx_glr_04-extrapolation_stress_3d_004.png :class: sphx-glr-multi-img * .. image-sg:: /examples/04-advanced/images/sphx_glr_04-extrapolation_stress_3d_005.png :alt: 04 extrapolation stress 3d :srcset: /examples/04-advanced/images/sphx_glr_04-extrapolation_stress_3d_005.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 8.146 seconds) .. _sphx_glr_download_examples_04-advanced_04-extrapolation_stress_3d.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 04-extrapolation_stress_3d.ipynb <04-extrapolation_stress_3d.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 04-extrapolation_stress_3d.py <04-extrapolation_stress_3d.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_