.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\13-streamlines\01_plot_surface_streamlines.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_13-streamlines_01_plot_surface_streamlines.py: .. _plot_surf_streamlines: Compute and plot 2D streamlines ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This example shows you how to compute and plot streamlines of fluid simulation results, for 2D models. .. note:: This example requires DPF 7.0 (ansys-dpf-server-2024-1-pre0) or above. For more information, see :ref:`ref_compatibility`. .. GENERATED FROM PYTHON SOURCE LINES 38-40 Plot surface streamlines ~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 42-45 Import modules, create the data sources and the model ----------------------------------------------------- Import modules: .. GENERATED FROM PYTHON SOURCE LINES 45-51 .. code-block:: Python from ansys.dpf import core as dpf from ansys.dpf.core import examples from ansys.dpf.core.helpers.streamlines import compute_streamlines from ansys.dpf.core.plotter import DpfPlotter .. GENERATED FROM PYTHON SOURCE LINES 52-53 Create data sources for fluids simulation result: .. GENERATED FROM PYTHON SOURCE LINES 53-58 .. code-block:: Python fluent_files = examples.download_fluent_multi_species() ds_fluent = dpf.DataSources() ds_fluent.set_result_file_path(fluent_files["cas"], "cas") ds_fluent.add_file_path(fluent_files["dat"], "dat") .. GENERATED FROM PYTHON SOURCE LINES 59-60 Create model from fluid simulation result data sources: .. GENERATED FROM PYTHON SOURCE LINES 60-62 .. code-block:: Python m_fluent = dpf.Model(ds_fluent) .. GENERATED FROM PYTHON SOURCE LINES 63-67 Get meshed region and velocity data ----------------------------------- Meshed region is used as the geometric base to compute the streamlines. Velocity data is used to compute the streamlines. The velocity data must be nodal. .. GENERATED FROM PYTHON SOURCE LINES 69-70 Get the meshed region: .. GENERATED FROM PYTHON SOURCE LINES 70-72 .. code-block:: Python meshed_region = m_fluent.metadata.meshed_region .. GENERATED FROM PYTHON SOURCE LINES 73-74 Get the velocity result at nodes: .. GENERATED FROM PYTHON SOURCE LINES 74-78 .. code-block:: Python velocity_op = m_fluent.results.velocity() fc = velocity_op.outputs.fields_container() field = dpf.operators.averaging.to_nodal_fc(fields_container=fc).outputs.fields_container()[0] .. GENERATED FROM PYTHON SOURCE LINES 79-81 Compute single streamline ------------------------- .. GENERATED FROM PYTHON SOURCE LINES 81-90 .. code-block:: Python single_2d_streamline, single_2d_source = compute_streamlines( meshed_region=meshed_region, field=field, start_position=(0.005, 0.0005, 0.0), surface_streamlines=True, return_source=True, ) .. GENERATED FROM PYTHON SOURCE LINES 91-93 Plot single streamline ---------------------- .. GENERATED FROM PYTHON SOURCE LINES 93-115 .. code-block:: Python pl_single = DpfPlotter() pl_single.add_field(field, meshed_region, opacity=0.2) pl_single.add_streamlines( streamlines=single_2d_streamline, source=single_2d_source, radius=0.00002, ) # Use the PyVista 'cpos' optional argument to control the camera position. # To easily save a camera position, plot the figure a first time with the argument # 'return_cpos=True'. This will make the ``DpfPlotter.show_figure`` function return # the camera position at the time the PyVista interactive plotting window is closed. # You can also define a plane to use for the camera with 'cpos="xy"'. # In this case the camera will fit the entire model in the window. # Starting from a returned 'cpos', you can build a custom camera position, such as: cpos = [ (0.005, 0.0004, 0.015), # Camera position (X, Y, Z) (0.005, 0.0004, 0.0), # Target point (X, Y, Z) (0.0, 1.0, 0.0), # Upward direction (+y) ] return_cpos = pl_single.show_figure(return_cpos=True, cpos=cpos, show_axes=True) print(return_cpos) .. image-sg:: /examples/13-streamlines/images/sphx_glr_01_plot_surface_streamlines_001.png :alt: 01 plot surface streamlines :srcset: /examples/13-streamlines/images/sphx_glr_01_plot_surface_streamlines_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [(0.005, 0.0004, 0.015), (0.005, 0.0004, 0.0), (0.0, 1.0, 0.0)] .. GENERATED FROM PYTHON SOURCE LINES 116-118 Compute multiple streamlines ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 118-129 .. code-block:: Python multiple_2d_streamlines, multiple_2d_source = compute_streamlines( meshed_region=meshed_region, field=field, pointa=(0.005, 0.0001, 0.0), pointb=(0.005, 0.001, 0.0), n_points=10, surface_streamlines=True, return_source=True, ) .. GENERATED FROM PYTHON SOURCE LINES 130-132 Plot multiple streamlines ------------------------- .. GENERATED FROM PYTHON SOURCE LINES 132-141 .. code-block:: Python pl_multiple = DpfPlotter() pl_multiple.add_field(field, meshed_region, opacity=0.2) pl_multiple.add_streamlines( streamlines=multiple_2d_streamlines, source=multiple_2d_source, radius=0.000015, ) pl_multiple.show_figure(cpos=cpos, show_axes=True) .. image-sg:: /examples/13-streamlines/images/sphx_glr_01_plot_surface_streamlines_002.png :alt: 01 plot surface streamlines :srcset: /examples/13-streamlines/images/sphx_glr_01_plot_surface_streamlines_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.537 seconds) .. _sphx_glr_download_examples_13-streamlines_01_plot_surface_streamlines.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01_plot_surface_streamlines.ipynb <01_plot_surface_streamlines.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01_plot_surface_streamlines.py <01_plot_surface_streamlines.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 01_plot_surface_streamlines.zip <01_plot_surface_streamlines.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_