.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\06-plotting\04-plot_on_path.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_06-plotting_04-plot_on_path.py: .. _plot_on_path: Plot results on a specific path ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This example shows how to get a result mapped over a specific path and how to plot it. .. GENERATED FROM PYTHON SOURCE LINES 12-21 .. code-block:: Python import matplotlib.pyplot as plt from ansys.dpf import core as dpf from ansys.dpf.core import examples from ansys.dpf.core import operators as ops from ansys.dpf.core.plotter import DpfPlotter .. GENERATED FROM PYTHON SOURCE LINES 22-26 Plot path ~~~~~~~~~ Use the :class:`ansys.dpf.core.plotter.DpfPlotter` class to plot a mapped result over a defined path of coordinates. .. GENERATED FROM PYTHON SOURCE LINES 26-32 .. code-block:: Python # Create the model and request its mesh and displacement data. model = dpf.Model(examples.find_static_rst()) mesh = model.metadata.meshed_region stress_fc = model.results.stress().eqv().eval() .. GENERATED FROM PYTHON SOURCE LINES 33-34 Create a coordinates field to map on. .. GENERATED FROM PYTHON SOURCE LINES 34-45 .. code-block:: Python coordinates = [[0.024, 0.03, 0.003]] delta = 0.001 n_points = 51 for i in range(1, n_points): coord_copy = coordinates[0].copy() coord_copy[1] = coord_copy[0] + i * delta coordinates.append(coord_copy) field_coord = dpf.fields_factory.create_3d_vector_field(len(coordinates)) field_coord.data = coordinates field_coord.scoping.ids = list(range(1, len(coordinates) + 1)) .. GENERATED FROM PYTHON SOURCE LINES 46-47 Compute the mapped data using the mapping operator. .. GENERATED FROM PYTHON SOURCE LINES 47-52 .. code-block:: Python mapping_operator = ops.mapping.on_coordinates( fields_container=stress_fc, coordinates=field_coord, create_support=True, mesh=mesh ) fields_mapped = mapping_operator.outputs.fields_container() .. GENERATED FROM PYTHON SOURCE LINES 53-54 Request the mapped field data and its mesh. .. GENERATED FROM PYTHON SOURCE LINES 54-57 .. code-block:: Python field_m = fields_mapped[0] mesh_m = field_m.meshed_region .. GENERATED FROM PYTHON SOURCE LINES 58-59 Create the plotter and add fields and meshes. .. GENERATED FROM PYTHON SOURCE LINES 59-67 .. code-block:: Python pl = DpfPlotter() pl.add_field(field_m, mesh_m) pl.add_mesh(mesh, style="surface", show_edges=True, color="w", opacity=0.3) # Plot the result. pl.show_figure(show_axes=True) .. image-sg:: /examples/06-plotting/images/sphx_glr_04-plot_on_path_001.png :alt: 04 plot on path :srcset: /examples/06-plotting/images/sphx_glr_04-plot_on_path_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 68-70 Plot the solution along the specified line. Note that since the line is only moving along the y-axis, the stresses are plotted with respect to the y coordinate. .. GENERATED FROM PYTHON SOURCE LINES 70-75 .. code-block:: Python y_coords = [mesh_m.nodes.coordinates_field.data[i][1] for i in range(mesh_m.nodes.n_nodes)] plt.plot(y_coords, field_m.data, "r") plt.xlabel(f"y-coordinate [{mesh.unit}]") plt.ylabel(f"Stress [{field_m.unit}]") plt.show() .. image-sg:: /examples/06-plotting/images/sphx_glr_04-plot_on_path_002.png :alt: 04 plot on path :srcset: /examples/06-plotting/images/sphx_glr_04-plot_on_path_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.923 seconds) .. _sphx_glr_download_examples_06-plotting_04-plot_on_path.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 04-plot_on_path.ipynb <04-plot_on_path.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 04-plot_on_path.py <04-plot_on_path.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_