.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\13-streamlines\00_plot_3d_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_00_plot_3d_streamlines.py: .. _plot_3d_streamlines: Compute and plot 3D streamlines ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This example shows you how to compute and plot streamlines of fluid simulation results, for 3D 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 39-41 Compute and plot streamlines from single source ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 43-46 Import modules, create the data sources and the model ----------------------------------------------------- Import modules: .. GENERATED FROM PYTHON SOURCE LINES 46-52 .. 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 53-54 Create data sources for fluids simulation result: .. GENERATED FROM PYTHON SOURCE LINES 54-59 .. code-block:: Python fluent_files = examples.download_fluent_mixing_elbow_steady_state() ds_fluent = dpf.DataSources() ds_fluent.set_result_file_path(fluent_files["cas"][0], "cas") ds_fluent.add_file_path(fluent_files["dat"][1], "dat") .. GENERATED FROM PYTHON SOURCE LINES 60-61 Create model from fluid simulation result data sources: .. GENERATED FROM PYTHON SOURCE LINES 61-63 .. code-block:: Python m_fluent = dpf.Model(ds_fluent) .. GENERATED FROM PYTHON SOURCE LINES 64-68 Get meshed region and velocity data ----------------------------------- Meshed region is used as 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 70-71 Get the meshed region: .. GENERATED FROM PYTHON SOURCE LINES 71-73 .. code-block:: Python meshed_region = m_fluent.metadata.meshed_region .. GENERATED FROM PYTHON SOURCE LINES 74-75 Get the velocity result at nodes: .. GENERATED FROM PYTHON SOURCE LINES 75-79 .. 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 80-84 Compute and plot the streamlines adjusting the request ------------------------------------------------------ The following steps show you how to create streamlines using DpfPlotter, with several sets of parameters. It demonstrates the issues that can happen and the adjustments that you can make. .. GENERATED FROM PYTHON SOURCE LINES 86-93 First, Streamlines and StreamlinesSource objects are created. The StreamlinesSource is available using the 'return_source' argument. Then, you can correctly set the source coordinates using the "source_center" argument that moves the source center, and "permissive" option that allows you to display the source even, if the computed streamline size is zero. Default value for "permissive" argument is True. If permissive is set to False, the "add_streamlines" method throws. .. GENERATED FROM PYTHON SOURCE LINES 93-108 .. code-block:: Python streamline_obj, source_obj = compute_streamlines( meshed_region=meshed_region, field=field, return_source=True, source_center=(0.1, 0.1, 0.2), ) pl1 = DpfPlotter() pl1.add_mesh(meshed_region=meshed_region, opacity=0.3) pl1.add_streamlines( streamlines=streamline_obj, source=source_obj, permissive=True, ) pl1.show_figure(show_axes=True) .. image-sg:: /examples/13-streamlines/images/sphx_glr_00_plot_3d_streamlines_001.png :alt: 00 plot 3d streamlines :srcset: /examples/13-streamlines/images/sphx_glr_00_plot_3d_streamlines_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 109-119 After the adjustment, the correct values for the "source_center" argument are set. You can remove the "permissive" option. You can display velocity data with a small opacity value to avoid hiding the streamlines. More settings are added to adapt the streamlines creation to the geometry and the data of the model: - radius: streamlines radius - n_points: source number of points - source_radius - max_time: maximum integration time of the streamline. It controls the streamline length. .. GENERATED FROM PYTHON SOURCE LINES 119-137 .. code-block:: Python streamline_obj, source_obj = compute_streamlines( meshed_region=meshed_region, field=field, return_source=True, source_center=(0.56, 0.48, 0.0), n_points=10, source_radius=0.075, max_time=10.0, ) pl2 = DpfPlotter() pl2.add_field(field, meshed_region, opacity=0.2) pl2.add_streamlines( streamlines=streamline_obj, source=source_obj, radius=0.001, ) pl2.show_figure(show_axes=True) .. image-sg:: /examples/13-streamlines/images/sphx_glr_00_plot_3d_streamlines_002.png :alt: 00 plot 3d streamlines :srcset: /examples/13-streamlines/images/sphx_glr_00_plot_3d_streamlines_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 138-140 Compute and plot streamlines from several sources ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 142-145 Get data to plot ---------------- Create data sources for fluid simulation result: .. GENERATED FROM PYTHON SOURCE LINES 145-151 .. code-block:: Python files_cfx = examples.download_cfx_heating_coil() ds_cfx = dpf.DataSources() ds_cfx.set_result_file_path(files_cfx["cas"], "cas") ds_cfx.add_file_path(files_cfx["dat"], "dat") .. GENERATED FROM PYTHON SOURCE LINES 152-153 Create model from fluid simulation result data sources: .. GENERATED FROM PYTHON SOURCE LINES 153-155 .. code-block:: Python m_cfx = dpf.Model(ds_cfx) .. GENERATED FROM PYTHON SOURCE LINES 156-157 Get meshed region and velocity data .. GENERATED FROM PYTHON SOURCE LINES 157-161 .. code-block:: Python meshed_region = m_cfx.metadata.meshed_region velocity_op = m_cfx.results.velocity() field = velocity_op.outputs.fields_container()[0] .. GENERATED FROM PYTHON SOURCE LINES 162-164 Compute streamlines from different sources ------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 166-167 Compute streamlines from different sources: .. GENERATED FROM PYTHON SOURCE LINES 167-196 .. code-block:: Python streamline_1, source_1 = compute_streamlines( meshed_region=meshed_region, field=field, return_source=True, source_radius=0.25, source_center=(0.75, 0.0, 0.0), ) streamline_2, source_2 = compute_streamlines( meshed_region=meshed_region, field=field, return_source=True, source_radius=0.25, source_center=(0.0, 0.75, 0.0), ) streamline_3, source_3 = compute_streamlines( meshed_region=meshed_region, field=field, return_source=True, source_radius=0.25, source_center=(-0.75, 0.0, 0.0), ) streamline_4, source_4 = compute_streamlines( meshed_region=meshed_region, field=field, return_source=True, source_radius=0.25, source_center=(0.0, -0.75, 0.0), ) .. GENERATED FROM PYTHON SOURCE LINES 197-199 Plot streamlines from different sources --------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 199-223 .. code-block:: Python pl = DpfPlotter() pl.add_field(field, meshed_region, opacity=0.2) pl.add_streamlines( streamlines=streamline_1, source=source_1, radius=0.007, ) pl.add_streamlines( streamlines=streamline_2, source=source_2, radius=0.007, ) pl.add_streamlines( streamlines=streamline_3, source=source_3, radius=0.007, ) pl.add_streamlines( streamlines=streamline_4, source=source_4, radius=0.007, ) pl.show_figure(show_axes=True) .. image-sg:: /examples/13-streamlines/images/sphx_glr_00_plot_3d_streamlines_003.png :alt: 00 plot 3d streamlines :srcset: /examples/13-streamlines/images/sphx_glr_00_plot_3d_streamlines_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 11.885 seconds) .. _sphx_glr_download_examples_13-streamlines_00_plot_3d_streamlines.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 00_plot_3d_streamlines.ipynb <00_plot_3d_streamlines.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 00_plot_3d_streamlines.py <00_plot_3d_streamlines.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 00_plot_3d_streamlines.zip <00_plot_3d_streamlines.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_