.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\04-advanced\05-extrapolation_strain_2d.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_05-extrapolation_strain_2d.py: .. _extrapolation_test_strain_2Delement: Extrapolation method for strain result of a 2D element ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This example shows how to compute the stress nodal components from Gaussian points (integration points) for a 2D 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 elastic strain. #. Get the result for nodal elastic strain from the data source. The analysis was computed by MAPDL. #. Compare the result for nodal elastic strain from the data source and the nodal elastic strain 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 analyse of integration points and data source's analyse reference .. GENERATED FROM PYTHON SOURCE LINES 41-55 .. code-block:: Python datafile = examples.download_extrapolation_2d_result() # integration points (Gaussian points) data_integration_points = datafile["file_integrated"] data_sources_integration_points = dpf.DataSources(data_integration_points) # 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 .. GENERATED FROM PYTHON SOURCE LINES 56-60 Extrapolate from integration points for elastic strain result ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This example uses the ``gauss_to_node_fc`` operator to compute nodal component elastic strain results from the elastic strain at the integration points. .. GENERATED FROM PYTHON SOURCE LINES 60-66 .. code-block:: Python # Create elastic strain operator to get strain result of integration points strainop = dpf.operators.result.elastic_strain() strainop.inputs.data_sources.connect(data_sources_integration_points) strain = strainop.outputs.fields_container() .. GENERATED FROM PYTHON SOURCE LINES 67-78 Nodal elastic strain result of integration points: ############################################################################## The command ``ERESX,NO`` in MAPDL is used to copy directly the Gaussian (integration) points results to the nodes, instead of the results at nodes or elements (which are an interpolation of results at a few Gaussian points). The following plot shows the nodal values that are the averaged values of elastic strain at each node. The value shown at the node is the average of the elastic strains from the Gaussian points of each element that it belongs to. .. GENERATED FROM PYTHON SOURCE LINES 78-84 .. code-block:: Python # plot strain_nodal_op = dpf.operators.averaging.elemental_nodal_to_nodal_fc() strain_nodal_op.inputs.fields_container.connect(strain) mesh.plot(strain_nodal_op.outputs.fields_container()) .. image-sg:: /examples/04-advanced/images/sphx_glr_05-extrapolation_strain_2d_001.png :alt: 05 extrapolation strain 2d :srcset: /examples/04-advanced/images/sphx_glr_05-extrapolation_strain_2d_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 85-87 Create the ``gauss_to_node_fc`` operator and compute nodal component elastic strain by applying the extrapolation method. .. GENERATED FROM PYTHON SOURCE LINES 87-96 .. code-block:: Python ex_strain = dpf.operators.averaging.gauss_to_node_fc() # connect mesh ex_strain.inputs.mesh.connect(mesh) # connect fields container elastic strain ex_strain.inputs.fields_container.connect(strain) # get output fex = ex_strain.outputs.fields_container() .. GENERATED FROM PYTHON SOURCE LINES 97-99 Elastic strain result of reference Ansys Workbench ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 99-105 .. code-block:: Python # Strain from file dataSourceref strainop_ref = dpf.operators.result.elastic_strain() strainop_ref.inputs.data_sources.connect(data_sources_ref) strain_ref = strainop_ref.outputs.fields_container() .. GENERATED FROM PYTHON SOURCE LINES 106-109 Plot ~~~~ Show plots of extrapolation's elastic strain result and reference's elastic strain result .. GENERATED FROM PYTHON SOURCE LINES 109-119 .. code-block:: Python # extrapolation fex_nodal_op = dpf.operators.averaging.elemental_nodal_to_nodal_fc() fex_nodal_op.inputs.fields_container.connect(fex) mesh.plot(fex_nodal_op.outputs.fields_container()) # reference strain_ref_nodal_op = dpf.operators.averaging.elemental_nodal_to_nodal_fc() strain_ref_nodal_op.inputs.fields_container.connect(strain_ref) mesh.plot(strain_ref_nodal_op.outputs.fields_container()) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/04-advanced/images/sphx_glr_05-extrapolation_strain_2d_002.png :alt: 05 extrapolation strain 2d :srcset: /examples/04-advanced/images/sphx_glr_05-extrapolation_strain_2d_002.png :class: sphx-glr-multi-img * .. image-sg:: /examples/04-advanced/images/sphx_glr_05-extrapolation_strain_2d_003.png :alt: 05 extrapolation strain 2d :srcset: /examples/04-advanced/images/sphx_glr_05-extrapolation_strain_2d_003.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 120-127 Comparison ~~~~~~~~~~~~ Compare the elastic strain result computed by extrapolation and reference's result. Check if the two fields containers are identical. The relative tolerance is set to 1e-14. The smallest value that is to be considered during the comparison step : all the ``abs(values)`` in the field less than 1e-2 are considered null. .. GENERATED FROM PYTHON SOURCE LINES 127-136 .. 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(strain_ref_nodal_op) op.inputs.tolerance.connect(1.0e-14) op.inputs.small_value.connect(0.01) print(op.outputs.boolean()) .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 137-138 Compute absolute and relative errors .. GENERATED FROM PYTHON SOURCE LINES 138-151 .. code-block:: Python abs_error_sqr = dpf.operators.math.sqr_fc() abs_error = dpf.operators.math.sqrt_fc() error = strain_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(strain_ref_nodal_op - fex_nodal_op) divide.inputs.fieldB.connect(strain_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 152-158 Plot absolute and relative errors. The absolute value is the order of 1e-13, which is very small when compared to the magnitude of 1e-5 of the displacements. This is reflected in the relative error plot, where the errors are found to be below 1.1e-5%. The result of these plots can be used to set the tolerances for the :class:`identical_fc ` operator. .. GENERATED FROM PYTHON SOURCE LINES 158-160 .. 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_05-extrapolation_strain_2d_004.png :alt: 05 extrapolation strain 2d :srcset: /examples/04-advanced/images/sphx_glr_05-extrapolation_strain_2d_004.png :class: sphx-glr-multi-img * .. image-sg:: /examples/04-advanced/images/sphx_glr_05-extrapolation_strain_2d_005.png :alt: 05 extrapolation strain 2d :srcset: /examples/04-advanced/images/sphx_glr_05-extrapolation_strain_2d_005.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 8.193 seconds) .. _sphx_glr_download_examples_04-advanced_05-extrapolation_strain_2d.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 05-extrapolation_strain_2d.ipynb <05-extrapolation_strain_2d.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 05-extrapolation_strain_2d.py <05-extrapolation_strain_2d.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_